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.
23 /* \summary: IEEE 802.11 printer */
29 #include "netdissect-stdinc.h"
33 #include "netdissect.h"
34 #include "addrtoname.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_ADDR1_LEN 6
50 #define IEEE802_11_SEQ_LEN 2
51 #define IEEE802_11_CTL_LEN 2
52 #define IEEE802_11_CARRIED_FC_LEN 2
53 #define IEEE802_11_HT_CONTROL_LEN 4
54 #define IEEE802_11_IV_LEN 3
55 #define IEEE802_11_KID_LEN 1
57 /* Frame check sequence length. */
58 #define IEEE802_11_FCS_LEN 4
60 /* Lengths of beacon components. */
61 #define IEEE802_11_TSTAMP_LEN 8
62 #define IEEE802_11_BCNINT_LEN 2
63 #define IEEE802_11_CAPINFO_LEN 2
64 #define IEEE802_11_LISTENINT_LEN 2
66 #define IEEE802_11_AID_LEN 2
67 #define IEEE802_11_STATUS_LEN 2
68 #define IEEE802_11_REASON_LEN 2
70 /* Length of previous AP in reassocation frame */
71 #define IEEE802_11_AP_LEN 6
73 #define T_MGMT 0x0 /* management */
74 #define T_CTRL 0x1 /* control */
75 #define T_DATA 0x2 /* data */
76 #define T_RESV 0x3 /* reserved */
78 #define ST_ASSOC_REQUEST 0x0
79 #define ST_ASSOC_RESPONSE 0x1
80 #define ST_REASSOC_REQUEST 0x2
81 #define ST_REASSOC_RESPONSE 0x3
82 #define ST_PROBE_REQUEST 0x4
83 #define ST_PROBE_RESPONSE 0x5
88 #define ST_DISASSOC 0xA
95 static const struct tok st_str
[] = {
96 { ST_ASSOC_REQUEST
, "Assoc Request" },
97 { ST_ASSOC_RESPONSE
, "Assoc Response" },
98 { ST_REASSOC_REQUEST
, "ReAssoc Request" },
99 { ST_REASSOC_RESPONSE
, "ReAssoc Response" },
100 { ST_PROBE_REQUEST
, "Probe Request" },
101 { ST_PROBE_RESPONSE
, "Probe Response" },
102 { ST_BEACON
, "Beacon" },
104 { ST_DISASSOC
, "Disassociation" },
105 { ST_AUTH
, "Authentication" },
106 { ST_DEAUTH
, "DeAuthentication" },
107 { ST_ACTION
, "Action" },
111 #define CTRL_CONTROL_WRAPPER 0x7
114 #define CTRL_PS_POLL 0xA
118 #define CTRL_CF_END 0xE
119 #define CTRL_END_ACK 0xF
121 static const struct tok ctrl_str
[] = {
122 { CTRL_CONTROL_WRAPPER
, "Control Wrapper" },
125 { CTRL_PS_POLL
, "Power Save-Poll" },
126 { CTRL_RTS
, "Request-To-Send" },
127 { CTRL_CTS
, "Clear-To-Send" },
128 { CTRL_ACK
, "Acknowledgment" },
129 { CTRL_CF_END
, "CF-End" },
130 { CTRL_END_ACK
, "CF-End+CF-Ack" },
134 #define DATA_DATA 0x0
135 #define DATA_DATA_CF_ACK 0x1
136 #define DATA_DATA_CF_POLL 0x2
137 #define DATA_DATA_CF_ACK_POLL 0x3
138 #define DATA_NODATA 0x4
139 #define DATA_NODATA_CF_ACK 0x5
140 #define DATA_NODATA_CF_POLL 0x6
141 #define DATA_NODATA_CF_ACK_POLL 0x7
143 #define DATA_QOS_DATA 0x8
144 #define DATA_QOS_DATA_CF_ACK 0x9
145 #define DATA_QOS_DATA_CF_POLL 0xA
146 #define DATA_QOS_DATA_CF_ACK_POLL 0xB
147 #define DATA_QOS_NODATA 0xC
148 #define DATA_QOS_CF_POLL_NODATA 0xE
149 #define DATA_QOS_CF_ACK_POLL_NODATA 0xF
152 * The subtype field of a data frame is, in effect, composed of 4 flag
153 * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
154 * any data), and QoS.
156 #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01)
157 #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02)
158 #define DATA_FRAME_IS_NULL(x) ((x) & 0x04)
159 #define DATA_FRAME_IS_QOS(x) ((x) & 0x08)
162 * Bits in the frame control field.
164 #define FC_VERSION(fc) ((fc) & 0x3)
165 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
166 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
167 #define FC_TO_DS(fc) ((fc) & 0x0100)
168 #define FC_FROM_DS(fc) ((fc) & 0x0200)
169 #define FC_MORE_FLAG(fc) ((fc) & 0x0400)
170 #define FC_RETRY(fc) ((fc) & 0x0800)
171 #define FC_POWER_MGMT(fc) ((fc) & 0x1000)
172 #define FC_MORE_DATA(fc) ((fc) & 0x2000)
173 #define FC_PROTECTED(fc) ((fc) & 0x4000)
174 #define FC_ORDER(fc) ((fc) & 0x8000)
176 struct mgmt_header_t
{
178 nd_uint16_t duration
;
182 nd_uint16_t seq_ctrl
;
185 #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
186 IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
187 IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
189 #define CAPABILITY_ESS(cap) ((cap) & 0x0001)
190 #define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
191 #define CAPABILITY_CFP(cap) ((cap) & 0x0004)
192 #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
193 #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
198 u_char ssid
[33]; /* 32 + 1 for null */
210 uint8_t text
[254]; /* 1-253 + 1 for null */
233 uint16_t max_duration
;
234 uint16_t dur_remaing
;
242 uint8_t bitmap_control
;
264 #define E_CHALLENGE 16
273 uint8_t timestamp
[IEEE802_11_TSTAMP_LEN
];
274 uint16_t beacon_interval
;
275 uint16_t listen_interval
;
276 uint16_t status_code
;
278 u_char ap
[IEEE802_11_AP_LEN
];
279 uint16_t reason_code
;
281 uint16_t auth_trans_seq_num
;
282 int challenge_present
;
283 struct challenge_t challenge
;
284 uint16_t capability_info
;
288 struct rates_t rates
;
299 struct ctrl_control_wrapper_hdr_t
{
301 nd_uint16_t duration
;
303 nd_uint16_t carried_fc
[IEEE802_11_CARRIED_FC_LEN
];
304 nd_uint16_t ht_control
[IEEE802_11_HT_CONTROL_LEN
];
307 #define CTRL_CONTROL_WRAPPER_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
308 IEEE802_11_ADDR1_LEN+\
309 IEEE802_11_CARRIED_FC_LEN+\
310 IEEE802_11_HT_CONTROL_LEN)
312 struct ctrl_rts_hdr_t
{
314 nd_uint16_t duration
;
319 #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
320 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
322 struct ctrl_cts_hdr_t
{
324 nd_uint16_t duration
;
328 #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
330 struct ctrl_ack_hdr_t
{
332 nd_uint16_t duration
;
336 #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
338 struct ctrl_ps_poll_hdr_t
{
345 #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
346 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
348 struct ctrl_end_hdr_t
{
350 nd_uint16_t duration
;
355 #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
356 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
358 struct ctrl_end_ack_hdr_t
{
360 nd_uint16_t duration
;
365 #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
366 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
368 struct ctrl_ba_hdr_t
{
370 nd_uint16_t duration
;
374 #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
376 struct ctrl_bar_hdr_t
{
385 #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
386 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
387 IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
398 #define IV_IV(iv) ((iv) & 0xFFFFFF)
399 #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
400 #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
402 #define PRINT_SSID(p) \
403 if (p.ssid_present) { \
405 fn_print(ndo, p.ssid.ssid, NULL); \
409 #define PRINT_RATE(_sep, _r, _suf) \
410 ND_PRINT("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
411 #define PRINT_RATES(p) \
412 if (p.rates_present) { \
414 const char *sep = " ["; \
415 for (z = 0; z < p.rates.length ; z++) { \
416 PRINT_RATE(sep, p.rates.rate[z], \
417 (p.rates.rate[z] & 0x80 ? "*" : "")); \
420 if (p.rates.length != 0) \
421 ND_PRINT(" Mbit]"); \
424 #define PRINT_DS_CHANNEL(p) \
426 ND_PRINT(" CH: %u", p.ds.channel); \
428 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "");
430 #define MAX_MCS_INDEX 76
435 * the MCS index (0-76);
437 * 0 for 20 MHz, 1 for 40 MHz;
439 * 0 for a long guard interval, 1 for a short guard interval.
441 static const float ieee80211_float_htrates
[MAX_MCS_INDEX
+1][2][2] = {
443 { /* 20 Mhz */ { 6.5f
, /* SGI */ 7.2f
, },
444 /* 40 Mhz */ { 13.5f
, /* SGI */ 15.0f
, },
448 { /* 20 Mhz */ { 13.0f
, /* SGI */ 14.4f
, },
449 /* 40 Mhz */ { 27.0f
, /* SGI */ 30.0f
, },
453 { /* 20 Mhz */ { 19.5f
, /* SGI */ 21.7f
, },
454 /* 40 Mhz */ { 40.5f
, /* SGI */ 45.0f
, },
458 { /* 20 Mhz */ { 26.0f
, /* SGI */ 28.9f
, },
459 /* 40 Mhz */ { 54.0f
, /* SGI */ 60.0f
, },
463 { /* 20 Mhz */ { 39.0f
, /* SGI */ 43.3f
, },
464 /* 40 Mhz */ { 81.0f
, /* SGI */ 90.0f
, },
468 { /* 20 Mhz */ { 52.0f
, /* SGI */ 57.8f
, },
469 /* 40 Mhz */ { 108.0f
, /* SGI */ 120.0f
, },
473 { /* 20 Mhz */ { 58.5f
, /* SGI */ 65.0f
, },
474 /* 40 Mhz */ { 121.5f
, /* SGI */ 135.0f
, },
478 { /* 20 Mhz */ { 65.0f
, /* SGI */ 72.2f
, },
479 /* 40 Mhz */ { 135.0f
, /* SGI */ 150.0f
, },
483 { /* 20 Mhz */ { 13.0f
, /* SGI */ 14.4f
, },
484 /* 40 Mhz */ { 27.0f
, /* SGI */ 30.0f
, },
488 { /* 20 Mhz */ { 26.0f
, /* SGI */ 28.9f
, },
489 /* 40 Mhz */ { 54.0f
, /* SGI */ 60.0f
, },
493 { /* 20 Mhz */ { 39.0f
, /* SGI */ 43.3f
, },
494 /* 40 Mhz */ { 81.0f
, /* SGI */ 90.0f
, },
498 { /* 20 Mhz */ { 52.0f
, /* SGI */ 57.8f
, },
499 /* 40 Mhz */ { 108.0f
, /* SGI */ 120.0f
, },
503 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
504 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
508 { /* 20 Mhz */ { 104.0f
, /* SGI */ 115.6f
, },
509 /* 40 Mhz */ { 216.0f
, /* SGI */ 240.0f
, },
513 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
514 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
518 { /* 20 Mhz */ { 130.0f
, /* SGI */ 144.4f
, },
519 /* 40 Mhz */ { 270.0f
, /* SGI */ 300.0f
, },
523 { /* 20 Mhz */ { 19.5f
, /* SGI */ 21.7f
, },
524 /* 40 Mhz */ { 40.5f
, /* SGI */ 45.0f
, },
528 { /* 20 Mhz */ { 39.0f
, /* SGI */ 43.3f
, },
529 /* 40 Mhz */ { 81.0f
, /* SGI */ 90.0f
, },
533 { /* 20 Mhz */ { 58.5f
, /* SGI */ 65.0f
, },
534 /* 40 Mhz */ { 121.5f
, /* SGI */ 135.0f
, },
538 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
539 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
543 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
544 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
548 { /* 20 Mhz */ { 156.0f
, /* SGI */ 173.3f
, },
549 /* 40 Mhz */ { 324.0f
, /* SGI */ 360.0f
, },
553 { /* 20 Mhz */ { 175.5f
, /* SGI */ 195.0f
, },
554 /* 40 Mhz */ { 364.5f
, /* SGI */ 405.0f
, },
558 { /* 20 Mhz */ { 195.0f
, /* SGI */ 216.7f
, },
559 /* 40 Mhz */ { 405.0f
, /* SGI */ 450.0f
, },
563 { /* 20 Mhz */ { 26.0f
, /* SGI */ 28.9f
, },
564 /* 40 Mhz */ { 54.0f
, /* SGI */ 60.0f
, },
568 { /* 20 Mhz */ { 52.0f
, /* SGI */ 57.8f
, },
569 /* 40 Mhz */ { 108.0f
, /* SGI */ 120.0f
, },
573 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
574 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
578 { /* 20 Mhz */ { 104.0f
, /* SGI */ 115.6f
, },
579 /* 40 Mhz */ { 216.0f
, /* SGI */ 240.0f
, },
583 { /* 20 Mhz */ { 156.0f
, /* SGI */ 173.3f
, },
584 /* 40 Mhz */ { 324.0f
, /* SGI */ 360.0f
, },
588 { /* 20 Mhz */ { 208.0f
, /* SGI */ 231.1f
, },
589 /* 40 Mhz */ { 432.0f
, /* SGI */ 480.0f
, },
593 { /* 20 Mhz */ { 234.0f
, /* SGI */ 260.0f
, },
594 /* 40 Mhz */ { 486.0f
, /* SGI */ 540.0f
, },
598 { /* 20 Mhz */ { 260.0f
, /* SGI */ 288.9f
, },
599 /* 40 Mhz */ { 540.0f
, /* SGI */ 600.0f
, },
603 { /* 20 Mhz */ { 0.0f
, /* SGI */ 0.0f
, }, /* not valid */
604 /* 40 Mhz */ { 6.0f
, /* SGI */ 6.7f
, },
608 { /* 20 Mhz */ { 39.0f
, /* SGI */ 43.3f
, },
609 /* 40 Mhz */ { 81.0f
, /* SGI */ 90.0f
, },
613 { /* 20 Mhz */ { 52.0f
, /* SGI */ 57.8f
, },
614 /* 40 Mhz */ { 108.0f
, /* SGI */ 120.0f
, },
618 { /* 20 Mhz */ { 65.0f
, /* SGI */ 72.2f
, },
619 /* 40 Mhz */ { 135.0f
, /* SGI */ 150.0f
, },
623 { /* 20 Mhz */ { 58.5f
, /* SGI */ 65.0f
, },
624 /* 40 Mhz */ { 121.5f
, /* SGI */ 135.0f
, },
628 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
629 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
633 { /* 20 Mhz */ { 97.5f
, /* SGI */ 108.3f
, },
634 /* 40 Mhz */ { 202.5f
, /* SGI */ 225.0f
, },
638 { /* 20 Mhz */ { 52.0f
, /* SGI */ 57.8f
, },
639 /* 40 Mhz */ { 108.0f
, /* SGI */ 120.0f
, },
643 { /* 20 Mhz */ { 65.0f
, /* SGI */ 72.2f
, },
644 /* 40 Mhz */ { 135.0f
, /* SGI */ 150.0f
, },
648 { /* 20 Mhz */ { 65.0f
, /* SGI */ 72.2f
, },
649 /* 40 Mhz */ { 135.0f
, /* SGI */ 150.0f
, },
653 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
654 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
658 { /* 20 Mhz */ { 91.0f
, /* SGI */ 101.1f
, },
659 /* 40 Mhz */ { 189.0f
, /* SGI */ 210.0f
, },
663 { /* 20 Mhz */ { 91.0f
, /* SGI */ 101.1f
, },
664 /* 40 Mhz */ { 189.0f
, /* SGI */ 210.0f
, },
668 { /* 20 Mhz */ { 104.0f
, /* SGI */ 115.6f
, },
669 /* 40 Mhz */ { 216.0f
, /* SGI */ 240.0f
, },
673 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
674 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
678 { /* 20 Mhz */ { 97.5f
, /* SGI */ 108.3f
, },
679 /* 40 Mhz */ { 202.5f
, /* SGI */ 225.0f
, },
683 { /* 20 Mhz */ { 97.5f
, /* SGI */ 108.3f
, },
684 /* 40 Mhz */ { 202.5f
, /* SGI */ 225.0f
, },
688 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
689 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
693 { /* 20 Mhz */ { 136.5f
, /* SGI */ 151.7f
, },
694 /* 40 Mhz */ { 283.5f
, /* SGI */ 315.0f
, },
698 { /* 20 Mhz */ { 136.5f
, /* SGI */ 151.7f
, },
699 /* 40 Mhz */ { 283.5f
, /* SGI */ 315.0f
, },
703 { /* 20 Mhz */ { 156.0f
, /* SGI */ 173.3f
, },
704 /* 40 Mhz */ { 324.0f
, /* SGI */ 360.0f
, },
708 { /* 20 Mhz */ { 65.0f
, /* SGI */ 72.2f
, },
709 /* 40 Mhz */ { 135.0f
, /* SGI */ 150.0f
, },
713 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
714 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
718 { /* 20 Mhz */ { 91.0f
, /* SGI */ 101.1f
, },
719 /* 40 Mhz */ { 189.0f
, /* SGI */ 210.0f
, },
723 { /* 20 Mhz */ { 78.0f
, /* SGI */ 86.7f
, },
724 /* 40 Mhz */ { 162.0f
, /* SGI */ 180.0f
, },
728 { /* 20 Mhz */ { 91.0f
, /* SGI */ 101.1f
, },
729 /* 40 Mhz */ { 189.0f
, /* SGI */ 210.0f
, },
733 { /* 20 Mhz */ { 104.0f
, /* SGI */ 115.6f
, },
734 /* 40 Mhz */ { 216.0f
, /* SGI */ 240.0f
, },
738 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
739 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
743 { /* 20 Mhz */ { 104.0f
, /* SGI */ 115.6f
, },
744 /* 40 Mhz */ { 216.0f
, /* SGI */ 240.0f
, },
748 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
749 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
753 { /* 20 Mhz */ { 130.0f
, /* SGI */ 144.4f
, },
754 /* 40 Mhz */ { 270.0f
, /* SGI */ 300.0f
, },
758 { /* 20 Mhz */ { 130.0f
, /* SGI */ 144.4f
, },
759 /* 40 Mhz */ { 270.0f
, /* SGI */ 300.0f
, },
763 { /* 20 Mhz */ { 143.0f
, /* SGI */ 158.9f
, },
764 /* 40 Mhz */ { 297.0f
, /* SGI */ 330.0f
, },
768 { /* 20 Mhz */ { 97.5f
, /* SGI */ 108.3f
, },
769 /* 40 Mhz */ { 202.5f
, /* SGI */ 225.0f
, },
773 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
774 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
778 { /* 20 Mhz */ { 136.5f
, /* SGI */ 151.7f
, },
779 /* 40 Mhz */ { 283.5f
, /* SGI */ 315.0f
, },
783 { /* 20 Mhz */ { 117.0f
, /* SGI */ 130.0f
, },
784 /* 40 Mhz */ { 243.0f
, /* SGI */ 270.0f
, },
788 { /* 20 Mhz */ { 136.5f
, /* SGI */ 151.7f
, },
789 /* 40 Mhz */ { 283.5f
, /* SGI */ 315.0f
, },
793 { /* 20 Mhz */ { 156.0f
, /* SGI */ 173.3f
, },
794 /* 40 Mhz */ { 324.0f
, /* SGI */ 360.0f
, },
798 { /* 20 Mhz */ { 175.5f
, /* SGI */ 195.0f
, },
799 /* 40 Mhz */ { 364.5f
, /* SGI */ 405.0f
, },
803 { /* 20 Mhz */ { 156.0f
, /* SGI */ 173.3f
, },
804 /* 40 Mhz */ { 324.0f
, /* SGI */ 360.0f
, },
808 { /* 20 Mhz */ { 175.5f
, /* SGI */ 195.0f
, },
809 /* 40 Mhz */ { 364.5f
, /* SGI */ 405.0f
, },
813 { /* 20 Mhz */ { 195.0f
, /* SGI */ 216.7f
, },
814 /* 40 Mhz */ { 405.0f
, /* SGI */ 450.0f
, },
818 { /* 20 Mhz */ { 195.0f
, /* SGI */ 216.7f
, },
819 /* 40 Mhz */ { 405.0f
, /* SGI */ 450.0f
, },
823 { /* 20 Mhz */ { 214.5f
, /* SGI */ 238.3f
, },
824 /* 40 Mhz */ { 445.5f
, /* SGI */ 495.0f
, },
828 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
829 #define NUM_AUTH_ALGS (sizeof(auth_alg_text) / sizeof(auth_alg_text[0]))
831 static const char *status_text
[] = {
832 "Successful", /* 0 */
833 "Unspecified failure", /* 1 */
842 "Cannot Support all requested capabilities in the Capability "
843 "Information field", /* 10 */
844 "Reassociation denied due to inability to confirm that association "
846 "Association denied due to reason outside the scope of the "
848 "Responding station does not support the specified authentication "
849 "algorithm ", /* 13 */
850 "Received an Authentication frame with authentication transaction "
851 "sequence number out of expected sequence", /* 14 */
852 "Authentication rejected because of challenge failure", /* 15 */
853 "Authentication rejected due to timeout waiting for next frame in "
855 "Association denied because AP is unable to handle additional"
856 "associated stations", /* 17 */
857 "Association denied due to requesting station not supporting all of "
858 "the data rates in BSSBasicRateSet parameter", /* 18 */
859 "Association denied due to requesting station not supporting "
860 "short preamble operation", /* 19 */
861 "Association denied due to requesting station not supporting "
862 "PBCC encoding", /* 20 */
863 "Association denied due to requesting station not supporting "
864 "channel agility", /* 21 */
865 "Association request rejected because Spectrum Management "
866 "capability is required", /* 22 */
867 "Association request rejected because the information in the "
868 "Power Capability element is unacceptable", /* 23 */
869 "Association request rejected because the information in the "
870 "Supported Channels element is unacceptable", /* 24 */
871 "Association denied due to requesting station not supporting "
872 "short slot operation", /* 25 */
873 "Association denied due to requesting station not supporting "
874 "DSSS-OFDM operation", /* 26 */
875 "Association denied because the requested STA does not support HT "
878 "Association denied because the requested STA does not support "
879 "the PCO transition time required by the AP", /* 29 */
882 "Unspecified, QoS-related failure", /* 32 */
883 "Association denied due to QAP having insufficient bandwidth "
884 "to handle another QSTA", /* 33 */
885 "Association denied due to excessive frame loss rates and/or "
886 "poor conditions on current operating channel", /* 34 */
887 "Association (with QBSS) denied due to requesting station not "
888 "supporting the QoS facility", /* 35 */
889 "Association denied due to requesting station not supporting "
890 "Block Ack", /* 36 */
891 "The request has been declined", /* 37 */
892 "The request has not been successful as one or more parameters "
893 "have invalid values", /* 38 */
894 "The TS has not been created because the request cannot be honored. "
895 "Try again with the suggested changes to the TSPEC", /* 39 */
896 "Invalid Information Element", /* 40 */
897 "Group Cipher is not valid", /* 41 */
898 "Pairwise Cipher is not valid", /* 42 */
899 "AKMP is not valid", /* 43 */
900 "Unsupported RSN IE version", /* 44 */
901 "Invalid RSN IE Capabilities", /* 45 */
902 "Cipher suite is rejected per security policy", /* 46 */
903 "The TS has not been created. However, the HC may be capable of "
904 "creating a TS, in response to a request, after the time indicated "
905 "in the TS Delay element", /* 47 */
906 "Direct Link is not allowed in the BSS by policy", /* 48 */
907 "Destination STA is not present within this QBSS.", /* 49 */
908 "The Destination STA is not a QSTA.", /* 50 */
911 #define NUM_STATUSES (sizeof(status_text) / sizeof(status_text[0]))
913 static const char *reason_text
[] = {
915 "Unspecified reason", /* 1 */
916 "Previous authentication no longer valid", /* 2 */
917 "Deauthenticated because sending station is leaving (or has left) "
918 "IBSS or ESS", /* 3 */
919 "Disassociated due to inactivity", /* 4 */
920 "Disassociated because AP is unable to handle all currently "
921 " associated stations", /* 5 */
922 "Class 2 frame received from nonauthenticated station", /* 6 */
923 "Class 3 frame received from nonassociated station", /* 7 */
924 "Disassociated because sending station is leaving "
925 "(or has left) BSS", /* 8 */
926 "Station requesting (re)association is not authenticated with "
927 "responding station", /* 9 */
928 "Disassociated because the information in the Power Capability "
929 "element is unacceptable", /* 10 */
930 "Disassociated because the information in the SupportedChannels "
931 "element is unacceptable", /* 11 */
932 "Invalid Information Element", /* 12 */
934 "Michael MIC failure", /* 14 */
935 "4-Way Handshake timeout", /* 15 */
936 "Group key update timeout", /* 16 */
937 "Information element in 4-Way Handshake different from (Re)Association"
938 "Request/Probe Response/Beacon", /* 17 */
939 "Group Cipher is not valid", /* 18 */
940 "AKMP is not valid", /* 20 */
941 "Unsupported RSN IE version", /* 21 */
942 "Invalid RSN IE Capabilities", /* 22 */
943 "IEEE 802.1X Authentication failed", /* 23 */
944 "Cipher suite is rejected per security policy", /* 24 */
951 "TS deleted because QoS AP lacks sufficient bandwidth for this "
952 "QoS STA due to a change in BSS service characteristics or "
953 "operational mode (e.g. an HT BSS change from 40 MHz channel "
954 "to 20 MHz channel)", /* 31 */
955 "Disassociated for unspecified, QoS-related reason", /* 32 */
956 "Disassociated because QoS AP lacks sufficient bandwidth for this "
958 "Disassociated because of excessive number of frames that need to be "
959 "acknowledged, but are not acknowledged for AP transmissions "
960 "and/or poor channel conditions", /* 34 */
961 "Disassociated because STA is transmitting outside the limits "
962 "of its TXOPs", /* 35 */
963 "Requested from peer STA as the STA is leaving the BSS "
964 "(or resetting)", /* 36 */
965 "Requested from peer STA as it does not want to use the "
966 "mechanism", /* 37 */
967 "Requested from peer STA as the STA received frames using the "
968 "mechanism for which a set up is required", /* 38 */
969 "Requested from peer STA due to time out", /* 39 */
975 "Peer STA does not support the requested cipher suite", /* 45 */
976 "Association denied due to requesting STA not supporting HT "
979 #define NUM_REASONS (sizeof(reason_text) / sizeof(reason_text[0]))
982 wep_print(netdissect_options
*ndo
,
987 if (!ND_TTEST_LEN(p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
989 iv
= EXTRACT_LE_U_4(p
);
991 ND_PRINT(" IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
998 parse_elements(netdissect_options
*ndo
,
999 struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
,
1004 struct challenge_t challenge
;
1005 struct rates_t rates
;
1011 * We haven't seen any elements yet.
1013 pbody
->challenge_present
= 0;
1014 pbody
->ssid_present
= 0;
1015 pbody
->rates_present
= 0;
1016 pbody
->ds_present
= 0;
1017 pbody
->cf_present
= 0;
1018 pbody
->tim_present
= 0;
1020 while (length
!= 0) {
1021 /* Make sure we at least have the element ID and length. */
1022 if (!ND_TTEST_2(p
+ offset
))
1026 elementlen
= EXTRACT_U_1(p
+ offset
+ 1);
1028 /* Make sure we have the entire element. */
1029 if (!ND_TTEST_LEN(p
+ offset
+ 2, elementlen
))
1031 if (length
< elementlen
+ 2)
1034 switch (EXTRACT_U_1(p
+ offset
)) {
1036 memcpy(&ssid
, p
+ offset
, 2);
1039 if (ssid
.length
!= 0) {
1040 if (ssid
.length
> sizeof(ssid
.ssid
) - 1)
1042 memcpy(&ssid
.ssid
, p
+ offset
, ssid
.length
);
1043 offset
+= ssid
.length
;
1044 length
-= ssid
.length
;
1046 ssid
.ssid
[ssid
.length
] = '\0';
1048 * Present and not truncated.
1050 * If we haven't already seen an SSID IE,
1051 * copy this one, otherwise ignore this one,
1052 * so we later report the first one we saw.
1054 if (!pbody
->ssid_present
) {
1056 pbody
->ssid_present
= 1;
1060 memcpy(&challenge
, p
+ offset
, 2);
1063 if (challenge
.length
!= 0) {
1064 if (challenge
.length
>
1065 sizeof(challenge
.text
) - 1)
1067 memcpy(&challenge
.text
, p
+ offset
,
1069 offset
+= challenge
.length
;
1070 length
-= challenge
.length
;
1072 challenge
.text
[challenge
.length
] = '\0';
1074 * Present and not truncated.
1076 * If we haven't already seen a challenge IE,
1077 * copy this one, otherwise ignore this one,
1078 * so we later report the first one we saw.
1080 if (!pbody
->challenge_present
) {
1081 pbody
->challenge
= challenge
;
1082 pbody
->challenge_present
= 1;
1086 memcpy(&rates
, p
+ offset
, 2);
1089 if (rates
.length
!= 0) {
1090 if (rates
.length
> sizeof(rates
.rate
))
1092 memcpy(&rates
.rate
, p
+ offset
, rates
.length
);
1093 offset
+= rates
.length
;
1094 length
-= rates
.length
;
1097 * Present and not truncated.
1099 * If we haven't already seen a rates IE,
1100 * copy this one if it's not zero-length,
1101 * otherwise ignore this one, so we later
1102 * report the first one we saw.
1104 * We ignore zero-length rates IEs as some
1105 * devices seem to put a zero-length rates
1106 * IE, followed by an SSID IE, followed by
1107 * a non-zero-length rates IE into frames,
1108 * even though IEEE Std 802.11-2007 doesn't
1109 * seem to indicate that a zero-length rates
1112 if (!pbody
->rates_present
&& rates
.length
!= 0) {
1113 pbody
->rates
= rates
;
1114 pbody
->rates_present
= 1;
1118 memcpy(&ds
, p
+ offset
, 2);
1121 if (ds
.length
!= 1) {
1122 offset
+= ds
.length
;
1123 length
-= ds
.length
;
1126 ds
.channel
= EXTRACT_U_1(p
+ offset
);
1130 * Present and not truncated.
1132 * If we haven't already seen a DS IE,
1133 * copy this one, otherwise ignore this one,
1134 * so we later report the first one we saw.
1136 if (!pbody
->ds_present
) {
1138 pbody
->ds_present
= 1;
1142 memcpy(&cf
, p
+ offset
, 2);
1145 if (cf
.length
!= 6) {
1146 offset
+= cf
.length
;
1147 length
-= cf
.length
;
1150 memcpy(&cf
.count
, p
+ offset
, 6);
1154 * Present and not truncated.
1156 * If we haven't already seen a CF IE,
1157 * copy this one, otherwise ignore this one,
1158 * so we later report the first one we saw.
1160 if (!pbody
->cf_present
) {
1162 pbody
->cf_present
= 1;
1166 memcpy(&tim
, p
+ offset
, 2);
1169 if (tim
.length
<= 3U) {
1170 offset
+= tim
.length
;
1171 length
-= tim
.length
;
1174 if (tim
.length
- 3U > sizeof(tim
.bitmap
))
1176 memcpy(&tim
.count
, p
+ offset
, 3);
1180 memcpy(tim
.bitmap
, p
+ offset
, tim
.length
- 3);
1181 offset
+= tim
.length
- 3;
1182 length
-= tim
.length
- 3;
1184 * Present and not truncated.
1186 * If we haven't already seen a TIM IE,
1187 * copy this one, otherwise ignore this one,
1188 * so we later report the first one we saw.
1190 if (!pbody
->tim_present
) {
1192 pbody
->tim_present
= 1;
1197 ND_PRINT("(1) unhandled element_id (%u) ",
1198 EXTRACT_U_1(p
+ offset
));
1200 offset
+= 2 + elementlen
;
1201 length
-= 2 + elementlen
;
1206 /* No problems found. */
1210 /*********************************************************************************
1211 * Print Handle functions for the management frame types
1212 *********************************************************************************/
1215 handle_beacon(netdissect_options
*ndo
,
1216 const u_char
*p
, u_int length
)
1218 struct mgmt_body_t pbody
;
1222 memset(&pbody
, 0, sizeof(pbody
));
1224 if (!ND_TTEST_LEN(p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+ IEEE802_11_CAPINFO_LEN
))
1226 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1227 IEEE802_11_CAPINFO_LEN
)
1229 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1230 offset
+= IEEE802_11_TSTAMP_LEN
;
1231 length
-= IEEE802_11_TSTAMP_LEN
;
1232 pbody
.beacon_interval
= EXTRACT_LE_U_2(p
+ offset
);
1233 offset
+= IEEE802_11_BCNINT_LEN
;
1234 length
-= IEEE802_11_BCNINT_LEN
;
1235 pbody
.capability_info
= EXTRACT_LE_U_2(p
+ offset
);
1236 offset
+= IEEE802_11_CAPINFO_LEN
;
1237 length
-= IEEE802_11_CAPINFO_LEN
;
1239 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1244 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS");
1245 PRINT_DS_CHANNEL(pbody
);
1251 handle_assoc_request(netdissect_options
*ndo
,
1252 const u_char
*p
, u_int length
)
1254 struct mgmt_body_t pbody
;
1258 memset(&pbody
, 0, sizeof(pbody
));
1260 if (!ND_TTEST_LEN(p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
1262 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
)
1264 pbody
.capability_info
= EXTRACT_LE_U_2(p
);
1265 offset
+= IEEE802_11_CAPINFO_LEN
;
1266 length
-= IEEE802_11_CAPINFO_LEN
;
1267 pbody
.listen_interval
= EXTRACT_LE_U_2(p
+ offset
);
1268 offset
+= IEEE802_11_LISTENINT_LEN
;
1269 length
-= IEEE802_11_LISTENINT_LEN
;
1271 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1279 handle_assoc_response(netdissect_options
*ndo
,
1280 const u_char
*p
, u_int length
)
1282 struct mgmt_body_t pbody
;
1286 memset(&pbody
, 0, sizeof(pbody
));
1288 if (!ND_TTEST_LEN(p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+ IEEE802_11_AID_LEN
))
1290 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1293 pbody
.capability_info
= EXTRACT_LE_U_2(p
);
1294 offset
+= IEEE802_11_CAPINFO_LEN
;
1295 length
-= IEEE802_11_CAPINFO_LEN
;
1296 pbody
.status_code
= EXTRACT_LE_U_2(p
+ offset
);
1297 offset
+= IEEE802_11_STATUS_LEN
;
1298 length
-= IEEE802_11_STATUS_LEN
;
1299 pbody
.aid
= EXTRACT_LE_U_2(p
+ offset
);
1300 offset
+= IEEE802_11_AID_LEN
;
1301 length
-= IEEE802_11_AID_LEN
;
1303 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1305 ND_PRINT(" AID(%x) :%s: %s", ((uint16_t)(pbody
.aid
<< 2 )) >> 2 ,
1306 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
1307 (pbody
.status_code
< NUM_STATUSES
1308 ? status_text
[pbody
.status_code
]
1315 handle_reassoc_request(netdissect_options
*ndo
,
1316 const u_char
*p
, u_int length
)
1318 struct mgmt_body_t pbody
;
1322 memset(&pbody
, 0, sizeof(pbody
));
1324 if (!ND_TTEST_LEN(p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+ IEEE802_11_AP_LEN
))
1326 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1329 pbody
.capability_info
= EXTRACT_LE_U_2(p
);
1330 offset
+= IEEE802_11_CAPINFO_LEN
;
1331 length
-= IEEE802_11_CAPINFO_LEN
;
1332 pbody
.listen_interval
= EXTRACT_LE_U_2(p
+ offset
);
1333 offset
+= IEEE802_11_LISTENINT_LEN
;
1334 length
-= IEEE802_11_LISTENINT_LEN
;
1335 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
1336 offset
+= IEEE802_11_AP_LEN
;
1337 length
-= IEEE802_11_AP_LEN
;
1339 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1342 ND_PRINT(" AP : %s", etheraddr_string(ndo
, pbody
.ap
));
1348 handle_reassoc_response(netdissect_options
*ndo
,
1349 const u_char
*p
, u_int length
)
1351 /* Same as a Association Reponse */
1352 return handle_assoc_response(ndo
, p
, length
);
1356 handle_probe_request(netdissect_options
*ndo
,
1357 const u_char
*p
, u_int length
)
1359 struct mgmt_body_t pbody
;
1363 memset(&pbody
, 0, sizeof(pbody
));
1365 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1374 handle_probe_response(netdissect_options
*ndo
,
1375 const u_char
*p
, u_int length
)
1377 struct mgmt_body_t pbody
;
1381 memset(&pbody
, 0, sizeof(pbody
));
1383 if (!ND_TTEST_LEN(p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+ IEEE802_11_CAPINFO_LEN
))
1385 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1386 IEEE802_11_CAPINFO_LEN
)
1388 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1389 offset
+= IEEE802_11_TSTAMP_LEN
;
1390 length
-= IEEE802_11_TSTAMP_LEN
;
1391 pbody
.beacon_interval
= EXTRACT_LE_U_2(p
+ offset
);
1392 offset
+= IEEE802_11_BCNINT_LEN
;
1393 length
-= IEEE802_11_BCNINT_LEN
;
1394 pbody
.capability_info
= EXTRACT_LE_U_2(p
+ offset
);
1395 offset
+= IEEE802_11_CAPINFO_LEN
;
1396 length
-= IEEE802_11_CAPINFO_LEN
;
1398 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1402 PRINT_DS_CHANNEL(pbody
);
1410 /* the frame body for ATIM is null. */
1415 handle_disassoc(netdissect_options
*ndo
,
1416 const u_char
*p
, u_int length
)
1418 struct mgmt_body_t pbody
;
1420 memset(&pbody
, 0, sizeof(pbody
));
1422 if (!ND_TTEST_LEN(p
, IEEE802_11_REASON_LEN
))
1424 if (length
< IEEE802_11_REASON_LEN
)
1426 pbody
.reason_code
= EXTRACT_LE_U_2(p
);
1429 (pbody
.reason_code
< NUM_REASONS
)
1430 ? reason_text
[pbody
.reason_code
]
1437 handle_auth(netdissect_options
*ndo
,
1438 const u_char
*p
, u_int length
)
1440 struct mgmt_body_t pbody
;
1444 memset(&pbody
, 0, sizeof(pbody
));
1450 pbody
.auth_alg
= EXTRACT_LE_U_2(p
);
1453 pbody
.auth_trans_seq_num
= EXTRACT_LE_U_2(p
+ offset
);
1456 pbody
.status_code
= EXTRACT_LE_U_2(p
+ offset
);
1460 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1462 if ((pbody
.auth_alg
== 1) &&
1463 ((pbody
.auth_trans_seq_num
== 2) ||
1464 (pbody
.auth_trans_seq_num
== 3))) {
1465 ND_PRINT(" (%s)-%x [Challenge Text] %s",
1466 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1467 ? auth_alg_text
[pbody
.auth_alg
]
1469 pbody
.auth_trans_seq_num
,
1470 ((pbody
.auth_trans_seq_num
% 2)
1471 ? ((pbody
.status_code
< NUM_STATUSES
)
1472 ? status_text
[pbody
.status_code
]
1476 ND_PRINT(" (%s)-%x: %s",
1477 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1478 ? auth_alg_text
[pbody
.auth_alg
]
1480 pbody
.auth_trans_seq_num
,
1481 (pbody
.auth_trans_seq_num
% 2)
1482 ? ((pbody
.status_code
< NUM_STATUSES
)
1483 ? status_text
[pbody
.status_code
]
1491 handle_deauth(netdissect_options
*ndo
,
1492 const uint8_t *src
, const u_char
*p
, u_int length
)
1494 struct mgmt_body_t pbody
;
1495 const char *reason
= NULL
;
1497 memset(&pbody
, 0, sizeof(pbody
));
1499 if (!ND_TTEST_LEN(p
, IEEE802_11_REASON_LEN
))
1501 if (length
< IEEE802_11_REASON_LEN
)
1503 pbody
.reason_code
= EXTRACT_LE_U_2(p
);
1505 reason
= (pbody
.reason_code
< NUM_REASONS
)
1506 ? reason_text
[pbody
.reason_code
]
1509 if (ndo
->ndo_eflag
) {
1510 ND_PRINT(": %s", reason
);
1512 ND_PRINT(" (%s): %s", etheraddr_string(ndo
, src
), reason
);
1517 #define PRINT_HT_ACTION(v) (\
1518 (v) == 0 ? ND_PRINT("TxChWidth"): \
1519 (v) == 1 ? ND_PRINT("MIMOPwrSave"): \
1520 ND_PRINT("Act#%u", (v)))
1521 #define PRINT_BA_ACTION(v) (\
1522 (v) == 0 ? ND_PRINT("ADDBA Request"): \
1523 (v) == 1 ? ND_PRINT("ADDBA Response"): \
1524 (v) == 2 ? ND_PRINT("DELBA"): \
1525 ND_PRINT("Act#%u", (v)))
1526 #define PRINT_MESHLINK_ACTION(v) (\
1527 (v) == 0 ? ND_PRINT("Request"): \
1528 (v) == 1 ? ND_PRINT("Report"): \
1529 ND_PRINT("Act#%u", (v)))
1530 #define PRINT_MESHPEERING_ACTION(v) (\
1531 (v) == 0 ? ND_PRINT("Open"): \
1532 (v) == 1 ? ND_PRINT("Confirm"): \
1533 (v) == 2 ? ND_PRINT("Close"): \
1534 ND_PRINT("Act#%u", (v)))
1535 #define PRINT_MESHPATH_ACTION(v) (\
1536 (v) == 0 ? ND_PRINT("Request"): \
1537 (v) == 1 ? ND_PRINT("Report"): \
1538 (v) == 2 ? ND_PRINT("Error"): \
1539 (v) == 3 ? ND_PRINT("RootAnnouncement"): \
1540 ND_PRINT("Act#%u", (v)))
1542 #define PRINT_MESH_ACTION(v) (\
1543 (v) == 0 ? ND_PRINT("MeshLink"): \
1544 (v) == 1 ? ND_PRINT("HWMP"): \
1545 (v) == 2 ? ND_PRINT("Gate Announcement"): \
1546 (v) == 3 ? ND_PRINT("Congestion Control"): \
1547 (v) == 4 ? ND_PRINT("MCCA Setup Request"): \
1548 (v) == 5 ? ND_PRINT("MCCA Setup Reply"): \
1549 (v) == 6 ? ND_PRINT("MCCA Advertisement Request"): \
1550 (v) == 7 ? ND_PRINT("MCCA Advertisement"): \
1551 (v) == 8 ? ND_PRINT("MCCA Teardown"): \
1552 (v) == 9 ? ND_PRINT("TBTT Adjustment Request"): \
1553 (v) == 10 ? ND_PRINT("TBTT Adjustment Response"): \
1554 ND_PRINT("Act#%u", (v)))
1555 #define PRINT_MULTIHOP_ACTION(v) (\
1556 (v) == 0 ? ND_PRINT("Proxy Update"): \
1557 (v) == 1 ? ND_PRINT("Proxy Update Confirmation"): \
1558 ND_PRINT("Act#%u", (v)))
1559 #define PRINT_SELFPROT_ACTION(v) (\
1560 (v) == 1 ? ND_PRINT("Peering Open"): \
1561 (v) == 2 ? ND_PRINT("Peering Confirm"): \
1562 (v) == 3 ? ND_PRINT("Peering Close"): \
1563 (v) == 4 ? ND_PRINT("Group Key Inform"): \
1564 (v) == 5 ? ND_PRINT("Group Key Acknowledge"): \
1565 ND_PRINT("Act#%u", (v)))
1568 handle_action(netdissect_options
*ndo
,
1569 const uint8_t *src
, const u_char
*p
, u_int length
)
1575 if (ndo
->ndo_eflag
) {
1578 ND_PRINT(" (%s): ", etheraddr_string(ndo
, src
));
1580 switch (EXTRACT_U_1(p
)) {
1581 case 0: ND_PRINT("Spectrum Management Act#%u", EXTRACT_U_1(p
+ 1)); break;
1582 case 1: ND_PRINT("QoS Act#%u", EXTRACT_U_1(p
+ 1)); break;
1583 case 2: ND_PRINT("DLS Act#%u", EXTRACT_U_1(p
+ 1)); break;
1584 case 3: ND_PRINT("BA "); PRINT_BA_ACTION(EXTRACT_U_1(p
+ 1)); break;
1585 case 7: ND_PRINT("HT "); PRINT_HT_ACTION(EXTRACT_U_1(p
+ 1)); break;
1586 case 13: ND_PRINT("MeshAction "); PRINT_MESH_ACTION(EXTRACT_U_1(p
+ 1)); break;
1588 ND_PRINT("MultiohopAction ");
1589 PRINT_MULTIHOP_ACTION(EXTRACT_U_1(p
+ 1)); break;
1591 ND_PRINT("SelfprotectAction ");
1592 PRINT_SELFPROT_ACTION(EXTRACT_U_1(p
+ 1)); break;
1593 case 127: ND_PRINT("Vendor Act#%u", EXTRACT_U_1(p
+ 1)); break;
1595 ND_PRINT("Reserved(%u) Act#%u", EXTRACT_U_1(p
), EXTRACT_U_1(p
+ 1));
1602 /*********************************************************************************
1604 *********************************************************************************/
1608 mgmt_body_print(netdissect_options
*ndo
,
1609 uint16_t fc
, const uint8_t *src
, const u_char
*p
, u_int length
)
1611 ND_PRINT("%s", tok2str(st_str
, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc
)));
1613 /* There may be a problem w/ AP not having this bit set */
1614 if (FC_PROTECTED(fc
))
1615 return wep_print(ndo
, p
);
1616 switch (FC_SUBTYPE(fc
)) {
1617 case ST_ASSOC_REQUEST
:
1618 return handle_assoc_request(ndo
, p
, length
);
1619 case ST_ASSOC_RESPONSE
:
1620 return handle_assoc_response(ndo
, p
, length
);
1621 case ST_REASSOC_REQUEST
:
1622 return handle_reassoc_request(ndo
, p
, length
);
1623 case ST_REASSOC_RESPONSE
:
1624 return handle_reassoc_response(ndo
, p
, length
);
1625 case ST_PROBE_REQUEST
:
1626 return handle_probe_request(ndo
, p
, length
);
1627 case ST_PROBE_RESPONSE
:
1628 return handle_probe_response(ndo
, p
, length
);
1630 return handle_beacon(ndo
, p
, length
);
1632 return handle_atim();
1634 return handle_disassoc(ndo
, p
, length
);
1636 return handle_auth(ndo
, p
, length
);
1638 return handle_deauth(ndo
, src
, p
, length
);
1640 return handle_action(ndo
, src
, p
, length
);
1647 /*********************************************************************************
1648 * Handles printing all the control frame types
1649 *********************************************************************************/
1652 ctrl_body_print(netdissect_options
*ndo
,
1653 uint16_t fc
, const u_char
*p
)
1655 ND_PRINT("%s", tok2str(ctrl_str
, "Unknown Ctrl Subtype", FC_SUBTYPE(fc
)));
1656 switch (FC_SUBTYPE(fc
)) {
1657 case CTRL_CONTROL_WRAPPER
:
1658 /* XXX - requires special handling */
1661 if (!ND_TTEST_LEN(p
, CTRL_BAR_HDRLEN
))
1663 if (!ndo
->ndo_eflag
)
1664 ND_PRINT(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
1665 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ra
),
1666 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ta
),
1667 EXTRACT_LE_U_2(((const struct ctrl_bar_hdr_t
*)p
)->ctl
),
1668 EXTRACT_LE_U_2(((const struct ctrl_bar_hdr_t
*)p
)->seq
));
1671 if (!ND_TTEST_LEN(p
, CTRL_BA_HDRLEN
))
1673 if (!ndo
->ndo_eflag
)
1675 etheraddr_string(ndo
, ((const struct ctrl_ba_hdr_t
*)p
)->ra
));
1678 if (!ND_TTEST_LEN(p
, CTRL_PS_POLL_HDRLEN
))
1680 ND_PRINT(" AID(%x)",
1681 EXTRACT_LE_U_2(((const struct ctrl_ps_poll_hdr_t
*)p
)->aid
));
1684 if (!ND_TTEST_LEN(p
, CTRL_RTS_HDRLEN
))
1686 if (!ndo
->ndo_eflag
)
1688 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ta
));
1691 if (!ND_TTEST_LEN(p
, CTRL_CTS_HDRLEN
))
1693 if (!ndo
->ndo_eflag
)
1695 etheraddr_string(ndo
, ((const struct ctrl_cts_hdr_t
*)p
)->ra
));
1698 if (!ND_TTEST_LEN(p
, CTRL_ACK_HDRLEN
))
1700 if (!ndo
->ndo_eflag
)
1702 etheraddr_string(ndo
, ((const struct ctrl_ack_hdr_t
*)p
)->ra
));
1705 if (!ND_TTEST_LEN(p
, CTRL_END_HDRLEN
))
1707 if (!ndo
->ndo_eflag
)
1709 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->ra
));
1712 if (!ND_TTEST_LEN(p
, CTRL_END_ACK_HDRLEN
))
1714 if (!ndo
->ndo_eflag
)
1716 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->ra
));
1723 * Data Frame - Address field contents
1725 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
1726 * 0 | 0 | DA | SA | BSSID | n/a
1727 * 0 | 1 | DA | BSSID | SA | n/a
1728 * 1 | 0 | BSSID | SA | DA | n/a
1729 * 1 | 1 | RA | TA | DA | SA
1733 * Function to get source and destination MAC addresses for a data frame.
1736 get_data_src_dst_mac(uint16_t fc
, const u_char
*p
, const uint8_t **srcp
,
1737 const uint8_t **dstp
)
1739 #define ADDR1 (p + 4)
1740 #define ADDR2 (p + 10)
1741 #define ADDR3 (p + 16)
1742 #define ADDR4 (p + 24)
1744 if (!FC_TO_DS(fc
)) {
1745 if (!FC_FROM_DS(fc
)) {
1746 /* not To DS and not From DS */
1750 /* not To DS and From DS */
1755 if (!FC_FROM_DS(fc
)) {
1756 /* From DS and not To DS */
1760 /* To DS and From DS */
1773 get_mgmt_src_dst_mac(const u_char
*p
, const uint8_t **srcp
, const uint8_t **dstp
)
1775 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
1784 * Print Header funcs
1788 data_header_print(netdissect_options
*ndo
, uint16_t fc
, const u_char
*p
)
1790 u_int subtype
= FC_SUBTYPE(fc
);
1792 if (DATA_FRAME_IS_CF_ACK(subtype
) || DATA_FRAME_IS_CF_POLL(subtype
) ||
1793 DATA_FRAME_IS_QOS(subtype
)) {
1795 if (DATA_FRAME_IS_CF_ACK(subtype
)) {
1796 if (DATA_FRAME_IS_CF_POLL(subtype
))
1797 ND_PRINT("Ack/Poll");
1801 if (DATA_FRAME_IS_CF_POLL(subtype
))
1804 if (DATA_FRAME_IS_QOS(subtype
))
1809 #define ADDR1 (p + 4)
1810 #define ADDR2 (p + 10)
1811 #define ADDR3 (p + 16)
1812 #define ADDR4 (p + 24)
1814 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
1815 ND_PRINT("DA:%s SA:%s BSSID:%s ",
1816 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1817 etheraddr_string(ndo
, ADDR3
));
1818 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
1819 ND_PRINT("DA:%s BSSID:%s SA:%s ",
1820 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1821 etheraddr_string(ndo
, ADDR3
));
1822 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
1823 ND_PRINT("BSSID:%s SA:%s DA:%s ",
1824 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1825 etheraddr_string(ndo
, ADDR3
));
1826 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
1827 ND_PRINT("RA:%s TA:%s DA:%s SA:%s ",
1828 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1829 etheraddr_string(ndo
, ADDR3
), etheraddr_string(ndo
, ADDR4
));
1839 mgmt_header_print(netdissect_options
*ndo
, const u_char
*p
)
1841 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
1843 ND_PRINT("BSSID:%s DA:%s SA:%s ",
1844 etheraddr_string(ndo
, (hp
)->bssid
), etheraddr_string(ndo
, (hp
)->da
),
1845 etheraddr_string(ndo
, (hp
)->sa
));
1849 ctrl_header_print(netdissect_options
*ndo
, uint16_t fc
, const u_char
*p
)
1851 switch (FC_SUBTYPE(fc
)) {
1853 ND_PRINT(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
1854 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ra
),
1855 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ta
),
1856 EXTRACT_LE_U_2(((const struct ctrl_bar_hdr_t
*)p
)->ctl
),
1857 EXTRACT_LE_U_2(((const struct ctrl_bar_hdr_t
*)p
)->seq
));
1861 etheraddr_string(ndo
, ((const struct ctrl_ba_hdr_t
*)p
)->ra
));
1864 ND_PRINT("BSSID:%s TA:%s ",
1865 etheraddr_string(ndo
, ((const struct ctrl_ps_poll_hdr_t
*)p
)->bssid
),
1866 etheraddr_string(ndo
, ((const struct ctrl_ps_poll_hdr_t
*)p
)->ta
));
1869 ND_PRINT("RA:%s TA:%s ",
1870 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ra
),
1871 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ta
));
1875 etheraddr_string(ndo
, ((const struct ctrl_cts_hdr_t
*)p
)->ra
));
1879 etheraddr_string(ndo
, ((const struct ctrl_ack_hdr_t
*)p
)->ra
));
1882 ND_PRINT("RA:%s BSSID:%s ",
1883 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->ra
),
1884 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->bssid
));
1887 ND_PRINT("RA:%s BSSID:%s ",
1888 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->ra
),
1889 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->bssid
));
1892 /* We shouldn't get here - we should already have quit */
1898 extract_header_length(netdissect_options
*ndo
,
1903 switch (FC_TYPE(fc
)) {
1907 switch (FC_SUBTYPE(fc
)) {
1908 case CTRL_CONTROL_WRAPPER
:
1909 return CTRL_CONTROL_WRAPPER_HDRLEN
;
1911 return CTRL_BAR_HDRLEN
;
1913 return CTRL_BA_HDRLEN
;
1915 return CTRL_PS_POLL_HDRLEN
;
1917 return CTRL_RTS_HDRLEN
;
1919 return CTRL_CTS_HDRLEN
;
1921 return CTRL_ACK_HDRLEN
;
1923 return CTRL_END_HDRLEN
;
1925 return CTRL_END_ACK_HDRLEN
;
1927 ND_PRINT("unknown 802.11 ctrl frame subtype (%u)", FC_SUBTYPE(fc
));
1931 len
= (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
1932 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
)))
1936 ND_PRINT("unknown 802.11 frame type (%u)", FC_TYPE(fc
));
1942 extract_mesh_header_length(const u_char
*p
)
1944 return (EXTRACT_U_1(p
) &~ 3) ? 0 : 6*(1 + (EXTRACT_U_1(p
) & 3));
1948 * Print the 802.11 MAC header.
1951 ieee_802_11_hdr_print(netdissect_options
*ndo
,
1952 uint16_t fc
, const u_char
*p
, u_int hdrlen
,
1955 if (ndo
->ndo_vflag
) {
1956 if (FC_MORE_DATA(fc
))
1957 ND_PRINT("More Data ");
1958 if (FC_MORE_FLAG(fc
))
1959 ND_PRINT("More Fragments ");
1960 if (FC_POWER_MGMT(fc
))
1961 ND_PRINT("Pwr Mgmt ");
1965 ND_PRINT("Strictly Ordered ");
1966 if (FC_PROTECTED(fc
))
1967 ND_PRINT("Protected ");
1968 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
1970 EXTRACT_LE_U_2(((const struct mgmt_header_t
*)p
)->duration
));
1972 if (meshdrlen
!= 0) {
1973 const struct meshcntl_t
*mc
=
1974 (const struct meshcntl_t
*)(p
+ hdrlen
- meshdrlen
);
1975 u_int ae
= EXTRACT_U_1(mc
->flags
) & 3;
1977 ND_PRINT("MeshData (AE %u TTL %u seq %u", ae
,
1978 EXTRACT_U_1(mc
->ttl
), EXTRACT_LE_U_4(mc
->seq
));
1980 ND_PRINT(" A4:%s", etheraddr_string(ndo
, mc
->addr4
));
1982 ND_PRINT(" A5:%s", etheraddr_string(ndo
, mc
->addr5
));
1984 ND_PRINT(" A6:%s", etheraddr_string(ndo
, mc
->addr6
));
1988 switch (FC_TYPE(fc
)) {
1990 mgmt_header_print(ndo
, p
);
1993 ctrl_header_print(ndo
, fc
, p
);
1996 data_header_print(ndo
, fc
, p
);
2004 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2007 static const char tstr
[] = "[|802.11]";
2010 ieee802_11_print(netdissect_options
*ndo
,
2011 const u_char
*p
, u_int length
, u_int orig_caplen
, int pad
,
2015 u_int caplen
, hdrlen
, meshdrlen
;
2016 struct lladdr_info src
, dst
;
2019 ndo
->ndo_protocol
= "802.11";
2020 caplen
= orig_caplen
;
2021 /* Remove FCS, if present */
2022 if (length
< fcslen
) {
2023 ND_PRINT("%s", tstr
);
2027 if (caplen
> length
) {
2028 /* Amount of FCS in actual packet data, if any */
2029 fcslen
= caplen
- length
;
2031 ndo
->ndo_snapend
-= fcslen
;
2034 if (caplen
< IEEE802_11_FC_LEN
) {
2035 ND_PRINT("%s", tstr
);
2039 fc
= EXTRACT_LE_U_2(p
);
2040 hdrlen
= extract_header_length(ndo
, fc
);
2042 /* Unknown frame type or control frame subtype; quit. */
2046 hdrlen
= roundup2(hdrlen
, 4);
2047 if (ndo
->ndo_Hflag
&& FC_TYPE(fc
) == T_DATA
&&
2048 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
))) {
2049 meshdrlen
= extract_mesh_header_length(p
+hdrlen
);
2050 hdrlen
+= meshdrlen
;
2054 if (caplen
< hdrlen
) {
2055 ND_PRINT("%s", tstr
);
2060 ieee_802_11_hdr_print(ndo
, fc
, p
, hdrlen
, meshdrlen
);
2063 * Go past the 802.11 header.
2069 src
.addr_string
= etheraddr_string
;
2070 dst
.addr_string
= etheraddr_string
;
2071 switch (FC_TYPE(fc
)) {
2073 get_mgmt_src_dst_mac(p
- hdrlen
, &src
.addr
, &dst
.addr
);
2074 if (!mgmt_body_print(ndo
, fc
, src
.addr
, p
, length
)) {
2075 ND_PRINT("%s", tstr
);
2080 if (!ctrl_body_print(ndo
, fc
, p
- hdrlen
)) {
2081 ND_PRINT("%s", tstr
);
2086 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc
)))
2087 return hdrlen
; /* no-data frame */
2088 /* There may be a problem w/ AP not having this bit set */
2089 if (FC_PROTECTED(fc
)) {
2091 if (!wep_print(ndo
, p
)) {
2092 ND_PRINT("%s", tstr
);
2096 get_data_src_dst_mac(fc
, p
- hdrlen
, &src
.addr
, &dst
.addr
);
2097 llc_hdrlen
= llc_print(ndo
, p
, length
, caplen
, &src
, &dst
);
2098 if (llc_hdrlen
< 0) {
2100 * Some kinds of LLC packet we cannot
2101 * handle intelligently
2103 if (!ndo
->ndo_suppress_default_print
)
2104 ND_DEFAULTPRINT(p
, caplen
);
2105 llc_hdrlen
= -llc_hdrlen
;
2107 hdrlen
+= llc_hdrlen
;
2111 /* We shouldn't get here - we should already have quit */
2119 * This is the top level routine of the printer. 'p' points
2120 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2121 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2122 * is the number of bytes actually captured.
2125 ieee802_11_if_print(netdissect_options
*ndo
,
2126 const struct pcap_pkthdr
*h
, const u_char
*p
)
2128 ndo
->ndo_protocol
= "802.11_if";
2129 return ieee802_11_print(ndo
, p
, h
->len
, h
->caplen
, 0, 0);
2133 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
2134 /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
2137 * Copyright (c) 2003, 2004 David Young. All rights reserved.
2139 * Redistribution and use in source and binary forms, with or without
2140 * modification, are permitted provided that the following conditions
2142 * 1. Redistributions of source code must retain the above copyright
2143 * notice, this list of conditions and the following disclaimer.
2144 * 2. Redistributions in binary form must reproduce the above copyright
2145 * notice, this list of conditions and the following disclaimer in the
2146 * documentation and/or other materials provided with the distribution.
2147 * 3. The name of David Young may not be used to endorse or promote
2148 * products derived from this software without specific prior
2149 * written permission.
2151 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
2152 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2153 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
2154 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
2155 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2156 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2157 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2158 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2159 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2160 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2161 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2165 /* A generic radio capture format is desirable. It must be
2166 * rigidly defined (e.g., units for fields should be given),
2167 * and easily extensible.
2169 * The following is an extensible radio capture format. It is
2170 * based on a bitmap indicating which fields are present.
2172 * I am trying to describe precisely what the application programmer
2173 * should expect in the following, and for that reason I tell the
2174 * units and origin of each measurement (where it applies), or else I
2175 * use sufficiently weaselly language ("is a monotonically nondecreasing
2176 * function of...") that I cannot set false expectations for lawyerly
2181 * The radio capture header precedes the 802.11 header.
2183 * Note well: all radiotap fields are little-endian.
2185 struct ieee80211_radiotap_header
{
2186 nd_uint8_t it_version
; /* Version 0. Only increases
2187 * for drastic changes,
2188 * introduction of compatible
2189 * new fields does not count.
2192 nd_uint16_t it_len
; /* length of the whole
2193 * header in bytes, including
2194 * it_version, it_pad,
2195 * it_len, and data fields.
2197 nd_uint32_t it_present
; /* A bitmap telling which
2198 * fields are present. Set bit 31
2199 * (0x80000000) to extend the
2200 * bitmap by another 32 bits.
2201 * Additional extensions are made
2202 * by setting bit 31.
2206 /* Name Data type Units
2207 * ---- --------- -----
2209 * IEEE80211_RADIOTAP_TSFT uint64_t microseconds
2211 * Value in microseconds of the MAC's 64-bit 802.11 Time
2212 * Synchronization Function timer when the first bit of the
2213 * MPDU arrived at the MAC. For received frames, only.
2215 * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap
2217 * Tx/Rx frequency in MHz, followed by flags (see below).
2218 * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
2219 * represent an HT channel as there is not enough room in
2222 * IEEE80211_RADIOTAP_FHSS uint16_t see below
2224 * For frequency-hopping radios, the hop set (first byte)
2225 * and pattern (second byte).
2227 * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index
2229 * Tx/Rx data rate. If bit 0x80 is set then it represents an
2230 * an MCS index and not an IEEE rate.
2232 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
2233 * one milliwatt (dBm)
2235 * RF signal power at the antenna, decibel difference from
2238 * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
2239 * one milliwatt (dBm)
2241 * RF noise power at the antenna, decibel difference from one
2244 * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
2246 * RF signal power at the antenna, decibel difference from an
2247 * arbitrary, fixed reference.
2249 * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
2251 * RF noise power at the antenna, decibel difference from an
2252 * arbitrary, fixed reference point.
2254 * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless
2256 * Quality of Barker code lock. Unitless. Monotonically
2257 * nondecreasing with "better" lock strength. Called "Signal
2258 * Quality" in datasheets. (Is there a standard way to measure
2261 * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless
2263 * Transmit power expressed as unitless distance from max
2264 * power set at factory calibration. 0 is max power.
2265 * Monotonically nondecreasing with lower power levels.
2267 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB)
2269 * Transmit power expressed as decibel distance from max power
2270 * set at factory calibration. 0 is max power. Monotonically
2271 * nondecreasing with lower power levels.
2273 * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
2274 * one milliwatt (dBm)
2276 * Transmit power expressed as dBm (decibels from a 1 milliwatt
2277 * reference). This is the absolute power level measured at
2280 * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap
2282 * Properties of transmitted and received frames. See flags
2285 * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index
2287 * Unitless indication of the Rx/Tx antenna for this packet.
2288 * The first antenna is antenna 0.
2290 * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap
2292 * Properties of received frames. See flags defined below.
2294 * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap
2296 * uint8_t channel number
2299 * Extended channel specification: flags (see below) followed by
2300 * frequency in MHz, the corresponding IEEE channel number, and
2301 * finally the maximum regulatory transmit power cap in .5 dBm
2302 * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
2303 * and only one of the two should be present.
2305 * IEEE80211_RADIOTAP_MCS uint8_t known
2309 * Bitset indicating which fields have known values, followed
2310 * by bitset of flag values, followed by the MCS rate index as
2314 * IEEE80211_RADIOTAP_AMPDU_STATUS u32, u16, u8, u8 unitless
2316 * Contains the AMPDU information for the subframe.
2318 * IEEE80211_RADIOTAP_VHT u16, u8, u8, u8[4], u8, u8, u16
2320 * Contains VHT information about this frame.
2322 * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
2327 * The Vendor Namespace Field contains three sub-fields. The first
2328 * sub-field is 3 bytes long. It contains the vendor's IEEE 802
2329 * Organizationally Unique Identifier (OUI). The fourth byte is a
2330 * vendor-specific "namespace selector."
2333 enum ieee80211_radiotap_type
{
2334 IEEE80211_RADIOTAP_TSFT
= 0,
2335 IEEE80211_RADIOTAP_FLAGS
= 1,
2336 IEEE80211_RADIOTAP_RATE
= 2,
2337 IEEE80211_RADIOTAP_CHANNEL
= 3,
2338 IEEE80211_RADIOTAP_FHSS
= 4,
2339 IEEE80211_RADIOTAP_DBM_ANTSIGNAL
= 5,
2340 IEEE80211_RADIOTAP_DBM_ANTNOISE
= 6,
2341 IEEE80211_RADIOTAP_LOCK_QUALITY
= 7,
2342 IEEE80211_RADIOTAP_TX_ATTENUATION
= 8,
2343 IEEE80211_RADIOTAP_DB_TX_ATTENUATION
= 9,
2344 IEEE80211_RADIOTAP_DBM_TX_POWER
= 10,
2345 IEEE80211_RADIOTAP_ANTENNA
= 11,
2346 IEEE80211_RADIOTAP_DB_ANTSIGNAL
= 12,
2347 IEEE80211_RADIOTAP_DB_ANTNOISE
= 13,
2348 IEEE80211_RADIOTAP_RX_FLAGS
= 14,
2349 /* NB: gap for netbsd definitions */
2350 IEEE80211_RADIOTAP_XCHANNEL
= 18,
2351 IEEE80211_RADIOTAP_MCS
= 19,
2352 IEEE80211_RADIOTAP_AMPDU_STATUS
= 20,
2353 IEEE80211_RADIOTAP_VHT
= 21,
2354 IEEE80211_RADIOTAP_NAMESPACE
= 29,
2355 IEEE80211_RADIOTAP_VENDOR_NAMESPACE
= 30,
2356 IEEE80211_RADIOTAP_EXT
= 31
2359 /* channel attributes */
2360 #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
2361 #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
2362 #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
2363 #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
2364 #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
2365 #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
2366 #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
2367 #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
2368 #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
2369 #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
2370 #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
2371 #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
2372 #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
2373 #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
2374 #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
2376 /* Useful combinations of channel characteristics, borrowed from Ethereal */
2377 #define IEEE80211_CHAN_A \
2378 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2379 #define IEEE80211_CHAN_B \
2380 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2381 #define IEEE80211_CHAN_G \
2382 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2383 #define IEEE80211_CHAN_TA \
2384 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
2385 #define IEEE80211_CHAN_TG \
2386 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
2389 /* For IEEE80211_RADIOTAP_FLAGS */
2390 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
2393 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
2397 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
2398 * with WEP encryption
2400 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
2401 * with fragmentation
2403 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
2404 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
2405 * 802.11 header and payload
2406 * (to 32-bit boundary)
2408 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
2410 /* For IEEE80211_RADIOTAP_RX_FLAGS */
2411 #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
2412 #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
2414 /* For IEEE80211_RADIOTAP_MCS known */
2415 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
2416 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
2417 #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
2418 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
2419 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
2420 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
2421 #define IEEE80211_RADIOTAP_MCS_NESS_KNOWN 0x40
2422 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_1 0x80
2424 /* For IEEE80211_RADIOTAP_MCS flags */
2425 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
2426 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
2427 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
2428 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
2429 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
2430 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
2431 #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
2432 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
2433 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
2434 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
2435 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
2436 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
2437 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
2438 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_0 0x80
2440 /* For IEEE80211_RADIOTAP_AMPDU_STATUS */
2441 #define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001
2442 #define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002
2443 #define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004
2444 #define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008
2445 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010
2446 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020
2448 /* For IEEE80211_RADIOTAP_VHT known */
2449 #define IEEE80211_RADIOTAP_VHT_STBC_KNOWN 0x0001
2450 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA_KNOWN 0x0002
2451 #define IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN 0x0004
2452 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_DIS_KNOWN 0x0008
2453 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM_KNOWN 0x0010
2454 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED_KNOWN 0x0020
2455 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN 0x0040
2456 #define IEEE80211_RADIOTAP_VHT_GROUP_ID_KNOWN 0x0080
2457 #define IEEE80211_RADIOTAP_VHT_PARTIAL_AID_KNOWN 0x0100
2459 /* For IEEE80211_RADIOTAP_VHT flags */
2460 #define IEEE80211_RADIOTAP_VHT_STBC 0x01
2461 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA 0x02
2462 #define IEEE80211_RADIOTAP_VHT_SHORT_GI 0x04
2463 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_M10_9 0x08
2464 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM 0x10
2465 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED 0x20
2467 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK 0x1f
2469 #define IEEE80211_RADIOTAP_VHT_NSS_MASK 0x0f
2470 #define IEEE80211_RADIOTAP_VHT_MCS_MASK 0xf0
2471 #define IEEE80211_RADIOTAP_VHT_MCS_SHIFT 4
2473 #define IEEE80211_RADIOTAP_CODING_LDPC_USERn 0x01
2475 #define IEEE80211_CHAN_FHSS \
2476 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2477 #define IEEE80211_CHAN_A \
2478 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2479 #define IEEE80211_CHAN_B \
2480 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2481 #define IEEE80211_CHAN_PUREG \
2482 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2483 #define IEEE80211_CHAN_G \
2484 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2486 #define IS_CHAN_FHSS(flags) \
2487 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2488 #define IS_CHAN_A(flags) \
2489 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2490 #define IS_CHAN_B(flags) \
2491 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2492 #define IS_CHAN_PUREG(flags) \
2493 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2494 #define IS_CHAN_G(flags) \
2495 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2496 #define IS_CHAN_ANYG(flags) \
2497 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2500 print_chaninfo(netdissect_options
*ndo
,
2501 uint16_t freq
, int flags
, int presentflags
)
2503 ND_PRINT("%u MHz", freq
);
2504 if (presentflags
& (1 << IEEE80211_RADIOTAP_MCS
)) {
2506 * We have the MCS field, so this is 11n, regardless
2507 * of what the channel flags say.
2511 if (IS_CHAN_FHSS(flags
))
2513 if (IS_CHAN_A(flags
)) {
2514 if (flags
& IEEE80211_CHAN_HALF
)
2515 ND_PRINT(" 11a/10Mhz");
2516 else if (flags
& IEEE80211_CHAN_QUARTER
)
2517 ND_PRINT(" 11a/5Mhz");
2521 if (IS_CHAN_ANYG(flags
)) {
2522 if (flags
& IEEE80211_CHAN_HALF
)
2523 ND_PRINT(" 11g/10Mhz");
2524 else if (flags
& IEEE80211_CHAN_QUARTER
)
2525 ND_PRINT(" 11g/5Mhz");
2528 } else if (IS_CHAN_B(flags
))
2530 if (flags
& IEEE80211_CHAN_TURBO
)
2534 * These apply to 11n.
2536 if (flags
& IEEE80211_CHAN_HT20
)
2538 else if (flags
& IEEE80211_CHAN_HT40D
)
2539 ND_PRINT(" ht/40-");
2540 else if (flags
& IEEE80211_CHAN_HT40U
)
2541 ND_PRINT(" ht/40+");
2546 print_radiotap_field(netdissect_options
*ndo
,
2547 struct cpack_state
*s
, uint32_t bit
, uint8_t *flagsp
,
2548 uint32_t presentflags
)
2555 case IEEE80211_RADIOTAP_TSFT
: {
2558 rc
= cpack_uint64(s
, &tsft
);
2561 ND_PRINT("%" PRIu64
"us tsft ", tsft
);
2565 case IEEE80211_RADIOTAP_FLAGS
: {
2568 rc
= cpack_uint8(s
, &flagsval
);
2572 if (flagsval
& IEEE80211_RADIOTAP_F_CFP
)
2574 if (flagsval
& IEEE80211_RADIOTAP_F_SHORTPRE
)
2575 ND_PRINT("short preamble ");
2576 if (flagsval
& IEEE80211_RADIOTAP_F_WEP
)
2578 if (flagsval
& IEEE80211_RADIOTAP_F_FRAG
)
2579 ND_PRINT("fragmented ");
2580 if (flagsval
& IEEE80211_RADIOTAP_F_BADFCS
)
2581 ND_PRINT("bad-fcs ");
2585 case IEEE80211_RADIOTAP_RATE
: {
2588 rc
= cpack_uint8(s
, &rate
);
2592 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2593 * Linux and AirPcap it does not. (What about
2594 * macOS, NetBSD, OpenBSD, and DragonFly BSD?)
2596 * This is an issue either for proprietary extensions
2597 * to 11a or 11g, which do exist, or for 11n
2598 * implementations that stuff a rate value into
2599 * this field, which also appear to exist.
2601 * We currently handle that by assuming that
2602 * if the 0x80 bit is set *and* the remaining
2603 * bits have a value between 0 and 15 it's
2604 * an MCS value, otherwise it's a rate. If
2605 * there are cases where systems that use
2606 * "0x80 + MCS index" for MCS indices > 15,
2607 * or stuff a rate value here between 64 and
2608 * 71.5 Mb/s in here, we'll need a preference
2609 * setting. Such rates do exist, e.g. 11n
2610 * MCS 7 at 20 MHz with a long guard interval.
2612 if (rate
>= 0x80 && rate
<= 0x8f) {
2614 * XXX - we don't know the channel width
2615 * or guard interval length, so we can't
2616 * convert this to a data rate.
2618 * If you want us to show a data rate,
2619 * use the MCS field, not the Rate field;
2620 * the MCS field includes not only the
2621 * MCS index, it also includes bandwidth
2622 * and guard interval information.
2624 * XXX - can we get the channel width
2625 * from XChannel and the guard interval
2626 * information from Flags, at least on
2629 ND_PRINT("MCS %u ", rate
& 0x7f);
2631 ND_PRINT("%2.1f Mb/s ", .5 * rate
);
2635 case IEEE80211_RADIOTAP_CHANNEL
: {
2639 rc
= cpack_uint16(s
, &frequency
);
2642 rc
= cpack_uint16(s
, &flags
);
2646 * If CHANNEL and XCHANNEL are both present, skip
2649 if (presentflags
& (1 << IEEE80211_RADIOTAP_XCHANNEL
))
2651 print_chaninfo(ndo
, frequency
, flags
, presentflags
);
2655 case IEEE80211_RADIOTAP_FHSS
: {
2659 rc
= cpack_uint8(s
, &hopset
);
2662 rc
= cpack_uint8(s
, &hoppat
);
2665 ND_PRINT("fhset %u fhpat %u ", hopset
, hoppat
);
2669 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
: {
2670 int8_t dbm_antsignal
;
2672 rc
= cpack_int8(s
, &dbm_antsignal
);
2675 ND_PRINT("%ddBm signal ", dbm_antsignal
);
2679 case IEEE80211_RADIOTAP_DBM_ANTNOISE
: {
2680 int8_t dbm_antnoise
;
2682 rc
= cpack_int8(s
, &dbm_antnoise
);
2685 ND_PRINT("%ddBm noise ", dbm_antnoise
);
2689 case IEEE80211_RADIOTAP_LOCK_QUALITY
: {
2690 uint16_t lock_quality
;
2692 rc
= cpack_uint16(s
, &lock_quality
);
2695 ND_PRINT("%u sq ", lock_quality
);
2699 case IEEE80211_RADIOTAP_TX_ATTENUATION
: {
2700 int16_t tx_attenuation
;
2702 rc
= cpack_int16(s
, &tx_attenuation
);
2705 ND_PRINT("%d tx power ", -tx_attenuation
);
2709 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
: {
2710 int8_t db_tx_attenuation
;
2712 rc
= cpack_int8(s
, &db_tx_attenuation
);
2715 ND_PRINT("%ddB tx attenuation ", -db_tx_attenuation
);
2719 case IEEE80211_RADIOTAP_DBM_TX_POWER
: {
2720 int8_t dbm_tx_power
;
2722 rc
= cpack_int8(s
, &dbm_tx_power
);
2725 ND_PRINT("%ddBm tx power ", dbm_tx_power
);
2729 case IEEE80211_RADIOTAP_ANTENNA
: {
2732 rc
= cpack_uint8(s
, &antenna
);
2735 ND_PRINT("antenna %u ", antenna
);
2739 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
: {
2740 uint8_t db_antsignal
;
2742 rc
= cpack_uint8(s
, &db_antsignal
);
2745 ND_PRINT("%udB signal ", db_antsignal
);
2749 case IEEE80211_RADIOTAP_DB_ANTNOISE
: {
2750 uint8_t db_antnoise
;
2752 rc
= cpack_uint8(s
, &db_antnoise
);
2755 ND_PRINT("%udB noise ", db_antnoise
);
2759 case IEEE80211_RADIOTAP_RX_FLAGS
: {
2762 rc
= cpack_uint16(s
, &rx_flags
);
2765 /* Do nothing for now */
2769 case IEEE80211_RADIOTAP_XCHANNEL
: {
2775 rc
= cpack_uint32(s
, &flags
);
2778 rc
= cpack_uint16(s
, &frequency
);
2781 rc
= cpack_uint8(s
, &channel
);
2784 rc
= cpack_uint8(s
, &maxpower
);
2787 print_chaninfo(ndo
, frequency
, flags
, presentflags
);
2791 case IEEE80211_RADIOTAP_MCS
: {
2795 static const char *ht_bandwidth
[4] = {
2803 rc
= cpack_uint8(s
, &known
);
2806 rc
= cpack_uint8(s
, &flags
);
2809 rc
= cpack_uint8(s
, &mcs_index
);
2812 if (known
& IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN
) {
2814 * We know the MCS index.
2816 if (mcs_index
<= MAX_MCS_INDEX
) {
2818 * And it's in-range.
2820 if (known
& (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
)) {
2822 * And we know both the bandwidth and
2823 * the guard interval, so we can look
2827 ieee80211_float_htrates
2829 [((flags
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40
? 1 : 0)]
2830 [((flags
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ? 1 : 0)];
2833 * We don't know both the bandwidth
2834 * and the guard interval, so we can
2835 * only report the MCS index.
2841 * The MCS value is out of range.
2845 if (htrate
!= 0.0) {
2850 ND_PRINT("%.1f Mb/s MCS %u ", htrate
, mcs_index
);
2853 * We at least have the MCS index.
2856 ND_PRINT("MCS %u ", mcs_index
);
2859 if (known
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
) {
2861 ht_bandwidth
[flags
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
]);
2863 if (known
& IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
) {
2865 (flags
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ?
2868 if (known
& IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN
) {
2870 (flags
& IEEE80211_RADIOTAP_MCS_HT_GREENFIELD
) ?
2871 "greenfield" : "mixed");
2873 if (known
& IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN
) {
2875 (flags
& IEEE80211_RADIOTAP_MCS_FEC_LDPC
) ?
2878 if (known
& IEEE80211_RADIOTAP_MCS_STBC_KNOWN
) {
2879 ND_PRINT("RX-STBC%u ",
2880 (flags
& IEEE80211_RADIOTAP_MCS_STBC_MASK
) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT
);
2885 case IEEE80211_RADIOTAP_AMPDU_STATUS
: {
2886 uint32_t reference_num
;
2891 rc
= cpack_uint32(s
, &reference_num
);
2894 rc
= cpack_uint16(s
, &flags
);
2897 rc
= cpack_uint8(s
, &delim_crc
);
2900 rc
= cpack_uint8(s
, &reserved
);
2903 /* Do nothing for now */
2907 case IEEE80211_RADIOTAP_VHT
: {
2914 uint16_t partial_aid
;
2915 static const char *vht_bandwidth
[32] = {
2950 rc
= cpack_uint16(s
, &known
);
2953 rc
= cpack_uint8(s
, &flags
);
2956 rc
= cpack_uint8(s
, &bandwidth
);
2959 for (i
= 0; i
< 4; i
++) {
2960 rc
= cpack_uint8(s
, &mcs_nss
[i
]);
2964 rc
= cpack_uint8(s
, &coding
);
2967 rc
= cpack_uint8(s
, &group_id
);
2970 rc
= cpack_uint16(s
, &partial_aid
);
2973 for (i
= 0; i
< 4; i
++) {
2975 nss
= mcs_nss
[i
] & IEEE80211_RADIOTAP_VHT_NSS_MASK
;
2976 mcs
= (mcs_nss
[i
] & IEEE80211_RADIOTAP_VHT_MCS_MASK
) >> IEEE80211_RADIOTAP_VHT_MCS_SHIFT
;
2981 ND_PRINT("User %u MCS %u ", i
, mcs
);
2983 (coding
& (IEEE80211_RADIOTAP_CODING_LDPC_USERn
<< i
)) ?
2986 if (known
& IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN
) {
2988 vht_bandwidth
[bandwidth
& IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK
]);
2990 if (known
& IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN
) {
2992 (flags
& IEEE80211_RADIOTAP_VHT_SHORT_GI
) ?
2999 /* this bit indicates a field whose
3000 * size we do not know, so we cannot
3001 * proceed. Just print the bit number.
3003 ND_PRINT("[bit %u] ", bit
);
3010 ND_PRINT("%s", tstr
);
3016 print_in_radiotap_namespace(netdissect_options
*ndo
,
3017 struct cpack_state
*s
, uint8_t *flags
,
3018 uint32_t presentflags
, int bit0
)
3020 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
3021 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
3022 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
3023 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
3024 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
3025 uint32_t present
, next_present
;
3027 enum ieee80211_radiotap_type bit
;
3030 for (present
= presentflags
; present
; present
= next_present
) {
3032 * Clear the least significant bit that is set.
3034 next_present
= present
& (present
- 1);
3037 * Get the bit number, within this presence word,
3038 * of the remaining least significant bit that
3041 bitno
= BITNO_32(present
^ next_present
);
3044 * Stop if this is one of the "same meaning
3045 * in all presence flags" bits.
3047 if (bitno
>= IEEE80211_RADIOTAP_NAMESPACE
)
3051 * Get the radiotap bit number of that bit.
3053 bit
= (enum ieee80211_radiotap_type
)(bit0
+ bitno
);
3055 rc
= print_radiotap_field(ndo
, s
, bit
, flags
, presentflags
);
3064 ieee802_11_radio_print(netdissect_options
*ndo
,
3065 const u_char
*p
, u_int length
, u_int caplen
)
3067 #define BIT(n) (1U << n)
3068 #define IS_EXTENDED(__p) \
3069 (EXTRACT_LE_U_4(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
3071 struct cpack_state cpacker
;
3072 const struct ieee80211_radiotap_header
*hdr
;
3073 uint32_t presentflags
;
3074 const nd_uint32_t
*presentp
, *last_presentp
;
3075 int vendor_namespace
;
3076 uint8_t vendor_oui
[3];
3077 uint8_t vendor_subnamespace
;
3078 uint16_t skip_length
;
3085 ndo
->ndo_protocol
= "802.11_radio";
3086 if (caplen
< sizeof(*hdr
)) {
3087 ND_PRINT("%s", tstr
);
3091 hdr
= (const struct ieee80211_radiotap_header
*)p
;
3093 len
= EXTRACT_LE_U_2(hdr
->it_len
);
3096 * If we don't have the entire radiotap header, just give up.
3099 ND_PRINT("%s", tstr
);
3102 cpack_init(&cpacker
, (const uint8_t *)hdr
, len
); /* align against header start */
3103 cpack_advance(&cpacker
, sizeof(*hdr
)); /* includes the 1st bitmap */
3104 for (last_presentp
= &hdr
->it_present
;
3105 (const u_char
*)(last_presentp
+ 1) <= p
+ len
&&
3106 IS_EXTENDED(last_presentp
);
3108 cpack_advance(&cpacker
, sizeof(hdr
->it_present
)); /* more bitmaps */
3110 /* are there more bitmap extensions than bytes in header? */
3111 if ((const u_char
*)(last_presentp
+ 1) > p
+ len
) {
3112 ND_PRINT("%s", tstr
);
3117 * Start out at the beginning of the default radiotap namespace.
3120 vendor_namespace
= 0;
3121 memset(vendor_oui
, 0, 3);
3122 vendor_subnamespace
= 0;
3124 /* Assume no flags */
3126 /* Assume no Atheros padding between 802.11 header and body */
3128 /* Assume no FCS at end of frame */
3130 for (presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
3132 presentflags
= EXTRACT_LE_U_4(presentp
);
3135 * If this is a vendor namespace, we don't handle it.
3137 if (vendor_namespace
) {
3139 * Skip past the stuff we don't understand.
3140 * If we add support for any vendor namespaces,
3141 * it'd be added here; use vendor_oui and
3142 * vendor_subnamespace to interpret the fields.
3144 if (cpack_advance(&cpacker
, skip_length
) != 0) {
3146 * Ran out of space in the packet.
3152 * We've skipped it all; nothing more to
3157 if (print_in_radiotap_namespace(ndo
, &cpacker
,
3158 &flags
, presentflags
, bit0
) != 0) {
3160 * Fatal error - can't process anything
3161 * more in the radiotap header.
3168 * Handle the namespace switch bits; we've already handled
3169 * the extension bit in all but the last word above.
3171 switch (presentflags
&
3172 (BIT(IEEE80211_RADIOTAP_NAMESPACE
)|BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE
))) {
3176 * We're not changing namespaces.
3177 * advance to the next 32 bits in the current
3183 case BIT(IEEE80211_RADIOTAP_NAMESPACE
):
3185 * We're switching to the radiotap namespace.
3186 * Reset the presence-bitmap index to 0, and
3187 * reset the namespace to the default radiotap
3191 vendor_namespace
= 0;
3192 memset(vendor_oui
, 0, 3);
3193 vendor_subnamespace
= 0;
3197 case BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE
):
3199 * We're switching to a vendor namespace.
3200 * Reset the presence-bitmap index to 0,
3201 * note that we're in a vendor namespace,
3202 * and fetch the fields of the Vendor Namespace
3206 vendor_namespace
= 1;
3207 if ((cpack_align_and_reserve(&cpacker
, 2)) == NULL
) {
3208 ND_PRINT("%s", tstr
);
3211 if (cpack_uint8(&cpacker
, &vendor_oui
[0]) != 0) {
3212 ND_PRINT("%s", tstr
);
3215 if (cpack_uint8(&cpacker
, &vendor_oui
[1]) != 0) {
3216 ND_PRINT("%s", tstr
);
3219 if (cpack_uint8(&cpacker
, &vendor_oui
[2]) != 0) {
3220 ND_PRINT("%s", tstr
);
3223 if (cpack_uint8(&cpacker
, &vendor_subnamespace
) != 0) {
3224 ND_PRINT("%s", tstr
);
3227 if (cpack_uint16(&cpacker
, &skip_length
) != 0) {
3228 ND_PRINT("%s", tstr
);
3235 * Illegal combination. The behavior in this
3236 * case is undefined by the radiotap spec; we
3237 * just ignore both bits.
3243 if (flags
& IEEE80211_RADIOTAP_F_DATAPAD
)
3244 pad
= 1; /* Atheros padding */
3245 if (flags
& IEEE80211_RADIOTAP_F_FCS
)
3246 fcslen
= 4; /* FCS at end of packet */
3247 return len
+ ieee802_11_print(ndo
, p
+ len
, length
- len
, caplen
- len
, pad
,
3258 ieee802_11_radio_avs_print(netdissect_options
*ndo
,
3259 const u_char
*p
, u_int length
, u_int caplen
)
3261 uint32_t caphdr_len
;
3263 ndo
->ndo_protocol
= "802.11_radio_avs";
3265 ND_PRINT("%s", tstr
);
3269 caphdr_len
= EXTRACT_BE_U_4(p
+ 4);
3270 if (caphdr_len
< 8) {
3272 * Yow! The capture header length is claimed not
3273 * to be large enough to include even the version
3274 * cookie or capture header length!
3276 ND_PRINT("%s", tstr
);
3280 if (caplen
< caphdr_len
) {
3281 ND_PRINT("%s", tstr
);
3285 return caphdr_len
+ ieee802_11_print(ndo
, p
+ caphdr_len
,
3286 length
- caphdr_len
, caplen
- caphdr_len
, 0, 0);
3289 #define PRISM_HDR_LEN 144
3291 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
3292 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
3293 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
3296 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
3297 * containing information such as radio information, which we
3300 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
3301 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
3302 * (currently, on Linux, there's no ARPHRD_ type for
3303 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
3304 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
3305 * the AVS header, and the first 4 bytes of the header are used to
3306 * indicate whether it's a Prism header or an AVS header).
3309 prism_if_print(netdissect_options
*ndo
,
3310 const struct pcap_pkthdr
*h
, const u_char
*p
)
3312 u_int caplen
= h
->caplen
;
3313 u_int length
= h
->len
;
3316 ndo
->ndo_protocol
= "prism_if";
3318 ND_PRINT("%s", tstr
);
3322 msgcode
= EXTRACT_BE_U_4(p
);
3323 if (msgcode
== WLANCAP_MAGIC_COOKIE_V1
||
3324 msgcode
== WLANCAP_MAGIC_COOKIE_V2
)
3325 return ieee802_11_radio_avs_print(ndo
, p
, length
, caplen
);
3327 if (caplen
< PRISM_HDR_LEN
) {
3328 ND_PRINT("%s", tstr
);
3332 return PRISM_HDR_LEN
+ ieee802_11_print(ndo
, p
+ PRISM_HDR_LEN
,
3333 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
, 0, 0);
3337 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
3338 * header, containing information such as radio information.
3341 ieee802_11_radio_if_print(netdissect_options
*ndo
,
3342 const struct pcap_pkthdr
*h
, const u_char
*p
)
3344 ndo
->ndo_protocol
= "802.11_radio_if";
3345 return ieee802_11_radio_print(ndo
, p
, h
->len
, h
->caplen
);
3349 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
3350 * extra header, containing information such as radio information,
3351 * which we currently ignore.
3354 ieee802_11_radio_avs_if_print(netdissect_options
*ndo
,
3355 const struct pcap_pkthdr
*h
, const u_char
*p
)
3357 ndo
->ndo_protocol
= "802.11_radio_avs_if";
3358 return ieee802_11_radio_avs_print(ndo
, p
, h
->len
, h
->caplen
);