]> The Tcpdump Group git mirrors - tcpdump/blob - print-802_11.c
Skip the LLC and SNAP headers with -x.
[tcpdump] / print-802_11.c
1 /*
2 * Copyright (c) 2001
3 * Fortress Technologies, Inc. All rights reserved.
4 * Charlie Lenahan (clenahan@fortresstech.com)
5 *
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
17 * written permission.
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.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <tcpdump-stdinc.h>
28
29 #include <string.h>
30
31 #include "interface.h"
32 #include "addrtoname.h"
33
34 #include "extract.h"
35
36 #include "cpack.h"
37
38
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
54
55 /* Frame check sequence length. */
56 #define IEEE802_11_FCS_LEN 4
57
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
63
64 #define IEEE802_11_AID_LEN 2
65 #define IEEE802_11_STATUS_LEN 2
66 #define IEEE802_11_REASON_LEN 2
67
68 /* Length of previous AP in reassocation frame */
69 #define IEEE802_11_AP_LEN 6
70
71 #define T_MGMT 0x0 /* management */
72 #define T_CTRL 0x1 /* control */
73 #define T_DATA 0x2 /* data */
74 #define T_RESV 0x3 /* reserved */
75
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
82 /* RESERVED 0x6 */
83 /* RESERVED 0x7 */
84 #define ST_BEACON 0x8
85 #define ST_ATIM 0x9
86 #define ST_DISASSOC 0xA
87 #define ST_AUTH 0xB
88 #define ST_DEAUTH 0xC
89 #define ST_ACTION 0xD
90 /* RESERVED 0xE */
91 /* RESERVED 0xF */
92
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" },
101 { ST_ATIM, "ATIM" },
102 { ST_DISASSOC, "Disassociation" },
103 { ST_AUTH, "Authentication" },
104 { ST_DEAUTH, "DeAuthentication" },
105 { ST_ACTION, "Action" },
106 { 0, NULL }
107 };
108
109 #define CTRL_CONTROL_WRAPPER 0x7
110 #define CTRL_BAR 0x8
111 #define CTRL_BA 0x9
112 #define CTRL_PS_POLL 0xA
113 #define CTRL_RTS 0xB
114 #define CTRL_CTS 0xC
115 #define CTRL_ACK 0xD
116 #define CTRL_CF_END 0xE
117 #define CTRL_END_ACK 0xF
118
119 static const struct tok ctrl_str[] = {
120 { CTRL_CONTROL_WRAPPER, "Control Wrapper" },
121 { CTRL_BAR, "BAR" },
122 { CTRL_BA, "BA" },
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" },
129 { 0, NULL }
130 };
131
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
140
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
148
149 /*
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.
153 */
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)
158
159 /*
160 * Bits in the frame control field.
161 */
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)
173
174 struct mgmt_header_t {
175 uint16_t fc;
176 uint16_t duration;
177 uint8_t da[IEEE802_11_DA_LEN];
178 uint8_t sa[IEEE802_11_SA_LEN];
179 uint8_t bssid[IEEE802_11_BSSID_LEN];
180 uint16_t seq_ctrl;
181 };
182
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)
186
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)
192
193 struct ssid_t {
194 uint8_t element_id;
195 uint8_t length;
196 u_char ssid[33]; /* 32 + 1 for null */
197 };
198
199 struct rates_t {
200 uint8_t element_id;
201 uint8_t length;
202 uint8_t rate[16];
203 };
204
205 struct challenge_t {
206 uint8_t element_id;
207 uint8_t length;
208 uint8_t text[254]; /* 1-253 + 1 for null */
209 };
210
211 struct fh_t {
212 uint8_t element_id;
213 uint8_t length;
214 uint16_t dwell_time;
215 uint8_t hop_set;
216 uint8_t hop_pattern;
217 uint8_t hop_index;
218 };
219
220 struct ds_t {
221 uint8_t element_id;
222 uint8_t length;
223 uint8_t channel;
224 };
225
226 struct cf_t {
227 uint8_t element_id;
228 uint8_t length;
229 uint8_t count;
230 uint8_t period;
231 uint16_t max_duration;
232 uint16_t dur_remaing;
233 };
234
235 struct tim_t {
236 uint8_t element_id;
237 uint8_t length;
238 uint8_t count;
239 uint8_t period;
240 uint8_t bitmap_control;
241 uint8_t bitmap[251];
242 };
243
244 #define E_SSID 0
245 #define E_RATES 1
246 #define E_FH 2
247 #define E_DS 3
248 #define E_CF 4
249 #define E_TIM 5
250 #define E_IBSS 6
251 /* reserved 7 */
252 /* reserved 8 */
253 /* reserved 9 */
254 /* reserved 10 */
255 /* reserved 11 */
256 /* reserved 12 */
257 /* reserved 13 */
258 /* reserved 14 */
259 /* reserved 15 */
260 /* reserved 16 */
261
262 #define E_CHALLENGE 16
263 /* reserved 17 */
264 /* reserved 18 */
265 /* reserved 19 */
266 /* reserved 16 */
267 /* reserved 16 */
268
269
270 struct mgmt_body_t {
271 uint8_t timestamp[IEEE802_11_TSTAMP_LEN];
272 uint16_t beacon_interval;
273 uint16_t listen_interval;
274 uint16_t status_code;
275 uint16_t aid;
276 u_char ap[IEEE802_11_AP_LEN];
277 uint16_t reason_code;
278 uint16_t auth_alg;
279 uint16_t auth_trans_seq_num;
280 int challenge_present;
281 struct challenge_t challenge;
282 uint16_t capability_info;
283 int ssid_present;
284 struct ssid_t ssid;
285 int rates_present;
286 struct rates_t rates;
287 int ds_present;
288 struct ds_t ds;
289 int cf_present;
290 struct cf_t cf;
291 int fh_present;
292 struct fh_t fh;
293 int tim_present;
294 struct tim_t tim;
295 };
296
297 struct ctrl_control_wrapper_hdr_t {
298 uint16_t fc;
299 uint16_t duration;
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];
303 };
304
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)
309
310 struct ctrl_rts_hdr_t {
311 uint16_t fc;
312 uint16_t duration;
313 uint8_t ra[IEEE802_11_RA_LEN];
314 uint8_t ta[IEEE802_11_TA_LEN];
315 };
316
317 #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
318 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
319
320 struct ctrl_cts_hdr_t {
321 uint16_t fc;
322 uint16_t duration;
323 uint8_t ra[IEEE802_11_RA_LEN];
324 };
325
326 #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
327
328 struct ctrl_ack_hdr_t {
329 uint16_t fc;
330 uint16_t duration;
331 uint8_t ra[IEEE802_11_RA_LEN];
332 };
333
334 #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
335
336 struct ctrl_ps_poll_hdr_t {
337 uint16_t fc;
338 uint16_t aid;
339 uint8_t bssid[IEEE802_11_BSSID_LEN];
340 uint8_t ta[IEEE802_11_TA_LEN];
341 };
342
343 #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
344 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
345
346 struct ctrl_end_hdr_t {
347 uint16_t fc;
348 uint16_t duration;
349 uint8_t ra[IEEE802_11_RA_LEN];
350 uint8_t bssid[IEEE802_11_BSSID_LEN];
351 };
352
353 #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
354 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
355
356 struct ctrl_end_ack_hdr_t {
357 uint16_t fc;
358 uint16_t duration;
359 uint8_t ra[IEEE802_11_RA_LEN];
360 uint8_t bssid[IEEE802_11_BSSID_LEN];
361 };
362
363 #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
364 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
365
366 struct ctrl_ba_hdr_t {
367 uint16_t fc;
368 uint16_t duration;
369 uint8_t ra[IEEE802_11_RA_LEN];
370 };
371
372 #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
373
374 struct ctrl_bar_hdr_t {
375 uint16_t fc;
376 uint16_t dur;
377 uint8_t ra[IEEE802_11_RA_LEN];
378 uint8_t ta[IEEE802_11_TA_LEN];
379 uint16_t ctl;
380 uint16_t seq;
381 };
382
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)
386
387 struct meshcntl_t {
388 uint8_t flags;
389 uint8_t ttl;
390 uint8_t seq[4];
391 uint8_t addr4[6];
392 uint8_t addr5[6];
393 uint8_t addr6[6];
394 };
395
396 #define IV_IV(iv) ((iv) & 0xFFFFFF)
397 #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
398 #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
399
400 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
401 /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
402
403 /*-
404 * Copyright (c) 2003, 2004 David Young. All rights reserved.
405 *
406 * Redistribution and use in source and binary forms, with or without
407 * modification, are permitted provided that the following conditions
408 * are met:
409 * 1. Redistributions of source code must retain the above copyright
410 * notice, this list of conditions and the following disclaimer.
411 * 2. Redistributions in binary form must reproduce the above copyright
412 * notice, this list of conditions and the following disclaimer in the
413 * documentation and/or other materials provided with the distribution.
414 * 3. The name of David Young may not be used to endorse or promote
415 * products derived from this software without specific prior
416 * written permission.
417 *
418 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
419 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
420 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
421 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
422 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
423 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
424 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
425 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
426 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
427 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
428 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
429 * OF SUCH DAMAGE.
430 */
431
432 /* A generic radio capture format is desirable. It must be
433 * rigidly defined (e.g., units for fields should be given),
434 * and easily extensible.
435 *
436 * The following is an extensible radio capture format. It is
437 * based on a bitmap indicating which fields are present.
438 *
439 * I am trying to describe precisely what the application programmer
440 * should expect in the following, and for that reason I tell the
441 * units and origin of each measurement (where it applies), or else I
442 * use sufficiently weaselly language ("is a monotonically nondecreasing
443 * function of...") that I cannot set false expectations for lawyerly
444 * readers.
445 */
446
447 /*
448 * The radio capture header precedes the 802.11 header.
449 *
450 * Note well: all radiotap fields are little-endian.
451 */
452 struct ieee80211_radiotap_header {
453 uint8_t it_version; /* Version 0. Only increases
454 * for drastic changes,
455 * introduction of compatible
456 * new fields does not count.
457 */
458 uint8_t it_pad;
459 uint16_t it_len; /* length of the whole
460 * header in bytes, including
461 * it_version, it_pad,
462 * it_len, and data fields.
463 */
464 uint32_t it_present; /* A bitmap telling which
465 * fields are present. Set bit 31
466 * (0x80000000) to extend the
467 * bitmap by another 32 bits.
468 * Additional extensions are made
469 * by setting bit 31.
470 */
471 };
472
473 /* Name Data type Units
474 * ---- --------- -----
475 *
476 * IEEE80211_RADIOTAP_TSFT uint64_t microseconds
477 *
478 * Value in microseconds of the MAC's 64-bit 802.11 Time
479 * Synchronization Function timer when the first bit of the
480 * MPDU arrived at the MAC. For received frames, only.
481 *
482 * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap
483 *
484 * Tx/Rx frequency in MHz, followed by flags (see below).
485 * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
486 * represent an HT channel as there is not enough room in
487 * the flags word.
488 *
489 * IEEE80211_RADIOTAP_FHSS uint16_t see below
490 *
491 * For frequency-hopping radios, the hop set (first byte)
492 * and pattern (second byte).
493 *
494 * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index
495 *
496 * Tx/Rx data rate. If bit 0x80 is set then it represents an
497 * an MCS index and not an IEEE rate.
498 *
499 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
500 * one milliwatt (dBm)
501 *
502 * RF signal power at the antenna, decibel difference from
503 * one milliwatt.
504 *
505 * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
506 * one milliwatt (dBm)
507 *
508 * RF noise power at the antenna, decibel difference from one
509 * milliwatt.
510 *
511 * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
512 *
513 * RF signal power at the antenna, decibel difference from an
514 * arbitrary, fixed reference.
515 *
516 * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
517 *
518 * RF noise power at the antenna, decibel difference from an
519 * arbitrary, fixed reference point.
520 *
521 * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless
522 *
523 * Quality of Barker code lock. Unitless. Monotonically
524 * nondecreasing with "better" lock strength. Called "Signal
525 * Quality" in datasheets. (Is there a standard way to measure
526 * this?)
527 *
528 * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless
529 *
530 * Transmit power expressed as unitless distance from max
531 * power set at factory calibration. 0 is max power.
532 * Monotonically nondecreasing with lower power levels.
533 *
534 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB)
535 *
536 * Transmit power expressed as decibel distance from max power
537 * set at factory calibration. 0 is max power. Monotonically
538 * nondecreasing with lower power levels.
539 *
540 * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
541 * one milliwatt (dBm)
542 *
543 * Transmit power expressed as dBm (decibels from a 1 milliwatt
544 * reference). This is the absolute power level measured at
545 * the antenna port.
546 *
547 * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap
548 *
549 * Properties of transmitted and received frames. See flags
550 * defined below.
551 *
552 * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index
553 *
554 * Unitless indication of the Rx/Tx antenna for this packet.
555 * The first antenna is antenna 0.
556 *
557 * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap
558 *
559 * Properties of received frames. See flags defined below.
560 *
561 * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap
562 * uint16_t MHz
563 * uint8_t channel number
564 * uint8_t .5 dBm
565 *
566 * Extended channel specification: flags (see below) followed by
567 * frequency in MHz, the corresponding IEEE channel number, and
568 * finally the maximum regulatory transmit power cap in .5 dBm
569 * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
570 * and only one of the two should be present.
571 *
572 * IEEE80211_RADIOTAP_MCS uint8_t known
573 * uint8_t flags
574 * uint8_t mcs
575 *
576 * Bitset indicating which fields have known values, followed
577 * by bitset of flag values, followed by the MCS rate index as
578 * in IEEE 802.11n.
579 *
580 * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
581 * uint8_t OUI[3]
582 * uint8_t subspace
583 * uint16_t length
584 *
585 * The Vendor Namespace Field contains three sub-fields. The first
586 * sub-field is 3 bytes long. It contains the vendor's IEEE 802
587 * Organizationally Unique Identifier (OUI). The fourth byte is a
588 * vendor-specific "namespace selector."
589 *
590 */
591 enum ieee80211_radiotap_type {
592 IEEE80211_RADIOTAP_TSFT = 0,
593 IEEE80211_RADIOTAP_FLAGS = 1,
594 IEEE80211_RADIOTAP_RATE = 2,
595 IEEE80211_RADIOTAP_CHANNEL = 3,
596 IEEE80211_RADIOTAP_FHSS = 4,
597 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
598 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
599 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
600 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
601 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
602 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
603 IEEE80211_RADIOTAP_ANTENNA = 11,
604 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
605 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
606 IEEE80211_RADIOTAP_RX_FLAGS = 14,
607 /* NB: gap for netbsd definitions */
608 IEEE80211_RADIOTAP_XCHANNEL = 18,
609 IEEE80211_RADIOTAP_MCS = 19,
610 IEEE80211_RADIOTAP_NAMESPACE = 29,
611 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
612 IEEE80211_RADIOTAP_EXT = 31
613 };
614
615 /* channel attributes */
616 #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
617 #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
618 #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
619 #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
620 #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
621 #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
622 #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
623 #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
624 #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
625 #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
626 #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
627 #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
628 #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
629 #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
630 #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
631
632 /* Useful combinations of channel characteristics, borrowed from Ethereal */
633 #define IEEE80211_CHAN_A \
634 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
635 #define IEEE80211_CHAN_B \
636 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
637 #define IEEE80211_CHAN_G \
638 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
639 #define IEEE80211_CHAN_TA \
640 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
641 #define IEEE80211_CHAN_TG \
642 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
643
644
645 /* For IEEE80211_RADIOTAP_FLAGS */
646 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
647 * during CFP
648 */
649 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
650 * with short
651 * preamble
652 */
653 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
654 * with WEP encryption
655 */
656 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
657 * with fragmentation
658 */
659 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
660 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
661 * 802.11 header and payload
662 * (to 32-bit boundary)
663 */
664 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
665
666 /* For IEEE80211_RADIOTAP_RX_FLAGS */
667 #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
668 #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
669
670 /* For IEEE80211_RADIOTAP_MCS known */
671 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
672 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
673 #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
674 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
675 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
676 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
677
678 /* For IEEE80211_RADIOTAP_MCS flags */
679 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
680 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
681 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
682 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
683 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
684 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
685 #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
686 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
687 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
688 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
689 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
690 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
691 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
692
693 static const char tstr[] = "[|802.11]";
694
695 /* Radiotap state */
696 /* This is used to save state when parsing/processing parameters */
697 struct radiotap_state
698 {
699 uint32_t present;
700
701 uint8_t rate;
702 };
703
704 #define PRINT_SSID(p) \
705 if (p.ssid_present) { \
706 ND_PRINT((ndo, " (")); \
707 fn_print(ndo, p.ssid.ssid, NULL); \
708 ND_PRINT((ndo, ")")); \
709 }
710
711 #define PRINT_RATE(_sep, _r, _suf) \
712 ND_PRINT((ndo, "%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf))
713 #define PRINT_RATES(p) \
714 if (p.rates_present) { \
715 int z; \
716 const char *sep = " ["; \
717 for (z = 0; z < p.rates.length ; z++) { \
718 PRINT_RATE(sep, p.rates.rate[z], \
719 (p.rates.rate[z] & 0x80 ? "*" : "")); \
720 sep = " "; \
721 } \
722 if (p.rates.length != 0) \
723 ND_PRINT((ndo, " Mbit]")); \
724 }
725
726 #define PRINT_DS_CHANNEL(p) \
727 if (p.ds_present) \
728 ND_PRINT((ndo, " CH: %u", p.ds.channel)); \
729 ND_PRINT((ndo, "%s", \
730 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : ""));
731
732 #define MAX_MCS_INDEX 76
733
734 /*
735 * Indices are:
736 *
737 * the MCS index (0-76);
738 *
739 * 0 for 20 MHz, 1 for 40 MHz;
740 *
741 * 0 for a long guard interval, 1 for a short guard interval.
742 */
743 static const float ieee80211_float_htrates[MAX_MCS_INDEX+1][2][2] = {
744 /* MCS 0 */
745 { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, },
746 /* 40 Mhz */ { 13.5, /* SGI */ 15.0, },
747 },
748
749 /* MCS 1 */
750 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
751 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
752 },
753
754 /* MCS 2 */
755 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
756 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
757 },
758
759 /* MCS 3 */
760 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
761 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
762 },
763
764 /* MCS 4 */
765 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
766 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
767 },
768
769 /* MCS 5 */
770 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
771 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
772 },
773
774 /* MCS 6 */
775 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
776 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
777 },
778
779 /* MCS 7 */
780 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
781 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
782 },
783
784 /* MCS 8 */
785 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
786 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
787 },
788
789 /* MCS 9 */
790 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
791 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
792 },
793
794 /* MCS 10 */
795 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
796 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
797 },
798
799 /* MCS 11 */
800 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
801 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
802 },
803
804 /* MCS 12 */
805 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
806 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
807 },
808
809 /* MCS 13 */
810 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
811 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
812 },
813
814 /* MCS 14 */
815 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
816 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
817 },
818
819 /* MCS 15 */
820 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
821 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
822 },
823
824 /* MCS 16 */
825 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
826 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
827 },
828
829 /* MCS 17 */
830 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
831 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
832 },
833
834 /* MCS 18 */
835 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
836 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
837 },
838
839 /* MCS 19 */
840 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
841 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
842 },
843
844 /* MCS 20 */
845 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
846 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
847 },
848
849 /* MCS 21 */
850 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
851 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
852 },
853
854 /* MCS 22 */
855 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
856 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
857 },
858
859 /* MCS 23 */
860 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
861 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
862 },
863
864 /* MCS 24 */
865 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
866 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
867 },
868
869 /* MCS 25 */
870 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
871 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
872 },
873
874 /* MCS 26 */
875 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
876 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
877 },
878
879 /* MCS 27 */
880 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
881 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
882 },
883
884 /* MCS 28 */
885 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
886 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
887 },
888
889 /* MCS 29 */
890 { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, },
891 /* 40 Mhz */ { 432.0, /* SGI */ 480.0, },
892 },
893
894 /* MCS 30 */
895 { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, },
896 /* 40 Mhz */ { 486.0, /* SGI */ 540.0, },
897 },
898
899 /* MCS 31 */
900 { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, },
901 /* 40 Mhz */ { 540.0, /* SGI */ 600.0, },
902 },
903
904 /* MCS 32 */
905 { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */
906 /* 40 Mhz */ { 6.0, /* SGI */ 6.7, },
907 },
908
909 /* MCS 33 */
910 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
911 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
912 },
913
914 /* MCS 34 */
915 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
916 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
917 },
918
919 /* MCS 35 */
920 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
921 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
922 },
923
924 /* MCS 36 */
925 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
926 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
927 },
928
929 /* MCS 37 */
930 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
931 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
932 },
933
934 /* MCS 38 */
935 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
936 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
937 },
938
939 /* MCS 39 */
940 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
941 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
942 },
943
944 /* MCS 40 */
945 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
946 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
947 },
948
949 /* MCS 41 */
950 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
951 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
952 },
953
954 /* MCS 42 */
955 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
956 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
957 },
958
959 /* MCS 43 */
960 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
961 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
962 },
963
964 /* MCS 44 */
965 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
966 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
967 },
968
969 /* MCS 45 */
970 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
971 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
972 },
973
974 /* MCS 46 */
975 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
976 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
977 },
978
979 /* MCS 47 */
980 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
981 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
982 },
983
984 /* MCS 48 */
985 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
986 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
987 },
988
989 /* MCS 49 */
990 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
991 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
992 },
993
994 /* MCS 50 */
995 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
996 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
997 },
998
999 /* MCS 51 */
1000 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1001 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1002 },
1003
1004 /* MCS 52 */
1005 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1006 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1007 },
1008
1009 /* MCS 53 */
1010 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
1011 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
1012 },
1013
1014 /* MCS 54 */
1015 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
1016 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
1017 },
1018
1019 /* MCS 55 */
1020 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
1021 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
1022 },
1023
1024 /* MCS 56 */
1025 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
1026 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
1027 },
1028
1029 /* MCS 57 */
1030 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
1031 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
1032 },
1033
1034 /* MCS 58 */
1035 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1036 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1037 },
1038
1039 /* MCS 59 */
1040 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1041 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1042 },
1043
1044 /* MCS 60 */
1045 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1046 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1047 },
1048
1049 /* MCS 61 */
1050 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1051 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1052 },
1053
1054 /* MCS 62 */
1055 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1056 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1057 },
1058
1059 /* MCS 63 */
1060 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1061 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1062 },
1063
1064 /* MCS 64 */
1065 { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, },
1066 /* 40 Mhz */ { 297.0, /* SGI */ 330.0, },
1067 },
1068
1069 /* MCS 65 */
1070 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
1071 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
1072 },
1073
1074 /* MCS 66 */
1075 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1076 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1077 },
1078
1079 /* MCS 67 */
1080 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1081 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1082 },
1083
1084 /* MCS 68 */
1085 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1086 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1087 },
1088
1089 /* MCS 69 */
1090 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1091 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1092 },
1093
1094 /* MCS 70 */
1095 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1096 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1097 },
1098
1099 /* MCS 71 */
1100 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1101 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1102 },
1103
1104 /* MCS 72 */
1105 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1106 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1107 },
1108
1109 /* MCS 73 */
1110 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1111 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1112 },
1113
1114 /* MCS 74 */
1115 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1116 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1117 },
1118
1119 /* MCS 75 */
1120 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1121 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1122 },
1123
1124 /* MCS 76 */
1125 { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, },
1126 /* 40 Mhz */ { 445.5, /* SGI */ 495.0, },
1127 },
1128 };
1129
1130 static const char *auth_alg_text[]={"Open System","Shared Key","EAP"};
1131 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
1132
1133 static const char *status_text[] = {
1134 "Successful", /* 0 */
1135 "Unspecified failure", /* 1 */
1136 "Reserved", /* 2 */
1137 "Reserved", /* 3 */
1138 "Reserved", /* 4 */
1139 "Reserved", /* 5 */
1140 "Reserved", /* 6 */
1141 "Reserved", /* 7 */
1142 "Reserved", /* 8 */
1143 "Reserved", /* 9 */
1144 "Cannot Support all requested capabilities in the Capability "
1145 "Information field", /* 10 */
1146 "Reassociation denied due to inability to confirm that association "
1147 "exists", /* 11 */
1148 "Association denied due to reason outside the scope of the "
1149 "standard", /* 12 */
1150 "Responding station does not support the specified authentication "
1151 "algorithm ", /* 13 */
1152 "Received an Authentication frame with authentication transaction "
1153 "sequence number out of expected sequence", /* 14 */
1154 "Authentication rejected because of challenge failure", /* 15 */
1155 "Authentication rejected due to timeout waiting for next frame in "
1156 "sequence", /* 16 */
1157 "Association denied because AP is unable to handle additional"
1158 "associated stations", /* 17 */
1159 "Association denied due to requesting station not supporting all of "
1160 "the data rates in BSSBasicRateSet parameter", /* 18 */
1161 "Association denied due to requesting station not supporting "
1162 "short preamble operation", /* 19 */
1163 "Association denied due to requesting station not supporting "
1164 "PBCC encoding", /* 20 */
1165 "Association denied due to requesting station not supporting "
1166 "channel agility", /* 21 */
1167 "Association request rejected because Spectrum Management "
1168 "capability is required", /* 22 */
1169 "Association request rejected because the information in the "
1170 "Power Capability element is unacceptable", /* 23 */
1171 "Association request rejected because the information in the "
1172 "Supported Channels element is unacceptable", /* 24 */
1173 "Association denied due to requesting station not supporting "
1174 "short slot operation", /* 25 */
1175 "Association denied due to requesting station not supporting "
1176 "DSSS-OFDM operation", /* 26 */
1177 "Association denied because the requested STA does not support HT "
1178 "features", /* 27 */
1179 "Reserved", /* 28 */
1180 "Association denied because the requested STA does not support "
1181 "the PCO transition time required by the AP", /* 29 */
1182 "Reserved", /* 30 */
1183 "Reserved", /* 31 */
1184 "Unspecified, QoS-related failure", /* 32 */
1185 "Association denied due to QAP having insufficient bandwidth "
1186 "to handle another QSTA", /* 33 */
1187 "Association denied due to excessive frame loss rates and/or "
1188 "poor conditions on current operating channel", /* 34 */
1189 "Association (with QBSS) denied due to requesting station not "
1190 "supporting the QoS facility", /* 35 */
1191 "Association denied due to requesting station not supporting "
1192 "Block Ack", /* 36 */
1193 "The request has been declined", /* 37 */
1194 "The request has not been successful as one or more parameters "
1195 "have invalid values", /* 38 */
1196 "The TS has not been created because the request cannot be honored. "
1197 "Try again with the suggested changes to the TSPEC", /* 39 */
1198 "Invalid Information Element", /* 40 */
1199 "Group Cipher is not valid", /* 41 */
1200 "Pairwise Cipher is not valid", /* 42 */
1201 "AKMP is not valid", /* 43 */
1202 "Unsupported RSN IE version", /* 44 */
1203 "Invalid RSN IE Capabilities", /* 45 */
1204 "Cipher suite is rejected per security policy", /* 46 */
1205 "The TS has not been created. However, the HC may be capable of "
1206 "creating a TS, in response to a request, after the time indicated "
1207 "in the TS Delay element", /* 47 */
1208 "Direct Link is not allowed in the BSS by policy", /* 48 */
1209 "Destination STA is not present within this QBSS.", /* 49 */
1210 "The Destination STA is not a QSTA.", /* 50 */
1211
1212 };
1213 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
1214
1215 static const char *reason_text[] = {
1216 "Reserved", /* 0 */
1217 "Unspecified reason", /* 1 */
1218 "Previous authentication no longer valid", /* 2 */
1219 "Deauthenticated because sending station is leaving (or has left) "
1220 "IBSS or ESS", /* 3 */
1221 "Disassociated due to inactivity", /* 4 */
1222 "Disassociated because AP is unable to handle all currently "
1223 " associated stations", /* 5 */
1224 "Class 2 frame received from nonauthenticated station", /* 6 */
1225 "Class 3 frame received from nonassociated station", /* 7 */
1226 "Disassociated because sending station is leaving "
1227 "(or has left) BSS", /* 8 */
1228 "Station requesting (re)association is not authenticated with "
1229 "responding station", /* 9 */
1230 "Disassociated because the information in the Power Capability "
1231 "element is unacceptable", /* 10 */
1232 "Disassociated because the information in the SupportedChannels "
1233 "element is unacceptable", /* 11 */
1234 "Invalid Information Element", /* 12 */
1235 "Reserved", /* 13 */
1236 "Michael MIC failure", /* 14 */
1237 "4-Way Handshake timeout", /* 15 */
1238 "Group key update timeout", /* 16 */
1239 "Information element in 4-Way Handshake different from (Re)Association"
1240 "Request/Probe Response/Beacon", /* 17 */
1241 "Group Cipher is not valid", /* 18 */
1242 "AKMP is not valid", /* 20 */
1243 "Unsupported RSN IE version", /* 21 */
1244 "Invalid RSN IE Capabilities", /* 22 */
1245 "IEEE 802.1X Authentication failed", /* 23 */
1246 "Cipher suite is rejected per security policy", /* 24 */
1247 "Reserved", /* 25 */
1248 "Reserved", /* 26 */
1249 "Reserved", /* 27 */
1250 "Reserved", /* 28 */
1251 "Reserved", /* 29 */
1252 "Reserved", /* 30 */
1253 "TS deleted because QoS AP lacks sufficient bandwidth for this "
1254 "QoS STA due to a change in BSS service characteristics or "
1255 "operational mode (e.g. an HT BSS change from 40 MHz channel "
1256 "to 20 MHz channel)", /* 31 */
1257 "Disassociated for unspecified, QoS-related reason", /* 32 */
1258 "Disassociated because QoS AP lacks sufficient bandwidth for this "
1259 "QoS STA", /* 33 */
1260 "Disassociated because of excessive number of frames that need to be "
1261 "acknowledged, but are not acknowledged for AP transmissions "
1262 "and/or poor channel conditions", /* 34 */
1263 "Disassociated because STA is transmitting outside the limits "
1264 "of its TXOPs", /* 35 */
1265 "Requested from peer STA as the STA is leaving the BSS "
1266 "(or resetting)", /* 36 */
1267 "Requested from peer STA as it does not want to use the "
1268 "mechanism", /* 37 */
1269 "Requested from peer STA as the STA received frames using the "
1270 "mechanism for which a set up is required", /* 38 */
1271 "Requested from peer STA due to time out", /* 39 */
1272 "Reserved", /* 40 */
1273 "Reserved", /* 41 */
1274 "Reserved", /* 42 */
1275 "Reserved", /* 43 */
1276 "Reserved", /* 44 */
1277 "Peer STA does not support the requested cipher suite", /* 45 */
1278 "Association denied due to requesting STA not supporting HT "
1279 "features", /* 46 */
1280 };
1281 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
1282
1283 static int
1284 wep_print(netdissect_options *ndo,
1285 const u_char *p)
1286 {
1287 uint32_t iv;
1288
1289 if (!ND_TTEST2(*p, IEEE802_11_IV_LEN + IEEE802_11_KID_LEN))
1290 return 0;
1291 iv = EXTRACT_LE_32BITS(p);
1292
1293 ND_PRINT((ndo, " IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv),
1294 IV_KEYID(iv)));
1295
1296 return 1;
1297 }
1298
1299 static int
1300 parse_elements(netdissect_options *ndo,
1301 struct mgmt_body_t *pbody, const u_char *p, int offset,
1302 u_int length)
1303 {
1304 u_int elementlen;
1305 struct ssid_t ssid;
1306 struct challenge_t challenge;
1307 struct rates_t rates;
1308 struct ds_t ds;
1309 struct cf_t cf;
1310 struct tim_t tim;
1311
1312 /*
1313 * We haven't seen any elements yet.
1314 */
1315 pbody->challenge_present = 0;
1316 pbody->ssid_present = 0;
1317 pbody->rates_present = 0;
1318 pbody->ds_present = 0;
1319 pbody->cf_present = 0;
1320 pbody->tim_present = 0;
1321
1322 while (length != 0) {
1323 /* Make sure we at least have the element ID and length. */
1324 if (!ND_TTEST2(*(p + offset), 2))
1325 return 0;
1326 if (length < 2)
1327 return 0;
1328 elementlen = *(p + offset + 1);
1329
1330 /* Make sure we have the entire element. */
1331 if (!ND_TTEST2(*(p + offset + 2), elementlen))
1332 return 0;
1333 if (length < elementlen + 2)
1334 return 0;
1335
1336 switch (*(p + offset)) {
1337 case E_SSID:
1338 memcpy(&ssid, p + offset, 2);
1339 offset += 2;
1340 length -= 2;
1341 if (ssid.length != 0) {
1342 if (ssid.length > sizeof(ssid.ssid) - 1)
1343 return 0;
1344 if (!ND_TTEST2(*(p + offset), ssid.length))
1345 return 0;
1346 if (length < ssid.length)
1347 return 0;
1348 memcpy(&ssid.ssid, p + offset, ssid.length);
1349 offset += ssid.length;
1350 length -= ssid.length;
1351 }
1352 ssid.ssid[ssid.length] = '\0';
1353 /*
1354 * Present and not truncated.
1355 *
1356 * If we haven't already seen an SSID IE,
1357 * copy this one, otherwise ignore this one,
1358 * so we later report the first one we saw.
1359 */
1360 if (!pbody->ssid_present) {
1361 pbody->ssid = ssid;
1362 pbody->ssid_present = 1;
1363 }
1364 break;
1365 case E_CHALLENGE:
1366 memcpy(&challenge, p + offset, 2);
1367 offset += 2;
1368 length -= 2;
1369 if (challenge.length != 0) {
1370 if (challenge.length >
1371 sizeof(challenge.text) - 1)
1372 return 0;
1373 if (!ND_TTEST2(*(p + offset), challenge.length))
1374 return 0;
1375 if (length < challenge.length)
1376 return 0;
1377 memcpy(&challenge.text, p + offset,
1378 challenge.length);
1379 offset += challenge.length;
1380 length -= challenge.length;
1381 }
1382 challenge.text[challenge.length] = '\0';
1383 /*
1384 * Present and not truncated.
1385 *
1386 * If we haven't already seen a challenge IE,
1387 * copy this one, otherwise ignore this one,
1388 * so we later report the first one we saw.
1389 */
1390 if (!pbody->challenge_present) {
1391 pbody->challenge = challenge;
1392 pbody->challenge_present = 1;
1393 }
1394 break;
1395 case E_RATES:
1396 memcpy(&rates, p + offset, 2);
1397 offset += 2;
1398 length -= 2;
1399 if (rates.length != 0) {
1400 if (rates.length > sizeof rates.rate)
1401 return 0;
1402 if (!ND_TTEST2(*(p + offset), rates.length))
1403 return 0;
1404 if (length < rates.length)
1405 return 0;
1406 memcpy(&rates.rate, p + offset, rates.length);
1407 offset += rates.length;
1408 length -= rates.length;
1409 }
1410 /*
1411 * Present and not truncated.
1412 *
1413 * If we haven't already seen a rates IE,
1414 * copy this one if it's not zero-length,
1415 * otherwise ignore this one, so we later
1416 * report the first one we saw.
1417 *
1418 * We ignore zero-length rates IEs as some
1419 * devices seem to put a zero-length rates
1420 * IE, followed by an SSID IE, followed by
1421 * a non-zero-length rates IE into frames,
1422 * even though IEEE Std 802.11-2007 doesn't
1423 * seem to indicate that a zero-length rates
1424 * IE is valid.
1425 */
1426 if (!pbody->rates_present && rates.length != 0) {
1427 pbody->rates = rates;
1428 pbody->rates_present = 1;
1429 }
1430 break;
1431 case E_DS:
1432 memcpy(&ds, p + offset, 2);
1433 offset += 2;
1434 length -= 2;
1435 if (ds.length != 1) {
1436 offset += ds.length;
1437 length -= ds.length;
1438 break;
1439 }
1440 ds.channel = *(p + offset);
1441 offset += 1;
1442 length -= 1;
1443 /*
1444 * Present and not truncated.
1445 *
1446 * If we haven't already seen a DS IE,
1447 * copy this one, otherwise ignore this one,
1448 * so we later report the first one we saw.
1449 */
1450 if (!pbody->ds_present) {
1451 pbody->ds = ds;
1452 pbody->ds_present = 1;
1453 }
1454 break;
1455 case E_CF:
1456 memcpy(&cf, p + offset, 2);
1457 offset += 2;
1458 length -= 2;
1459 if (cf.length != 6) {
1460 offset += cf.length;
1461 length -= cf.length;
1462 break;
1463 }
1464 memcpy(&cf.count, p + offset, 6);
1465 offset += 6;
1466 length -= 6;
1467 /*
1468 * Present and not truncated.
1469 *
1470 * If we haven't already seen a CF IE,
1471 * copy this one, otherwise ignore this one,
1472 * so we later report the first one we saw.
1473 */
1474 if (!pbody->cf_present) {
1475 pbody->cf = cf;
1476 pbody->cf_present = 1;
1477 }
1478 break;
1479 case E_TIM:
1480 memcpy(&tim, p + offset, 2);
1481 offset += 2;
1482 length -= 2;
1483 if (tim.length <= 3) {
1484 offset += tim.length;
1485 length -= tim.length;
1486 break;
1487 }
1488 if (tim.length - 3 > (int)sizeof tim.bitmap)
1489 return 0;
1490 memcpy(&tim.count, p + offset, 3);
1491 offset += 3;
1492 length -= 3;
1493
1494 memcpy(tim.bitmap, p + (tim.length - 3),
1495 (tim.length - 3));
1496 offset += tim.length - 3;
1497 length -= tim.length - 3;
1498 /*
1499 * Present and not truncated.
1500 *
1501 * If we haven't already seen a TIM IE,
1502 * copy this one, otherwise ignore this one,
1503 * so we later report the first one we saw.
1504 */
1505 if (!pbody->tim_present) {
1506 pbody->tim = tim;
1507 pbody->tim_present = 1;
1508 }
1509 break;
1510 default:
1511 #if 0
1512 ND_PRINT((ndo, "(1) unhandled element_id (%d) ",
1513 *(p + offset)));
1514 #endif
1515 offset += 2 + elementlen;
1516 length -= 2 + elementlen;
1517 break;
1518 }
1519 }
1520
1521 /* No problems found. */
1522 return 1;
1523 }
1524
1525 /*********************************************************************************
1526 * Print Handle functions for the management frame types
1527 *********************************************************************************/
1528
1529 static int
1530 handle_beacon(netdissect_options *ndo,
1531 const u_char *p, u_int length)
1532 {
1533 struct mgmt_body_t pbody;
1534 int offset = 0;
1535 int ret;
1536
1537 memset(&pbody, 0, sizeof(pbody));
1538
1539 if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1540 IEEE802_11_CAPINFO_LEN))
1541 return 0;
1542 if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1543 IEEE802_11_CAPINFO_LEN)
1544 return 0;
1545 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
1546 offset += IEEE802_11_TSTAMP_LEN;
1547 length -= IEEE802_11_TSTAMP_LEN;
1548 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
1549 offset += IEEE802_11_BCNINT_LEN;
1550 length -= IEEE802_11_BCNINT_LEN;
1551 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
1552 offset += IEEE802_11_CAPINFO_LEN;
1553 length -= IEEE802_11_CAPINFO_LEN;
1554
1555 ret = parse_elements(ndo, &pbody, p, offset, length);
1556
1557 PRINT_SSID(pbody);
1558 PRINT_RATES(pbody);
1559 ND_PRINT((ndo, " %s",
1560 CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS"));
1561 PRINT_DS_CHANNEL(pbody);
1562
1563 return ret;
1564 }
1565
1566 static int
1567 handle_assoc_request(netdissect_options *ndo,
1568 const u_char *p, u_int length)
1569 {
1570 struct mgmt_body_t pbody;
1571 int offset = 0;
1572 int ret;
1573
1574 memset(&pbody, 0, sizeof(pbody));
1575
1576 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
1577 return 0;
1578 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)
1579 return 0;
1580 pbody.capability_info = EXTRACT_LE_16BITS(p);
1581 offset += IEEE802_11_CAPINFO_LEN;
1582 length -= IEEE802_11_CAPINFO_LEN;
1583 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
1584 offset += IEEE802_11_LISTENINT_LEN;
1585 length -= IEEE802_11_LISTENINT_LEN;
1586
1587 ret = parse_elements(ndo, &pbody, p, offset, length);
1588
1589 PRINT_SSID(pbody);
1590 PRINT_RATES(pbody);
1591 return ret;
1592 }
1593
1594 static int
1595 handle_assoc_response(netdissect_options *ndo,
1596 const u_char *p, u_int length)
1597 {
1598 struct mgmt_body_t pbody;
1599 int offset = 0;
1600 int ret;
1601
1602 memset(&pbody, 0, sizeof(pbody));
1603
1604 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
1605 IEEE802_11_AID_LEN))
1606 return 0;
1607 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
1608 IEEE802_11_AID_LEN)
1609 return 0;
1610 pbody.capability_info = EXTRACT_LE_16BITS(p);
1611 offset += IEEE802_11_CAPINFO_LEN;
1612 length -= IEEE802_11_CAPINFO_LEN;
1613 pbody.status_code = EXTRACT_LE_16BITS(p+offset);
1614 offset += IEEE802_11_STATUS_LEN;
1615 length -= IEEE802_11_STATUS_LEN;
1616 pbody.aid = EXTRACT_LE_16BITS(p+offset);
1617 offset += IEEE802_11_AID_LEN;
1618 length -= IEEE802_11_AID_LEN;
1619
1620 ret = parse_elements(ndo, &pbody, p, offset, length);
1621
1622 ND_PRINT((ndo, " AID(%x) :%s: %s", ((uint16_t)(pbody.aid << 2 )) >> 2 ,
1623 CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
1624 (pbody.status_code < NUM_STATUSES
1625 ? status_text[pbody.status_code]
1626 : "n/a")));
1627
1628 return ret;
1629 }
1630
1631 static int
1632 handle_reassoc_request(netdissect_options *ndo,
1633 const u_char *p, u_int length)
1634 {
1635 struct mgmt_body_t pbody;
1636 int offset = 0;
1637 int ret;
1638
1639 memset(&pbody, 0, sizeof(pbody));
1640
1641 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
1642 IEEE802_11_AP_LEN))
1643 return 0;
1644 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
1645 IEEE802_11_AP_LEN)
1646 return 0;
1647 pbody.capability_info = EXTRACT_LE_16BITS(p);
1648 offset += IEEE802_11_CAPINFO_LEN;
1649 length -= IEEE802_11_CAPINFO_LEN;
1650 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
1651 offset += IEEE802_11_LISTENINT_LEN;
1652 length -= IEEE802_11_LISTENINT_LEN;
1653 memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN);
1654 offset += IEEE802_11_AP_LEN;
1655 length -= IEEE802_11_AP_LEN;
1656
1657 ret = parse_elements(ndo, &pbody, p, offset, length);
1658
1659 PRINT_SSID(pbody);
1660 ND_PRINT((ndo, " AP : %s", etheraddr_string(ndo, pbody.ap )));
1661
1662 return ret;
1663 }
1664
1665 static int
1666 handle_reassoc_response(netdissect_options *ndo,
1667 const u_char *p, u_int length)
1668 {
1669 /* Same as a Association Reponse */
1670 return handle_assoc_response(ndo, p, length);
1671 }
1672
1673 static int
1674 handle_probe_request(netdissect_options *ndo,
1675 const u_char *p, u_int length)
1676 {
1677 struct mgmt_body_t pbody;
1678 int offset = 0;
1679 int ret;
1680
1681 memset(&pbody, 0, sizeof(pbody));
1682
1683 ret = parse_elements(ndo, &pbody, p, offset, length);
1684
1685 PRINT_SSID(pbody);
1686 PRINT_RATES(pbody);
1687
1688 return ret;
1689 }
1690
1691 static int
1692 handle_probe_response(netdissect_options *ndo,
1693 const u_char *p, u_int length)
1694 {
1695 struct mgmt_body_t pbody;
1696 int offset = 0;
1697 int ret;
1698
1699 memset(&pbody, 0, sizeof(pbody));
1700
1701 if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1702 IEEE802_11_CAPINFO_LEN))
1703 return 0;
1704 if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1705 IEEE802_11_CAPINFO_LEN)
1706 return 0;
1707 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
1708 offset += IEEE802_11_TSTAMP_LEN;
1709 length -= IEEE802_11_TSTAMP_LEN;
1710 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
1711 offset += IEEE802_11_BCNINT_LEN;
1712 length -= IEEE802_11_BCNINT_LEN;
1713 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
1714 offset += IEEE802_11_CAPINFO_LEN;
1715 length -= IEEE802_11_CAPINFO_LEN;
1716
1717 ret = parse_elements(ndo, &pbody, p, offset, length);
1718
1719 PRINT_SSID(pbody);
1720 PRINT_RATES(pbody);
1721 PRINT_DS_CHANNEL(pbody);
1722
1723 return ret;
1724 }
1725
1726 static int
1727 handle_atim(void)
1728 {
1729 /* the frame body for ATIM is null. */
1730 return 1;
1731 }
1732
1733 static int
1734 handle_disassoc(netdissect_options *ndo,
1735 const u_char *p, u_int length)
1736 {
1737 struct mgmt_body_t pbody;
1738
1739 memset(&pbody, 0, sizeof(pbody));
1740
1741 if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
1742 return 0;
1743 if (length < IEEE802_11_REASON_LEN)
1744 return 0;
1745 pbody.reason_code = EXTRACT_LE_16BITS(p);
1746
1747 ND_PRINT((ndo, ": %s",
1748 (pbody.reason_code < NUM_REASONS)
1749 ? reason_text[pbody.reason_code]
1750 : "Reserved"));
1751
1752 return 1;
1753 }
1754
1755 static int
1756 handle_auth(netdissect_options *ndo,
1757 const u_char *p, u_int length)
1758 {
1759 struct mgmt_body_t pbody;
1760 int offset = 0;
1761 int ret;
1762
1763 memset(&pbody, 0, sizeof(pbody));
1764
1765 if (!ND_TTEST2(*p, 6))
1766 return 0;
1767 if (length < 6)
1768 return 0;
1769 pbody.auth_alg = EXTRACT_LE_16BITS(p);
1770 offset += 2;
1771 length -= 2;
1772 pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset);
1773 offset += 2;
1774 length -= 2;
1775 pbody.status_code = EXTRACT_LE_16BITS(p + offset);
1776 offset += 2;
1777 length -= 2;
1778
1779 ret = parse_elements(ndo, &pbody, p, offset, length);
1780
1781 if ((pbody.auth_alg == 1) &&
1782 ((pbody.auth_trans_seq_num == 2) ||
1783 (pbody.auth_trans_seq_num == 3))) {
1784 ND_PRINT((ndo, " (%s)-%x [Challenge Text] %s",
1785 (pbody.auth_alg < NUM_AUTH_ALGS)
1786 ? auth_alg_text[pbody.auth_alg]
1787 : "Reserved",
1788 pbody.auth_trans_seq_num,
1789 ((pbody.auth_trans_seq_num % 2)
1790 ? ((pbody.status_code < NUM_STATUSES)
1791 ? status_text[pbody.status_code]
1792 : "n/a") : "")));
1793 return ret;
1794 }
1795 ND_PRINT((ndo, " (%s)-%x: %s",
1796 (pbody.auth_alg < NUM_AUTH_ALGS)
1797 ? auth_alg_text[pbody.auth_alg]
1798 : "Reserved",
1799 pbody.auth_trans_seq_num,
1800 (pbody.auth_trans_seq_num % 2)
1801 ? ((pbody.status_code < NUM_STATUSES)
1802 ? status_text[pbody.status_code]
1803 : "n/a")
1804 : ""));
1805
1806 return ret;
1807 }
1808
1809 static int
1810 handle_deauth(netdissect_options *ndo,
1811 const uint8_t *src, const u_char *p, u_int length)
1812 {
1813 struct mgmt_body_t pbody;
1814 const char *reason = NULL;
1815
1816 memset(&pbody, 0, sizeof(pbody));
1817
1818 if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
1819 return 0;
1820 if (length < IEEE802_11_REASON_LEN)
1821 return 0;
1822 pbody.reason_code = EXTRACT_LE_16BITS(p);
1823
1824 reason = (pbody.reason_code < NUM_REASONS)
1825 ? reason_text[pbody.reason_code]
1826 : "Reserved";
1827
1828 if (ndo->ndo_eflag) {
1829 ND_PRINT((ndo, ": %s", reason));
1830 } else {
1831 ND_PRINT((ndo, " (%s): %s", etheraddr_string(ndo, src), reason));
1832 }
1833 return 1;
1834 }
1835
1836 #define PRINT_HT_ACTION(v) (\
1837 (v) == 0 ? ND_PRINT((ndo, "TxChWidth")) : \
1838 (v) == 1 ? ND_PRINT((ndo, "MIMOPwrSave")) : \
1839 ND_PRINT((ndo, "Act#%d", (v))) \
1840 )
1841 #define PRINT_BA_ACTION(v) (\
1842 (v) == 0 ? ND_PRINT((ndo, "ADDBA Request")) : \
1843 (v) == 1 ? ND_PRINT((ndo, "ADDBA Response")) : \
1844 (v) == 2 ? ND_PRINT((ndo, "DELBA")) : \
1845 ND_PRINT((ndo, "Act#%d", (v))) \
1846 )
1847 #define PRINT_MESHLINK_ACTION(v) (\
1848 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1849 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1850 ND_PRINT((ndo, "Act#%d", (v))) \
1851 )
1852 #define PRINT_MESHPEERING_ACTION(v) (\
1853 (v) == 0 ? ND_PRINT((ndo, "Open")) : \
1854 (v) == 1 ? ND_PRINT((ndo, "Confirm")) : \
1855 (v) == 2 ? ND_PRINT((ndo, "Close")) : \
1856 ND_PRINT((ndo, "Act#%d", (v))) \
1857 )
1858 #define PRINT_MESHPATH_ACTION(v) (\
1859 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1860 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1861 (v) == 2 ? ND_PRINT((ndo, "Error")) : \
1862 (v) == 3 ? ND_PRINT((ndo, "RootAnnouncement")) : \
1863 ND_PRINT((ndo, "Act#%d", (v))) \
1864 )
1865
1866 #define PRINT_MESH_ACTION(v) (\
1867 (v) == 0 ? ND_PRINT((ndo, "MeshLink")) : \
1868 (v) == 1 ? ND_PRINT((ndo, "HWMP")) : \
1869 (v) == 2 ? ND_PRINT((ndo, "Gate Announcement")) : \
1870 (v) == 3 ? ND_PRINT((ndo, "Congestion Control")) : \
1871 (v) == 4 ? ND_PRINT((ndo, "MCCA Setup Request")) : \
1872 (v) == 5 ? ND_PRINT((ndo, "MCCA Setup Reply")) : \
1873 (v) == 6 ? ND_PRINT((ndo, "MCCA Advertisement Request")) : \
1874 (v) == 7 ? ND_PRINT((ndo, "MCCA Advertisement")) : \
1875 (v) == 8 ? ND_PRINT((ndo, "MCCA Teardown")) : \
1876 (v) == 9 ? ND_PRINT((ndo, "TBTT Adjustment Request")) : \
1877 (v) == 10 ? ND_PRINT((ndo, "TBTT Adjustment Response")) : \
1878 ND_PRINT((ndo, "Act#%d", (v))) \
1879 )
1880 #define PRINT_MULTIHOP_ACTION(v) (\
1881 (v) == 0 ? ND_PRINT((ndo, "Proxy Update")) : \
1882 (v) == 1 ? ND_PRINT((ndo, "Proxy Update Confirmation")) : \
1883 ND_PRINT((ndo, "Act#%d", (v))) \
1884 )
1885 #define PRINT_SELFPROT_ACTION(v) (\
1886 (v) == 1 ? ND_PRINT((ndo, "Peering Open")) : \
1887 (v) == 2 ? ND_PRINT((ndo, "Peering Confirm")) : \
1888 (v) == 3 ? ND_PRINT((ndo, "Peering Close")) : \
1889 (v) == 4 ? ND_PRINT((ndo, "Group Key Inform")) : \
1890 (v) == 5 ? ND_PRINT((ndo, "Group Key Acknowledge")) : \
1891 ND_PRINT((ndo, "Act#%d", (v))) \
1892 )
1893
1894 static int
1895 handle_action(netdissect_options *ndo,
1896 const uint8_t *src, const u_char *p, u_int length)
1897 {
1898 if (!ND_TTEST2(*p, 2))
1899 return 0;
1900 if (length < 2)
1901 return 0;
1902 if (ndo->ndo_eflag) {
1903 ND_PRINT((ndo, ": "));
1904 } else {
1905 ND_PRINT((ndo, " (%s): ", etheraddr_string(ndo, src)));
1906 }
1907 switch (p[0]) {
1908 case 0: ND_PRINT((ndo, "Spectrum Management Act#%d", p[1])); break;
1909 case 1: ND_PRINT((ndo, "QoS Act#%d", p[1])); break;
1910 case 2: ND_PRINT((ndo, "DLS Act#%d", p[1])); break;
1911 case 3: ND_PRINT((ndo, "BA ")); PRINT_BA_ACTION(p[1]); break;
1912 case 7: ND_PRINT((ndo, "HT ")); PRINT_HT_ACTION(p[1]); break;
1913 case 13: ND_PRINT((ndo, "MeshAction ")); PRINT_MESH_ACTION(p[1]); break;
1914 case 14:
1915 ND_PRINT((ndo, "MultiohopAction "));
1916 PRINT_MULTIHOP_ACTION(p[1]); break;
1917 case 15:
1918 ND_PRINT((ndo, "SelfprotectAction "));
1919 PRINT_SELFPROT_ACTION(p[1]); break;
1920 case 127: ND_PRINT((ndo, "Vendor Act#%d", p[1])); break;
1921 default:
1922 ND_PRINT((ndo, "Reserved(%d) Act#%d", p[0], p[1]));
1923 break;
1924 }
1925 return 1;
1926 }
1927
1928
1929 /*********************************************************************************
1930 * Print Body funcs
1931 *********************************************************************************/
1932
1933
1934 static int
1935 mgmt_body_print(netdissect_options *ndo,
1936 uint16_t fc, const uint8_t *src, const u_char *p, u_int length)
1937 {
1938 ND_PRINT((ndo, "%s", tok2str(st_str, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc))));
1939
1940 /* There may be a problem w/ AP not having this bit set */
1941 if (FC_PROTECTED(fc))
1942 return wep_print(ndo, p);
1943 switch (FC_SUBTYPE(fc)) {
1944 case ST_ASSOC_REQUEST:
1945 return handle_assoc_request(ndo, p, length);
1946 case ST_ASSOC_RESPONSE:
1947 return handle_assoc_response(ndo, p, length);
1948 case ST_REASSOC_REQUEST:
1949 return handle_reassoc_request(ndo, p, length);
1950 case ST_REASSOC_RESPONSE:
1951 return handle_reassoc_response(ndo, p, length);
1952 case ST_PROBE_REQUEST:
1953 return handle_probe_request(ndo, p, length);
1954 case ST_PROBE_RESPONSE:
1955 return handle_probe_response(ndo, p, length);
1956 case ST_BEACON:
1957 return handle_beacon(ndo, p, length);
1958 case ST_ATIM:
1959 return handle_atim();
1960 case ST_DISASSOC:
1961 return handle_disassoc(ndo, p, length);
1962 case ST_AUTH:
1963 return handle_auth(ndo, p, length);
1964 case ST_DEAUTH:
1965 return handle_deauth(ndo, src, p, length);
1966 case ST_ACTION:
1967 return handle_action(ndo, src, p, length);
1968 default:
1969 return 1;
1970 }
1971 }
1972
1973
1974 /*********************************************************************************
1975 * Handles printing all the control frame types
1976 *********************************************************************************/
1977
1978 static int
1979 ctrl_body_print(netdissect_options *ndo,
1980 uint16_t fc, const u_char *p)
1981 {
1982 ND_PRINT((ndo, "%s", tok2str(ctrl_str, "Unknown Ctrl Subtype", FC_SUBTYPE(fc))));
1983 switch (FC_SUBTYPE(fc)) {
1984 case CTRL_CONTROL_WRAPPER:
1985 /* XXX - requires special handling */
1986 break;
1987 case CTRL_BAR:
1988 if (!ND_TTEST2(*p, CTRL_BAR_HDRLEN))
1989 return 0;
1990 if (!ndo->ndo_eflag)
1991 ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
1992 etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra),
1993 etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta),
1994 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)),
1995 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq))));
1996 break;
1997 case CTRL_BA:
1998 if (!ND_TTEST2(*p, CTRL_BA_HDRLEN))
1999 return 0;
2000 if (!ndo->ndo_eflag)
2001 ND_PRINT((ndo, " RA:%s ",
2002 etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra)));
2003 break;
2004 case CTRL_PS_POLL:
2005 if (!ND_TTEST2(*p, CTRL_PS_POLL_HDRLEN))
2006 return 0;
2007 ND_PRINT((ndo, " AID(%x)",
2008 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_hdr_t *)p)->aid))));
2009 break;
2010 case CTRL_RTS:
2011 if (!ND_TTEST2(*p, CTRL_RTS_HDRLEN))
2012 return 0;
2013 if (!ndo->ndo_eflag)
2014 ND_PRINT((ndo, " TA:%s ",
2015 etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta)));
2016 break;
2017 case CTRL_CTS:
2018 if (!ND_TTEST2(*p, CTRL_CTS_HDRLEN))
2019 return 0;
2020 if (!ndo->ndo_eflag)
2021 ND_PRINT((ndo, " RA:%s ",
2022 etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra)));
2023 break;
2024 case CTRL_ACK:
2025 if (!ND_TTEST2(*p, CTRL_ACK_HDRLEN))
2026 return 0;
2027 if (!ndo->ndo_eflag)
2028 ND_PRINT((ndo, " RA:%s ",
2029 etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra)));
2030 break;
2031 case CTRL_CF_END:
2032 if (!ND_TTEST2(*p, CTRL_END_HDRLEN))
2033 return 0;
2034 if (!ndo->ndo_eflag)
2035 ND_PRINT((ndo, " RA:%s ",
2036 etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra)));
2037 break;
2038 case CTRL_END_ACK:
2039 if (!ND_TTEST2(*p, CTRL_END_ACK_HDRLEN))
2040 return 0;
2041 if (!ndo->ndo_eflag)
2042 ND_PRINT((ndo, " RA:%s ",
2043 etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra)));
2044 break;
2045 }
2046 return 1;
2047 }
2048
2049 /*
2050 * Data Frame - Address field contents
2051 *
2052 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
2053 * 0 | 0 | DA | SA | BSSID | n/a
2054 * 0 | 1 | DA | BSSID | SA | n/a
2055 * 1 | 0 | BSSID | SA | DA | n/a
2056 * 1 | 1 | RA | TA | DA | SA
2057 */
2058
2059 /*
2060 * Function to get source and destination MAC addresses for a data frame.
2061 */
2062 static void
2063 get_data_src_dst_mac(uint16_t fc, const u_char *p, const uint8_t **srcp,
2064 const uint8_t **dstp)
2065 {
2066 #define ADDR1 (p + 4)
2067 #define ADDR2 (p + 10)
2068 #define ADDR3 (p + 16)
2069 #define ADDR4 (p + 24)
2070
2071 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2072 *srcp = ADDR2;
2073 *dstp = ADDR1;
2074 } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2075 *srcp = ADDR3;
2076 *dstp = ADDR1;
2077 } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2078 *srcp = ADDR2;
2079 *dstp = ADDR3;
2080 } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2081 *srcp = ADDR4;
2082 *dstp = ADDR3;
2083 }
2084
2085 #undef ADDR1
2086 #undef ADDR2
2087 #undef ADDR3
2088 #undef ADDR4
2089 }
2090
2091 static void
2092 get_mgmt_src_dst_mac(const u_char *p, const uint8_t **srcp, const uint8_t **dstp)
2093 {
2094 const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
2095
2096 if (srcp != NULL)
2097 *srcp = hp->sa;
2098 if (dstp != NULL)
2099 *dstp = hp->da;
2100 }
2101
2102 /*
2103 * Print Header funcs
2104 */
2105
2106 static void
2107 data_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p)
2108 {
2109 u_int subtype = FC_SUBTYPE(fc);
2110
2111 if (DATA_FRAME_IS_CF_ACK(subtype) || DATA_FRAME_IS_CF_POLL(subtype) ||
2112 DATA_FRAME_IS_QOS(subtype)) {
2113 ND_PRINT((ndo, "CF "));
2114 if (DATA_FRAME_IS_CF_ACK(subtype)) {
2115 if (DATA_FRAME_IS_CF_POLL(subtype))
2116 ND_PRINT((ndo, "Ack/Poll"));
2117 else
2118 ND_PRINT((ndo, "Ack"));
2119 } else {
2120 if (DATA_FRAME_IS_CF_POLL(subtype))
2121 ND_PRINT((ndo, "Poll"));
2122 }
2123 if (DATA_FRAME_IS_QOS(subtype))
2124 ND_PRINT((ndo, "+QoS"));
2125 ND_PRINT((ndo, " "));
2126 }
2127
2128 #define ADDR1 (p + 4)
2129 #define ADDR2 (p + 10)
2130 #define ADDR3 (p + 16)
2131 #define ADDR4 (p + 24)
2132
2133 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2134 ND_PRINT((ndo, "DA:%s SA:%s BSSID:%s ",
2135 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2136 etheraddr_string(ndo, ADDR3)));
2137 } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2138 ND_PRINT((ndo, "DA:%s BSSID:%s SA:%s ",
2139 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2140 etheraddr_string(ndo, ADDR3)));
2141 } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2142 ND_PRINT((ndo, "BSSID:%s SA:%s DA:%s ",
2143 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2144 etheraddr_string(ndo, ADDR3)));
2145 } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2146 ND_PRINT((ndo, "RA:%s TA:%s DA:%s SA:%s ",
2147 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2148 etheraddr_string(ndo, ADDR3), etheraddr_string(ndo, ADDR4)));
2149 }
2150
2151 #undef ADDR1
2152 #undef ADDR2
2153 #undef ADDR3
2154 #undef ADDR4
2155 }
2156
2157 static void
2158 mgmt_header_print(netdissect_options *ndo, const u_char *p)
2159 {
2160 const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
2161
2162 ND_PRINT((ndo, "BSSID:%s DA:%s SA:%s ",
2163 etheraddr_string(ndo, (hp)->bssid), etheraddr_string(ndo, (hp)->da),
2164 etheraddr_string(ndo, (hp)->sa)));
2165 }
2166
2167 static void
2168 ctrl_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p)
2169 {
2170 switch (FC_SUBTYPE(fc)) {
2171 case CTRL_BAR:
2172 ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
2173 etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra),
2174 etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta),
2175 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)),
2176 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq))));
2177 break;
2178 case CTRL_BA:
2179 ND_PRINT((ndo, "RA:%s ",
2180 etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra)));
2181 break;
2182 case CTRL_PS_POLL:
2183 ND_PRINT((ndo, "BSSID:%s TA:%s ",
2184 etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->bssid),
2185 etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->ta)));
2186 break;
2187 case CTRL_RTS:
2188 ND_PRINT((ndo, "RA:%s TA:%s ",
2189 etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ra),
2190 etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta)));
2191 break;
2192 case CTRL_CTS:
2193 ND_PRINT((ndo, "RA:%s ",
2194 etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra)));
2195 break;
2196 case CTRL_ACK:
2197 ND_PRINT((ndo, "RA:%s ",
2198 etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra)));
2199 break;
2200 case CTRL_CF_END:
2201 ND_PRINT((ndo, "RA:%s BSSID:%s ",
2202 etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra),
2203 etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->bssid)));
2204 break;
2205 case CTRL_END_ACK:
2206 ND_PRINT((ndo, "RA:%s BSSID:%s ",
2207 etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra),
2208 etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->bssid)));
2209 break;
2210 default:
2211 /* We shouldn't get here - we should already have quit */
2212 break;
2213 }
2214 }
2215
2216 static int
2217 extract_header_length(netdissect_options *ndo,
2218 uint16_t fc)
2219 {
2220 int len;
2221
2222 switch (FC_TYPE(fc)) {
2223 case T_MGMT:
2224 return MGMT_HDRLEN;
2225 case T_CTRL:
2226 switch (FC_SUBTYPE(fc)) {
2227 case CTRL_CONTROL_WRAPPER:
2228 return CTRL_CONTROL_WRAPPER_HDRLEN;
2229 case CTRL_BAR:
2230 return CTRL_BAR_HDRLEN;
2231 case CTRL_BA:
2232 return CTRL_BA_HDRLEN;
2233 case CTRL_PS_POLL:
2234 return CTRL_PS_POLL_HDRLEN;
2235 case CTRL_RTS:
2236 return CTRL_RTS_HDRLEN;
2237 case CTRL_CTS:
2238 return CTRL_CTS_HDRLEN;
2239 case CTRL_ACK:
2240 return CTRL_ACK_HDRLEN;
2241 case CTRL_CF_END:
2242 return CTRL_END_HDRLEN;
2243 case CTRL_END_ACK:
2244 return CTRL_END_ACK_HDRLEN;
2245 default:
2246 ND_PRINT((ndo, "unknown 802.11 ctrl frame subtype (%d)", FC_SUBTYPE(fc)));
2247 return 0;
2248 }
2249 case T_DATA:
2250 len = (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24;
2251 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc)))
2252 len += 2;
2253 return len;
2254 default:
2255 ND_PRINT((ndo, "unknown 802.11 frame type (%d)", FC_TYPE(fc)));
2256 return 0;
2257 }
2258 }
2259
2260 static int
2261 extract_mesh_header_length(const u_char *p)
2262 {
2263 return (p[0] &~ 3) ? 0 : 6*(1 + (p[0] & 3));
2264 }
2265
2266 /*
2267 * Print the 802.11 MAC header.
2268 */
2269 static void
2270 ieee_802_11_hdr_print(netdissect_options *ndo,
2271 uint16_t fc, const u_char *p, u_int hdrlen,
2272 u_int meshdrlen)
2273 {
2274 if (ndo->ndo_vflag) {
2275 if (FC_MORE_DATA(fc))
2276 ND_PRINT((ndo, "More Data "));
2277 if (FC_MORE_FLAG(fc))
2278 ND_PRINT((ndo, "More Fragments "));
2279 if (FC_POWER_MGMT(fc))
2280 ND_PRINT((ndo, "Pwr Mgmt "));
2281 if (FC_RETRY(fc))
2282 ND_PRINT((ndo, "Retry "));
2283 if (FC_ORDER(fc))
2284 ND_PRINT((ndo, "Strictly Ordered "));
2285 if (FC_PROTECTED(fc))
2286 ND_PRINT((ndo, "Protected "));
2287 if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL)
2288 ND_PRINT((ndo, "%dus ",
2289 EXTRACT_LE_16BITS(
2290 &((const struct mgmt_header_t *)p)->duration)));
2291 }
2292 if (meshdrlen != 0) {
2293 const struct meshcntl_t *mc =
2294 (const struct meshcntl_t *)&p[hdrlen - meshdrlen];
2295 int ae = mc->flags & 3;
2296
2297 ND_PRINT((ndo, "MeshData (AE %d TTL %u seq %u", ae, mc->ttl,
2298 EXTRACT_LE_32BITS(mc->seq)));
2299 if (ae > 0)
2300 ND_PRINT((ndo, " A4:%s", etheraddr_string(ndo, mc->addr4)));
2301 if (ae > 1)
2302 ND_PRINT((ndo, " A5:%s", etheraddr_string(ndo, mc->addr5)));
2303 if (ae > 2)
2304 ND_PRINT((ndo, " A6:%s", etheraddr_string(ndo, mc->addr6)));
2305 ND_PRINT((ndo, ") "));
2306 }
2307
2308 switch (FC_TYPE(fc)) {
2309 case T_MGMT:
2310 mgmt_header_print(ndo, p);
2311 break;
2312 case T_CTRL:
2313 ctrl_header_print(ndo, fc, p);
2314 break;
2315 case T_DATA:
2316 data_header_print(ndo, fc, p);
2317 break;
2318 default:
2319 break;
2320 }
2321 }
2322
2323 #ifndef roundup2
2324 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2325 #endif
2326
2327 static u_int
2328 ieee802_11_print(netdissect_options *ndo,
2329 const u_char *p, u_int length, u_int orig_caplen, int pad,
2330 u_int fcslen)
2331 {
2332 uint16_t fc;
2333 u_int caplen, hdrlen, meshdrlen;
2334 const uint8_t *src, *dst;
2335 int llc_hdrlen;
2336
2337 caplen = orig_caplen;
2338 /* Remove FCS, if present */
2339 if (length < fcslen) {
2340 ND_PRINT((ndo, "%s", tstr));
2341 return caplen;
2342 }
2343 length -= fcslen;
2344 if (caplen > length) {
2345 /* Amount of FCS in actual packet data, if any */
2346 fcslen = caplen - length;
2347 caplen -= fcslen;
2348 ndo->ndo_snapend -= fcslen;
2349 }
2350
2351 if (caplen < IEEE802_11_FC_LEN) {
2352 ND_PRINT((ndo, "%s", tstr));
2353 return orig_caplen;
2354 }
2355
2356 fc = EXTRACT_LE_16BITS(p);
2357 hdrlen = extract_header_length(ndo, fc);
2358 if (hdrlen == 0) {
2359 /* Unknown frame type or control frame subtype; quit. */
2360 return (0);
2361 }
2362 if (pad)
2363 hdrlen = roundup2(hdrlen, 4);
2364 if (ndo->ndo_Hflag && FC_TYPE(fc) == T_DATA &&
2365 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) {
2366 meshdrlen = extract_mesh_header_length(p+hdrlen);
2367 hdrlen += meshdrlen;
2368 } else
2369 meshdrlen = 0;
2370
2371 if (caplen < hdrlen) {
2372 ND_PRINT((ndo, "%s", tstr));
2373 return hdrlen;
2374 }
2375
2376 if (ndo->ndo_eflag)
2377 ieee_802_11_hdr_print(ndo, fc, p, hdrlen, meshdrlen);
2378
2379 /*
2380 * Go past the 802.11 header.
2381 */
2382 length -= hdrlen;
2383 caplen -= hdrlen;
2384 p += hdrlen;
2385
2386 switch (FC_TYPE(fc)) {
2387 case T_MGMT:
2388 get_mgmt_src_dst_mac(p - hdrlen, &src, &dst);
2389 if (!mgmt_body_print(ndo, fc, src, p, length)) {
2390 ND_PRINT((ndo, "%s", tstr));
2391 return hdrlen;
2392 }
2393 break;
2394 case T_CTRL:
2395 if (!ctrl_body_print(ndo, fc, p - hdrlen)) {
2396 ND_PRINT((ndo, "%s", tstr));
2397 return hdrlen;
2398 }
2399 break;
2400 case T_DATA:
2401 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc)))
2402 return hdrlen; /* no-data frame */
2403 /* There may be a problem w/ AP not having this bit set */
2404 if (FC_PROTECTED(fc)) {
2405 ND_PRINT((ndo, "Data"));
2406 if (!wep_print(ndo, p)) {
2407 ND_PRINT((ndo, "%s", tstr));
2408 return hdrlen;
2409 }
2410 } else {
2411 get_data_src_dst_mac(fc, p - hdrlen, &src, &dst);
2412 llc_hdrlen = llc_print(ndo, p, length, caplen, dst, src);
2413 if (llc_hdrlen < 0) {
2414 /*
2415 * Some kinds of LLC packet we cannot
2416 * handle intelligently
2417 */
2418 if (!ndo->ndo_suppress_default_print)
2419 ND_DEFAULTPRINT(p, caplen);
2420 llc_hdrlen = -llc_hdrlen;
2421 }
2422 hdrlen += llc_hdrlen;
2423 }
2424 break;
2425 default:
2426 /* We shouldn't get here - we should already have quit */
2427 break;
2428 }
2429
2430 return hdrlen;
2431 }
2432
2433 /*
2434 * This is the top level routine of the printer. 'p' points
2435 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2436 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2437 * is the number of bytes actually captured.
2438 */
2439 u_int
2440 ieee802_11_if_print(netdissect_options *ndo,
2441 const struct pcap_pkthdr *h, const u_char *p)
2442 {
2443 return ieee802_11_print(ndo, p, h->len, h->caplen, 0, 0);
2444 }
2445
2446 #define IEEE80211_CHAN_FHSS \
2447 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2448 #define IEEE80211_CHAN_A \
2449 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2450 #define IEEE80211_CHAN_B \
2451 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2452 #define IEEE80211_CHAN_PUREG \
2453 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2454 #define IEEE80211_CHAN_G \
2455 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2456
2457 #define IS_CHAN_FHSS(flags) \
2458 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2459 #define IS_CHAN_A(flags) \
2460 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2461 #define IS_CHAN_B(flags) \
2462 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2463 #define IS_CHAN_PUREG(flags) \
2464 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2465 #define IS_CHAN_G(flags) \
2466 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2467 #define IS_CHAN_ANYG(flags) \
2468 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2469
2470 static void
2471 print_chaninfo(netdissect_options *ndo,
2472 int freq, int flags)
2473 {
2474 ND_PRINT((ndo, "%u MHz", freq));
2475 if (IS_CHAN_FHSS(flags))
2476 ND_PRINT((ndo, " FHSS"));
2477 if (IS_CHAN_A(flags)) {
2478 if (flags & IEEE80211_CHAN_HALF)
2479 ND_PRINT((ndo, " 11a/10Mhz"));
2480 else if (flags & IEEE80211_CHAN_QUARTER)
2481 ND_PRINT((ndo, " 11a/5Mhz"));
2482 else
2483 ND_PRINT((ndo, " 11a"));
2484 }
2485 if (IS_CHAN_ANYG(flags)) {
2486 if (flags & IEEE80211_CHAN_HALF)
2487 ND_PRINT((ndo, " 11g/10Mhz"));
2488 else if (flags & IEEE80211_CHAN_QUARTER)
2489 ND_PRINT((ndo, " 11g/5Mhz"));
2490 else
2491 ND_PRINT((ndo, " 11g"));
2492 } else if (IS_CHAN_B(flags))
2493 ND_PRINT((ndo, " 11b"));
2494 if (flags & IEEE80211_CHAN_TURBO)
2495 ND_PRINT((ndo, " Turbo"));
2496 if (flags & IEEE80211_CHAN_HT20)
2497 ND_PRINT((ndo, " ht/20"));
2498 else if (flags & IEEE80211_CHAN_HT40D)
2499 ND_PRINT((ndo, " ht/40-"));
2500 else if (flags & IEEE80211_CHAN_HT40U)
2501 ND_PRINT((ndo, " ht/40+"));
2502 ND_PRINT((ndo, " "));
2503 }
2504
2505 static int
2506 print_radiotap_field(netdissect_options *ndo,
2507 struct cpack_state *s, uint32_t bit, uint8_t *flags,
2508 struct radiotap_state *state, uint32_t presentflags)
2509 {
2510 union {
2511 int8_t i8;
2512 uint8_t u8;
2513 int16_t i16;
2514 uint16_t u16;
2515 uint32_t u32;
2516 uint64_t u64;
2517 } u, u2, u3, u4;
2518 int rc;
2519
2520 switch (bit) {
2521 case IEEE80211_RADIOTAP_FLAGS:
2522 rc = cpack_uint8(s, &u.u8);
2523 if (rc != 0)
2524 break;
2525 *flags = u.u8;
2526 break;
2527 case IEEE80211_RADIOTAP_RATE:
2528 rc = cpack_uint8(s, &u.u8);
2529 if (rc != 0)
2530 break;
2531
2532 /* Save state rate */
2533 state->rate = u.u8;
2534 break;
2535 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
2536 case IEEE80211_RADIOTAP_DB_ANTNOISE:
2537 case IEEE80211_RADIOTAP_ANTENNA:
2538 rc = cpack_uint8(s, &u.u8);
2539 break;
2540 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
2541 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
2542 rc = cpack_int8(s, &u.i8);
2543 break;
2544 case IEEE80211_RADIOTAP_CHANNEL:
2545 rc = cpack_uint16(s, &u.u16);
2546 if (rc != 0)
2547 break;
2548 rc = cpack_uint16(s, &u2.u16);
2549 break;
2550 case IEEE80211_RADIOTAP_FHSS:
2551 case IEEE80211_RADIOTAP_LOCK_QUALITY:
2552 case IEEE80211_RADIOTAP_TX_ATTENUATION:
2553 case IEEE80211_RADIOTAP_RX_FLAGS:
2554 rc = cpack_uint16(s, &u.u16);
2555 break;
2556 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
2557 rc = cpack_uint8(s, &u.u8);
2558 break;
2559 case IEEE80211_RADIOTAP_DBM_TX_POWER:
2560 rc = cpack_int8(s, &u.i8);
2561 break;
2562 case IEEE80211_RADIOTAP_TSFT:
2563 rc = cpack_uint64(s, &u.u64);
2564 break;
2565 case IEEE80211_RADIOTAP_XCHANNEL:
2566 rc = cpack_uint32(s, &u.u32);
2567 if (rc != 0)
2568 break;
2569 rc = cpack_uint16(s, &u2.u16);
2570 if (rc != 0)
2571 break;
2572 rc = cpack_uint8(s, &u3.u8);
2573 if (rc != 0)
2574 break;
2575 rc = cpack_uint8(s, &u4.u8);
2576 break;
2577 case IEEE80211_RADIOTAP_MCS:
2578 rc = cpack_uint8(s, &u.u8);
2579 if (rc != 0)
2580 break;
2581 rc = cpack_uint8(s, &u2.u8);
2582 if (rc != 0)
2583 break;
2584 rc = cpack_uint8(s, &u3.u8);
2585 break;
2586 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: {
2587 uint8_t vns[3];
2588 uint16_t length;
2589 uint8_t subspace;
2590
2591 if ((cpack_align_and_reserve(s, 2)) == NULL) {
2592 rc = -1;
2593 break;
2594 }
2595
2596 rc = cpack_uint8(s, &vns[0]);
2597 if (rc != 0)
2598 break;
2599 rc = cpack_uint8(s, &vns[1]);
2600 if (rc != 0)
2601 break;
2602 rc = cpack_uint8(s, &vns[2]);
2603 if (rc != 0)
2604 break;
2605 rc = cpack_uint8(s, &subspace);
2606 if (rc != 0)
2607 break;
2608 rc = cpack_uint16(s, &length);
2609 if (rc != 0)
2610 break;
2611
2612 /* Skip up to length */
2613 s->c_next += length;
2614 break;
2615 }
2616 default:
2617 /* this bit indicates a field whose
2618 * size we do not know, so we cannot
2619 * proceed. Just print the bit number.
2620 */
2621 ND_PRINT((ndo, "[bit %u] ", bit));
2622 return -1;
2623 }
2624
2625 if (rc != 0) {
2626 ND_PRINT((ndo, "%s", tstr));
2627 return rc;
2628 }
2629
2630 /* Preserve the state present flags */
2631 state->present = presentflags;
2632
2633 switch (bit) {
2634 case IEEE80211_RADIOTAP_CHANNEL:
2635 /*
2636 * If CHANNEL and XCHANNEL are both present, skip
2637 * CHANNEL.
2638 */
2639 if (presentflags & (1 << IEEE80211_RADIOTAP_XCHANNEL))
2640 break;
2641 print_chaninfo(ndo, u.u16, u2.u16);
2642 break;
2643 case IEEE80211_RADIOTAP_FHSS:
2644 ND_PRINT((ndo, "fhset %d fhpat %d ", u.u16 & 0xff, (u.u16 >> 8) & 0xff));
2645 break;
2646 case IEEE80211_RADIOTAP_RATE:
2647 /*
2648 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2649 * Linux and AirPcap it does not. (What about
2650 * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
2651 *
2652 * This is an issue either for proprietary extensions
2653 * to 11a or 11g, which do exist, or for 11n
2654 * implementations that stuff a rate value into
2655 * this field, which also appear to exist.
2656 *
2657 * We currently handle that by assuming that
2658 * if the 0x80 bit is set *and* the remaining
2659 * bits have a value between 0 and 15 it's
2660 * an MCS value, otherwise it's a rate. If
2661 * there are cases where systems that use
2662 * "0x80 + MCS index" for MCS indices > 15,
2663 * or stuff a rate value here between 64 and
2664 * 71.5 Mb/s in here, we'll need a preference
2665 * setting. Such rates do exist, e.g. 11n
2666 * MCS 7 at 20 MHz with a long guard interval.
2667 */
2668 if (u.u8 >= 0x80 && u.u8 <= 0x8f) {
2669 /*
2670 * XXX - we don't know the channel width
2671 * or guard interval length, so we can't
2672 * convert this to a data rate.
2673 *
2674 * If you want us to show a data rate,
2675 * use the MCS field, not the Rate field;
2676 * the MCS field includes not only the
2677 * MCS index, it also includes bandwidth
2678 * and guard interval information.
2679 *
2680 * XXX - can we get the channel width
2681 * from XChannel and the guard interval
2682 * information from Flags, at least on
2683 * FreeBSD?
2684 */
2685 ND_PRINT((ndo, "MCS %u ", u.u8 & 0x7f));
2686 } else
2687 ND_PRINT((ndo, "%2.1f Mb/s ", .5 * u.u8));
2688 break;
2689 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
2690 ND_PRINT((ndo, "%ddB signal ", u.i8));
2691 break;
2692 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
2693 ND_PRINT((ndo, "%ddB noise ", u.i8));
2694 break;
2695 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
2696 ND_PRINT((ndo, "%ddB signal ", u.u8));
2697 break;
2698 case IEEE80211_RADIOTAP_DB_ANTNOISE:
2699 ND_PRINT((ndo, "%ddB noise ", u.u8));
2700 break;
2701 case IEEE80211_RADIOTAP_LOCK_QUALITY:
2702 ND_PRINT((ndo, "%u sq ", u.u16));
2703 break;
2704 case IEEE80211_RADIOTAP_TX_ATTENUATION:
2705 ND_PRINT((ndo, "%d tx power ", -(int)u.u16));
2706 break;
2707 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
2708 ND_PRINT((ndo, "%ddB tx power ", -(int)u.u8));
2709 break;
2710 case IEEE80211_RADIOTAP_DBM_TX_POWER:
2711 ND_PRINT((ndo, "%ddBm tx power ", u.i8));
2712 break;
2713 case IEEE80211_RADIOTAP_FLAGS:
2714 if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
2715 ND_PRINT((ndo, "cfp "));
2716 if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
2717 ND_PRINT((ndo, "short preamble "));
2718 if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
2719 ND_PRINT((ndo, "wep "));
2720 if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
2721 ND_PRINT((ndo, "fragmented "));
2722 if (u.u8 & IEEE80211_RADIOTAP_F_BADFCS)
2723 ND_PRINT((ndo, "bad-fcs "));
2724 break;
2725 case IEEE80211_RADIOTAP_ANTENNA:
2726 ND_PRINT((ndo, "antenna %d ", u.u8));
2727 break;
2728 case IEEE80211_RADIOTAP_TSFT:
2729 ND_PRINT((ndo, "%" PRIu64 "us tsft ", u.u64));
2730 break;
2731 case IEEE80211_RADIOTAP_RX_FLAGS:
2732 /* Do nothing for now */
2733 break;
2734 case IEEE80211_RADIOTAP_XCHANNEL:
2735 print_chaninfo(ndo, u2.u16, u.u32);
2736 break;
2737 case IEEE80211_RADIOTAP_MCS: {
2738 static const char *bandwidth[4] = {
2739 "20 MHz",
2740 "40 MHz",
2741 "20 MHz (L)",
2742 "20 MHz (U)"
2743 };
2744 float htrate;
2745
2746 if (u.u8 & IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN) {
2747 /*
2748 * We know the MCS index.
2749 */
2750 if (u3.u8 <= MAX_MCS_INDEX) {
2751 /*
2752 * And it's in-range.
2753 */
2754 if (u.u8 & (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN)) {
2755 /*
2756 * And we know both the bandwidth and
2757 * the guard interval, so we can look
2758 * up the rate.
2759 */
2760 htrate =
2761 ieee80211_float_htrates \
2762 [u3.u8] \
2763 [((u2.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 ? 1 : 0)] \
2764 [((u2.u8 & IEEE80211_RADIOTAP_MCS_SHORT_GI) ? 1 : 0)];
2765 } else {
2766 /*
2767 * We don't know both the bandwidth
2768 * and the guard interval, so we can
2769 * only report the MCS index.
2770 */
2771 htrate = 0.0;
2772 }
2773 } else {
2774 /*
2775 * The MCS value is out of range.
2776 */
2777 htrate = 0.0;
2778 }
2779 if (htrate != 0.0) {
2780 /*
2781 * We have the rate.
2782 * Print it.
2783 */
2784 ND_PRINT((ndo, "%.1f Mb/s MCS %u ", htrate, u3.u8));
2785 } else {
2786 /*
2787 * We at least have the MCS index.
2788 * Print it.
2789 */
2790 ND_PRINT((ndo, "MCS %u ", u3.u8));
2791 }
2792 }
2793 if (u.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN) {
2794 ND_PRINT((ndo, "%s ",
2795 bandwidth[u2.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK]));
2796 }
2797 if (u.u8 & IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN) {
2798 ND_PRINT((ndo, "%s GI ",
2799 (u2.u8 & IEEE80211_RADIOTAP_MCS_SHORT_GI) ?
2800 "short" : "lon"));
2801 }
2802 if (u.u8 & IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN) {
2803 ND_PRINT((ndo, "%s ",
2804 (u2.u8 & IEEE80211_RADIOTAP_MCS_HT_GREENFIELD) ?
2805 "greenfield" : "mixed"));
2806 }
2807 if (u.u8 & IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN) {
2808 ND_PRINT((ndo, "%s FEC ",
2809 (u2.u8 & IEEE80211_RADIOTAP_MCS_FEC_LDPC) ?
2810 "LDPC" : "BCC"));
2811 }
2812 if (u.u8 & IEEE80211_RADIOTAP_MCS_STBC_KNOWN) {
2813 ND_PRINT((ndo, "RX-STBC%u ",
2814 (u2.u8 & IEEE80211_RADIOTAP_MCS_STBC_MASK) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT));
2815 }
2816
2817 break;
2818 }
2819 }
2820 return 0;
2821 }
2822
2823 static u_int
2824 ieee802_11_radio_print(netdissect_options *ndo,
2825 const u_char *p, u_int length, u_int caplen)
2826 {
2827 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
2828 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
2829 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
2830 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
2831 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
2832 #define BIT(n) (1U << n)
2833 #define IS_EXTENDED(__p) \
2834 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
2835
2836 struct cpack_state cpacker;
2837 struct ieee80211_radiotap_header *hdr;
2838 uint32_t present, next_present;
2839 uint32_t presentflags = 0;
2840 uint32_t *presentp, *last_presentp;
2841 enum ieee80211_radiotap_type bit;
2842 int bit0;
2843 u_int len;
2844 uint8_t flags;
2845 int pad;
2846 u_int fcslen;
2847 struct radiotap_state state;
2848
2849 if (caplen < sizeof(*hdr)) {
2850 ND_PRINT((ndo, "%s", tstr));
2851 return caplen;
2852 }
2853
2854 hdr = (struct ieee80211_radiotap_header *)p;
2855
2856 len = EXTRACT_LE_16BITS(&hdr->it_len);
2857
2858 if (caplen < len) {
2859 ND_PRINT((ndo, "%s", tstr));
2860 return caplen;
2861 }
2862 cpack_init(&cpacker, (uint8_t *)hdr, len); /* align against header start */
2863 cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */
2864 for (last_presentp = &hdr->it_present;
2865 IS_EXTENDED(last_presentp) &&
2866 (u_char*)(last_presentp + 1) <= p + len;
2867 last_presentp++)
2868 cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */
2869
2870 /* are there more bitmap extensions than bytes in header? */
2871 if (IS_EXTENDED(last_presentp)) {
2872 ND_PRINT((ndo, "%s", tstr));
2873 return caplen;
2874 }
2875
2876 /* Assume no flags */
2877 flags = 0;
2878 /* Assume no Atheros padding between 802.11 header and body */
2879 pad = 0;
2880 /* Assume no FCS at end of frame */
2881 fcslen = 0;
2882 for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp;
2883 presentp++, bit0 += 32) {
2884 presentflags = EXTRACT_LE_32BITS(presentp);
2885
2886 /* Clear state. */
2887 memset(&state, 0, sizeof(state));
2888
2889 for (present = EXTRACT_LE_32BITS(presentp); present;
2890 present = next_present) {
2891 /* clear the least significant bit that is set */
2892 next_present = present & (present - 1);
2893
2894 /* extract the least significant bit that is set */
2895 bit = (enum ieee80211_radiotap_type)
2896 (bit0 + BITNO_32(present ^ next_present));
2897
2898 if (print_radiotap_field(ndo, &cpacker, bit, &flags, &state, presentflags) != 0)
2899 goto out;
2900 }
2901 }
2902
2903 out:
2904 if (flags & IEEE80211_RADIOTAP_F_DATAPAD)
2905 pad = 1; /* Atheros padding */
2906 if (flags & IEEE80211_RADIOTAP_F_FCS)
2907 fcslen = 4; /* FCS at end of packet */
2908 return len + ieee802_11_print(ndo, p + len, length - len, caplen - len, pad,
2909 fcslen);
2910 #undef BITNO_32
2911 #undef BITNO_16
2912 #undef BITNO_8
2913 #undef BITNO_4
2914 #undef BITNO_2
2915 #undef BIT
2916 }
2917
2918 static u_int
2919 ieee802_11_avs_radio_print(netdissect_options *ndo,
2920 const u_char *p, u_int length, u_int caplen)
2921 {
2922 uint32_t caphdr_len;
2923
2924 if (caplen < 8) {
2925 ND_PRINT((ndo, "%s", tstr));
2926 return caplen;
2927 }
2928
2929 caphdr_len = EXTRACT_32BITS(p + 4);
2930 if (caphdr_len < 8) {
2931 /*
2932 * Yow! The capture header length is claimed not
2933 * to be large enough to include even the version
2934 * cookie or capture header length!
2935 */
2936 ND_PRINT((ndo, "%s", tstr));
2937 return caplen;
2938 }
2939
2940 if (caplen < caphdr_len) {
2941 ND_PRINT((ndo, "%s", tstr));
2942 return caplen;
2943 }
2944
2945 return caphdr_len + ieee802_11_print(ndo, p + caphdr_len,
2946 length - caphdr_len, caplen - caphdr_len, 0, 0);
2947 }
2948
2949 #define PRISM_HDR_LEN 144
2950
2951 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
2952 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
2953 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
2954
2955 /*
2956 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
2957 * containing information such as radio information, which we
2958 * currently ignore.
2959 *
2960 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
2961 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
2962 * (currently, on Linux, there's no ARPHRD_ type for
2963 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
2964 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
2965 * the AVS header, and the first 4 bytes of the header are used to
2966 * indicate whether it's a Prism header or an AVS header).
2967 */
2968 u_int
2969 prism_if_print(netdissect_options *ndo,
2970 const struct pcap_pkthdr *h, const u_char *p)
2971 {
2972 u_int caplen = h->caplen;
2973 u_int length = h->len;
2974 uint32_t msgcode;
2975
2976 if (caplen < 4) {
2977 ND_PRINT((ndo, "%s", tstr));
2978 return caplen;
2979 }
2980
2981 msgcode = EXTRACT_32BITS(p);
2982 if (msgcode == WLANCAP_MAGIC_COOKIE_V1 ||
2983 msgcode == WLANCAP_MAGIC_COOKIE_V2)
2984 return ieee802_11_avs_radio_print(ndo, p, length, caplen);
2985
2986 if (caplen < PRISM_HDR_LEN) {
2987 ND_PRINT((ndo, "%s", tstr));
2988 return caplen;
2989 }
2990
2991 return PRISM_HDR_LEN + ieee802_11_print(ndo, p + PRISM_HDR_LEN,
2992 length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN, 0, 0);
2993 }
2994
2995 /*
2996 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
2997 * header, containing information such as radio information.
2998 */
2999 u_int
3000 ieee802_11_radio_if_print(netdissect_options *ndo,
3001 const struct pcap_pkthdr *h, const u_char *p)
3002 {
3003 return ieee802_11_radio_print(ndo, p, h->len, h->caplen);
3004 }
3005
3006 /*
3007 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
3008 * extra header, containing information such as radio information,
3009 * which we currently ignore.
3010 */
3011 u_int
3012 ieee802_11_radio_avs_if_print(netdissect_options *ndo,
3013 const struct pcap_pkthdr *h, const u_char *p)
3014 {
3015 return ieee802_11_avs_radio_print(ndo, p, h->len, h->caplen);
3016 }