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