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>
32 #include "interface.h"
33 #include "addrtoname.h"
34 #include "ethertype.h"
41 /* Lengths of 802.11 header components. */
42 #define IEEE802_11_FC_LEN 2
43 #define IEEE802_11_DUR_LEN 2
44 #define IEEE802_11_DA_LEN 6
45 #define IEEE802_11_SA_LEN 6
46 #define IEEE802_11_BSSID_LEN 6
47 #define IEEE802_11_RA_LEN 6
48 #define IEEE802_11_TA_LEN 6
49 #define IEEE802_11_SEQ_LEN 2
50 #define IEEE802_11_CTL_LEN 2
51 #define IEEE802_11_IV_LEN 3
52 #define IEEE802_11_KID_LEN 1
54 /* Frame check sequence length. */
55 #define IEEE802_11_FCS_LEN 4
57 /* Lengths of beacon components. */
58 #define IEEE802_11_TSTAMP_LEN 8
59 #define IEEE802_11_BCNINT_LEN 2
60 #define IEEE802_11_CAPINFO_LEN 2
61 #define IEEE802_11_LISTENINT_LEN 2
63 #define IEEE802_11_AID_LEN 2
64 #define IEEE802_11_STATUS_LEN 2
65 #define IEEE802_11_REASON_LEN 2
67 /* Length of previous AP in reassocation frame */
68 #define IEEE802_11_AP_LEN 6
70 #define T_MGMT 0x0 /* management */
71 #define T_CTRL 0x1 /* control */
72 #define T_DATA 0x2 /* data */
73 #define T_RESV 0x3 /* reserved */
75 #define ST_ASSOC_REQUEST 0x0
76 #define ST_ASSOC_RESPONSE 0x1
77 #define ST_REASSOC_REQUEST 0x2
78 #define ST_REASSOC_RESPONSE 0x3
79 #define ST_PROBE_REQUEST 0x4
80 #define ST_PROBE_RESPONSE 0x5
85 #define ST_DISASSOC 0xA
93 #define CTRL_CONTROL_WRAPPER 0x7
96 #define CTRL_PS_POLL 0xA
100 #define CTRL_CF_END 0xE
101 #define CTRL_END_ACK 0xF
103 #define DATA_DATA 0x0
104 #define DATA_DATA_CF_ACK 0x1
105 #define DATA_DATA_CF_POLL 0x2
106 #define DATA_DATA_CF_ACK_POLL 0x3
107 #define DATA_NODATA 0x4
108 #define DATA_NODATA_CF_ACK 0x5
109 #define DATA_NODATA_CF_POLL 0x6
110 #define DATA_NODATA_CF_ACK_POLL 0x7
112 #define DATA_QOS_DATA 0x8
113 #define DATA_QOS_DATA_CF_ACK 0x9
114 #define DATA_QOS_DATA_CF_POLL 0xA
115 #define DATA_QOS_DATA_CF_ACK_POLL 0xB
116 #define DATA_QOS_NODATA 0xC
117 #define DATA_QOS_CF_POLL_NODATA 0xE
118 #define DATA_QOS_CF_ACK_POLL_NODATA 0xF
121 * The subtype field of a data frame is, in effect, composed of 4 flag
122 * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
123 * any data), and QoS.
125 #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01)
126 #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02)
127 #define DATA_FRAME_IS_NULL(x) ((x) & 0x04)
128 #define DATA_FRAME_IS_QOS(x) ((x) & 0x08)
131 * Bits in the frame control field.
133 #define FC_VERSION(fc) ((fc) & 0x3)
134 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
135 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
136 #define FC_TO_DS(fc) ((fc) & 0x0100)
137 #define FC_FROM_DS(fc) ((fc) & 0x0200)
138 #define FC_MORE_FLAG(fc) ((fc) & 0x0400)
139 #define FC_RETRY(fc) ((fc) & 0x0800)
140 #define FC_POWER_MGMT(fc) ((fc) & 0x1000)
141 #define FC_MORE_DATA(fc) ((fc) & 0x2000)
142 #define FC_WEP(fc) ((fc) & 0x4000)
143 #define FC_ORDER(fc) ((fc) & 0x8000)
145 struct mgmt_header_t
{
154 #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
155 IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
156 IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
158 #define CAPABILITY_ESS(cap) ((cap) & 0x0001)
159 #define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
160 #define CAPABILITY_CFP(cap) ((cap) & 0x0004)
161 #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
162 #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
167 u_char ssid
[33]; /* 32 + 1 for null */
179 u_int8_t text
[254]; /* 1-253 + 1 for null */
185 u_int16_t dwell_time
;
187 u_int8_t hop_pattern
;
202 u_int16_t max_duration
;
203 u_int16_t dur_remaing
;
211 u_int8_t bitmap_control
;
212 u_int8_t bitmap
[251];
233 #define E_CHALLENGE 16
242 u_int8_t timestamp
[IEEE802_11_TSTAMP_LEN
];
243 u_int16_t beacon_interval
;
244 u_int16_t listen_interval
;
245 u_int16_t status_code
;
247 u_char ap
[IEEE802_11_AP_LEN
];
248 u_int16_t reason_code
;
250 u_int16_t auth_trans_seq_num
;
251 int challenge_present
;
252 struct challenge_t challenge
;
253 u_int16_t capability_info
;
257 struct rates_t rates
;
276 #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
277 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
286 #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
295 #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
297 struct ctrl_ps_poll_t
{
305 #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
306 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
316 #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
317 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
319 struct ctrl_end_ack_t
{
327 #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
328 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
337 #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
349 #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
350 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
351 IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
362 #define IV_IV(iv) ((iv) & 0xFFFFFF)
363 #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
364 #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
366 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
367 /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
370 * Copyright (c) 2003, 2004 David Young. All rights reserved.
372 * Redistribution and use in source and binary forms, with or without
373 * modification, are permitted provided that the following conditions
375 * 1. Redistributions of source code must retain the above copyright
376 * notice, this list of conditions and the following disclaimer.
377 * 2. Redistributions in binary form must reproduce the above copyright
378 * notice, this list of conditions and the following disclaimer in the
379 * documentation and/or other materials provided with the distribution.
380 * 3. The name of David Young may not be used to endorse or promote
381 * products derived from this software without specific prior
382 * written permission.
384 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
385 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
386 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
387 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
388 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
389 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
390 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
391 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
392 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
393 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
394 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
398 /* A generic radio capture format is desirable. It must be
399 * rigidly defined (e.g., units for fields should be given),
400 * and easily extensible.
402 * The following is an extensible radio capture format. It is
403 * based on a bitmap indicating which fields are present.
405 * I am trying to describe precisely what the application programmer
406 * should expect in the following, and for that reason I tell the
407 * units and origin of each measurement (where it applies), or else I
408 * use sufficiently weaselly language ("is a monotonically nondecreasing
409 * function of...") that I cannot set false expectations for lawyerly
414 * The radio capture header precedes the 802.11 header.
416 * Note well: all radiotap fields are little-endian.
418 struct ieee80211_radiotap_header
{
419 u_int8_t it_version
; /* Version 0. Only increases
420 * for drastic changes,
421 * introduction of compatible
422 * new fields does not count.
425 u_int16_t it_len
; /* length of the whole
426 * header in bytes, including
427 * it_version, it_pad,
428 * it_len, and data fields.
430 u_int32_t it_present
; /* A bitmap telling which
431 * fields are present. Set bit 31
432 * (0x80000000) to extend the
433 * bitmap by another 32 bits.
434 * Additional extensions are made
439 /* Name Data type Units
440 * ---- --------- -----
442 * IEEE80211_RADIOTAP_TSFT u_int64_t microseconds
444 * Value in microseconds of the MAC's 64-bit 802.11 Time
445 * Synchronization Function timer when the first bit of the
446 * MPDU arrived at the MAC. For received frames, only.
448 * IEEE80211_RADIOTAP_CHANNEL 2 x u_int16_t MHz, bitmap
450 * Tx/Rx frequency in MHz, followed by flags (see below).
451 * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
452 * represent an HT channel as there is not enough room in
455 * IEEE80211_RADIOTAP_FHSS u_int16_t see below
457 * For frequency-hopping radios, the hop set (first byte)
458 * and pattern (second byte).
460 * IEEE80211_RADIOTAP_RATE u_int8_t 500kb/s or index
462 * Tx/Rx data rate. If bit 0x80 is set then it represents an
463 * an MCS index and not an IEEE rate.
465 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
466 * one milliwatt (dBm)
468 * RF signal power at the antenna, decibel difference from
471 * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
472 * one milliwatt (dBm)
474 * RF noise power at the antenna, decibel difference from one
477 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u_int8_t decibel (dB)
479 * RF signal power at the antenna, decibel difference from an
480 * arbitrary, fixed reference.
482 * IEEE80211_RADIOTAP_DB_ANTNOISE u_int8_t decibel (dB)
484 * RF noise power at the antenna, decibel difference from an
485 * arbitrary, fixed reference point.
487 * IEEE80211_RADIOTAP_LOCK_QUALITY u_int16_t unitless
489 * Quality of Barker code lock. Unitless. Monotonically
490 * nondecreasing with "better" lock strength. Called "Signal
491 * Quality" in datasheets. (Is there a standard way to measure
494 * IEEE80211_RADIOTAP_TX_ATTENUATION u_int16_t unitless
496 * Transmit power expressed as unitless distance from max
497 * power set at factory calibration. 0 is max power.
498 * Monotonically nondecreasing with lower power levels.
500 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION u_int16_t decibels (dB)
502 * Transmit power expressed as decibel distance from max power
503 * set at factory calibration. 0 is max power. Monotonically
504 * nondecreasing with lower power levels.
506 * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
507 * one milliwatt (dBm)
509 * Transmit power expressed as dBm (decibels from a 1 milliwatt
510 * reference). This is the absolute power level measured at
513 * IEEE80211_RADIOTAP_FLAGS u_int8_t bitmap
515 * Properties of transmitted and received frames. See flags
518 * IEEE80211_RADIOTAP_ANTENNA u_int8_t antenna index
520 * Unitless indication of the Rx/Tx antenna for this packet.
521 * The first antenna is antenna 0.
523 * IEEE80211_RADIOTAP_RX_FLAGS u_int16_t bitmap
525 * Properties of received frames. See flags defined below.
527 * IEEE80211_RADIOTAP_XCHANNEL u_int32_t bitmap
529 * u_int8_t channel number
532 * Extended channel specification: flags (see below) followed by
533 * frequency in MHz, the corresponding IEEE channel number, and
534 * finally the maximum regulatory transmit power cap in .5 dBm
535 * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
536 * and only one of the two should be present.
538 * IEEE80211_RADIOTAP_MCS u_int8_t known
542 * Bitset indicating which fields have known values, followed
543 * by bitset of flag values, followed by the MCS rate index as
546 * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
551 * The Vendor Namespace Field contains three sub-fields. The first
552 * sub-field is 3 bytes long. It contains the vendor's IEEE 802
553 * Organizationally Unique Identifier (OUI). The fourth byte is a
554 * vendor-specific "namespace selector."
557 enum ieee80211_radiotap_type
{
558 IEEE80211_RADIOTAP_TSFT
= 0,
559 IEEE80211_RADIOTAP_FLAGS
= 1,
560 IEEE80211_RADIOTAP_RATE
= 2,
561 IEEE80211_RADIOTAP_CHANNEL
= 3,
562 IEEE80211_RADIOTAP_FHSS
= 4,
563 IEEE80211_RADIOTAP_DBM_ANTSIGNAL
= 5,
564 IEEE80211_RADIOTAP_DBM_ANTNOISE
= 6,
565 IEEE80211_RADIOTAP_LOCK_QUALITY
= 7,
566 IEEE80211_RADIOTAP_TX_ATTENUATION
= 8,
567 IEEE80211_RADIOTAP_DB_TX_ATTENUATION
= 9,
568 IEEE80211_RADIOTAP_DBM_TX_POWER
= 10,
569 IEEE80211_RADIOTAP_ANTENNA
= 11,
570 IEEE80211_RADIOTAP_DB_ANTSIGNAL
= 12,
571 IEEE80211_RADIOTAP_DB_ANTNOISE
= 13,
572 IEEE80211_RADIOTAP_RX_FLAGS
= 14,
573 /* NB: gap for netbsd definitions */
574 IEEE80211_RADIOTAP_XCHANNEL
= 18,
575 IEEE80211_RADIOTAP_MCS
= 19,
576 IEEE80211_RADIOTAP_NAMESPACE
= 29,
577 IEEE80211_RADIOTAP_VENDOR_NAMESPACE
= 30,
578 IEEE80211_RADIOTAP_EXT
= 31
581 /* channel attributes */
582 #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
583 #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
584 #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
585 #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
586 #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
587 #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
588 #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
589 #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
590 #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
591 #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
592 #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
593 #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
594 #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
595 #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
596 #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
598 /* Useful combinations of channel characteristics, borrowed from Ethereal */
599 #define IEEE80211_CHAN_A \
600 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
601 #define IEEE80211_CHAN_B \
602 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
603 #define IEEE80211_CHAN_G \
604 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
605 #define IEEE80211_CHAN_TA \
606 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
607 #define IEEE80211_CHAN_TG \
608 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
611 /* For IEEE80211_RADIOTAP_FLAGS */
612 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
615 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
619 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
620 * with WEP encryption
622 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
625 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
626 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
627 * 802.11 header and payload
628 * (to 32-bit boundary)
630 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
632 /* For IEEE80211_RADIOTAP_RX_FLAGS */
633 #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
634 #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
636 /* For IEEE80211_RADIOTAP_MCS known */
637 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
638 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
639 #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
640 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
641 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
642 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
644 /* For IEEE80211_RADIOTAP_MCS flags */
645 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
646 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
647 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
648 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
649 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
650 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
651 #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
652 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
653 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
654 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
655 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
656 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
657 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
659 static const char tstr
[] = "[|802.11]";
662 /* This is used to save state when parsing/processing parameters */
663 struct radiotap_state
670 #define PRINT_SSID(p) \
671 if (p.ssid_present) { \
673 fn_print(p.ssid.ssid, NULL); \
677 #define PRINT_RATE(_sep, _r, _suf) \
678 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
679 #define PRINT_RATES(p) \
680 if (p.rates_present) { \
682 const char *sep = " ["; \
683 for (z = 0; z < p.rates.length ; z++) { \
684 PRINT_RATE(sep, p.rates.rate[z], \
685 (p.rates.rate[z] & 0x80 ? "*" : "")); \
688 if (p.rates.length != 0) \
692 #define PRINT_DS_CHANNEL(p) \
694 printf(" CH: %u", p.ds.channel); \
696 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "" );
698 #define MAX_MCS_INDEX 76
703 * the MCS index (0-76);
705 * 0 for 20 MHz, 1 for 40 MHz;
707 * 0 for a long guard interval, 1 for a short guard interval.
709 static const float ieee80211_float_htrates
[MAX_MCS_INDEX
+1][2][2] = {
711 { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, },
712 /* 40 Mhz */ { 13.5, /* SGI */ 15.0, },
716 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
717 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
721 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
722 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
726 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
727 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
731 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
732 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
736 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
737 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
741 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
742 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
746 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
747 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
751 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
752 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
756 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
757 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
761 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
762 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
766 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
767 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
771 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
772 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
776 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
777 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
781 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
782 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
786 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
787 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
791 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
792 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
796 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
797 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
801 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
802 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
806 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
807 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
811 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
812 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
816 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
817 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
821 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
822 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
826 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
827 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
831 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
832 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
836 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
837 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
841 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
842 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
846 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
847 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
851 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
852 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
856 { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, },
857 /* 40 Mhz */ { 432.0, /* SGI */ 480.0, },
861 { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, },
862 /* 40 Mhz */ { 486.0, /* SGI */ 540.0, },
866 { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, },
867 /* 40 Mhz */ { 540.0, /* SGI */ 600.0, },
871 { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */
872 /* 40 Mhz */ { 6.0, /* SGI */ 6.7, },
876 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
877 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
881 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
882 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
886 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
887 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
891 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
892 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
896 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
897 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
901 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
902 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
906 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
907 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
911 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
912 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
916 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
917 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
921 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
922 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
926 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
927 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
931 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
932 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
936 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
937 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
941 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
942 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
946 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
947 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
951 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
952 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
956 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
957 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
961 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
962 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
966 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
967 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
971 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
972 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
976 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
977 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
981 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
982 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
986 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
987 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
991 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
992 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
996 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
997 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
1001 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1002 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1006 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1007 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1011 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1012 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1016 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1017 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1021 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1022 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1026 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1027 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1031 { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, },
1032 /* 40 Mhz */ { 297.0, /* SGI */ 330.0, },
1036 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
1037 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
1041 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1042 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1046 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1047 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1051 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1052 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1056 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1057 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1061 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1062 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1066 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1067 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1071 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1072 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1076 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1077 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1081 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1082 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1086 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1087 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1091 { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, },
1092 /* 40 Mhz */ { 445.5, /* SGI */ 495.0, },
1096 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
1097 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
1099 static const char *status_text
[] = {
1100 "Successful", /* 0 */
1101 "Unspecified failure", /* 1 */
1110 "Cannot Support all requested capabilities in the Capability "
1111 "Information field", /* 10 */
1112 "Reassociation denied due to inability to confirm that association "
1114 "Association denied due to reason outside the scope of the "
1115 "standard", /* 12 */
1116 "Responding station does not support the specified authentication "
1117 "algorithm ", /* 13 */
1118 "Received an Authentication frame with authentication transaction "
1119 "sequence number out of expected sequence", /* 14 */
1120 "Authentication rejected because of challenge failure", /* 15 */
1121 "Authentication rejected due to timeout waiting for next frame in "
1122 "sequence", /* 16 */
1123 "Association denied because AP is unable to handle additional"
1124 "associated stations", /* 17 */
1125 "Association denied due to requesting station not supporting all of "
1126 "the data rates in BSSBasicRateSet parameter", /* 18 */
1127 "Association denied due to requesting station not supporting "
1128 "short preamble operation", /* 19 */
1129 "Association denied due to requesting station not supporting "
1130 "PBCC encoding", /* 20 */
1131 "Association denied due to requesting station not supporting "
1132 "channel agility", /* 21 */
1133 "Association request rejected because Spectrum Management "
1134 "capability is required", /* 22 */
1135 "Association request rejected because the information in the "
1136 "Power Capability element is unacceptable", /* 23 */
1137 "Association request rejected because the information in the "
1138 "Supported Channels element is unacceptable", /* 24 */
1139 "Association denied due to requesting station not supporting "
1140 "short slot operation", /* 25 */
1141 "Association denied due to requesting station not supporting "
1142 "DSSS-OFDM operation", /* 26 */
1143 "Association denied because the requested STA does not support HT "
1144 "features", /* 27 */
1145 "Reserved", /* 28 */
1146 "Association denied because the requested STA does not support "
1147 "the PCO transition time required by the AP", /* 29 */
1148 "Reserved", /* 30 */
1149 "Reserved", /* 31 */
1150 "Unspecified, QoS-related failure", /* 32 */
1151 "Association denied due to QAP having insufficient bandwidth "
1152 "to handle another QSTA", /* 33 */
1153 "Association denied due to excessive frame loss rates and/or "
1154 "poor conditions on current operating channel", /* 34 */
1155 "Association (with QBSS) denied due to requesting station not "
1156 "supporting the QoS facility", /* 35 */
1157 "Association denied due to requesting station not supporting "
1158 "Block Ack", /* 36 */
1159 "The request has been declined", /* 37 */
1160 "The request has not been successful as one or more parameters "
1161 "have invalid values", /* 38 */
1162 "The TS has not been created because the request cannot be honored. "
1163 "However, a suggested TSPEC is provided so that the initiating QSTA"
1164 "may attempt to set another TS with the suggested changes to the "
1166 "Invalid Information Element", /* 40 */
1167 "Group Cipher is not valid", /* 41 */
1168 "Pairwise Cipher is not valid", /* 42 */
1169 "AKMP is not valid", /* 43 */
1170 "Unsupported RSN IE version", /* 44 */
1171 "Invalid RSN IE Capabilities", /* 45 */
1172 "Cipher suite is rejected per security policy", /* 46 */
1173 "The TS has not been created. However, the HC may be capable of "
1174 "creating a TS, in response to a request, after the time indicated "
1175 "in the TS Delay element", /* 47 */
1176 "Direct Link is not allowed in the BSS by policy", /* 48 */
1177 "Destination STA is not present within this QBSS.", /* 49 */
1178 "The Destination STA is not a QSTA.", /* 50 */
1181 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
1183 static const char *reason_text
[] = {
1185 "Unspecified reason", /* 1 */
1186 "Previous authentication no longer valid", /* 2 */
1187 "Deauthenticated because sending station is leaving (or has left) "
1188 "IBSS or ESS", /* 3 */
1189 "Disassociated due to inactivity", /* 4 */
1190 "Disassociated because AP is unable to handle all currently "
1191 " associated stations", /* 5 */
1192 "Class 2 frame received from nonauthenticated station", /* 6 */
1193 "Class 3 frame received from nonassociated station", /* 7 */
1194 "Disassociated because sending station is leaving "
1195 "(or has left) BSS", /* 8 */
1196 "Station requesting (re)association is not authenticated with "
1197 "responding station", /* 9 */
1198 "Disassociated because the information in the Power Capability "
1199 "element is unacceptable", /* 10 */
1200 "Disassociated because the information in the SupportedChannels "
1201 "element is unacceptable", /* 11 */
1202 "Invalid Information Element", /* 12 */
1203 "Reserved", /* 13 */
1204 "Michael MIC failure", /* 14 */
1205 "4-Way Handshake timeout", /* 15 */
1206 "Group key update timeout", /* 16 */
1207 "Information element in 4-Way Handshake different from (Re)Association"
1208 "Request/Probe Response/Beacon", /* 17 */
1209 "Group Cipher is not valid", /* 18 */
1210 "AKMP is not valid", /* 20 */
1211 "Unsupported RSN IE version", /* 21 */
1212 "Invalid RSN IE Capabilities", /* 22 */
1213 "IEEE 802.1X Authentication failed", /* 23 */
1214 "Cipher suite is rejected per security policy", /* 24 */
1215 "Reserved", /* 25 */
1216 "Reserved", /* 26 */
1217 "Reserved", /* 27 */
1218 "Reserved", /* 28 */
1219 "Reserved", /* 29 */
1220 "Reserved", /* 30 */
1221 "TS deleted because QoS AP lacks sufficient bandwidth for this "
1222 "QoS STA due to a change in BSS service characteristics or "
1223 "operational mode (e.g. an HT BSS change from 40 MHz channel "
1224 "to 20 MHz channel)", /* 31 */
1225 "Disassociated for unspecified, QoS-related reason", /* 32 */
1226 "Disassociated because QoS AP lacks sufficient bandwidth for this "
1228 "Disassociated because of excessive number of frames that need to be "
1229 "acknowledged, but are not acknowledged for AP transmissions "
1230 "and/or poor channel conditions", /* 34 */
1231 "Disassociated because STA is transmitting outside the limits "
1232 "of its TXOPs", /* 35 */
1233 "Requested from peer STA as the STA is leaving the BSS "
1234 "(or resetting)", /* 36 */
1235 "Requested from peer STA as it does not want to use the "
1236 "mechanism", /* 37 */
1237 "Requested from peer STA as the STA received frames using the "
1238 "mechanism for which a set up is required", /* 38 */
1239 "Requested from peer STA due to time out", /* 39 */
1240 "Reserved", /* 40 */
1241 "Reserved", /* 41 */
1242 "Reserved", /* 42 */
1243 "Reserved", /* 43 */
1244 "Reserved", /* 44 */
1245 "Peer STA does not support the requested cipher suite", /* 45 */
1246 "Association denied due to requesting STA not supporting HT "
1247 "features", /* 46 */
1249 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
1252 wep_print(const u_char
*p
)
1256 if (!TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
1258 iv
= EXTRACT_LE_32BITS(p
);
1260 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
1267 parse_elements(struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
,
1272 struct challenge_t challenge
;
1273 struct rates_t rates
;
1279 * We haven't seen any elements yet.
1281 pbody
->challenge_present
= 0;
1282 pbody
->ssid_present
= 0;
1283 pbody
->rates_present
= 0;
1284 pbody
->ds_present
= 0;
1285 pbody
->cf_present
= 0;
1286 pbody
->tim_present
= 0;
1288 while (length
!= 0) {
1289 if (!TTEST2(*(p
+ offset
), 1))
1293 switch (*(p
+ offset
)) {
1295 if (!TTEST2(*(p
+ offset
), 2))
1299 memcpy(&ssid
, p
+ offset
, 2);
1302 if (ssid
.length
!= 0) {
1303 if (ssid
.length
> sizeof(ssid
.ssid
) - 1)
1305 if (!TTEST2(*(p
+ offset
), ssid
.length
))
1307 if (length
< ssid
.length
)
1309 memcpy(&ssid
.ssid
, p
+ offset
, ssid
.length
);
1310 offset
+= ssid
.length
;
1311 length
-= ssid
.length
;
1313 ssid
.ssid
[ssid
.length
] = '\0';
1315 * Present and not truncated.
1317 * If we haven't already seen an SSID IE,
1318 * copy this one, otherwise ignore this one,
1319 * so we later report the first one we saw.
1321 if (!pbody
->ssid_present
) {
1323 pbody
->ssid_present
= 1;
1327 if (!TTEST2(*(p
+ offset
), 2))
1331 memcpy(&challenge
, p
+ offset
, 2);
1334 if (challenge
.length
!= 0) {
1335 if (challenge
.length
>
1336 sizeof(challenge
.text
) - 1)
1338 if (!TTEST2(*(p
+ offset
), challenge
.length
))
1340 if (length
< challenge
.length
)
1342 memcpy(&challenge
.text
, p
+ offset
,
1344 offset
+= challenge
.length
;
1345 length
-= challenge
.length
;
1347 challenge
.text
[challenge
.length
] = '\0';
1349 * Present and not truncated.
1351 * If we haven't already seen a challenge IE,
1352 * copy this one, otherwise ignore this one,
1353 * so we later report the first one we saw.
1355 if (!pbody
->challenge_present
) {
1356 pbody
->challenge
= challenge
;
1357 pbody
->challenge_present
= 1;
1361 if (!TTEST2(*(p
+ offset
), 2))
1365 memcpy(&rates
, p
+ offset
, 2);
1368 if (rates
.length
!= 0) {
1369 if (rates
.length
> sizeof rates
.rate
)
1371 if (!TTEST2(*(p
+ offset
), rates
.length
))
1373 if (length
< rates
.length
)
1375 memcpy(&rates
.rate
, p
+ offset
, rates
.length
);
1376 offset
+= rates
.length
;
1377 length
-= rates
.length
;
1380 * Present and not truncated.
1382 * If we haven't already seen a rates IE,
1383 * copy this one if it's not zero-length,
1384 * otherwise ignore this one, so we later
1385 * report the first one we saw.
1387 * We ignore zero-length rates IEs as some
1388 * devices seem to put a zero-length rates
1389 * IE, followed by an SSID IE, followed by
1390 * a non-zero-length rates IE into frames,
1391 * even though IEEE Std 802.11-2007 doesn't
1392 * seem to indicate that a zero-length rates
1395 if (!pbody
->rates_present
&& rates
.length
!= 0) {
1396 pbody
->rates
= rates
;
1397 pbody
->rates_present
= 1;
1401 if (!TTEST2(*(p
+ offset
), 3))
1405 memcpy(&ds
, p
+ offset
, 3);
1409 * Present and not truncated.
1411 * If we haven't already seen a DS IE,
1412 * copy this one, otherwise ignore this one,
1413 * so we later report the first one we saw.
1415 if (!pbody
->ds_present
) {
1417 pbody
->ds_present
= 1;
1421 if (!TTEST2(*(p
+ offset
), 8))
1425 memcpy(&cf
, p
+ offset
, 8);
1429 * Present and not truncated.
1431 * If we haven't already seen a CF IE,
1432 * copy this one, otherwise ignore this one,
1433 * so we later report the first one we saw.
1435 if (!pbody
->cf_present
) {
1437 pbody
->cf_present
= 1;
1441 if (!TTEST2(*(p
+ offset
), 2))
1445 memcpy(&tim
, p
+ offset
, 2);
1448 if (!TTEST2(*(p
+ offset
), 3))
1452 memcpy(&tim
.count
, p
+ offset
, 3);
1456 if (tim
.length
<= 3)
1458 if (tim
.length
- 3 > (int)sizeof tim
.bitmap
)
1460 if (!TTEST2(*(p
+ offset
), tim
.length
- 3))
1462 if (length
< (u_int
)(tim
.length
- 3))
1464 memcpy(tim
.bitmap
, p
+ (tim
.length
- 3),
1466 offset
+= tim
.length
- 3;
1467 length
-= tim
.length
- 3;
1469 * Present and not truncated.
1471 * If we haven't already seen a TIM IE,
1472 * copy this one, otherwise ignore this one,
1473 * so we later report the first one we saw.
1475 if (!pbody
->tim_present
) {
1477 pbody
->tim_present
= 1;
1482 printf("(1) unhandled element_id (%d) ",
1485 if (!TTEST2(*(p
+ offset
), 2))
1489 elementlen
= *(p
+ offset
+ 1);
1490 if (!TTEST2(*(p
+ offset
+ 2), elementlen
))
1492 if (length
< elementlen
+ 2)
1494 offset
+= elementlen
+ 2;
1495 length
-= elementlen
+ 2;
1500 /* No problems found. */
1504 /*********************************************************************************
1505 * Print Handle functions for the management frame types
1506 *********************************************************************************/
1509 handle_beacon(const u_char
*p
, u_int length
)
1511 struct mgmt_body_t pbody
;
1515 memset(&pbody
, 0, sizeof(pbody
));
1517 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1518 IEEE802_11_CAPINFO_LEN
))
1520 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1521 IEEE802_11_CAPINFO_LEN
)
1523 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1524 offset
+= IEEE802_11_TSTAMP_LEN
;
1525 length
-= IEEE802_11_TSTAMP_LEN
;
1526 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1527 offset
+= IEEE802_11_BCNINT_LEN
;
1528 length
-= IEEE802_11_BCNINT_LEN
;
1529 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1530 offset
+= IEEE802_11_CAPINFO_LEN
;
1531 length
-= IEEE802_11_CAPINFO_LEN
;
1533 ret
= parse_elements(&pbody
, p
, offset
, length
);
1538 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS");
1539 PRINT_DS_CHANNEL(pbody
);
1545 handle_assoc_request(const u_char
*p
, u_int length
)
1547 struct mgmt_body_t pbody
;
1551 memset(&pbody
, 0, sizeof(pbody
));
1553 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
1555 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
)
1557 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1558 offset
+= IEEE802_11_CAPINFO_LEN
;
1559 length
-= IEEE802_11_CAPINFO_LEN
;
1560 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1561 offset
+= IEEE802_11_LISTENINT_LEN
;
1562 length
-= IEEE802_11_LISTENINT_LEN
;
1564 ret
= parse_elements(&pbody
, p
, offset
, length
);
1572 handle_assoc_response(const u_char
*p
, u_int length
)
1574 struct mgmt_body_t pbody
;
1578 memset(&pbody
, 0, sizeof(pbody
));
1580 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1581 IEEE802_11_AID_LEN
))
1583 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1586 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1587 offset
+= IEEE802_11_CAPINFO_LEN
;
1588 length
-= IEEE802_11_CAPINFO_LEN
;
1589 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
1590 offset
+= IEEE802_11_STATUS_LEN
;
1591 length
-= IEEE802_11_STATUS_LEN
;
1592 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
1593 offset
+= IEEE802_11_AID_LEN
;
1594 length
-= IEEE802_11_AID_LEN
;
1596 ret
= parse_elements(&pbody
, p
, offset
, length
);
1598 printf(" AID(%x) :%s: %s", ((u_int16_t
)(pbody
.aid
<< 2 )) >> 2 ,
1599 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
1600 (pbody
.status_code
< NUM_STATUSES
1601 ? status_text
[pbody
.status_code
]
1608 handle_reassoc_request(const u_char
*p
, u_int length
)
1610 struct mgmt_body_t pbody
;
1614 memset(&pbody
, 0, sizeof(pbody
));
1616 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1619 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1622 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1623 offset
+= IEEE802_11_CAPINFO_LEN
;
1624 length
-= IEEE802_11_CAPINFO_LEN
;
1625 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1626 offset
+= IEEE802_11_LISTENINT_LEN
;
1627 length
-= IEEE802_11_LISTENINT_LEN
;
1628 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
1629 offset
+= IEEE802_11_AP_LEN
;
1630 length
-= IEEE802_11_AP_LEN
;
1632 ret
= parse_elements(&pbody
, p
, offset
, length
);
1635 printf(" AP : %s", etheraddr_string( pbody
.ap
));
1641 handle_reassoc_response(const u_char
*p
, u_int length
)
1643 /* Same as a Association Reponse */
1644 return handle_assoc_response(p
, length
);
1648 handle_probe_request(const u_char
*p
, u_int length
)
1650 struct mgmt_body_t pbody
;
1654 memset(&pbody
, 0, sizeof(pbody
));
1656 ret
= parse_elements(&pbody
, p
, offset
, length
);
1665 handle_probe_response(const u_char
*p
, u_int length
)
1667 struct mgmt_body_t pbody
;
1671 memset(&pbody
, 0, sizeof(pbody
));
1673 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1674 IEEE802_11_CAPINFO_LEN
))
1676 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1677 IEEE802_11_CAPINFO_LEN
)
1679 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1680 offset
+= IEEE802_11_TSTAMP_LEN
;
1681 length
-= IEEE802_11_TSTAMP_LEN
;
1682 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1683 offset
+= IEEE802_11_BCNINT_LEN
;
1684 length
-= IEEE802_11_BCNINT_LEN
;
1685 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1686 offset
+= IEEE802_11_CAPINFO_LEN
;
1687 length
-= IEEE802_11_CAPINFO_LEN
;
1689 ret
= parse_elements(&pbody
, p
, offset
, length
);
1693 PRINT_DS_CHANNEL(pbody
);
1701 /* the frame body for ATIM is null. */
1706 handle_disassoc(const u_char
*p
, u_int length
)
1708 struct mgmt_body_t pbody
;
1710 memset(&pbody
, 0, sizeof(pbody
));
1712 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
1714 if (length
< IEEE802_11_REASON_LEN
)
1716 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1719 (pbody
.reason_code
< NUM_REASONS
)
1720 ? reason_text
[pbody
.reason_code
]
1727 handle_auth(const u_char
*p
, u_int length
)
1729 struct mgmt_body_t pbody
;
1733 memset(&pbody
, 0, sizeof(pbody
));
1739 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
1742 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
1745 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
1749 ret
= parse_elements(&pbody
, p
, offset
, length
);
1751 if ((pbody
.auth_alg
== 1) &&
1752 ((pbody
.auth_trans_seq_num
== 2) ||
1753 (pbody
.auth_trans_seq_num
== 3))) {
1754 printf(" (%s)-%x [Challenge Text] %s",
1755 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1756 ? auth_alg_text
[pbody
.auth_alg
]
1758 pbody
.auth_trans_seq_num
,
1759 ((pbody
.auth_trans_seq_num
% 2)
1760 ? ((pbody
.status_code
< NUM_STATUSES
)
1761 ? status_text
[pbody
.status_code
]
1765 printf(" (%s)-%x: %s",
1766 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1767 ? auth_alg_text
[pbody
.auth_alg
]
1769 pbody
.auth_trans_seq_num
,
1770 (pbody
.auth_trans_seq_num
% 2)
1771 ? ((pbody
.status_code
< NUM_STATUSES
)
1772 ? status_text
[pbody
.status_code
]
1780 handle_deauth(const struct mgmt_header_t
*pmh
, const u_char
*p
, u_int length
)
1782 struct mgmt_body_t pbody
;
1783 const char *reason
= NULL
;
1785 memset(&pbody
, 0, sizeof(pbody
));
1787 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
1789 if (length
< IEEE802_11_REASON_LEN
)
1791 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1793 reason
= (pbody
.reason_code
< NUM_REASONS
)
1794 ? reason_text
[pbody
.reason_code
]
1798 printf(": %s", reason
);
1800 printf(" (%s): %s", etheraddr_string(pmh
->sa
), reason
);
1805 #define PRINT_HT_ACTION(v) (\
1806 (v) == 0 ? printf("TxChWidth") : \
1807 (v) == 1 ? printf("MIMOPwrSave") : \
1808 printf("Act#%d", (v)) \
1810 #define PRINT_BA_ACTION(v) (\
1811 (v) == 0 ? printf("ADDBA Request") : \
1812 (v) == 1 ? printf("ADDBA Response") : \
1813 (v) == 2 ? printf("DELBA") : \
1814 printf("Act#%d", (v)) \
1816 #define PRINT_MESHLINK_ACTION(v) (\
1817 (v) == 0 ? printf("Request") : \
1818 (v) == 1 ? printf("Report") : \
1819 printf("Act#%d", (v)) \
1821 #define PRINT_MESHPEERING_ACTION(v) (\
1822 (v) == 0 ? printf("Open") : \
1823 (v) == 1 ? printf("Confirm") : \
1824 (v) == 2 ? printf("Close") : \
1825 printf("Act#%d", (v)) \
1827 #define PRINT_MESHPATH_ACTION(v) (\
1828 (v) == 0 ? printf("Request") : \
1829 (v) == 1 ? printf("Report") : \
1830 (v) == 2 ? printf("Error") : \
1831 (v) == 3 ? printf("RootAnnouncement") : \
1832 printf("Act#%d", (v)) \
1835 #define PRINT_MESH_ACTION(v) (\
1836 (v) == 0 ? printf("MeshLink") : \
1837 (v) == 1 ? printf("HWMP") : \
1838 (v) == 2 ? printf("Gate Announcement") : \
1839 (v) == 3 ? printf("Congestion Control") : \
1840 (v) == 4 ? printf("MCCA Setup Request") : \
1841 (v) == 5 ? printf("MCCA Setup Reply") : \
1842 (v) == 6 ? printf("MCCA Advertisement Request") : \
1843 (v) == 7 ? printf("MCCA Advertisement") : \
1844 (v) == 8 ? printf("MCCA Teardown") : \
1845 (v) == 9 ? printf("TBTT Adjustment Request") : \
1846 (v) == 10 ? printf("TBTT Adjustment Response") : \
1847 printf("Act#%d", (v)) \
1849 #define PRINT_MULTIHOP_ACTION(v) (\
1850 (v) == 0 ? printf("Proxy Update") : \
1851 (v) == 1 ? printf("Proxy Update Confirmation") : \
1852 printf("Act#%d", (v)) \
1854 #define PRINT_SELFPROT_ACTION(v) (\
1855 (v) == 1 ? printf("Peering Open") : \
1856 (v) == 2 ? printf("Peering Confirm") : \
1857 (v) == 3 ? printf("Peering Close") : \
1858 (v) == 4 ? printf("Group Key Inform") : \
1859 (v) == 5 ? printf("Group Key Acknowledge") : \
1860 printf("Act#%d", (v)) \
1864 handle_action(const struct mgmt_header_t
*pmh
, const u_char
*p
, u_int length
)
1873 printf(" (%s): ", etheraddr_string(pmh
->sa
));
1876 case 0: printf("Spectrum Management Act#%d", p
[1]); break;
1877 case 1: printf("QoS Act#%d", p
[1]); break;
1878 case 2: printf("DLS Act#%d", p
[1]); break;
1879 case 3: printf("BA "); PRINT_BA_ACTION(p
[1]); break;
1880 case 7: printf("HT "); PRINT_HT_ACTION(p
[1]); break;
1881 case 13: printf("MeshAction "); PRINT_MESH_ACTION(p
[1]); break;
1883 printf("MultiohopAction ");
1884 PRINT_MULTIHOP_ACTION(p
[1]); break;
1886 printf("SelfprotectAction ");
1887 PRINT_SELFPROT_ACTION(p
[1]); break;
1888 case 127: printf("Vendor Act#%d", p
[1]); break;
1890 printf("Reserved(%d) Act#%d", p
[0], p
[1]);
1897 /*********************************************************************************
1899 *********************************************************************************/
1903 mgmt_body_print(u_int16_t fc
, const struct mgmt_header_t
*pmh
,
1904 const u_char
*p
, u_int length
)
1906 switch (FC_SUBTYPE(fc
)) {
1907 case ST_ASSOC_REQUEST
:
1908 printf("Assoc Request");
1909 return handle_assoc_request(p
, length
);
1910 case ST_ASSOC_RESPONSE
:
1911 printf("Assoc Response");
1912 return handle_assoc_response(p
, length
);
1913 case ST_REASSOC_REQUEST
:
1914 printf("ReAssoc Request");
1915 return handle_reassoc_request(p
, length
);
1916 case ST_REASSOC_RESPONSE
:
1917 printf("ReAssoc Response");
1918 return handle_reassoc_response(p
, length
);
1919 case ST_PROBE_REQUEST
:
1920 printf("Probe Request");
1921 return handle_probe_request(p
, length
);
1922 case ST_PROBE_RESPONSE
:
1923 printf("Probe Response");
1924 return handle_probe_response(p
, length
);
1927 return handle_beacon(p
, length
);
1930 return handle_atim();
1932 printf("Disassociation");
1933 return handle_disassoc(p
, length
);
1935 printf("Authentication");
1938 if ((p
[0] == 0 ) && (p
[1] == 0) && (p
[2] == 0)) {
1939 printf("Authentication (Shared-Key)-3 ");
1940 return wep_print(p
);
1942 return handle_auth(p
, length
);
1944 printf("DeAuthentication");
1945 return handle_deauth(pmh
, p
, length
);
1949 return handle_action(pmh
, p
, length
);
1952 printf("Unhandled Management subtype(%x)",
1959 /*********************************************************************************
1960 * Handles printing all the control frame types
1961 *********************************************************************************/
1964 ctrl_body_print(u_int16_t fc
, const u_char
*p
)
1966 switch (FC_SUBTYPE(fc
)) {
1967 case CTRL_CONTROL_WRAPPER
:
1968 printf("Control Wrapper");
1969 /* XXX - requires special handling */
1973 if (!TTEST2(*p
, CTRL_BAR_HDRLEN
))
1976 printf(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
1977 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ra
),
1978 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ta
),
1979 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->ctl
)),
1980 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->seq
)));
1984 if (!TTEST2(*p
, CTRL_BA_HDRLEN
))
1988 etheraddr_string(((const struct ctrl_ba_t
*)p
)->ra
));
1991 printf("Power Save-Poll");
1992 if (!TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
1995 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t
*)p
)->aid
)));
1998 printf("Request-To-Send");
1999 if (!TTEST2(*p
, CTRL_RTS_HDRLEN
))
2003 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
2006 printf("Clear-To-Send");
2007 if (!TTEST2(*p
, CTRL_CTS_HDRLEN
))
2011 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
2014 printf("Acknowledgment");
2015 if (!TTEST2(*p
, CTRL_ACK_HDRLEN
))
2019 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
2023 if (!TTEST2(*p
, CTRL_END_HDRLEN
))
2027 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
));
2030 printf("CF-End+CF-Ack");
2031 if (!TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
2035 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
));
2038 printf("Unknown Ctrl Subtype");
2044 * Print Header funcs
2048 * Data Frame - Address field contents
2050 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
2051 * 0 | 0 | DA | SA | BSSID | n/a
2052 * 0 | 1 | DA | BSSID | SA | n/a
2053 * 1 | 0 | BSSID | SA | DA | n/a
2054 * 1 | 1 | RA | TA | DA | SA
2058 data_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
2059 const u_int8_t
**dstp
)
2061 u_int subtype
= FC_SUBTYPE(fc
);
2063 if (DATA_FRAME_IS_CF_ACK(subtype
) || DATA_FRAME_IS_CF_POLL(subtype
) ||
2064 DATA_FRAME_IS_QOS(subtype
)) {
2066 if (DATA_FRAME_IS_CF_ACK(subtype
)) {
2067 if (DATA_FRAME_IS_CF_POLL(subtype
))
2072 if (DATA_FRAME_IS_CF_POLL(subtype
))
2075 if (DATA_FRAME_IS_QOS(subtype
))
2080 #define ADDR1 (p + 4)
2081 #define ADDR2 (p + 10)
2082 #define ADDR3 (p + 16)
2083 #define ADDR4 (p + 24)
2085 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
2092 printf("DA:%s SA:%s BSSID:%s ",
2093 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2094 etheraddr_string(ADDR3
));
2095 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
2102 printf("DA:%s BSSID:%s SA:%s ",
2103 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2104 etheraddr_string(ADDR3
));
2105 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
2112 printf("BSSID:%s SA:%s DA:%s ",
2113 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2114 etheraddr_string(ADDR3
));
2115 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
2122 printf("RA:%s TA:%s DA:%s SA:%s ",
2123 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2124 etheraddr_string(ADDR3
), etheraddr_string(ADDR4
));
2134 mgmt_header_print(const u_char
*p
, const u_int8_t
**srcp
,
2135 const u_int8_t
**dstp
)
2137 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
2146 printf("BSSID:%s DA:%s SA:%s ",
2147 etheraddr_string((hp
)->bssid
), etheraddr_string((hp
)->da
),
2148 etheraddr_string((hp
)->sa
));
2152 ctrl_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
2153 const u_int8_t
**dstp
)
2162 switch (FC_SUBTYPE(fc
)) {
2164 printf(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
2165 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ra
),
2166 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ta
),
2167 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->ctl
)),
2168 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->seq
)));
2172 etheraddr_string(((const struct ctrl_ba_t
*)p
)->ra
));
2175 printf("BSSID:%s TA:%s ",
2176 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->bssid
),
2177 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->ta
));
2180 printf("RA:%s TA:%s ",
2181 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ra
),
2182 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
2186 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
2190 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
2193 printf("RA:%s BSSID:%s ",
2194 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
),
2195 etheraddr_string(((const struct ctrl_end_t
*)p
)->bssid
));
2198 printf("RA:%s BSSID:%s ",
2199 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
),
2200 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->bssid
));
2203 printf("(H) Unknown Ctrl Subtype");
2209 extract_header_length(u_int16_t fc
)
2213 switch (FC_TYPE(fc
)) {
2217 switch (FC_SUBTYPE(fc
)) {
2219 return CTRL_BAR_HDRLEN
;
2221 return CTRL_PS_POLL_HDRLEN
;
2223 return CTRL_RTS_HDRLEN
;
2225 return CTRL_CTS_HDRLEN
;
2227 return CTRL_ACK_HDRLEN
;
2229 return CTRL_END_HDRLEN
;
2231 return CTRL_END_ACK_HDRLEN
;
2236 len
= (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
2237 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
)))
2241 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc
));
2247 extract_mesh_header_length(const u_char
*p
)
2249 return (p
[0] &~ 3) ? 0 : 6*(1 + (p
[0] & 3));
2253 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
2254 * to point to the source and destination MAC addresses in any case if
2255 * "srcp" and "dstp" aren't null.
2258 ieee_802_11_hdr_print(u_int16_t fc
, const u_char
*p
, u_int hdrlen
,
2259 u_int meshdrlen
, const u_int8_t
**srcp
, const u_int8_t
**dstp
)
2262 if (FC_MORE_DATA(fc
))
2263 printf("More Data ");
2264 if (FC_MORE_FLAG(fc
))
2265 printf("More Fragments ");
2266 if (FC_POWER_MGMT(fc
))
2267 printf("Pwr Mgmt ");
2271 printf("Strictly Ordered ");
2273 printf("WEP Encrypted ");
2274 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
2277 &((const struct mgmt_header_t
*)p
)->duration
));
2279 if (meshdrlen
!= 0) {
2280 const struct meshcntl_t
*mc
=
2281 (const struct meshcntl_t
*)&p
[hdrlen
- meshdrlen
];
2282 int ae
= mc
->flags
& 3;
2284 printf("MeshData (AE %d TTL %u seq %u", ae
, mc
->ttl
,
2285 EXTRACT_LE_32BITS(mc
->seq
));
2287 printf(" A4:%s", etheraddr_string(mc
->addr4
));
2289 printf(" A5:%s", etheraddr_string(mc
->addr5
));
2291 printf(" A6:%s", etheraddr_string(mc
->addr6
));
2295 switch (FC_TYPE(fc
)) {
2297 mgmt_header_print(p
, srcp
, dstp
);
2300 ctrl_header_print(fc
, p
, srcp
, dstp
);
2303 data_header_print(fc
, p
, srcp
, dstp
);
2306 printf("(header) unknown IEEE802.11 frame type (%d)",
2315 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2319 ieee802_11_print(const u_char
*p
, u_int length
, u_int orig_caplen
, int pad
,
2323 u_int caplen
, hdrlen
, meshdrlen
;
2324 const u_int8_t
*src
, *dst
;
2325 u_short extracted_ethertype
;
2327 caplen
= orig_caplen
;
2328 /* Remove FCS, if present */
2329 if (length
< fcslen
) {
2334 if (caplen
> length
) {
2335 /* Amount of FCS in actual packet data, if any */
2336 fcslen
= caplen
- length
;
2341 if (caplen
< IEEE802_11_FC_LEN
) {
2346 fc
= EXTRACT_LE_16BITS(p
);
2347 hdrlen
= extract_header_length(fc
);
2349 hdrlen
= roundup2(hdrlen
, 4);
2350 if (Hflag
&& FC_TYPE(fc
) == T_DATA
&&
2351 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
))) {
2352 meshdrlen
= extract_mesh_header_length(p
+hdrlen
);
2353 hdrlen
+= meshdrlen
;
2358 if (caplen
< hdrlen
) {
2363 ieee_802_11_hdr_print(fc
, p
, hdrlen
, meshdrlen
, &src
, &dst
);
2366 * Go past the 802.11 header.
2372 switch (FC_TYPE(fc
)) {
2374 if (!mgmt_body_print(fc
,
2375 (const struct mgmt_header_t
*)(p
- hdrlen
), p
, length
)) {
2381 if (!ctrl_body_print(fc
, p
- hdrlen
)) {
2387 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc
)))
2388 return hdrlen
; /* no-data frame */
2389 /* There may be a problem w/ AP not having this bit set */
2391 if (!wep_print(p
)) {
2395 } else if (llc_print(gndo
, p
, length
, caplen
, dst
, src
,
2396 &extracted_ethertype
) == 0) {
2398 * Some kinds of LLC packet we cannot
2399 * handle intelligently
2402 ieee_802_11_hdr_print(fc
, p
- hdrlen
, hdrlen
,
2403 meshdrlen
, NULL
, NULL
);
2404 if (extracted_ethertype
)
2407 htons(extracted_ethertype
)));
2408 if (!suppress_default_print
)
2409 default_print(p
, caplen
);
2413 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc
));
2421 * This is the top level routine of the printer. 'p' points
2422 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2423 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2424 * is the number of bytes actually captured.
2427 ieee802_11_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2429 return ieee802_11_print(p
, h
->len
, h
->caplen
, 0, 0);
2432 #define IEEE80211_CHAN_FHSS \
2433 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2434 #define IEEE80211_CHAN_A \
2435 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2436 #define IEEE80211_CHAN_B \
2437 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2438 #define IEEE80211_CHAN_PUREG \
2439 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2440 #define IEEE80211_CHAN_G \
2441 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2443 #define IS_CHAN_FHSS(flags) \
2444 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2445 #define IS_CHAN_A(flags) \
2446 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2447 #define IS_CHAN_B(flags) \
2448 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2449 #define IS_CHAN_PUREG(flags) \
2450 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2451 #define IS_CHAN_G(flags) \
2452 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2453 #define IS_CHAN_ANYG(flags) \
2454 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2457 print_chaninfo(int freq
, int flags
)
2459 printf("%u MHz", freq
);
2460 if (IS_CHAN_FHSS(flags
))
2462 if (IS_CHAN_A(flags
)) {
2463 if (flags
& IEEE80211_CHAN_HALF
)
2464 printf(" 11a/10Mhz");
2465 else if (flags
& IEEE80211_CHAN_QUARTER
)
2466 printf(" 11a/5Mhz");
2470 if (IS_CHAN_ANYG(flags
)) {
2471 if (flags
& IEEE80211_CHAN_HALF
)
2472 printf(" 11g/10Mhz");
2473 else if (flags
& IEEE80211_CHAN_QUARTER
)
2474 printf(" 11g/5Mhz");
2477 } else if (IS_CHAN_B(flags
))
2479 if (flags
& IEEE80211_CHAN_TURBO
)
2481 if (flags
& IEEE80211_CHAN_HT20
)
2483 else if (flags
& IEEE80211_CHAN_HT40D
)
2485 else if (flags
& IEEE80211_CHAN_HT40U
)
2491 print_radiotap_field(struct cpack_state
*s
, u_int32_t bit
, u_int8_t
*flags
,
2492 struct radiotap_state
*state
, u_int32_t presentflags
)
2505 case IEEE80211_RADIOTAP_FLAGS
:
2506 rc
= cpack_uint8(s
, &u
.u8
);
2511 case IEEE80211_RADIOTAP_RATE
:
2512 rc
= cpack_uint8(s
, &u
.u8
);
2516 /* Save state rate */
2519 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2520 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2521 case IEEE80211_RADIOTAP_ANTENNA
:
2522 rc
= cpack_uint8(s
, &u
.u8
);
2524 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2525 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2526 rc
= cpack_int8(s
, &u
.i8
);
2528 case IEEE80211_RADIOTAP_CHANNEL
:
2529 rc
= cpack_uint16(s
, &u
.u16
);
2532 rc
= cpack_uint16(s
, &u2
.u16
);
2534 case IEEE80211_RADIOTAP_FHSS
:
2535 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2536 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2537 case IEEE80211_RADIOTAP_RX_FLAGS
:
2538 rc
= cpack_uint16(s
, &u
.u16
);
2540 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2541 rc
= cpack_uint8(s
, &u
.u8
);
2543 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2544 rc
= cpack_int8(s
, &u
.i8
);
2546 case IEEE80211_RADIOTAP_TSFT
:
2547 rc
= cpack_uint64(s
, &u
.u64
);
2549 case IEEE80211_RADIOTAP_XCHANNEL
:
2550 rc
= cpack_uint32(s
, &u
.u32
);
2553 rc
= cpack_uint16(s
, &u2
.u16
);
2556 rc
= cpack_uint8(s
, &u3
.u8
);
2559 rc
= cpack_uint8(s
, &u4
.u8
);
2561 case IEEE80211_RADIOTAP_MCS
:
2562 rc
= cpack_uint8(s
, &u
.u8
);
2565 rc
= cpack_uint8(s
, &u2
.u8
);
2568 rc
= cpack_uint8(s
, &u3
.u8
);
2570 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE
: {
2575 if ((cpack_align_and_reserve(s
, 2)) == NULL
) {
2580 rc
= cpack_uint8(s
, &vns
[0]);
2583 rc
= cpack_uint8(s
, &vns
[1]);
2586 rc
= cpack_uint8(s
, &vns
[2]);
2589 rc
= cpack_uint8(s
, &subspace
);
2592 rc
= cpack_uint16(s
, &length
);
2596 /* Skip up to length */
2597 s
->c_next
+= length
;
2601 /* this bit indicates a field whose
2602 * size we do not know, so we cannot
2603 * proceed. Just print the bit number.
2605 printf("[bit %u] ", bit
);
2614 /* Preserve the state present flags */
2615 state
->present
= presentflags
;
2618 case IEEE80211_RADIOTAP_CHANNEL
:
2620 * If CHANNEL and XCHANNEL are both present, skip
2623 if (presentflags
& (1 << IEEE80211_RADIOTAP_XCHANNEL
))
2625 print_chaninfo(u
.u16
, u2
.u16
);
2627 case IEEE80211_RADIOTAP_FHSS
:
2628 printf("fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff);
2630 case IEEE80211_RADIOTAP_RATE
:
2632 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2633 * Linux and AirPcap it does not. (What about
2634 * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
2636 * This is an issue either for proprietary extensions
2637 * to 11a or 11g, which do exist, or for 11n
2638 * implementations that stuff a rate value into
2639 * this field, which also appear to exist.
2641 * We currently handle that by assuming that
2642 * if the 0x80 bit is set *and* the remaining
2643 * bits have a value between 0 and 15 it's
2644 * an MCS value, otherwise it's a rate. If
2645 * there are cases where systems that use
2646 * "0x80 + MCS index" for MCS indices > 15,
2647 * or stuff a rate value here between 64 and
2648 * 71.5 Mb/s in here, we'll need a preference
2649 * setting. Such rates do exist, e.g. 11n
2650 * MCS 7 at 20 MHz with a long guard interval.
2652 if (u
.u8
>= 0x80 && u
.u8
<= 0x8f) {
2654 * XXX - we don't know the channel width
2655 * or guard interval length, so we can't
2656 * convert this to a data rate.
2658 * If you want us to show a data rate,
2659 * use the MCS field, not the Rate field;
2660 * the MCS field includes not only the
2661 * MCS index, it also includes bandwidth
2662 * and guard interval information.
2664 * XXX - can we get the channel width
2665 * from XChannel and the guard interval
2666 * information from Flags, at least on
2669 printf("MCS %u ", u
.u8
& 0x7f);
2671 printf("%2.1f Mb/s ", .5*u
.u8
);
2673 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2674 printf("%ddB signal ", u
.i8
);
2676 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2677 printf("%ddB noise ", u
.i8
);
2679 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2680 printf("%ddB signal ", u
.u8
);
2682 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2683 printf("%ddB noise ", u
.u8
);
2685 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2686 printf("%u sq ", u
.u16
);
2688 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2689 printf("%d tx power ", -(int)u
.u16
);
2691 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2692 printf("%ddB tx power ", -(int)u
.u8
);
2694 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2695 printf("%ddBm tx power ", u
.i8
);
2697 case IEEE80211_RADIOTAP_FLAGS
:
2698 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
2700 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
2701 printf("short preamble ");
2702 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
2704 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
2705 printf("fragmented ");
2706 if (u
.u8
& IEEE80211_RADIOTAP_F_BADFCS
)
2709 case IEEE80211_RADIOTAP_ANTENNA
:
2710 printf("antenna %d ", u
.u8
);
2712 case IEEE80211_RADIOTAP_TSFT
:
2713 printf("%" PRIu64
"us tsft ", u
.u64
);
2715 case IEEE80211_RADIOTAP_RX_FLAGS
:
2716 /* Do nothing for now */
2718 case IEEE80211_RADIOTAP_XCHANNEL
:
2719 print_chaninfo(u2
.u16
, u
.u32
);
2721 case IEEE80211_RADIOTAP_MCS
: {
2722 static const char *bandwidth
[4] = {
2730 if (u
.u8
& IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN
) {
2732 * We know the MCS index.
2734 if (u3
.u8
<= MAX_MCS_INDEX
) {
2736 * And it's in-range.
2738 if (u
.u8
& (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
)) {
2740 * And we know both the bandwidth and
2741 * the guard interval, so we can look
2745 ieee80211_float_htrates \
2747 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40
? 1 : 0)] \
2748 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ? 1 : 0)];
2751 * We don't know both the bandwidth
2752 * and the guard interval, so we can
2753 * only report the MCS index.
2759 * The MCS value is out of range.
2763 if (htrate
!= 0.0) {
2768 printf("%.1f Mb/s MCS %u ", htrate
, u3
.u8
);
2771 * We at least have the MCS index.
2774 printf("MCS %u ", u3
.u8
);
2777 if (u
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
) {
2779 bandwidth
[u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
]);
2781 if (u
.u8
& IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
) {
2783 (u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ?
2786 if (u
.u8
& IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN
) {
2788 (u2
.u8
& IEEE80211_RADIOTAP_MCS_HT_GREENFIELD
) ?
2789 "greenfield" : "mixed");
2791 if (u
.u8
& IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN
) {
2793 (u2
.u8
& IEEE80211_RADIOTAP_MCS_FEC_LDPC
) ?
2796 if (u
.u8
& IEEE80211_RADIOTAP_MCS_STBC_KNOWN
) {
2797 printf("RX-STBC%u ",
2798 (u2
.u8
& IEEE80211_RADIOTAP_MCS_STBC_MASK
) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT
);
2808 ieee802_11_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
2810 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
2811 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
2812 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
2813 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
2814 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
2815 #define BIT(n) (1U << n)
2816 #define IS_EXTENDED(__p) \
2817 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
2819 struct cpack_state cpacker
;
2820 struct ieee80211_radiotap_header
*hdr
;
2821 u_int32_t present
, next_present
;
2822 u_int32_t presentflags
= 0;
2823 u_int32_t
*presentp
, *last_presentp
;
2824 enum ieee80211_radiotap_type bit
;
2830 struct radiotap_state state
;
2832 if (caplen
< sizeof(*hdr
)) {
2837 hdr
= (struct ieee80211_radiotap_header
*)p
;
2839 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
2845 cpack_init(&cpacker
, (u_int8_t
*)hdr
, len
); /* align against header start */
2846 cpack_advance(&cpacker
, sizeof(*hdr
)); /* includes the 1st bitmap */
2847 for (last_presentp
= &hdr
->it_present
;
2848 IS_EXTENDED(last_presentp
) &&
2849 (u_char
*)(last_presentp
+ 1) <= p
+ len
;
2851 cpack_advance(&cpacker
, sizeof(hdr
->it_present
)); /* more bitmaps */
2853 /* are there more bitmap extensions than bytes in header? */
2854 if (IS_EXTENDED(last_presentp
)) {
2859 /* Assume no flags */
2861 /* Assume no Atheros padding between 802.11 header and body */
2863 /* Assume no FCS at end of frame */
2865 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
2866 presentp
++, bit0
+= 32) {
2867 presentflags
= EXTRACT_LE_32BITS(presentp
);
2870 memset(&state
, 0, sizeof(state
));
2872 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
2873 present
= next_present
) {
2874 /* clear the least significant bit that is set */
2875 next_present
= present
& (present
- 1);
2877 /* extract the least significant bit that is set */
2878 bit
= (enum ieee80211_radiotap_type
)
2879 (bit0
+ BITNO_32(present
^ next_present
));
2881 if (print_radiotap_field(&cpacker
, bit
, &flags
, &state
, presentflags
) != 0)
2887 if (flags
& IEEE80211_RADIOTAP_F_DATAPAD
)
2888 pad
= 1; /* Atheros padding */
2889 if (flags
& IEEE80211_RADIOTAP_F_FCS
)
2890 fcslen
= 4; /* FCS at end of packet */
2891 return len
+ ieee802_11_print(p
+ len
, length
- len
, caplen
- len
, pad
,
2902 ieee802_11_avs_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
2904 u_int32_t caphdr_len
;
2911 caphdr_len
= EXTRACT_32BITS(p
+ 4);
2912 if (caphdr_len
< 8) {
2914 * Yow! The capture header length is claimed not
2915 * to be large enough to include even the version
2916 * cookie or capture header length!
2922 if (caplen
< caphdr_len
) {
2927 return caphdr_len
+ ieee802_11_print(p
+ caphdr_len
,
2928 length
- caphdr_len
, caplen
- caphdr_len
, 0, 0);
2931 #define PRISM_HDR_LEN 144
2933 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
2934 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
2935 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
2938 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
2939 * containing information such as radio information, which we
2942 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
2943 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
2944 * (currently, on Linux, there's no ARPHRD_ type for
2945 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
2946 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
2947 * the AVS header, and the first 4 bytes of the header are used to
2948 * indicate whether it's a Prism header or an AVS header).
2951 prism_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2953 u_int caplen
= h
->caplen
;
2954 u_int length
= h
->len
;
2962 msgcode
= EXTRACT_32BITS(p
);
2963 if (msgcode
== WLANCAP_MAGIC_COOKIE_V1
||
2964 msgcode
== WLANCAP_MAGIC_COOKIE_V2
)
2965 return ieee802_11_avs_radio_print(p
, length
, caplen
);
2967 if (caplen
< PRISM_HDR_LEN
) {
2972 return PRISM_HDR_LEN
+ ieee802_11_print(p
+ PRISM_HDR_LEN
,
2973 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
, 0, 0);
2977 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
2978 * header, containing information such as radio information.
2981 ieee802_11_radio_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2983 return ieee802_11_radio_print(p
, h
->len
, h
->caplen
);
2987 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
2988 * extra header, containing information such as radio information,
2989 * which we currently ignore.
2992 ieee802_11_radio_avs_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2994 return ieee802_11_avs_radio_print(p
, h
->len
, h
->caplen
);