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 <netdissect-stdinc.h>
31 #include "netdissect.h"
32 #include "addrtoname.h"
39 /* Lengths of 802.11 header components. */
40 #define IEEE802_11_FC_LEN 2
41 #define IEEE802_11_DUR_LEN 2
42 #define IEEE802_11_DA_LEN 6
43 #define IEEE802_11_SA_LEN 6
44 #define IEEE802_11_BSSID_LEN 6
45 #define IEEE802_11_RA_LEN 6
46 #define IEEE802_11_TA_LEN 6
47 #define IEEE802_11_ADDR1_LEN 6
48 #define IEEE802_11_SEQ_LEN 2
49 #define IEEE802_11_CTL_LEN 2
50 #define IEEE802_11_CARRIED_FC_LEN 2
51 #define IEEE802_11_HT_CONTROL_LEN 4
52 #define IEEE802_11_IV_LEN 3
53 #define IEEE802_11_KID_LEN 1
55 /* Frame check sequence length. */
56 #define IEEE802_11_FCS_LEN 4
58 /* Lengths of beacon components. */
59 #define IEEE802_11_TSTAMP_LEN 8
60 #define IEEE802_11_BCNINT_LEN 2
61 #define IEEE802_11_CAPINFO_LEN 2
62 #define IEEE802_11_LISTENINT_LEN 2
64 #define IEEE802_11_AID_LEN 2
65 #define IEEE802_11_STATUS_LEN 2
66 #define IEEE802_11_REASON_LEN 2
68 /* Length of previous AP in reassocation frame */
69 #define IEEE802_11_AP_LEN 6
71 #define T_MGMT 0x0 /* management */
72 #define T_CTRL 0x1 /* control */
73 #define T_DATA 0x2 /* data */
74 #define T_RESV 0x3 /* reserved */
76 #define ST_ASSOC_REQUEST 0x0
77 #define ST_ASSOC_RESPONSE 0x1
78 #define ST_REASSOC_REQUEST 0x2
79 #define ST_REASSOC_RESPONSE 0x3
80 #define ST_PROBE_REQUEST 0x4
81 #define ST_PROBE_RESPONSE 0x5
86 #define ST_DISASSOC 0xA
93 static const struct tok st_str
[] = {
94 { ST_ASSOC_REQUEST
, "Assoc Request" },
95 { ST_ASSOC_RESPONSE
, "Assoc Response" },
96 { ST_REASSOC_REQUEST
, "ReAssoc Request" },
97 { ST_REASSOC_RESPONSE
, "ReAssoc Response" },
98 { ST_PROBE_REQUEST
, "Probe Request" },
99 { ST_PROBE_RESPONSE
, "Probe Response" },
100 { ST_BEACON
, "Beacon" },
102 { ST_DISASSOC
, "Disassociation" },
103 { ST_AUTH
, "Authentication" },
104 { ST_DEAUTH
, "DeAuthentication" },
105 { ST_ACTION
, "Action" },
109 #define CTRL_CONTROL_WRAPPER 0x7
112 #define CTRL_PS_POLL 0xA
116 #define CTRL_CF_END 0xE
117 #define CTRL_END_ACK 0xF
119 static const struct tok ctrl_str
[] = {
120 { CTRL_CONTROL_WRAPPER
, "Control Wrapper" },
123 { CTRL_PS_POLL
, "Power Save-Poll" },
124 { CTRL_RTS
, "Request-To-Send" },
125 { CTRL_CTS
, "Clear-To-Send" },
126 { CTRL_ACK
, "Acknowledgment" },
127 { CTRL_CF_END
, "CF-End" },
128 { CTRL_END_ACK
, "CF-End+CF-Ack" },
132 #define DATA_DATA 0x0
133 #define DATA_DATA_CF_ACK 0x1
134 #define DATA_DATA_CF_POLL 0x2
135 #define DATA_DATA_CF_ACK_POLL 0x3
136 #define DATA_NODATA 0x4
137 #define DATA_NODATA_CF_ACK 0x5
138 #define DATA_NODATA_CF_POLL 0x6
139 #define DATA_NODATA_CF_ACK_POLL 0x7
141 #define DATA_QOS_DATA 0x8
142 #define DATA_QOS_DATA_CF_ACK 0x9
143 #define DATA_QOS_DATA_CF_POLL 0xA
144 #define DATA_QOS_DATA_CF_ACK_POLL 0xB
145 #define DATA_QOS_NODATA 0xC
146 #define DATA_QOS_CF_POLL_NODATA 0xE
147 #define DATA_QOS_CF_ACK_POLL_NODATA 0xF
150 * The subtype field of a data frame is, in effect, composed of 4 flag
151 * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
152 * any data), and QoS.
154 #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01)
155 #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02)
156 #define DATA_FRAME_IS_NULL(x) ((x) & 0x04)
157 #define DATA_FRAME_IS_QOS(x) ((x) & 0x08)
160 * Bits in the frame control field.
162 #define FC_VERSION(fc) ((fc) & 0x3)
163 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
164 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
165 #define FC_TO_DS(fc) ((fc) & 0x0100)
166 #define FC_FROM_DS(fc) ((fc) & 0x0200)
167 #define FC_MORE_FLAG(fc) ((fc) & 0x0400)
168 #define FC_RETRY(fc) ((fc) & 0x0800)
169 #define FC_POWER_MGMT(fc) ((fc) & 0x1000)
170 #define FC_MORE_DATA(fc) ((fc) & 0x2000)
171 #define FC_PROTECTED(fc) ((fc) & 0x4000)
172 #define FC_ORDER(fc) ((fc) & 0x8000)
174 struct mgmt_header_t
{
177 uint8_t da
[IEEE802_11_DA_LEN
];
178 uint8_t sa
[IEEE802_11_SA_LEN
];
179 uint8_t bssid
[IEEE802_11_BSSID_LEN
];
183 #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
184 IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
185 IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
187 #define CAPABILITY_ESS(cap) ((cap) & 0x0001)
188 #define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
189 #define CAPABILITY_CFP(cap) ((cap) & 0x0004)
190 #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
191 #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
196 u_char ssid
[33]; /* 32 + 1 for null */
208 uint8_t text
[254]; /* 1-253 + 1 for null */
231 uint16_t max_duration
;
232 uint16_t dur_remaing
;
240 uint8_t bitmap_control
;
262 #define E_CHALLENGE 16
271 uint8_t timestamp
[IEEE802_11_TSTAMP_LEN
];
272 uint16_t beacon_interval
;
273 uint16_t listen_interval
;
274 uint16_t status_code
;
276 u_char ap
[IEEE802_11_AP_LEN
];
277 uint16_t reason_code
;
279 uint16_t auth_trans_seq_num
;
280 int challenge_present
;
281 struct challenge_t challenge
;
282 uint16_t capability_info
;
286 struct rates_t rates
;
297 struct ctrl_control_wrapper_hdr_t
{
300 uint8_t addr1
[IEEE802_11_ADDR1_LEN
];
301 uint16_t carried_fc
[IEEE802_11_CARRIED_FC_LEN
];
302 uint16_t ht_control
[IEEE802_11_HT_CONTROL_LEN
];
305 #define CTRL_CONTROL_WRAPPER_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
306 IEEE802_11_ADDR1_LEN+\
307 IEEE802_11_CARRIED_FC_LEN+\
308 IEEE802_11_HT_CONTROL_LEN)
310 struct ctrl_rts_hdr_t
{
313 uint8_t ra
[IEEE802_11_RA_LEN
];
314 uint8_t ta
[IEEE802_11_TA_LEN
];
317 #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
318 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
320 struct ctrl_cts_hdr_t
{
323 uint8_t ra
[IEEE802_11_RA_LEN
];
326 #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
328 struct ctrl_ack_hdr_t
{
331 uint8_t ra
[IEEE802_11_RA_LEN
];
334 #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
336 struct ctrl_ps_poll_hdr_t
{
339 uint8_t bssid
[IEEE802_11_BSSID_LEN
];
340 uint8_t ta
[IEEE802_11_TA_LEN
];
343 #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
344 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
346 struct ctrl_end_hdr_t
{
349 uint8_t ra
[IEEE802_11_RA_LEN
];
350 uint8_t bssid
[IEEE802_11_BSSID_LEN
];
353 #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
354 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
356 struct ctrl_end_ack_hdr_t
{
359 uint8_t ra
[IEEE802_11_RA_LEN
];
360 uint8_t bssid
[IEEE802_11_BSSID_LEN
];
363 #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
364 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
366 struct ctrl_ba_hdr_t
{
369 uint8_t ra
[IEEE802_11_RA_LEN
];
372 #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
374 struct ctrl_bar_hdr_t
{
377 uint8_t ra
[IEEE802_11_RA_LEN
];
378 uint8_t ta
[IEEE802_11_TA_LEN
];
383 #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
384 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
385 IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
396 #define IV_IV(iv) ((iv) & 0xFFFFFF)
397 #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
398 #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
400 #define PRINT_SSID(p) \
401 if (p.ssid_present) { \
402 ND_PRINT((ndo, " (")); \
403 fn_print(ndo, p.ssid.ssid, NULL); \
404 ND_PRINT((ndo, ")")); \
407 #define PRINT_RATE(_sep, _r, _suf) \
408 ND_PRINT((ndo, "%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf))
409 #define PRINT_RATES(p) \
410 if (p.rates_present) { \
412 const char *sep = " ["; \
413 for (z = 0; z < p.rates.length ; z++) { \
414 PRINT_RATE(sep, p.rates.rate[z], \
415 (p.rates.rate[z] & 0x80 ? "*" : "")); \
418 if (p.rates.length != 0) \
419 ND_PRINT((ndo, " Mbit]")); \
422 #define PRINT_DS_CHANNEL(p) \
424 ND_PRINT((ndo, " CH: %u", p.ds.channel)); \
425 ND_PRINT((ndo, "%s", \
426 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : ""));
428 #define MAX_MCS_INDEX 76
433 * the MCS index (0-76);
435 * 0 for 20 MHz, 1 for 40 MHz;
437 * 0 for a long guard interval, 1 for a short guard interval.
439 static const float ieee80211_float_htrates
[MAX_MCS_INDEX
+1][2][2] = {
441 { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, },
442 /* 40 Mhz */ { 13.5, /* SGI */ 15.0, },
446 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
447 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
451 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
452 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
456 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
457 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
461 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
462 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
466 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
467 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
471 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
472 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
476 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
477 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
481 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
482 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
486 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
487 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
491 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
492 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
496 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
497 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
501 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
502 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
506 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
507 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
511 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
512 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
516 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
517 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
521 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
522 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
526 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
527 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
531 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
532 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
536 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
537 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
541 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
542 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
546 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
547 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
551 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
552 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
556 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
557 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
561 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
562 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
566 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
567 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
571 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
572 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
576 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
577 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
581 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
582 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
586 { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, },
587 /* 40 Mhz */ { 432.0, /* SGI */ 480.0, },
591 { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, },
592 /* 40 Mhz */ { 486.0, /* SGI */ 540.0, },
596 { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, },
597 /* 40 Mhz */ { 540.0, /* SGI */ 600.0, },
601 { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */
602 /* 40 Mhz */ { 6.0, /* SGI */ 6.7, },
606 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
607 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
611 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
612 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
616 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
617 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
621 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
622 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
626 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
627 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
631 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
632 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
636 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
637 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
641 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
642 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
646 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
647 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
651 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
652 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
656 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
657 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
661 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
662 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
666 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
667 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
671 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
672 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
676 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
677 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
681 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
682 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
686 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
687 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
691 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
692 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
696 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
697 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
701 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
702 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
706 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
707 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
711 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
712 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
716 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
717 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
721 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
722 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
726 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
727 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
731 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
732 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
736 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
737 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
741 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
742 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
746 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
747 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
751 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
752 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
756 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
757 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
761 { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, },
762 /* 40 Mhz */ { 297.0, /* SGI */ 330.0, },
766 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
767 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
771 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
772 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
776 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
777 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
781 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
782 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
786 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
787 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
791 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
792 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
796 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
797 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
801 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
802 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
806 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
807 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
811 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
812 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
816 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
817 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
821 { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, },
822 /* 40 Mhz */ { 445.5, /* SGI */ 495.0, },
826 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
827 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
829 static const char *status_text
[] = {
830 "Successful", /* 0 */
831 "Unspecified failure", /* 1 */
840 "Cannot Support all requested capabilities in the Capability "
841 "Information field", /* 10 */
842 "Reassociation denied due to inability to confirm that association "
844 "Association denied due to reason outside the scope of the "
846 "Responding station does not support the specified authentication "
847 "algorithm ", /* 13 */
848 "Received an Authentication frame with authentication transaction "
849 "sequence number out of expected sequence", /* 14 */
850 "Authentication rejected because of challenge failure", /* 15 */
851 "Authentication rejected due to timeout waiting for next frame in "
853 "Association denied because AP is unable to handle additional"
854 "associated stations", /* 17 */
855 "Association denied due to requesting station not supporting all of "
856 "the data rates in BSSBasicRateSet parameter", /* 18 */
857 "Association denied due to requesting station not supporting "
858 "short preamble operation", /* 19 */
859 "Association denied due to requesting station not supporting "
860 "PBCC encoding", /* 20 */
861 "Association denied due to requesting station not supporting "
862 "channel agility", /* 21 */
863 "Association request rejected because Spectrum Management "
864 "capability is required", /* 22 */
865 "Association request rejected because the information in the "
866 "Power Capability element is unacceptable", /* 23 */
867 "Association request rejected because the information in the "
868 "Supported Channels element is unacceptable", /* 24 */
869 "Association denied due to requesting station not supporting "
870 "short slot operation", /* 25 */
871 "Association denied due to requesting station not supporting "
872 "DSSS-OFDM operation", /* 26 */
873 "Association denied because the requested STA does not support HT "
876 "Association denied because the requested STA does not support "
877 "the PCO transition time required by the AP", /* 29 */
880 "Unspecified, QoS-related failure", /* 32 */
881 "Association denied due to QAP having insufficient bandwidth "
882 "to handle another QSTA", /* 33 */
883 "Association denied due to excessive frame loss rates and/or "
884 "poor conditions on current operating channel", /* 34 */
885 "Association (with QBSS) denied due to requesting station not "
886 "supporting the QoS facility", /* 35 */
887 "Association denied due to requesting station not supporting "
888 "Block Ack", /* 36 */
889 "The request has been declined", /* 37 */
890 "The request has not been successful as one or more parameters "
891 "have invalid values", /* 38 */
892 "The TS has not been created because the request cannot be honored. "
893 "Try again with the suggested changes to the TSPEC", /* 39 */
894 "Invalid Information Element", /* 40 */
895 "Group Cipher is not valid", /* 41 */
896 "Pairwise Cipher is not valid", /* 42 */
897 "AKMP is not valid", /* 43 */
898 "Unsupported RSN IE version", /* 44 */
899 "Invalid RSN IE Capabilities", /* 45 */
900 "Cipher suite is rejected per security policy", /* 46 */
901 "The TS has not been created. However, the HC may be capable of "
902 "creating a TS, in response to a request, after the time indicated "
903 "in the TS Delay element", /* 47 */
904 "Direct Link is not allowed in the BSS by policy", /* 48 */
905 "Destination STA is not present within this QBSS.", /* 49 */
906 "The Destination STA is not a QSTA.", /* 50 */
909 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
911 static const char *reason_text
[] = {
913 "Unspecified reason", /* 1 */
914 "Previous authentication no longer valid", /* 2 */
915 "Deauthenticated because sending station is leaving (or has left) "
916 "IBSS or ESS", /* 3 */
917 "Disassociated due to inactivity", /* 4 */
918 "Disassociated because AP is unable to handle all currently "
919 " associated stations", /* 5 */
920 "Class 2 frame received from nonauthenticated station", /* 6 */
921 "Class 3 frame received from nonassociated station", /* 7 */
922 "Disassociated because sending station is leaving "
923 "(or has left) BSS", /* 8 */
924 "Station requesting (re)association is not authenticated with "
925 "responding station", /* 9 */
926 "Disassociated because the information in the Power Capability "
927 "element is unacceptable", /* 10 */
928 "Disassociated because the information in the SupportedChannels "
929 "element is unacceptable", /* 11 */
930 "Invalid Information Element", /* 12 */
932 "Michael MIC failure", /* 14 */
933 "4-Way Handshake timeout", /* 15 */
934 "Group key update timeout", /* 16 */
935 "Information element in 4-Way Handshake different from (Re)Association"
936 "Request/Probe Response/Beacon", /* 17 */
937 "Group Cipher is not valid", /* 18 */
938 "AKMP is not valid", /* 20 */
939 "Unsupported RSN IE version", /* 21 */
940 "Invalid RSN IE Capabilities", /* 22 */
941 "IEEE 802.1X Authentication failed", /* 23 */
942 "Cipher suite is rejected per security policy", /* 24 */
949 "TS deleted because QoS AP lacks sufficient bandwidth for this "
950 "QoS STA due to a change in BSS service characteristics or "
951 "operational mode (e.g. an HT BSS change from 40 MHz channel "
952 "to 20 MHz channel)", /* 31 */
953 "Disassociated for unspecified, QoS-related reason", /* 32 */
954 "Disassociated because QoS AP lacks sufficient bandwidth for this "
956 "Disassociated because of excessive number of frames that need to be "
957 "acknowledged, but are not acknowledged for AP transmissions "
958 "and/or poor channel conditions", /* 34 */
959 "Disassociated because STA is transmitting outside the limits "
960 "of its TXOPs", /* 35 */
961 "Requested from peer STA as the STA is leaving the BSS "
962 "(or resetting)", /* 36 */
963 "Requested from peer STA as it does not want to use the "
964 "mechanism", /* 37 */
965 "Requested from peer STA as the STA received frames using the "
966 "mechanism for which a set up is required", /* 38 */
967 "Requested from peer STA due to time out", /* 39 */
973 "Peer STA does not support the requested cipher suite", /* 45 */
974 "Association denied due to requesting STA not supporting HT "
977 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
980 wep_print(netdissect_options
*ndo
,
985 if (!ND_TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
987 iv
= EXTRACT_LE_32BITS(p
);
989 ND_PRINT((ndo
, " IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
996 parse_elements(netdissect_options
*ndo
,
997 struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
,
1002 struct challenge_t challenge
;
1003 struct rates_t rates
;
1009 * We haven't seen any elements yet.
1011 pbody
->challenge_present
= 0;
1012 pbody
->ssid_present
= 0;
1013 pbody
->rates_present
= 0;
1014 pbody
->ds_present
= 0;
1015 pbody
->cf_present
= 0;
1016 pbody
->tim_present
= 0;
1018 while (length
!= 0) {
1019 /* Make sure we at least have the element ID and length. */
1020 if (!ND_TTEST2(*(p
+ offset
), 2))
1024 elementlen
= *(p
+ offset
+ 1);
1026 /* Make sure we have the entire element. */
1027 if (!ND_TTEST2(*(p
+ offset
+ 2), elementlen
))
1029 if (length
< elementlen
+ 2)
1032 switch (*(p
+ offset
)) {
1034 memcpy(&ssid
, p
+ offset
, 2);
1037 if (ssid
.length
!= 0) {
1038 if (ssid
.length
> sizeof(ssid
.ssid
) - 1)
1040 if (!ND_TTEST2(*(p
+ offset
), ssid
.length
))
1042 if (length
< ssid
.length
)
1044 memcpy(&ssid
.ssid
, p
+ offset
, ssid
.length
);
1045 offset
+= ssid
.length
;
1046 length
-= ssid
.length
;
1048 ssid
.ssid
[ssid
.length
] = '\0';
1050 * Present and not truncated.
1052 * If we haven't already seen an SSID IE,
1053 * copy this one, otherwise ignore this one,
1054 * so we later report the first one we saw.
1056 if (!pbody
->ssid_present
) {
1058 pbody
->ssid_present
= 1;
1062 memcpy(&challenge
, p
+ offset
, 2);
1065 if (challenge
.length
!= 0) {
1066 if (challenge
.length
>
1067 sizeof(challenge
.text
) - 1)
1069 if (!ND_TTEST2(*(p
+ offset
), challenge
.length
))
1071 if (length
< challenge
.length
)
1073 memcpy(&challenge
.text
, p
+ offset
,
1075 offset
+= challenge
.length
;
1076 length
-= challenge
.length
;
1078 challenge
.text
[challenge
.length
] = '\0';
1080 * Present and not truncated.
1082 * If we haven't already seen a challenge IE,
1083 * copy this one, otherwise ignore this one,
1084 * so we later report the first one we saw.
1086 if (!pbody
->challenge_present
) {
1087 pbody
->challenge
= challenge
;
1088 pbody
->challenge_present
= 1;
1092 memcpy(&rates
, p
+ offset
, 2);
1095 if (rates
.length
!= 0) {
1096 if (rates
.length
> sizeof rates
.rate
)
1098 if (!ND_TTEST2(*(p
+ offset
), rates
.length
))
1100 if (length
< rates
.length
)
1102 memcpy(&rates
.rate
, p
+ offset
, rates
.length
);
1103 offset
+= rates
.length
;
1104 length
-= rates
.length
;
1107 * Present and not truncated.
1109 * If we haven't already seen a rates IE,
1110 * copy this one if it's not zero-length,
1111 * otherwise ignore this one, so we later
1112 * report the first one we saw.
1114 * We ignore zero-length rates IEs as some
1115 * devices seem to put a zero-length rates
1116 * IE, followed by an SSID IE, followed by
1117 * a non-zero-length rates IE into frames,
1118 * even though IEEE Std 802.11-2007 doesn't
1119 * seem to indicate that a zero-length rates
1122 if (!pbody
->rates_present
&& rates
.length
!= 0) {
1123 pbody
->rates
= rates
;
1124 pbody
->rates_present
= 1;
1128 memcpy(&ds
, p
+ offset
, 2);
1131 if (ds
.length
!= 1) {
1132 offset
+= ds
.length
;
1133 length
-= ds
.length
;
1136 ds
.channel
= *(p
+ offset
);
1140 * Present and not truncated.
1142 * If we haven't already seen a DS IE,
1143 * copy this one, otherwise ignore this one,
1144 * so we later report the first one we saw.
1146 if (!pbody
->ds_present
) {
1148 pbody
->ds_present
= 1;
1152 memcpy(&cf
, p
+ offset
, 2);
1155 if (cf
.length
!= 6) {
1156 offset
+= cf
.length
;
1157 length
-= cf
.length
;
1160 memcpy(&cf
.count
, p
+ offset
, 6);
1164 * Present and not truncated.
1166 * If we haven't already seen a CF IE,
1167 * copy this one, otherwise ignore this one,
1168 * so we later report the first one we saw.
1170 if (!pbody
->cf_present
) {
1172 pbody
->cf_present
= 1;
1176 memcpy(&tim
, p
+ offset
, 2);
1179 if (tim
.length
<= 3) {
1180 offset
+= tim
.length
;
1181 length
-= tim
.length
;
1184 if (tim
.length
- 3 > (int)sizeof tim
.bitmap
)
1186 memcpy(&tim
.count
, p
+ offset
, 3);
1190 memcpy(tim
.bitmap
, p
+ (tim
.length
- 3),
1192 offset
+= tim
.length
- 3;
1193 length
-= tim
.length
- 3;
1195 * Present and not truncated.
1197 * If we haven't already seen a TIM IE,
1198 * copy this one, otherwise ignore this one,
1199 * so we later report the first one we saw.
1201 if (!pbody
->tim_present
) {
1203 pbody
->tim_present
= 1;
1208 ND_PRINT((ndo
, "(1) unhandled element_id (%d) ",
1211 offset
+= 2 + elementlen
;
1212 length
-= 2 + elementlen
;
1217 /* No problems found. */
1221 /*********************************************************************************
1222 * Print Handle functions for the management frame types
1223 *********************************************************************************/
1226 handle_beacon(netdissect_options
*ndo
,
1227 const u_char
*p
, u_int length
)
1229 struct mgmt_body_t pbody
;
1233 memset(&pbody
, 0, sizeof(pbody
));
1235 if (!ND_TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1236 IEEE802_11_CAPINFO_LEN
))
1238 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1239 IEEE802_11_CAPINFO_LEN
)
1241 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1242 offset
+= IEEE802_11_TSTAMP_LEN
;
1243 length
-= IEEE802_11_TSTAMP_LEN
;
1244 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1245 offset
+= IEEE802_11_BCNINT_LEN
;
1246 length
-= IEEE802_11_BCNINT_LEN
;
1247 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1248 offset
+= IEEE802_11_CAPINFO_LEN
;
1249 length
-= IEEE802_11_CAPINFO_LEN
;
1251 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1255 ND_PRINT((ndo
, " %s",
1256 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS"));
1257 PRINT_DS_CHANNEL(pbody
);
1263 handle_assoc_request(netdissect_options
*ndo
,
1264 const u_char
*p
, u_int length
)
1266 struct mgmt_body_t pbody
;
1270 memset(&pbody
, 0, sizeof(pbody
));
1272 if (!ND_TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
1274 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
)
1276 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1277 offset
+= IEEE802_11_CAPINFO_LEN
;
1278 length
-= IEEE802_11_CAPINFO_LEN
;
1279 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1280 offset
+= IEEE802_11_LISTENINT_LEN
;
1281 length
-= IEEE802_11_LISTENINT_LEN
;
1283 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1291 handle_assoc_response(netdissect_options
*ndo
,
1292 const u_char
*p
, u_int length
)
1294 struct mgmt_body_t pbody
;
1298 memset(&pbody
, 0, sizeof(pbody
));
1300 if (!ND_TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1301 IEEE802_11_AID_LEN
))
1303 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1306 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1307 offset
+= IEEE802_11_CAPINFO_LEN
;
1308 length
-= IEEE802_11_CAPINFO_LEN
;
1309 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
1310 offset
+= IEEE802_11_STATUS_LEN
;
1311 length
-= IEEE802_11_STATUS_LEN
;
1312 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
1313 offset
+= IEEE802_11_AID_LEN
;
1314 length
-= IEEE802_11_AID_LEN
;
1316 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1318 ND_PRINT((ndo
, " AID(%x) :%s: %s", ((uint16_t)(pbody
.aid
<< 2 )) >> 2 ,
1319 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
1320 (pbody
.status_code
< NUM_STATUSES
1321 ? status_text
[pbody
.status_code
]
1328 handle_reassoc_request(netdissect_options
*ndo
,
1329 const u_char
*p
, u_int length
)
1331 struct mgmt_body_t pbody
;
1335 memset(&pbody
, 0, sizeof(pbody
));
1337 if (!ND_TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1340 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1343 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1344 offset
+= IEEE802_11_CAPINFO_LEN
;
1345 length
-= IEEE802_11_CAPINFO_LEN
;
1346 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1347 offset
+= IEEE802_11_LISTENINT_LEN
;
1348 length
-= IEEE802_11_LISTENINT_LEN
;
1349 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
1350 offset
+= IEEE802_11_AP_LEN
;
1351 length
-= IEEE802_11_AP_LEN
;
1353 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1356 ND_PRINT((ndo
, " AP : %s", etheraddr_string(ndo
, pbody
.ap
)));
1362 handle_reassoc_response(netdissect_options
*ndo
,
1363 const u_char
*p
, u_int length
)
1365 /* Same as a Association Reponse */
1366 return handle_assoc_response(ndo
, p
, length
);
1370 handle_probe_request(netdissect_options
*ndo
,
1371 const u_char
*p
, u_int length
)
1373 struct mgmt_body_t pbody
;
1377 memset(&pbody
, 0, sizeof(pbody
));
1379 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1388 handle_probe_response(netdissect_options
*ndo
,
1389 const u_char
*p
, u_int length
)
1391 struct mgmt_body_t pbody
;
1395 memset(&pbody
, 0, sizeof(pbody
));
1397 if (!ND_TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1398 IEEE802_11_CAPINFO_LEN
))
1400 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1401 IEEE802_11_CAPINFO_LEN
)
1403 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1404 offset
+= IEEE802_11_TSTAMP_LEN
;
1405 length
-= IEEE802_11_TSTAMP_LEN
;
1406 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1407 offset
+= IEEE802_11_BCNINT_LEN
;
1408 length
-= IEEE802_11_BCNINT_LEN
;
1409 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1410 offset
+= IEEE802_11_CAPINFO_LEN
;
1411 length
-= IEEE802_11_CAPINFO_LEN
;
1413 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1417 PRINT_DS_CHANNEL(pbody
);
1425 /* the frame body for ATIM is null. */
1430 handle_disassoc(netdissect_options
*ndo
,
1431 const u_char
*p
, u_int length
)
1433 struct mgmt_body_t pbody
;
1435 memset(&pbody
, 0, sizeof(pbody
));
1437 if (!ND_TTEST2(*p
, IEEE802_11_REASON_LEN
))
1439 if (length
< IEEE802_11_REASON_LEN
)
1441 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1443 ND_PRINT((ndo
, ": %s",
1444 (pbody
.reason_code
< NUM_REASONS
)
1445 ? reason_text
[pbody
.reason_code
]
1452 handle_auth(netdissect_options
*ndo
,
1453 const u_char
*p
, u_int length
)
1455 struct mgmt_body_t pbody
;
1459 memset(&pbody
, 0, sizeof(pbody
));
1461 if (!ND_TTEST2(*p
, 6))
1465 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
1468 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
1471 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
1475 ret
= parse_elements(ndo
, &pbody
, p
, offset
, length
);
1477 if ((pbody
.auth_alg
== 1) &&
1478 ((pbody
.auth_trans_seq_num
== 2) ||
1479 (pbody
.auth_trans_seq_num
== 3))) {
1480 ND_PRINT((ndo
, " (%s)-%x [Challenge Text] %s",
1481 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1482 ? auth_alg_text
[pbody
.auth_alg
]
1484 pbody
.auth_trans_seq_num
,
1485 ((pbody
.auth_trans_seq_num
% 2)
1486 ? ((pbody
.status_code
< NUM_STATUSES
)
1487 ? status_text
[pbody
.status_code
]
1491 ND_PRINT((ndo
, " (%s)-%x: %s",
1492 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1493 ? auth_alg_text
[pbody
.auth_alg
]
1495 pbody
.auth_trans_seq_num
,
1496 (pbody
.auth_trans_seq_num
% 2)
1497 ? ((pbody
.status_code
< NUM_STATUSES
)
1498 ? status_text
[pbody
.status_code
]
1506 handle_deauth(netdissect_options
*ndo
,
1507 const uint8_t *src
, const u_char
*p
, u_int length
)
1509 struct mgmt_body_t pbody
;
1510 const char *reason
= NULL
;
1512 memset(&pbody
, 0, sizeof(pbody
));
1514 if (!ND_TTEST2(*p
, IEEE802_11_REASON_LEN
))
1516 if (length
< IEEE802_11_REASON_LEN
)
1518 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1520 reason
= (pbody
.reason_code
< NUM_REASONS
)
1521 ? reason_text
[pbody
.reason_code
]
1524 if (ndo
->ndo_eflag
) {
1525 ND_PRINT((ndo
, ": %s", reason
));
1527 ND_PRINT((ndo
, " (%s): %s", etheraddr_string(ndo
, src
), reason
));
1532 #define PRINT_HT_ACTION(v) (\
1533 (v) == 0 ? ND_PRINT((ndo, "TxChWidth")) : \
1534 (v) == 1 ? ND_PRINT((ndo, "MIMOPwrSave")) : \
1535 ND_PRINT((ndo, "Act#%d", (v))) \
1537 #define PRINT_BA_ACTION(v) (\
1538 (v) == 0 ? ND_PRINT((ndo, "ADDBA Request")) : \
1539 (v) == 1 ? ND_PRINT((ndo, "ADDBA Response")) : \
1540 (v) == 2 ? ND_PRINT((ndo, "DELBA")) : \
1541 ND_PRINT((ndo, "Act#%d", (v))) \
1543 #define PRINT_MESHLINK_ACTION(v) (\
1544 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1545 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1546 ND_PRINT((ndo, "Act#%d", (v))) \
1548 #define PRINT_MESHPEERING_ACTION(v) (\
1549 (v) == 0 ? ND_PRINT((ndo, "Open")) : \
1550 (v) == 1 ? ND_PRINT((ndo, "Confirm")) : \
1551 (v) == 2 ? ND_PRINT((ndo, "Close")) : \
1552 ND_PRINT((ndo, "Act#%d", (v))) \
1554 #define PRINT_MESHPATH_ACTION(v) (\
1555 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1556 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1557 (v) == 2 ? ND_PRINT((ndo, "Error")) : \
1558 (v) == 3 ? ND_PRINT((ndo, "RootAnnouncement")) : \
1559 ND_PRINT((ndo, "Act#%d", (v))) \
1562 #define PRINT_MESH_ACTION(v) (\
1563 (v) == 0 ? ND_PRINT((ndo, "MeshLink")) : \
1564 (v) == 1 ? ND_PRINT((ndo, "HWMP")) : \
1565 (v) == 2 ? ND_PRINT((ndo, "Gate Announcement")) : \
1566 (v) == 3 ? ND_PRINT((ndo, "Congestion Control")) : \
1567 (v) == 4 ? ND_PRINT((ndo, "MCCA Setup Request")) : \
1568 (v) == 5 ? ND_PRINT((ndo, "MCCA Setup Reply")) : \
1569 (v) == 6 ? ND_PRINT((ndo, "MCCA Advertisement Request")) : \
1570 (v) == 7 ? ND_PRINT((ndo, "MCCA Advertisement")) : \
1571 (v) == 8 ? ND_PRINT((ndo, "MCCA Teardown")) : \
1572 (v) == 9 ? ND_PRINT((ndo, "TBTT Adjustment Request")) : \
1573 (v) == 10 ? ND_PRINT((ndo, "TBTT Adjustment Response")) : \
1574 ND_PRINT((ndo, "Act#%d", (v))) \
1576 #define PRINT_MULTIHOP_ACTION(v) (\
1577 (v) == 0 ? ND_PRINT((ndo, "Proxy Update")) : \
1578 (v) == 1 ? ND_PRINT((ndo, "Proxy Update Confirmation")) : \
1579 ND_PRINT((ndo, "Act#%d", (v))) \
1581 #define PRINT_SELFPROT_ACTION(v) (\
1582 (v) == 1 ? ND_PRINT((ndo, "Peering Open")) : \
1583 (v) == 2 ? ND_PRINT((ndo, "Peering Confirm")) : \
1584 (v) == 3 ? ND_PRINT((ndo, "Peering Close")) : \
1585 (v) == 4 ? ND_PRINT((ndo, "Group Key Inform")) : \
1586 (v) == 5 ? ND_PRINT((ndo, "Group Key Acknowledge")) : \
1587 ND_PRINT((ndo, "Act#%d", (v))) \
1591 handle_action(netdissect_options
*ndo
,
1592 const uint8_t *src
, const u_char
*p
, u_int length
)
1594 if (!ND_TTEST2(*p
, 2))
1598 if (ndo
->ndo_eflag
) {
1599 ND_PRINT((ndo
, ": "));
1601 ND_PRINT((ndo
, " (%s): ", etheraddr_string(ndo
, src
)));
1604 case 0: ND_PRINT((ndo
, "Spectrum Management Act#%d", p
[1])); break;
1605 case 1: ND_PRINT((ndo
, "QoS Act#%d", p
[1])); break;
1606 case 2: ND_PRINT((ndo
, "DLS Act#%d", p
[1])); break;
1607 case 3: ND_PRINT((ndo
, "BA ")); PRINT_BA_ACTION(p
[1]); break;
1608 case 7: ND_PRINT((ndo
, "HT ")); PRINT_HT_ACTION(p
[1]); break;
1609 case 13: ND_PRINT((ndo
, "MeshAction ")); PRINT_MESH_ACTION(p
[1]); break;
1611 ND_PRINT((ndo
, "MultiohopAction "));
1612 PRINT_MULTIHOP_ACTION(p
[1]); break;
1614 ND_PRINT((ndo
, "SelfprotectAction "));
1615 PRINT_SELFPROT_ACTION(p
[1]); break;
1616 case 127: ND_PRINT((ndo
, "Vendor Act#%d", p
[1])); break;
1618 ND_PRINT((ndo
, "Reserved(%d) Act#%d", p
[0], p
[1]));
1625 /*********************************************************************************
1627 *********************************************************************************/
1631 mgmt_body_print(netdissect_options
*ndo
,
1632 uint16_t fc
, const uint8_t *src
, const u_char
*p
, u_int length
)
1634 ND_PRINT((ndo
, "%s", tok2str(st_str
, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc
))));
1636 /* There may be a problem w/ AP not having this bit set */
1637 if (FC_PROTECTED(fc
))
1638 return wep_print(ndo
, p
);
1639 switch (FC_SUBTYPE(fc
)) {
1640 case ST_ASSOC_REQUEST
:
1641 return handle_assoc_request(ndo
, p
, length
);
1642 case ST_ASSOC_RESPONSE
:
1643 return handle_assoc_response(ndo
, p
, length
);
1644 case ST_REASSOC_REQUEST
:
1645 return handle_reassoc_request(ndo
, p
, length
);
1646 case ST_REASSOC_RESPONSE
:
1647 return handle_reassoc_response(ndo
, p
, length
);
1648 case ST_PROBE_REQUEST
:
1649 return handle_probe_request(ndo
, p
, length
);
1650 case ST_PROBE_RESPONSE
:
1651 return handle_probe_response(ndo
, p
, length
);
1653 return handle_beacon(ndo
, p
, length
);
1655 return handle_atim();
1657 return handle_disassoc(ndo
, p
, length
);
1659 return handle_auth(ndo
, p
, length
);
1661 return handle_deauth(ndo
, src
, p
, length
);
1663 return handle_action(ndo
, src
, p
, length
);
1670 /*********************************************************************************
1671 * Handles printing all the control frame types
1672 *********************************************************************************/
1675 ctrl_body_print(netdissect_options
*ndo
,
1676 uint16_t fc
, const u_char
*p
)
1678 ND_PRINT((ndo
, "%s", tok2str(ctrl_str
, "Unknown Ctrl Subtype", FC_SUBTYPE(fc
))));
1679 switch (FC_SUBTYPE(fc
)) {
1680 case CTRL_CONTROL_WRAPPER
:
1681 /* XXX - requires special handling */
1684 if (!ND_TTEST2(*p
, CTRL_BAR_HDRLEN
))
1686 if (!ndo
->ndo_eflag
)
1687 ND_PRINT((ndo
, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
1688 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ra
),
1689 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ta
),
1690 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t
*)p
)->ctl
)),
1691 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t
*)p
)->seq
))));
1694 if (!ND_TTEST2(*p
, CTRL_BA_HDRLEN
))
1696 if (!ndo
->ndo_eflag
)
1697 ND_PRINT((ndo
, " RA:%s ",
1698 etheraddr_string(ndo
, ((const struct ctrl_ba_hdr_t
*)p
)->ra
)));
1701 if (!ND_TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
1703 ND_PRINT((ndo
, " AID(%x)",
1704 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_hdr_t
*)p
)->aid
))));
1707 if (!ND_TTEST2(*p
, CTRL_RTS_HDRLEN
))
1709 if (!ndo
->ndo_eflag
)
1710 ND_PRINT((ndo
, " TA:%s ",
1711 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ta
)));
1714 if (!ND_TTEST2(*p
, CTRL_CTS_HDRLEN
))
1716 if (!ndo
->ndo_eflag
)
1717 ND_PRINT((ndo
, " RA:%s ",
1718 etheraddr_string(ndo
, ((const struct ctrl_cts_hdr_t
*)p
)->ra
)));
1721 if (!ND_TTEST2(*p
, CTRL_ACK_HDRLEN
))
1723 if (!ndo
->ndo_eflag
)
1724 ND_PRINT((ndo
, " RA:%s ",
1725 etheraddr_string(ndo
, ((const struct ctrl_ack_hdr_t
*)p
)->ra
)));
1728 if (!ND_TTEST2(*p
, CTRL_END_HDRLEN
))
1730 if (!ndo
->ndo_eflag
)
1731 ND_PRINT((ndo
, " RA:%s ",
1732 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->ra
)));
1735 if (!ND_TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
1737 if (!ndo
->ndo_eflag
)
1738 ND_PRINT((ndo
, " RA:%s ",
1739 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->ra
)));
1746 * Data Frame - Address field contents
1748 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
1749 * 0 | 0 | DA | SA | BSSID | n/a
1750 * 0 | 1 | DA | BSSID | SA | n/a
1751 * 1 | 0 | BSSID | SA | DA | n/a
1752 * 1 | 1 | RA | TA | DA | SA
1756 * Function to get source and destination MAC addresses for a data frame.
1759 get_data_src_dst_mac(uint16_t fc
, const u_char
*p
, const uint8_t **srcp
,
1760 const uint8_t **dstp
)
1762 #define ADDR1 (p + 4)
1763 #define ADDR2 (p + 10)
1764 #define ADDR3 (p + 16)
1765 #define ADDR4 (p + 24)
1767 if (!FC_TO_DS(fc
)) {
1768 if (!FC_FROM_DS(fc
)) {
1769 /* not To DS and not From DS */
1773 /* not To DS and From DS */
1778 if (!FC_FROM_DS(fc
)) {
1779 /* From DS and not To DS */
1783 /* To DS and From DS */
1796 get_mgmt_src_dst_mac(const u_char
*p
, const uint8_t **srcp
, const uint8_t **dstp
)
1798 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
1807 * Print Header funcs
1811 data_header_print(netdissect_options
*ndo
, uint16_t fc
, const u_char
*p
)
1813 u_int subtype
= FC_SUBTYPE(fc
);
1815 if (DATA_FRAME_IS_CF_ACK(subtype
) || DATA_FRAME_IS_CF_POLL(subtype
) ||
1816 DATA_FRAME_IS_QOS(subtype
)) {
1817 ND_PRINT((ndo
, "CF "));
1818 if (DATA_FRAME_IS_CF_ACK(subtype
)) {
1819 if (DATA_FRAME_IS_CF_POLL(subtype
))
1820 ND_PRINT((ndo
, "Ack/Poll"));
1822 ND_PRINT((ndo
, "Ack"));
1824 if (DATA_FRAME_IS_CF_POLL(subtype
))
1825 ND_PRINT((ndo
, "Poll"));
1827 if (DATA_FRAME_IS_QOS(subtype
))
1828 ND_PRINT((ndo
, "+QoS"));
1829 ND_PRINT((ndo
, " "));
1832 #define ADDR1 (p + 4)
1833 #define ADDR2 (p + 10)
1834 #define ADDR3 (p + 16)
1835 #define ADDR4 (p + 24)
1837 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
1838 ND_PRINT((ndo
, "DA:%s SA:%s BSSID:%s ",
1839 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1840 etheraddr_string(ndo
, ADDR3
)));
1841 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
1842 ND_PRINT((ndo
, "DA:%s BSSID:%s SA:%s ",
1843 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1844 etheraddr_string(ndo
, ADDR3
)));
1845 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
1846 ND_PRINT((ndo
, "BSSID:%s SA:%s DA:%s ",
1847 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1848 etheraddr_string(ndo
, ADDR3
)));
1849 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
1850 ND_PRINT((ndo
, "RA:%s TA:%s DA:%s SA:%s ",
1851 etheraddr_string(ndo
, ADDR1
), etheraddr_string(ndo
, ADDR2
),
1852 etheraddr_string(ndo
, ADDR3
), etheraddr_string(ndo
, ADDR4
)));
1862 mgmt_header_print(netdissect_options
*ndo
, const u_char
*p
)
1864 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
1866 ND_PRINT((ndo
, "BSSID:%s DA:%s SA:%s ",
1867 etheraddr_string(ndo
, (hp
)->bssid
), etheraddr_string(ndo
, (hp
)->da
),
1868 etheraddr_string(ndo
, (hp
)->sa
)));
1872 ctrl_header_print(netdissect_options
*ndo
, uint16_t fc
, const u_char
*p
)
1874 switch (FC_SUBTYPE(fc
)) {
1876 ND_PRINT((ndo
, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
1877 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ra
),
1878 etheraddr_string(ndo
, ((const struct ctrl_bar_hdr_t
*)p
)->ta
),
1879 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t
*)p
)->ctl
)),
1880 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t
*)p
)->seq
))));
1883 ND_PRINT((ndo
, "RA:%s ",
1884 etheraddr_string(ndo
, ((const struct ctrl_ba_hdr_t
*)p
)->ra
)));
1887 ND_PRINT((ndo
, "BSSID:%s TA:%s ",
1888 etheraddr_string(ndo
, ((const struct ctrl_ps_poll_hdr_t
*)p
)->bssid
),
1889 etheraddr_string(ndo
, ((const struct ctrl_ps_poll_hdr_t
*)p
)->ta
)));
1892 ND_PRINT((ndo
, "RA:%s TA:%s ",
1893 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ra
),
1894 etheraddr_string(ndo
, ((const struct ctrl_rts_hdr_t
*)p
)->ta
)));
1897 ND_PRINT((ndo
, "RA:%s ",
1898 etheraddr_string(ndo
, ((const struct ctrl_cts_hdr_t
*)p
)->ra
)));
1901 ND_PRINT((ndo
, "RA:%s ",
1902 etheraddr_string(ndo
, ((const struct ctrl_ack_hdr_t
*)p
)->ra
)));
1905 ND_PRINT((ndo
, "RA:%s BSSID:%s ",
1906 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->ra
),
1907 etheraddr_string(ndo
, ((const struct ctrl_end_hdr_t
*)p
)->bssid
)));
1910 ND_PRINT((ndo
, "RA:%s BSSID:%s ",
1911 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->ra
),
1912 etheraddr_string(ndo
, ((const struct ctrl_end_ack_hdr_t
*)p
)->bssid
)));
1915 /* We shouldn't get here - we should already have quit */
1921 extract_header_length(netdissect_options
*ndo
,
1926 switch (FC_TYPE(fc
)) {
1930 switch (FC_SUBTYPE(fc
)) {
1931 case CTRL_CONTROL_WRAPPER
:
1932 return CTRL_CONTROL_WRAPPER_HDRLEN
;
1934 return CTRL_BAR_HDRLEN
;
1936 return CTRL_BA_HDRLEN
;
1938 return CTRL_PS_POLL_HDRLEN
;
1940 return CTRL_RTS_HDRLEN
;
1942 return CTRL_CTS_HDRLEN
;
1944 return CTRL_ACK_HDRLEN
;
1946 return CTRL_END_HDRLEN
;
1948 return CTRL_END_ACK_HDRLEN
;
1950 ND_PRINT((ndo
, "unknown 802.11 ctrl frame subtype (%d)", FC_SUBTYPE(fc
)));
1954 len
= (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
1955 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
)))
1959 ND_PRINT((ndo
, "unknown 802.11 frame type (%d)", FC_TYPE(fc
)));
1965 extract_mesh_header_length(const u_char
*p
)
1967 return (p
[0] &~ 3) ? 0 : 6*(1 + (p
[0] & 3));
1971 * Print the 802.11 MAC header.
1974 ieee_802_11_hdr_print(netdissect_options
*ndo
,
1975 uint16_t fc
, const u_char
*p
, u_int hdrlen
,
1978 if (ndo
->ndo_vflag
) {
1979 if (FC_MORE_DATA(fc
))
1980 ND_PRINT((ndo
, "More Data "));
1981 if (FC_MORE_FLAG(fc
))
1982 ND_PRINT((ndo
, "More Fragments "));
1983 if (FC_POWER_MGMT(fc
))
1984 ND_PRINT((ndo
, "Pwr Mgmt "));
1986 ND_PRINT((ndo
, "Retry "));
1988 ND_PRINT((ndo
, "Strictly Ordered "));
1989 if (FC_PROTECTED(fc
))
1990 ND_PRINT((ndo
, "Protected "));
1991 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
1992 ND_PRINT((ndo
, "%dus ",
1994 &((const struct mgmt_header_t
*)p
)->duration
)));
1996 if (meshdrlen
!= 0) {
1997 const struct meshcntl_t
*mc
=
1998 (const struct meshcntl_t
*)&p
[hdrlen
- meshdrlen
];
1999 int ae
= mc
->flags
& 3;
2001 ND_PRINT((ndo
, "MeshData (AE %d TTL %u seq %u", ae
, mc
->ttl
,
2002 EXTRACT_LE_32BITS(mc
->seq
)));
2004 ND_PRINT((ndo
, " A4:%s", etheraddr_string(ndo
, mc
->addr4
)));
2006 ND_PRINT((ndo
, " A5:%s", etheraddr_string(ndo
, mc
->addr5
)));
2008 ND_PRINT((ndo
, " A6:%s", etheraddr_string(ndo
, mc
->addr6
)));
2009 ND_PRINT((ndo
, ") "));
2012 switch (FC_TYPE(fc
)) {
2014 mgmt_header_print(ndo
, p
);
2017 ctrl_header_print(ndo
, fc
, p
);
2020 data_header_print(ndo
, fc
, p
);
2028 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2031 static const char tstr
[] = "[|802.11]";
2034 ieee802_11_print(netdissect_options
*ndo
,
2035 const u_char
*p
, u_int length
, u_int orig_caplen
, int pad
,
2039 u_int caplen
, hdrlen
, meshdrlen
;
2040 const uint8_t *src
, *dst
;
2043 caplen
= orig_caplen
;
2044 /* Remove FCS, if present */
2045 if (length
< fcslen
) {
2046 ND_PRINT((ndo
, "%s", tstr
));
2050 if (caplen
> length
) {
2051 /* Amount of FCS in actual packet data, if any */
2052 fcslen
= caplen
- length
;
2054 ndo
->ndo_snapend
-= fcslen
;
2057 if (caplen
< IEEE802_11_FC_LEN
) {
2058 ND_PRINT((ndo
, "%s", tstr
));
2062 fc
= EXTRACT_LE_16BITS(p
);
2063 hdrlen
= extract_header_length(ndo
, fc
);
2065 /* Unknown frame type or control frame subtype; quit. */
2069 hdrlen
= roundup2(hdrlen
, 4);
2070 if (ndo
->ndo_Hflag
&& FC_TYPE(fc
) == T_DATA
&&
2071 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
))) {
2072 meshdrlen
= extract_mesh_header_length(p
+hdrlen
);
2073 hdrlen
+= meshdrlen
;
2077 if (caplen
< hdrlen
) {
2078 ND_PRINT((ndo
, "%s", tstr
));
2083 ieee_802_11_hdr_print(ndo
, fc
, p
, hdrlen
, meshdrlen
);
2086 * Go past the 802.11 header.
2092 switch (FC_TYPE(fc
)) {
2094 get_mgmt_src_dst_mac(p
- hdrlen
, &src
, &dst
);
2095 if (!mgmt_body_print(ndo
, fc
, src
, p
, length
)) {
2096 ND_PRINT((ndo
, "%s", tstr
));
2101 if (!ctrl_body_print(ndo
, fc
, p
- hdrlen
)) {
2102 ND_PRINT((ndo
, "%s", tstr
));
2107 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc
)))
2108 return hdrlen
; /* no-data frame */
2109 /* There may be a problem w/ AP not having this bit set */
2110 if (FC_PROTECTED(fc
)) {
2111 ND_PRINT((ndo
, "Data"));
2112 if (!wep_print(ndo
, p
)) {
2113 ND_PRINT((ndo
, "%s", tstr
));
2117 get_data_src_dst_mac(fc
, p
- hdrlen
, &src
, &dst
);
2118 llc_hdrlen
= llc_print(ndo
, p
, length
, caplen
, src
, dst
);
2119 if (llc_hdrlen
< 0) {
2121 * Some kinds of LLC packet we cannot
2122 * handle intelligently
2124 if (!ndo
->ndo_suppress_default_print
)
2125 ND_DEFAULTPRINT(p
, caplen
);
2126 llc_hdrlen
= -llc_hdrlen
;
2128 hdrlen
+= llc_hdrlen
;
2132 /* We shouldn't get here - we should already have quit */
2140 * This is the top level routine of the printer. 'p' points
2141 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2142 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2143 * is the number of bytes actually captured.
2146 ieee802_11_if_print(netdissect_options
*ndo
,
2147 const struct pcap_pkthdr
*h
, const u_char
*p
)
2149 return ieee802_11_print(ndo
, p
, h
->len
, h
->caplen
, 0, 0);
2153 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
2154 /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
2157 * Copyright (c) 2003, 2004 David Young. All rights reserved.
2159 * Redistribution and use in source and binary forms, with or without
2160 * modification, are permitted provided that the following conditions
2162 * 1. Redistributions of source code must retain the above copyright
2163 * notice, this list of conditions and the following disclaimer.
2164 * 2. Redistributions in binary form must reproduce the above copyright
2165 * notice, this list of conditions and the following disclaimer in the
2166 * documentation and/or other materials provided with the distribution.
2167 * 3. The name of David Young may not be used to endorse or promote
2168 * products derived from this software without specific prior
2169 * written permission.
2171 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
2172 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2173 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
2174 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
2175 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2176 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2177 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2178 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2179 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2180 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2181 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2185 /* A generic radio capture format is desirable. It must be
2186 * rigidly defined (e.g., units for fields should be given),
2187 * and easily extensible.
2189 * The following is an extensible radio capture format. It is
2190 * based on a bitmap indicating which fields are present.
2192 * I am trying to describe precisely what the application programmer
2193 * should expect in the following, and for that reason I tell the
2194 * units and origin of each measurement (where it applies), or else I
2195 * use sufficiently weaselly language ("is a monotonically nondecreasing
2196 * function of...") that I cannot set false expectations for lawyerly
2201 * The radio capture header precedes the 802.11 header.
2203 * Note well: all radiotap fields are little-endian.
2205 struct ieee80211_radiotap_header
{
2206 uint8_t it_version
; /* Version 0. Only increases
2207 * for drastic changes,
2208 * introduction of compatible
2209 * new fields does not count.
2212 uint16_t it_len
; /* length of the whole
2213 * header in bytes, including
2214 * it_version, it_pad,
2215 * it_len, and data fields.
2217 uint32_t it_present
; /* A bitmap telling which
2218 * fields are present. Set bit 31
2219 * (0x80000000) to extend the
2220 * bitmap by another 32 bits.
2221 * Additional extensions are made
2222 * by setting bit 31.
2226 /* Name Data type Units
2227 * ---- --------- -----
2229 * IEEE80211_RADIOTAP_TSFT uint64_t microseconds
2231 * Value in microseconds of the MAC's 64-bit 802.11 Time
2232 * Synchronization Function timer when the first bit of the
2233 * MPDU arrived at the MAC. For received frames, only.
2235 * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap
2237 * Tx/Rx frequency in MHz, followed by flags (see below).
2238 * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
2239 * represent an HT channel as there is not enough room in
2242 * IEEE80211_RADIOTAP_FHSS uint16_t see below
2244 * For frequency-hopping radios, the hop set (first byte)
2245 * and pattern (second byte).
2247 * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index
2249 * Tx/Rx data rate. If bit 0x80 is set then it represents an
2250 * an MCS index and not an IEEE rate.
2252 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
2253 * one milliwatt (dBm)
2255 * RF signal power at the antenna, decibel difference from
2258 * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
2259 * one milliwatt (dBm)
2261 * RF noise power at the antenna, decibel difference from one
2264 * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
2266 * RF signal power at the antenna, decibel difference from an
2267 * arbitrary, fixed reference.
2269 * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
2271 * RF noise power at the antenna, decibel difference from an
2272 * arbitrary, fixed reference point.
2274 * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless
2276 * Quality of Barker code lock. Unitless. Monotonically
2277 * nondecreasing with "better" lock strength. Called "Signal
2278 * Quality" in datasheets. (Is there a standard way to measure
2281 * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless
2283 * Transmit power expressed as unitless distance from max
2284 * power set at factory calibration. 0 is max power.
2285 * Monotonically nondecreasing with lower power levels.
2287 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB)
2289 * Transmit power expressed as decibel distance from max power
2290 * set at factory calibration. 0 is max power. Monotonically
2291 * nondecreasing with lower power levels.
2293 * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
2294 * one milliwatt (dBm)
2296 * Transmit power expressed as dBm (decibels from a 1 milliwatt
2297 * reference). This is the absolute power level measured at
2300 * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap
2302 * Properties of transmitted and received frames. See flags
2305 * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index
2307 * Unitless indication of the Rx/Tx antenna for this packet.
2308 * The first antenna is antenna 0.
2310 * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap
2312 * Properties of received frames. See flags defined below.
2314 * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap
2316 * uint8_t channel number
2319 * Extended channel specification: flags (see below) followed by
2320 * frequency in MHz, the corresponding IEEE channel number, and
2321 * finally the maximum regulatory transmit power cap in .5 dBm
2322 * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
2323 * and only one of the two should be present.
2325 * IEEE80211_RADIOTAP_MCS uint8_t known
2329 * Bitset indicating which fields have known values, followed
2330 * by bitset of flag values, followed by the MCS rate index as
2334 * IEEE80211_RADIOTAP_AMPDU_STATUS u32, u16, u8, u8 unitless
2336 * Contains the AMPDU information for the subframe.
2338 * IEEE80211_RADIOTAP_VHT u16, u8, u8, u8[4], u8, u8, u16
2340 * Contains VHT information about this frame.
2342 * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
2347 * The Vendor Namespace Field contains three sub-fields. The first
2348 * sub-field is 3 bytes long. It contains the vendor's IEEE 802
2349 * Organizationally Unique Identifier (OUI). The fourth byte is a
2350 * vendor-specific "namespace selector."
2353 enum ieee80211_radiotap_type
{
2354 IEEE80211_RADIOTAP_TSFT
= 0,
2355 IEEE80211_RADIOTAP_FLAGS
= 1,
2356 IEEE80211_RADIOTAP_RATE
= 2,
2357 IEEE80211_RADIOTAP_CHANNEL
= 3,
2358 IEEE80211_RADIOTAP_FHSS
= 4,
2359 IEEE80211_RADIOTAP_DBM_ANTSIGNAL
= 5,
2360 IEEE80211_RADIOTAP_DBM_ANTNOISE
= 6,
2361 IEEE80211_RADIOTAP_LOCK_QUALITY
= 7,
2362 IEEE80211_RADIOTAP_TX_ATTENUATION
= 8,
2363 IEEE80211_RADIOTAP_DB_TX_ATTENUATION
= 9,
2364 IEEE80211_RADIOTAP_DBM_TX_POWER
= 10,
2365 IEEE80211_RADIOTAP_ANTENNA
= 11,
2366 IEEE80211_RADIOTAP_DB_ANTSIGNAL
= 12,
2367 IEEE80211_RADIOTAP_DB_ANTNOISE
= 13,
2368 IEEE80211_RADIOTAP_RX_FLAGS
= 14,
2369 /* NB: gap for netbsd definitions */
2370 IEEE80211_RADIOTAP_XCHANNEL
= 18,
2371 IEEE80211_RADIOTAP_MCS
= 19,
2372 IEEE80211_RADIOTAP_AMPDU_STATUS
= 20,
2373 IEEE80211_RADIOTAP_VHT
= 21,
2374 IEEE80211_RADIOTAP_NAMESPACE
= 29,
2375 IEEE80211_RADIOTAP_VENDOR_NAMESPACE
= 30,
2376 IEEE80211_RADIOTAP_EXT
= 31
2379 /* channel attributes */
2380 #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
2381 #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
2382 #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
2383 #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
2384 #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
2385 #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
2386 #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
2387 #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
2388 #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
2389 #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
2390 #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
2391 #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
2392 #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
2393 #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
2394 #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
2396 /* Useful combinations of channel characteristics, borrowed from Ethereal */
2397 #define IEEE80211_CHAN_A \
2398 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2399 #define IEEE80211_CHAN_B \
2400 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2401 #define IEEE80211_CHAN_G \
2402 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2403 #define IEEE80211_CHAN_TA \
2404 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
2405 #define IEEE80211_CHAN_TG \
2406 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
2409 /* For IEEE80211_RADIOTAP_FLAGS */
2410 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
2413 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
2417 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
2418 * with WEP encryption
2420 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
2421 * with fragmentation
2423 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
2424 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
2425 * 802.11 header and payload
2426 * (to 32-bit boundary)
2428 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
2430 /* For IEEE80211_RADIOTAP_RX_FLAGS */
2431 #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
2432 #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
2434 /* For IEEE80211_RADIOTAP_MCS known */
2435 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
2436 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
2437 #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
2438 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
2439 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
2440 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
2441 #define IEEE80211_RADIOTAP_MCS_NESS_KNOWN 0x40
2442 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_1 0x80
2444 /* For IEEE80211_RADIOTAP_MCS flags */
2445 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
2446 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
2447 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
2448 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
2449 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
2450 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
2451 #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
2452 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
2453 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
2454 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
2455 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
2456 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
2457 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
2458 #define IEEE80211_RADIOTAP_MCS_NESS_BIT_0 0x80
2460 /* For IEEE80211_RADIOTAP_AMPDU_STATUS */
2461 #define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001
2462 #define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002
2463 #define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004
2464 #define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008
2465 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010
2466 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020
2468 /* For IEEE80211_RADIOTAP_VHT known */
2469 #define IEEE80211_RADIOTAP_VHT_STBC_KNOWN 0x0001
2470 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA_KNOWN 0x0002
2471 #define IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN 0x0004
2472 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_DIS_KNOWN 0x0008
2473 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM_KNOWN 0x0010
2474 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED_KNOWN 0x0020
2475 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN 0x0040
2476 #define IEEE80211_RADIOTAP_VHT_GROUP_ID_KNOWN 0x0080
2477 #define IEEE80211_RADIOTAP_VHT_PARTIAL_AID_KNOWN 0x0100
2479 /* For IEEE80211_RADIOTAP_VHT flags */
2480 #define IEEE80211_RADIOTAP_VHT_STBC 0x01
2481 #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA 0x02
2482 #define IEEE80211_RADIOTAP_VHT_SHORT_GI 0x04
2483 #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_M10_9 0x08
2484 #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM 0x10
2485 #define IEEE80211_RADIOTAP_VHT_BEAMFORMED 0x20
2487 #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK 0x1f
2489 #define IEEE80211_RADIOTAP_VHT_NSS_MASK 0x0f
2490 #define IEEE80211_RADIOTAP_VHT_MCS_MASK 0xf0
2491 #define IEEE80211_RADIOTAP_VHT_MCS_SHIFT 4
2493 #define IEEE80211_RADIOTAP_CODING_LDPC_USERn 0x01
2496 /* Radiotap state */
2497 /* This is used to save state when parsing/processing parameters */
2498 struct radiotap_state
2505 #define IEEE80211_CHAN_FHSS \
2506 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2507 #define IEEE80211_CHAN_A \
2508 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2509 #define IEEE80211_CHAN_B \
2510 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2511 #define IEEE80211_CHAN_PUREG \
2512 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2513 #define IEEE80211_CHAN_G \
2514 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2516 #define IS_CHAN_FHSS(flags) \
2517 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2518 #define IS_CHAN_A(flags) \
2519 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2520 #define IS_CHAN_B(flags) \
2521 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2522 #define IS_CHAN_PUREG(flags) \
2523 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2524 #define IS_CHAN_G(flags) \
2525 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2526 #define IS_CHAN_ANYG(flags) \
2527 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2530 print_chaninfo(netdissect_options
*ndo
,
2531 int freq
, int flags
, int presentflags
)
2533 ND_PRINT((ndo
, "%u MHz", freq
));
2534 if (presentflags
& (1 << IEEE80211_RADIOTAP_MCS
)) {
2536 * We have the MCS field, so this is 11n, regardless
2537 * of what the channel flags say.
2539 ND_PRINT((ndo
, " 11n"));
2541 if (IS_CHAN_FHSS(flags
))
2542 ND_PRINT((ndo
, " FHSS"));
2543 if (IS_CHAN_A(flags
)) {
2544 if (flags
& IEEE80211_CHAN_HALF
)
2545 ND_PRINT((ndo
, " 11a/10Mhz"));
2546 else if (flags
& IEEE80211_CHAN_QUARTER
)
2547 ND_PRINT((ndo
, " 11a/5Mhz"));
2549 ND_PRINT((ndo
, " 11a"));
2551 if (IS_CHAN_ANYG(flags
)) {
2552 if (flags
& IEEE80211_CHAN_HALF
)
2553 ND_PRINT((ndo
, " 11g/10Mhz"));
2554 else if (flags
& IEEE80211_CHAN_QUARTER
)
2555 ND_PRINT((ndo
, " 11g/5Mhz"));
2557 ND_PRINT((ndo
, " 11g"));
2558 } else if (IS_CHAN_B(flags
))
2559 ND_PRINT((ndo
, " 11b"));
2560 if (flags
& IEEE80211_CHAN_TURBO
)
2561 ND_PRINT((ndo
, " Turbo"));
2564 * These apply to 11n.
2566 if (flags
& IEEE80211_CHAN_HT20
)
2567 ND_PRINT((ndo
, " ht/20"));
2568 else if (flags
& IEEE80211_CHAN_HT40D
)
2569 ND_PRINT((ndo
, " ht/40-"));
2570 else if (flags
& IEEE80211_CHAN_HT40U
)
2571 ND_PRINT((ndo
, " ht/40+"));
2572 ND_PRINT((ndo
, " "));
2576 print_radiotap_field(netdissect_options
*ndo
,
2577 struct cpack_state
*s
, uint32_t bit
, uint8_t *flags
,
2578 struct radiotap_state
*state
, uint32_t presentflags
)
2587 } u
, u2
, u3
, u4
, u5
, u6
;
2593 case IEEE80211_RADIOTAP_FLAGS
:
2594 rc
= cpack_uint8(s
, &u
.u8
);
2599 case IEEE80211_RADIOTAP_RATE
:
2600 rc
= cpack_uint8(s
, &u
.u8
);
2604 /* Save state rate */
2607 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2608 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2609 case IEEE80211_RADIOTAP_ANTENNA
:
2610 rc
= cpack_uint8(s
, &u
.u8
);
2612 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2613 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2614 rc
= cpack_int8(s
, &u
.i8
);
2616 case IEEE80211_RADIOTAP_CHANNEL
:
2617 rc
= cpack_uint16(s
, &u
.u16
);
2620 rc
= cpack_uint16(s
, &u2
.u16
);
2622 case IEEE80211_RADIOTAP_FHSS
:
2623 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2624 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2625 case IEEE80211_RADIOTAP_RX_FLAGS
:
2626 rc
= cpack_uint16(s
, &u
.u16
);
2628 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2629 rc
= cpack_uint8(s
, &u
.u8
);
2631 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2632 rc
= cpack_int8(s
, &u
.i8
);
2634 case IEEE80211_RADIOTAP_TSFT
:
2635 rc
= cpack_uint64(s
, &u
.u64
);
2637 case IEEE80211_RADIOTAP_XCHANNEL
:
2638 rc
= cpack_uint32(s
, &u
.u32
);
2641 rc
= cpack_uint16(s
, &u2
.u16
);
2644 rc
= cpack_uint8(s
, &u3
.u8
);
2647 rc
= cpack_uint8(s
, &u4
.u8
);
2649 case IEEE80211_RADIOTAP_MCS
:
2650 rc
= cpack_uint8(s
, &u
.u8
);
2653 rc
= cpack_uint8(s
, &u2
.u8
);
2656 rc
= cpack_uint8(s
, &u3
.u8
);
2658 case IEEE80211_RADIOTAP_AMPDU_STATUS
:
2659 rc
= cpack_uint32(s
, &u
.u32
);
2662 rc
= cpack_uint16(s
, &u2
.u16
);
2665 rc
= cpack_uint8(s
, &u3
.u8
);
2668 rc
= cpack_uint8(s
, &u4
.u8
);
2670 case IEEE80211_RADIOTAP_VHT
:
2671 rc
= cpack_uint16(s
, &u
.u16
);
2674 rc
= cpack_uint8(s
, &u2
.u8
);
2677 rc
= cpack_uint8(s
, &u3
.u8
);
2680 for (i
= 0; i
< 4; i
++) {
2681 rc
= cpack_uint8(s
, &mcs_nss
[i
]);
2685 rc
= cpack_uint8(s
, &u4
.u8
);
2688 rc
= cpack_uint8(s
, &u5
.u8
);
2691 rc
= cpack_uint16(s
, &u6
.u16
);
2694 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE
: {
2699 if ((cpack_align_and_reserve(s
, 2)) == NULL
) {
2704 rc
= cpack_uint8(s
, &vns
[0]);
2707 rc
= cpack_uint8(s
, &vns
[1]);
2710 rc
= cpack_uint8(s
, &vns
[2]);
2713 rc
= cpack_uint8(s
, &subspace
);
2716 rc
= cpack_uint16(s
, &length
);
2720 /* Skip up to length */
2721 s
->c_next
+= length
;
2725 /* this bit indicates a field whose
2726 * size we do not know, so we cannot
2727 * proceed. Just print the bit number.
2729 ND_PRINT((ndo
, "[bit %u] ", bit
));
2734 ND_PRINT((ndo
, "%s", tstr
));
2738 /* Preserve the state present flags */
2739 state
->present
= presentflags
;
2742 case IEEE80211_RADIOTAP_CHANNEL
:
2744 * If CHANNEL and XCHANNEL are both present, skip
2747 if (presentflags
& (1 << IEEE80211_RADIOTAP_XCHANNEL
))
2749 print_chaninfo(ndo
, u
.u16
, u2
.u16
, presentflags
);
2751 case IEEE80211_RADIOTAP_FHSS
:
2752 ND_PRINT((ndo
, "fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff));
2754 case IEEE80211_RADIOTAP_RATE
:
2756 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2757 * Linux and AirPcap it does not. (What about
2758 * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
2760 * This is an issue either for proprietary extensions
2761 * to 11a or 11g, which do exist, or for 11n
2762 * implementations that stuff a rate value into
2763 * this field, which also appear to exist.
2765 * We currently handle that by assuming that
2766 * if the 0x80 bit is set *and* the remaining
2767 * bits have a value between 0 and 15 it's
2768 * an MCS value, otherwise it's a rate. If
2769 * there are cases where systems that use
2770 * "0x80 + MCS index" for MCS indices > 15,
2771 * or stuff a rate value here between 64 and
2772 * 71.5 Mb/s in here, we'll need a preference
2773 * setting. Such rates do exist, e.g. 11n
2774 * MCS 7 at 20 MHz with a long guard interval.
2776 if (u
.u8
>= 0x80 && u
.u8
<= 0x8f) {
2778 * XXX - we don't know the channel width
2779 * or guard interval length, so we can't
2780 * convert this to a data rate.
2782 * If you want us to show a data rate,
2783 * use the MCS field, not the Rate field;
2784 * the MCS field includes not only the
2785 * MCS index, it also includes bandwidth
2786 * and guard interval information.
2788 * XXX - can we get the channel width
2789 * from XChannel and the guard interval
2790 * information from Flags, at least on
2793 ND_PRINT((ndo
, "MCS %u ", u
.u8
& 0x7f));
2795 ND_PRINT((ndo
, "%2.1f Mb/s ", .5 * u
.u8
));
2797 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2798 ND_PRINT((ndo
, "%ddBm signal ", u
.i8
));
2800 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2801 ND_PRINT((ndo
, "%ddBm noise ", u
.i8
));
2803 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2804 ND_PRINT((ndo
, "%ddB signal ", u
.u8
));
2806 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2807 ND_PRINT((ndo
, "%ddB noise ", u
.u8
));
2809 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2810 ND_PRINT((ndo
, "%u sq ", u
.u16
));
2812 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2813 ND_PRINT((ndo
, "%d tx power ", -(int)u
.u16
));
2815 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2816 ND_PRINT((ndo
, "%ddB tx power ", -(int)u
.u8
));
2818 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2819 ND_PRINT((ndo
, "%ddBm tx power ", u
.i8
));
2821 case IEEE80211_RADIOTAP_FLAGS
:
2822 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
2823 ND_PRINT((ndo
, "cfp "));
2824 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
2825 ND_PRINT((ndo
, "short preamble "));
2826 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
2827 ND_PRINT((ndo
, "wep "));
2828 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
2829 ND_PRINT((ndo
, "fragmented "));
2830 if (u
.u8
& IEEE80211_RADIOTAP_F_BADFCS
)
2831 ND_PRINT((ndo
, "bad-fcs "));
2833 case IEEE80211_RADIOTAP_ANTENNA
:
2834 ND_PRINT((ndo
, "antenna %d ", u
.u8
));
2836 case IEEE80211_RADIOTAP_TSFT
:
2837 ND_PRINT((ndo
, "%" PRIu64
"us tsft ", u
.u64
));
2839 case IEEE80211_RADIOTAP_RX_FLAGS
:
2840 /* Do nothing for now */
2842 case IEEE80211_RADIOTAP_XCHANNEL
:
2843 print_chaninfo(ndo
, u2
.u16
, u
.u32
, presentflags
);
2845 case IEEE80211_RADIOTAP_MCS
: {
2846 static const char *ht_bandwidth
[4] = {
2854 if (u
.u8
& IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN
) {
2856 * We know the MCS index.
2858 if (u3
.u8
<= MAX_MCS_INDEX
) {
2860 * And it's in-range.
2862 if (u
.u8
& (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
)) {
2864 * And we know both the bandwidth and
2865 * the guard interval, so we can look
2869 ieee80211_float_htrates \
2871 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40
? 1 : 0)] \
2872 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ? 1 : 0)];
2875 * We don't know both the bandwidth
2876 * and the guard interval, so we can
2877 * only report the MCS index.
2883 * The MCS value is out of range.
2887 if (htrate
!= 0.0) {
2892 ND_PRINT((ndo
, "%.1f Mb/s MCS %u ", htrate
, u3
.u8
));
2895 * We at least have the MCS index.
2898 ND_PRINT((ndo
, "MCS %u ", u3
.u8
));
2901 if (u
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
) {
2902 ND_PRINT((ndo
, "%s ",
2903 ht_bandwidth
[u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
]));
2905 if (u
.u8
& IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
) {
2906 ND_PRINT((ndo
, "%s GI ",
2907 (u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ?
2910 if (u
.u8
& IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN
) {
2911 ND_PRINT((ndo
, "%s ",
2912 (u2
.u8
& IEEE80211_RADIOTAP_MCS_HT_GREENFIELD
) ?
2913 "greenfield" : "mixed"));
2915 if (u
.u8
& IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN
) {
2916 ND_PRINT((ndo
, "%s FEC ",
2917 (u2
.u8
& IEEE80211_RADIOTAP_MCS_FEC_LDPC
) ?
2920 if (u
.u8
& IEEE80211_RADIOTAP_MCS_STBC_KNOWN
) {
2921 ND_PRINT((ndo
, "RX-STBC%u ",
2922 (u2
.u8
& IEEE80211_RADIOTAP_MCS_STBC_MASK
) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT
));
2927 case IEEE80211_RADIOTAP_AMPDU_STATUS
:
2929 case IEEE80211_RADIOTAP_VHT
: {
2930 static const char *vht_bandwidth
[32] = {
2965 for (i
= 0; i
< 4; i
++) {
2967 nss
= mcs_nss
[i
] & IEEE80211_RADIOTAP_VHT_NSS_MASK
;
2968 mcs
= (mcs_nss
[i
] & IEEE80211_RADIOTAP_VHT_MCS_MASK
) >> IEEE80211_RADIOTAP_VHT_MCS_SHIFT
;
2973 ND_PRINT((ndo
, "User %u MCS %u ", i
, mcs
));
2974 ND_PRINT((ndo
, "%s FEC ",
2975 (u4
.u8
& (IEEE80211_RADIOTAP_CODING_LDPC_USERn
<< i
)) ?
2978 if (u
.u16
& IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN
) {
2979 ND_PRINT((ndo
, "%s ",
2980 vht_bandwidth
[u3
.u8
& IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK
]));
2982 if (u
.u16
& IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN
) {
2983 ND_PRINT((ndo
, "%s GI ",
2984 (u2
.u8
& IEEE80211_RADIOTAP_VHT_SHORT_GI
) ?
2994 ieee802_11_radio_print(netdissect_options
*ndo
,
2995 const u_char
*p
, u_int length
, u_int caplen
)
2997 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
2998 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
2999 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
3000 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
3001 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
3002 #define BIT(n) (1U << n)
3003 #define IS_EXTENDED(__p) \
3004 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
3006 struct cpack_state cpacker
;
3007 const struct ieee80211_radiotap_header
*hdr
;
3008 uint32_t present
, next_present
;
3009 uint32_t presentflags
= 0;
3010 const uint32_t *presentp
, *last_presentp
;
3011 enum ieee80211_radiotap_type bit
;
3017 struct radiotap_state state
;
3019 if (caplen
< sizeof(*hdr
)) {
3020 ND_PRINT((ndo
, "%s", tstr
));
3024 hdr
= (const struct ieee80211_radiotap_header
*)p
;
3026 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
3029 ND_PRINT((ndo
, "%s", tstr
));
3032 cpack_init(&cpacker
, (const uint8_t *)hdr
, len
); /* align against header start */
3033 cpack_advance(&cpacker
, sizeof(*hdr
)); /* includes the 1st bitmap */
3034 for (last_presentp
= &hdr
->it_present
;
3035 IS_EXTENDED(last_presentp
) &&
3036 (const u_char
*)(last_presentp
+ 1) <= p
+ len
;
3038 cpack_advance(&cpacker
, sizeof(hdr
->it_present
)); /* more bitmaps */
3040 /* are there more bitmap extensions than bytes in header? */
3041 if (IS_EXTENDED(last_presentp
)) {
3042 ND_PRINT((ndo
, "%s", tstr
));
3046 /* Assume no flags */
3048 /* Assume no Atheros padding between 802.11 header and body */
3050 /* Assume no FCS at end of frame */
3052 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
3053 presentp
++, bit0
+= 32) {
3054 presentflags
= EXTRACT_LE_32BITS(presentp
);
3057 memset(&state
, 0, sizeof(state
));
3059 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
3060 present
= next_present
) {
3061 /* clear the least significant bit that is set */
3062 next_present
= present
& (present
- 1);
3064 /* extract the least significant bit that is set */
3065 bit
= (enum ieee80211_radiotap_type
)
3066 (bit0
+ BITNO_32(present
^ next_present
));
3068 if (print_radiotap_field(ndo
, &cpacker
, bit
, &flags
, &state
, presentflags
) != 0)
3074 if (flags
& IEEE80211_RADIOTAP_F_DATAPAD
)
3075 pad
= 1; /* Atheros padding */
3076 if (flags
& IEEE80211_RADIOTAP_F_FCS
)
3077 fcslen
= 4; /* FCS at end of packet */
3078 return len
+ ieee802_11_print(ndo
, p
+ len
, length
- len
, caplen
- len
, pad
,
3089 ieee802_11_avs_radio_print(netdissect_options
*ndo
,
3090 const u_char
*p
, u_int length
, u_int caplen
)
3092 uint32_t caphdr_len
;
3095 ND_PRINT((ndo
, "%s", tstr
));
3099 caphdr_len
= EXTRACT_32BITS(p
+ 4);
3100 if (caphdr_len
< 8) {
3102 * Yow! The capture header length is claimed not
3103 * to be large enough to include even the version
3104 * cookie or capture header length!
3106 ND_PRINT((ndo
, "%s", tstr
));
3110 if (caplen
< caphdr_len
) {
3111 ND_PRINT((ndo
, "%s", tstr
));
3115 return caphdr_len
+ ieee802_11_print(ndo
, p
+ caphdr_len
,
3116 length
- caphdr_len
, caplen
- caphdr_len
, 0, 0);
3119 #define PRISM_HDR_LEN 144
3121 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
3122 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
3123 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
3126 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
3127 * containing information such as radio information, which we
3130 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
3131 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
3132 * (currently, on Linux, there's no ARPHRD_ type for
3133 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
3134 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
3135 * the AVS header, and the first 4 bytes of the header are used to
3136 * indicate whether it's a Prism header or an AVS header).
3139 prism_if_print(netdissect_options
*ndo
,
3140 const struct pcap_pkthdr
*h
, const u_char
*p
)
3142 u_int caplen
= h
->caplen
;
3143 u_int length
= h
->len
;
3147 ND_PRINT((ndo
, "%s", tstr
));
3151 msgcode
= EXTRACT_32BITS(p
);
3152 if (msgcode
== WLANCAP_MAGIC_COOKIE_V1
||
3153 msgcode
== WLANCAP_MAGIC_COOKIE_V2
)
3154 return ieee802_11_avs_radio_print(ndo
, p
, length
, caplen
);
3156 if (caplen
< PRISM_HDR_LEN
) {
3157 ND_PRINT((ndo
, "%s", tstr
));
3161 return PRISM_HDR_LEN
+ ieee802_11_print(ndo
, p
+ PRISM_HDR_LEN
,
3162 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
, 0, 0);
3166 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
3167 * header, containing information such as radio information.
3170 ieee802_11_radio_if_print(netdissect_options
*ndo
,
3171 const struct pcap_pkthdr
*h
, const u_char
*p
)
3173 return ieee802_11_radio_print(ndo
, p
, h
->len
, h
->caplen
);
3177 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
3178 * extra header, containing information such as radio information,
3179 * which we currently ignore.
3182 ieee802_11_radio_avs_if_print(netdissect_options
*ndo
,
3183 const struct pcap_pkthdr
*h
, const u_char
*p
)
3185 return ieee802_11_avs_radio_print(ndo
, p
, h
->len
, h
->caplen
);