]> The Tcpdump Group git mirrors - tcpdump/blob - print-802_11.c
IEEE 802.11: use tok2str()
[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 u_int16_t fc;
174 u_int16_t duration;
175 u_int8_t da[6];
176 u_int8_t sa[6];
177 u_int8_t bssid[6];
178 u_int16_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 u_int8_t element_id;
193 u_int8_t length;
194 u_char ssid[33]; /* 32 + 1 for null */
195 };
196
197 struct rates_t {
198 u_int8_t element_id;
199 u_int8_t length;
200 u_int8_t rate[16];
201 };
202
203 struct challenge_t {
204 u_int8_t element_id;
205 u_int8_t length;
206 u_int8_t text[254]; /* 1-253 + 1 for null */
207 };
208
209 struct fh_t {
210 u_int8_t element_id;
211 u_int8_t length;
212 u_int16_t dwell_time;
213 u_int8_t hop_set;
214 u_int8_t hop_pattern;
215 u_int8_t hop_index;
216 };
217
218 struct ds_t {
219 u_int8_t element_id;
220 u_int8_t length;
221 u_int8_t channel;
222 };
223
224 struct cf_t {
225 u_int8_t element_id;
226 u_int8_t length;
227 u_int8_t count;
228 u_int8_t period;
229 u_int16_t max_duration;
230 u_int16_t dur_remaing;
231 };
232
233 struct tim_t {
234 u_int8_t element_id;
235 u_int8_t length;
236 u_int8_t count;
237 u_int8_t period;
238 u_int8_t bitmap_control;
239 u_int8_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 u_int8_t timestamp[IEEE802_11_TSTAMP_LEN];
270 u_int16_t beacon_interval;
271 u_int16_t listen_interval;
272 u_int16_t status_code;
273 u_int16_t aid;
274 u_char ap[IEEE802_11_AP_LEN];
275 u_int16_t reason_code;
276 u_int16_t auth_alg;
277 u_int16_t auth_trans_seq_num;
278 int challenge_present;
279 struct challenge_t challenge;
280 u_int16_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 u_int16_t fc;
297 u_int16_t duration;
298 u_int8_t ra[6];
299 u_int8_t ta[6];
300 u_int8_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 u_int16_t fc;
308 u_int16_t duration;
309 u_int8_t ra[6];
310 u_int8_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 u_int16_t fc;
317 u_int16_t duration;
318 u_int8_t ra[6];
319 u_int8_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 u_int16_t fc;
326 u_int16_t aid;
327 u_int8_t bssid[6];
328 u_int8_t ta[6];
329 u_int8_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 u_int16_t fc;
337 u_int16_t duration;
338 u_int8_t ra[6];
339 u_int8_t bssid[6];
340 u_int8_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 u_int16_t fc;
348 u_int16_t duration;
349 u_int8_t ra[6];
350 u_int8_t bssid[6];
351 u_int8_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 u_int16_t fc;
359 u_int16_t duration;
360 u_int8_t ra[6];
361 u_int8_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 u_int16_t fc;
368 u_int16_t dur;
369 u_int8_t ra[6];
370 u_int8_t ta[6];
371 u_int16_t ctl;
372 u_int16_t seq;
373 u_int8_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 u_int8_t flags;
382 u_int8_t ttl;
383 u_int8_t seq[4];
384 u_int8_t addr4[6];
385 u_int8_t addr5[6];
386 u_int8_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 u_int8_t it_version; /* Version 0. Only increases
447 * for drastic changes,
448 * introduction of compatible
449 * new fields does not count.
450 */
451 u_int8_t it_pad;
452 u_int16_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 u_int32_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 u_int64_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 u_int16_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 u_int16_t see below
483 *
484 * For frequency-hopping radios, the hop set (first byte)
485 * and pattern (second byte).
486 *
487 * IEEE80211_RADIOTAP_RATE u_int8_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 u_int8_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 u_int8_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 u_int16_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 u_int16_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 u_int16_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 u_int8_t bitmap
541 *
542 * Properties of transmitted and received frames. See flags
543 * defined below.
544 *
545 * IEEE80211_RADIOTAP_ANTENNA u_int8_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 u_int16_t bitmap
551 *
552 * Properties of received frames. See flags defined below.
553 *
554 * IEEE80211_RADIOTAP_XCHANNEL u_int32_t bitmap
555 * u_int16_t MHz
556 * u_int8_t channel number
557 * u_int8_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 u_int8_t known
566 * u_int8_t flags
567 * u_int8_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 * u_int8_t OUI[3]
575 * u_int8_t subspace
576 * u_int16_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 u_int32_t present;
693
694 u_int8_t rate;
695 };
696
697 #define PRINT_SSID(p) \
698 if (p.ssid_present) { \
699 ND_PRINT((ndo, " (")); \
700 fn_print(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 u_int32_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 if (!ND_TTEST2(*(p + offset), 1))
1319 return 0;
1320 if (length < 1)
1321 return 0;
1322 switch (*(p + offset)) {
1323 case E_SSID:
1324 if (!ND_TTEST2(*(p + offset), 2))
1325 return 0;
1326 if (length < 2)
1327 return 0;
1328 memcpy(&ssid, p + offset, 2);
1329 offset += 2;
1330 length -= 2;
1331 if (ssid.length != 0) {
1332 if (ssid.length > sizeof(ssid.ssid) - 1)
1333 return 0;
1334 if (!ND_TTEST2(*(p + offset), ssid.length))
1335 return 0;
1336 if (length < ssid.length)
1337 return 0;
1338 memcpy(&ssid.ssid, p + offset, ssid.length);
1339 offset += ssid.length;
1340 length -= ssid.length;
1341 }
1342 ssid.ssid[ssid.length] = '\0';
1343 /*
1344 * Present and not truncated.
1345 *
1346 * If we haven't already seen an SSID IE,
1347 * copy this one, otherwise ignore this one,
1348 * so we later report the first one we saw.
1349 */
1350 if (!pbody->ssid_present) {
1351 pbody->ssid = ssid;
1352 pbody->ssid_present = 1;
1353 }
1354 break;
1355 case E_CHALLENGE:
1356 if (!ND_TTEST2(*(p + offset), 2))
1357 return 0;
1358 if (length < 2)
1359 return 0;
1360 memcpy(&challenge, p + offset, 2);
1361 offset += 2;
1362 length -= 2;
1363 if (challenge.length != 0) {
1364 if (challenge.length >
1365 sizeof(challenge.text) - 1)
1366 return 0;
1367 if (!ND_TTEST2(*(p + offset), challenge.length))
1368 return 0;
1369 if (length < challenge.length)
1370 return 0;
1371 memcpy(&challenge.text, p + offset,
1372 challenge.length);
1373 offset += challenge.length;
1374 length -= challenge.length;
1375 }
1376 challenge.text[challenge.length] = '\0';
1377 /*
1378 * Present and not truncated.
1379 *
1380 * If we haven't already seen a challenge IE,
1381 * copy this one, otherwise ignore this one,
1382 * so we later report the first one we saw.
1383 */
1384 if (!pbody->challenge_present) {
1385 pbody->challenge = challenge;
1386 pbody->challenge_present = 1;
1387 }
1388 break;
1389 case E_RATES:
1390 if (!ND_TTEST2(*(p + offset), 2))
1391 return 0;
1392 if (length < 2)
1393 return 0;
1394 memcpy(&rates, p + offset, 2);
1395 offset += 2;
1396 length -= 2;
1397 if (rates.length != 0) {
1398 if (rates.length > sizeof rates.rate)
1399 return 0;
1400 if (!ND_TTEST2(*(p + offset), rates.length))
1401 return 0;
1402 if (length < rates.length)
1403 return 0;
1404 memcpy(&rates.rate, p + offset, rates.length);
1405 offset += rates.length;
1406 length -= rates.length;
1407 }
1408 /*
1409 * Present and not truncated.
1410 *
1411 * If we haven't already seen a rates IE,
1412 * copy this one if it's not zero-length,
1413 * otherwise ignore this one, so we later
1414 * report the first one we saw.
1415 *
1416 * We ignore zero-length rates IEs as some
1417 * devices seem to put a zero-length rates
1418 * IE, followed by an SSID IE, followed by
1419 * a non-zero-length rates IE into frames,
1420 * even though IEEE Std 802.11-2007 doesn't
1421 * seem to indicate that a zero-length rates
1422 * IE is valid.
1423 */
1424 if (!pbody->rates_present && rates.length != 0) {
1425 pbody->rates = rates;
1426 pbody->rates_present = 1;
1427 }
1428 break;
1429 case E_DS:
1430 if (!ND_TTEST2(*(p + offset), 3))
1431 return 0;
1432 if (length < 3)
1433 return 0;
1434 memcpy(&ds, p + offset, 3);
1435 offset += 3;
1436 length -= 3;
1437 /*
1438 * Present and not truncated.
1439 *
1440 * If we haven't already seen a DS IE,
1441 * copy this one, otherwise ignore this one,
1442 * so we later report the first one we saw.
1443 */
1444 if (!pbody->ds_present) {
1445 pbody->ds = ds;
1446 pbody->ds_present = 1;
1447 }
1448 break;
1449 case E_CF:
1450 if (!ND_TTEST2(*(p + offset), 8))
1451 return 0;
1452 if (length < 8)
1453 return 0;
1454 memcpy(&cf, p + offset, 8);
1455 offset += 8;
1456 length -= 8;
1457 /*
1458 * Present and not truncated.
1459 *
1460 * If we haven't already seen a CF IE,
1461 * copy this one, otherwise ignore this one,
1462 * so we later report the first one we saw.
1463 */
1464 if (!pbody->cf_present) {
1465 pbody->cf = cf;
1466 pbody->cf_present = 1;
1467 }
1468 break;
1469 case E_TIM:
1470 if (!ND_TTEST2(*(p + offset), 2))
1471 return 0;
1472 if (length < 2)
1473 return 0;
1474 memcpy(&tim, p + offset, 2);
1475 offset += 2;
1476 length -= 2;
1477 if (!ND_TTEST2(*(p + offset), 3))
1478 return 0;
1479 if (length < 3)
1480 return 0;
1481 memcpy(&tim.count, p + offset, 3);
1482 offset += 3;
1483 length -= 3;
1484
1485 if (tim.length <= 3)
1486 break;
1487 if (tim.length - 3 > (int)sizeof tim.bitmap)
1488 return 0;
1489 if (!ND_TTEST2(*(p + offset), tim.length - 3))
1490 return 0;
1491 if (length < (u_int)(tim.length - 3))
1492 return 0;
1493 memcpy(tim.bitmap, p + (tim.length - 3),
1494 (tim.length - 3));
1495 offset += tim.length - 3;
1496 length -= tim.length - 3;
1497 /*
1498 * Present and not truncated.
1499 *
1500 * If we haven't already seen a TIM IE,
1501 * copy this one, otherwise ignore this one,
1502 * so we later report the first one we saw.
1503 */
1504 if (!pbody->tim_present) {
1505 pbody->tim = tim;
1506 pbody->tim_present = 1;
1507 }
1508 break;
1509 default:
1510 #if 0
1511 ND_PRINT((ndo, "(1) unhandled element_id (%d) ",
1512 *(p + offset)));
1513 #endif
1514 if (!ND_TTEST2(*(p + offset), 2))
1515 return 0;
1516 if (length < 2)
1517 return 0;
1518 elementlen = *(p + offset + 1);
1519 if (!ND_TTEST2(*(p + offset + 2), elementlen))
1520 return 0;
1521 if (length < elementlen + 2)
1522 return 0;
1523 offset += elementlen + 2;
1524 length -= elementlen + 2;
1525 break;
1526 }
1527 }
1528
1529 /* No problems found. */
1530 return 1;
1531 }
1532
1533 /*********************************************************************************
1534 * Print Handle functions for the management frame types
1535 *********************************************************************************/
1536
1537 static int
1538 handle_beacon(netdissect_options *ndo,
1539 const u_char *p, u_int length)
1540 {
1541 struct mgmt_body_t pbody;
1542 int offset = 0;
1543 int ret;
1544
1545 memset(&pbody, 0, sizeof(pbody));
1546
1547 if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1548 IEEE802_11_CAPINFO_LEN))
1549 return 0;
1550 if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1551 IEEE802_11_CAPINFO_LEN)
1552 return 0;
1553 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
1554 offset += IEEE802_11_TSTAMP_LEN;
1555 length -= IEEE802_11_TSTAMP_LEN;
1556 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
1557 offset += IEEE802_11_BCNINT_LEN;
1558 length -= IEEE802_11_BCNINT_LEN;
1559 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
1560 offset += IEEE802_11_CAPINFO_LEN;
1561 length -= IEEE802_11_CAPINFO_LEN;
1562
1563 ret = parse_elements(ndo, &pbody, p, offset, length);
1564
1565 PRINT_SSID(pbody);
1566 PRINT_RATES(pbody);
1567 ND_PRINT((ndo, " %s",
1568 CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS"));
1569 PRINT_DS_CHANNEL(pbody);
1570
1571 return ret;
1572 }
1573
1574 static int
1575 handle_assoc_request(netdissect_options *ndo,
1576 const u_char *p, u_int length)
1577 {
1578 struct mgmt_body_t pbody;
1579 int offset = 0;
1580 int ret;
1581
1582 memset(&pbody, 0, sizeof(pbody));
1583
1584 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
1585 return 0;
1586 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)
1587 return 0;
1588 pbody.capability_info = EXTRACT_LE_16BITS(p);
1589 offset += IEEE802_11_CAPINFO_LEN;
1590 length -= IEEE802_11_CAPINFO_LEN;
1591 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
1592 offset += IEEE802_11_LISTENINT_LEN;
1593 length -= IEEE802_11_LISTENINT_LEN;
1594
1595 ret = parse_elements(ndo, &pbody, p, offset, length);
1596
1597 PRINT_SSID(pbody);
1598 PRINT_RATES(pbody);
1599 return ret;
1600 }
1601
1602 static int
1603 handle_assoc_response(netdissect_options *ndo,
1604 const u_char *p, u_int length)
1605 {
1606 struct mgmt_body_t pbody;
1607 int offset = 0;
1608 int ret;
1609
1610 memset(&pbody, 0, sizeof(pbody));
1611
1612 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
1613 IEEE802_11_AID_LEN))
1614 return 0;
1615 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
1616 IEEE802_11_AID_LEN)
1617 return 0;
1618 pbody.capability_info = EXTRACT_LE_16BITS(p);
1619 offset += IEEE802_11_CAPINFO_LEN;
1620 length -= IEEE802_11_CAPINFO_LEN;
1621 pbody.status_code = EXTRACT_LE_16BITS(p+offset);
1622 offset += IEEE802_11_STATUS_LEN;
1623 length -= IEEE802_11_STATUS_LEN;
1624 pbody.aid = EXTRACT_LE_16BITS(p+offset);
1625 offset += IEEE802_11_AID_LEN;
1626 length -= IEEE802_11_AID_LEN;
1627
1628 ret = parse_elements(ndo, &pbody, p, offset, length);
1629
1630 ND_PRINT((ndo, " AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 ,
1631 CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
1632 (pbody.status_code < NUM_STATUSES
1633 ? status_text[pbody.status_code]
1634 : "n/a")));
1635
1636 return ret;
1637 }
1638
1639 static int
1640 handle_reassoc_request(netdissect_options *ndo,
1641 const u_char *p, u_int length)
1642 {
1643 struct mgmt_body_t pbody;
1644 int offset = 0;
1645 int ret;
1646
1647 memset(&pbody, 0, sizeof(pbody));
1648
1649 if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
1650 IEEE802_11_AP_LEN))
1651 return 0;
1652 if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
1653 IEEE802_11_AP_LEN)
1654 return 0;
1655 pbody.capability_info = EXTRACT_LE_16BITS(p);
1656 offset += IEEE802_11_CAPINFO_LEN;
1657 length -= IEEE802_11_CAPINFO_LEN;
1658 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
1659 offset += IEEE802_11_LISTENINT_LEN;
1660 length -= IEEE802_11_LISTENINT_LEN;
1661 memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN);
1662 offset += IEEE802_11_AP_LEN;
1663 length -= IEEE802_11_AP_LEN;
1664
1665 ret = parse_elements(ndo, &pbody, p, offset, length);
1666
1667 PRINT_SSID(pbody);
1668 ND_PRINT((ndo, " AP : %s", etheraddr_string(ndo, pbody.ap )));
1669
1670 return ret;
1671 }
1672
1673 static int
1674 handle_reassoc_response(netdissect_options *ndo,
1675 const u_char *p, u_int length)
1676 {
1677 /* Same as a Association Reponse */
1678 return handle_assoc_response(ndo, p, length);
1679 }
1680
1681 static int
1682 handle_probe_request(netdissect_options *ndo,
1683 const u_char *p, u_int length)
1684 {
1685 struct mgmt_body_t pbody;
1686 int offset = 0;
1687 int ret;
1688
1689 memset(&pbody, 0, sizeof(pbody));
1690
1691 ret = parse_elements(ndo, &pbody, p, offset, length);
1692
1693 PRINT_SSID(pbody);
1694 PRINT_RATES(pbody);
1695
1696 return ret;
1697 }
1698
1699 static int
1700 handle_probe_response(netdissect_options *ndo,
1701 const u_char *p, u_int length)
1702 {
1703 struct mgmt_body_t pbody;
1704 int offset = 0;
1705 int ret;
1706
1707 memset(&pbody, 0, sizeof(pbody));
1708
1709 if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1710 IEEE802_11_CAPINFO_LEN))
1711 return 0;
1712 if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
1713 IEEE802_11_CAPINFO_LEN)
1714 return 0;
1715 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
1716 offset += IEEE802_11_TSTAMP_LEN;
1717 length -= IEEE802_11_TSTAMP_LEN;
1718 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
1719 offset += IEEE802_11_BCNINT_LEN;
1720 length -= IEEE802_11_BCNINT_LEN;
1721 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
1722 offset += IEEE802_11_CAPINFO_LEN;
1723 length -= IEEE802_11_CAPINFO_LEN;
1724
1725 ret = parse_elements(ndo, &pbody, p, offset, length);
1726
1727 PRINT_SSID(pbody);
1728 PRINT_RATES(pbody);
1729 PRINT_DS_CHANNEL(pbody);
1730
1731 return ret;
1732 }
1733
1734 static int
1735 handle_atim(void)
1736 {
1737 /* the frame body for ATIM is null. */
1738 return 1;
1739 }
1740
1741 static int
1742 handle_disassoc(netdissect_options *ndo,
1743 const u_char *p, u_int length)
1744 {
1745 struct mgmt_body_t pbody;
1746
1747 memset(&pbody, 0, sizeof(pbody));
1748
1749 if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
1750 return 0;
1751 if (length < IEEE802_11_REASON_LEN)
1752 return 0;
1753 pbody.reason_code = EXTRACT_LE_16BITS(p);
1754
1755 ND_PRINT((ndo, ": %s",
1756 (pbody.reason_code < NUM_REASONS)
1757 ? reason_text[pbody.reason_code]
1758 : "Reserved"));
1759
1760 return 1;
1761 }
1762
1763 static int
1764 handle_auth(netdissect_options *ndo,
1765 const u_char *p, u_int length)
1766 {
1767 struct mgmt_body_t pbody;
1768 int offset = 0;
1769 int ret;
1770
1771 memset(&pbody, 0, sizeof(pbody));
1772
1773 if (!ND_TTEST2(*p, 6))
1774 return 0;
1775 if (length < 6)
1776 return 0;
1777 pbody.auth_alg = EXTRACT_LE_16BITS(p);
1778 offset += 2;
1779 length -= 2;
1780 pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset);
1781 offset += 2;
1782 length -= 2;
1783 pbody.status_code = EXTRACT_LE_16BITS(p + offset);
1784 offset += 2;
1785 length -= 2;
1786
1787 ret = parse_elements(ndo, &pbody, p, offset, length);
1788
1789 if ((pbody.auth_alg == 1) &&
1790 ((pbody.auth_trans_seq_num == 2) ||
1791 (pbody.auth_trans_seq_num == 3))) {
1792 ND_PRINT((ndo, " (%s)-%x [Challenge Text] %s",
1793 (pbody.auth_alg < NUM_AUTH_ALGS)
1794 ? auth_alg_text[pbody.auth_alg]
1795 : "Reserved",
1796 pbody.auth_trans_seq_num,
1797 ((pbody.auth_trans_seq_num % 2)
1798 ? ((pbody.status_code < NUM_STATUSES)
1799 ? status_text[pbody.status_code]
1800 : "n/a") : "")));
1801 return ret;
1802 }
1803 ND_PRINT((ndo, " (%s)-%x: %s",
1804 (pbody.auth_alg < NUM_AUTH_ALGS)
1805 ? auth_alg_text[pbody.auth_alg]
1806 : "Reserved",
1807 pbody.auth_trans_seq_num,
1808 (pbody.auth_trans_seq_num % 2)
1809 ? ((pbody.status_code < NUM_STATUSES)
1810 ? status_text[pbody.status_code]
1811 : "n/a")
1812 : ""));
1813
1814 return ret;
1815 }
1816
1817 static int
1818 handle_deauth(netdissect_options *ndo,
1819 const struct mgmt_header_t *pmh, const u_char *p, u_int length)
1820 {
1821 struct mgmt_body_t pbody;
1822 const char *reason = NULL;
1823
1824 memset(&pbody, 0, sizeof(pbody));
1825
1826 if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
1827 return 0;
1828 if (length < IEEE802_11_REASON_LEN)
1829 return 0;
1830 pbody.reason_code = EXTRACT_LE_16BITS(p);
1831
1832 reason = (pbody.reason_code < NUM_REASONS)
1833 ? reason_text[pbody.reason_code]
1834 : "Reserved";
1835
1836 if (ndo->ndo_eflag) {
1837 ND_PRINT((ndo, ": %s", reason));
1838 } else {
1839 ND_PRINT((ndo, " (%s): %s", etheraddr_string(ndo, pmh->sa), reason));
1840 }
1841 return 1;
1842 }
1843
1844 #define PRINT_HT_ACTION(v) (\
1845 (v) == 0 ? ND_PRINT((ndo, "TxChWidth")) : \
1846 (v) == 1 ? ND_PRINT((ndo, "MIMOPwrSave")) : \
1847 ND_PRINT((ndo, "Act#%d", (v))) \
1848 )
1849 #define PRINT_BA_ACTION(v) (\
1850 (v) == 0 ? ND_PRINT((ndo, "ADDBA Request")) : \
1851 (v) == 1 ? ND_PRINT((ndo, "ADDBA Response")) : \
1852 (v) == 2 ? ND_PRINT((ndo, "DELBA")) : \
1853 ND_PRINT((ndo, "Act#%d", (v))) \
1854 )
1855 #define PRINT_MESHLINK_ACTION(v) (\
1856 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1857 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1858 ND_PRINT((ndo, "Act#%d", (v))) \
1859 )
1860 #define PRINT_MESHPEERING_ACTION(v) (\
1861 (v) == 0 ? ND_PRINT((ndo, "Open")) : \
1862 (v) == 1 ? ND_PRINT((ndo, "Confirm")) : \
1863 (v) == 2 ? ND_PRINT((ndo, "Close")) : \
1864 ND_PRINT((ndo, "Act#%d", (v))) \
1865 )
1866 #define PRINT_MESHPATH_ACTION(v) (\
1867 (v) == 0 ? ND_PRINT((ndo, "Request")) : \
1868 (v) == 1 ? ND_PRINT((ndo, "Report")) : \
1869 (v) == 2 ? ND_PRINT((ndo, "Error")) : \
1870 (v) == 3 ? ND_PRINT((ndo, "RootAnnouncement")) : \
1871 ND_PRINT((ndo, "Act#%d", (v))) \
1872 )
1873
1874 #define PRINT_MESH_ACTION(v) (\
1875 (v) == 0 ? ND_PRINT((ndo, "MeshLink")) : \
1876 (v) == 1 ? ND_PRINT((ndo, "HWMP")) : \
1877 (v) == 2 ? ND_PRINT((ndo, "Gate Announcement")) : \
1878 (v) == 3 ? ND_PRINT((ndo, "Congestion Control")) : \
1879 (v) == 4 ? ND_PRINT((ndo, "MCCA Setup Request")) : \
1880 (v) == 5 ? ND_PRINT((ndo, "MCCA Setup Reply")) : \
1881 (v) == 6 ? ND_PRINT((ndo, "MCCA Advertisement Request")) : \
1882 (v) == 7 ? ND_PRINT((ndo, "MCCA Advertisement")) : \
1883 (v) == 8 ? ND_PRINT((ndo, "MCCA Teardown")) : \
1884 (v) == 9 ? ND_PRINT((ndo, "TBTT Adjustment Request")) : \
1885 (v) == 10 ? ND_PRINT((ndo, "TBTT Adjustment Response")) : \
1886 ND_PRINT((ndo, "Act#%d", (v))) \
1887 )
1888 #define PRINT_MULTIHOP_ACTION(v) (\
1889 (v) == 0 ? ND_PRINT((ndo, "Proxy Update")) : \
1890 (v) == 1 ? ND_PRINT((ndo, "Proxy Update Confirmation")) : \
1891 ND_PRINT((ndo, "Act#%d", (v))) \
1892 )
1893 #define PRINT_SELFPROT_ACTION(v) (\
1894 (v) == 1 ? ND_PRINT((ndo, "Peering Open")) : \
1895 (v) == 2 ? ND_PRINT((ndo, "Peering Confirm")) : \
1896 (v) == 3 ? ND_PRINT((ndo, "Peering Close")) : \
1897 (v) == 4 ? ND_PRINT((ndo, "Group Key Inform")) : \
1898 (v) == 5 ? ND_PRINT((ndo, "Group Key Acknowledge")) : \
1899 ND_PRINT((ndo, "Act#%d", (v))) \
1900 )
1901
1902 static int
1903 handle_action(netdissect_options *ndo,
1904 const struct mgmt_header_t *pmh, const u_char *p, u_int length)
1905 {
1906 if (!ND_TTEST2(*p, 2))
1907 return 0;
1908 if (length < 2)
1909 return 0;
1910 if (ndo->ndo_eflag) {
1911 ND_PRINT((ndo, ": "));
1912 } else {
1913 ND_PRINT((ndo, " (%s): ", etheraddr_string(ndo, pmh->sa)));
1914 }
1915 switch (p[0]) {
1916 case 0: ND_PRINT((ndo, "Spectrum Management Act#%d", p[1])); break;
1917 case 1: ND_PRINT((ndo, "QoS Act#%d", p[1])); break;
1918 case 2: ND_PRINT((ndo, "DLS Act#%d", p[1])); break;
1919 case 3: ND_PRINT((ndo, "BA ")); PRINT_BA_ACTION(p[1]); break;
1920 case 7: ND_PRINT((ndo, "HT ")); PRINT_HT_ACTION(p[1]); break;
1921 case 13: ND_PRINT((ndo, "MeshAction ")); PRINT_MESH_ACTION(p[1]); break;
1922 case 14:
1923 ND_PRINT((ndo, "MultiohopAction "));
1924 PRINT_MULTIHOP_ACTION(p[1]); break;
1925 case 15:
1926 ND_PRINT((ndo, "SelfprotectAction "));
1927 PRINT_SELFPROT_ACTION(p[1]); break;
1928 case 127: ND_PRINT((ndo, "Vendor Act#%d", p[1])); break;
1929 default:
1930 ND_PRINT((ndo, "Reserved(%d) Act#%d", p[0], p[1]));
1931 break;
1932 }
1933 return 1;
1934 }
1935
1936
1937 /*********************************************************************************
1938 * Print Body funcs
1939 *********************************************************************************/
1940
1941
1942 static int
1943 mgmt_body_print(netdissect_options *ndo,
1944 u_int16_t fc, const struct mgmt_header_t *pmh,
1945 const u_char *p, u_int length)
1946 {
1947 ND_PRINT((ndo, "%s", tok2str(st_str, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc))));
1948 switch (FC_SUBTYPE(fc)) {
1949 case ST_ASSOC_REQUEST:
1950 return handle_assoc_request(ndo, p, length);
1951 case ST_ASSOC_RESPONSE:
1952 return handle_assoc_response(ndo, p, length);
1953 case ST_REASSOC_REQUEST:
1954 return handle_reassoc_request(ndo, p, length);
1955 case ST_REASSOC_RESPONSE:
1956 return handle_reassoc_response(ndo, p, length);
1957 case ST_PROBE_REQUEST:
1958 return handle_probe_request(ndo, p, length);
1959 case ST_PROBE_RESPONSE:
1960 return handle_probe_response(ndo, p, length);
1961 case ST_BEACON:
1962 return handle_beacon(ndo, p, length);
1963 case ST_ATIM:
1964 return handle_atim();
1965 case ST_DISASSOC:
1966 return handle_disassoc(ndo, p, length);
1967 case ST_AUTH:
1968 if (!ND_TTEST2(*p, 3))
1969 return 0;
1970 if ((p[0] == 0 ) && (p[1] == 0) && (p[2] == 0)) {
1971 ND_PRINT((ndo, "Authentication (Shared-Key)-3 "));
1972 return wep_print(ndo, p);
1973 }
1974 return handle_auth(ndo, p, length);
1975 case ST_DEAUTH:
1976 return handle_deauth(ndo, pmh, p, length);
1977 case ST_ACTION:
1978 return handle_action(ndo, pmh, p, length);
1979 default:
1980 return 1;
1981 }
1982 }
1983
1984
1985 /*********************************************************************************
1986 * Handles printing all the control frame types
1987 *********************************************************************************/
1988
1989 static int
1990 ctrl_body_print(netdissect_options *ndo,
1991 u_int16_t fc, const u_char *p)
1992 {
1993 ND_PRINT((ndo, "%s", tok2str(ctrl_str, "Unknown Ctrl Subtype", FC_SUBTYPE(fc))));
1994 switch (FC_SUBTYPE(fc)) {
1995 case CTRL_CONTROL_WRAPPER:
1996 /* XXX - requires special handling */
1997 break;
1998 case CTRL_BAR:
1999 if (!ND_TTEST2(*p, CTRL_BAR_HDRLEN))
2000 return 0;
2001 if (!ndo->ndo_eflag)
2002 ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
2003 etheraddr_string(ndo, ((const struct ctrl_bar_t *)p)->ra),
2004 etheraddr_string(ndo, ((const struct ctrl_bar_t *)p)->ta),
2005 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t *)p)->ctl)),
2006 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t *)p)->seq))));
2007 break;
2008 case CTRL_BA:
2009 if (!ND_TTEST2(*p, CTRL_BA_HDRLEN))
2010 return 0;
2011 if (!ndo->ndo_eflag)
2012 ND_PRINT((ndo, " RA:%s ",
2013 etheraddr_string(ndo, ((const struct ctrl_ba_t *)p)->ra)));
2014 break;
2015 case CTRL_PS_POLL:
2016 if (!ND_TTEST2(*p, CTRL_PS_POLL_HDRLEN))
2017 return 0;
2018 ND_PRINT((ndo, " AID(%x)",
2019 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t *)p)->aid))));
2020 break;
2021 case CTRL_RTS:
2022 if (!ND_TTEST2(*p, CTRL_RTS_HDRLEN))
2023 return 0;
2024 if (!ndo->ndo_eflag)
2025 ND_PRINT((ndo, " TA:%s ",
2026 etheraddr_string(ndo, ((const struct ctrl_rts_t *)p)->ta)));
2027 break;
2028 case CTRL_CTS:
2029 if (!ND_TTEST2(*p, CTRL_CTS_HDRLEN))
2030 return 0;
2031 if (!ndo->ndo_eflag)
2032 ND_PRINT((ndo, " RA:%s ",
2033 etheraddr_string(ndo, ((const struct ctrl_cts_t *)p)->ra)));
2034 break;
2035 case CTRL_ACK:
2036 if (!ND_TTEST2(*p, CTRL_ACK_HDRLEN))
2037 return 0;
2038 if (!ndo->ndo_eflag)
2039 ND_PRINT((ndo, " RA:%s ",
2040 etheraddr_string(ndo, ((const struct ctrl_ack_t *)p)->ra)));
2041 break;
2042 case CTRL_CF_END:
2043 if (!ND_TTEST2(*p, CTRL_END_HDRLEN))
2044 return 0;
2045 if (!ndo->ndo_eflag)
2046 ND_PRINT((ndo, " RA:%s ",
2047 etheraddr_string(ndo, ((const struct ctrl_end_t *)p)->ra)));
2048 break;
2049 case CTRL_END_ACK:
2050 if (!ND_TTEST2(*p, CTRL_END_ACK_HDRLEN))
2051 return 0;
2052 if (!ndo->ndo_eflag)
2053 ND_PRINT((ndo, " RA:%s ",
2054 etheraddr_string(ndo, ((const struct ctrl_end_ack_t *)p)->ra)));
2055 break;
2056 }
2057 return 1;
2058 }
2059
2060 /*
2061 * Print Header funcs
2062 */
2063
2064 /*
2065 * Data Frame - Address field contents
2066 *
2067 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
2068 * 0 | 0 | DA | SA | BSSID | n/a
2069 * 0 | 1 | DA | BSSID | SA | n/a
2070 * 1 | 0 | BSSID | SA | DA | n/a
2071 * 1 | 1 | RA | TA | DA | SA
2072 */
2073
2074 static void
2075 data_header_print(netdissect_options *ndo,
2076 u_int16_t fc, const u_char *p, const u_int8_t **srcp,
2077 const u_int8_t **dstp)
2078 {
2079 u_int subtype = FC_SUBTYPE(fc);
2080
2081 if (DATA_FRAME_IS_CF_ACK(subtype) || DATA_FRAME_IS_CF_POLL(subtype) ||
2082 DATA_FRAME_IS_QOS(subtype)) {
2083 ND_PRINT((ndo, "CF "));
2084 if (DATA_FRAME_IS_CF_ACK(subtype)) {
2085 if (DATA_FRAME_IS_CF_POLL(subtype))
2086 ND_PRINT((ndo, "Ack/Poll"));
2087 else
2088 ND_PRINT((ndo, "Ack"));
2089 } else {
2090 if (DATA_FRAME_IS_CF_POLL(subtype))
2091 ND_PRINT((ndo, "Poll"));
2092 }
2093 if (DATA_FRAME_IS_QOS(subtype))
2094 ND_PRINT((ndo, "+QoS"));
2095 ND_PRINT((ndo, " "));
2096 }
2097
2098 #define ADDR1 (p + 4)
2099 #define ADDR2 (p + 10)
2100 #define ADDR3 (p + 16)
2101 #define ADDR4 (p + 24)
2102
2103 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2104 if (srcp != NULL)
2105 *srcp = ADDR2;
2106 if (dstp != NULL)
2107 *dstp = ADDR1;
2108 if (!ndo->ndo_eflag)
2109 return;
2110 ND_PRINT((ndo, "DA:%s SA:%s BSSID:%s ",
2111 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2112 etheraddr_string(ndo, ADDR3)));
2113 } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2114 if (srcp != NULL)
2115 *srcp = ADDR3;
2116 if (dstp != NULL)
2117 *dstp = ADDR1;
2118 if (!ndo->ndo_eflag)
2119 return;
2120 ND_PRINT((ndo, "DA:%s BSSID:%s SA:%s ",
2121 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2122 etheraddr_string(ndo, ADDR3)));
2123 } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
2124 if (srcp != NULL)
2125 *srcp = ADDR2;
2126 if (dstp != NULL)
2127 *dstp = ADDR3;
2128 if (!ndo->ndo_eflag)
2129 return;
2130 ND_PRINT((ndo, "BSSID:%s SA:%s DA:%s ",
2131 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2132 etheraddr_string(ndo, ADDR3)));
2133 } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) {
2134 if (srcp != NULL)
2135 *srcp = ADDR4;
2136 if (dstp != NULL)
2137 *dstp = ADDR3;
2138 if (!ndo->ndo_eflag)
2139 return;
2140 ND_PRINT((ndo, "RA:%s TA:%s DA:%s SA:%s ",
2141 etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
2142 etheraddr_string(ndo, ADDR3), etheraddr_string(ndo, ADDR4)));
2143 }
2144
2145 #undef ADDR1
2146 #undef ADDR2
2147 #undef ADDR3
2148 #undef ADDR4
2149 }
2150
2151 static void
2152 mgmt_header_print(netdissect_options *ndo,
2153 const u_char *p, const u_int8_t **srcp, const u_int8_t **dstp)
2154 {
2155 const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
2156
2157 if (srcp != NULL)
2158 *srcp = hp->sa;
2159 if (dstp != NULL)
2160 *dstp = hp->da;
2161 if (!ndo->ndo_eflag)
2162 return;
2163
2164 ND_PRINT((ndo, "BSSID:%s DA:%s SA:%s ",
2165 etheraddr_string(ndo, (hp)->bssid), etheraddr_string(ndo, (hp)->da),
2166 etheraddr_string(ndo, (hp)->sa)));
2167 }
2168
2169 static void
2170 ctrl_header_print(netdissect_options *ndo,
2171 u_int16_t fc, const u_char *p, const u_int8_t **srcp,
2172 const u_int8_t **dstp)
2173 {
2174 if (srcp != NULL)
2175 *srcp = NULL;
2176 if (dstp != NULL)
2177 *dstp = NULL;
2178 if (!ndo->ndo_eflag)
2179 return;
2180
2181 switch (FC_SUBTYPE(fc)) {
2182 case CTRL_BAR:
2183 ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
2184 etheraddr_string(ndo, ((const struct ctrl_bar_t *)p)->ra),
2185 etheraddr_string(ndo, ((const struct ctrl_bar_t *)p)->ta),
2186 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t *)p)->ctl)),
2187 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t *)p)->seq))));
2188 break;
2189 case CTRL_BA:
2190 ND_PRINT((ndo, "RA:%s ",
2191 etheraddr_string(ndo, ((const struct ctrl_ba_t *)p)->ra)));
2192 break;
2193 case CTRL_PS_POLL:
2194 ND_PRINT((ndo, "BSSID:%s TA:%s ",
2195 etheraddr_string(ndo, ((const struct ctrl_ps_poll_t *)p)->bssid),
2196 etheraddr_string(ndo, ((const struct ctrl_ps_poll_t *)p)->ta)));
2197 break;
2198 case CTRL_RTS:
2199 ND_PRINT((ndo, "RA:%s TA:%s ",
2200 etheraddr_string(ndo, ((const struct ctrl_rts_t *)p)->ra),
2201 etheraddr_string(ndo, ((const struct ctrl_rts_t *)p)->ta)));
2202 break;
2203 case CTRL_CTS:
2204 ND_PRINT((ndo, "RA:%s ",
2205 etheraddr_string(ndo, ((const struct ctrl_cts_t *)p)->ra)));
2206 break;
2207 case CTRL_ACK:
2208 ND_PRINT((ndo, "RA:%s ",
2209 etheraddr_string(ndo, ((const struct ctrl_ack_t *)p)->ra)));
2210 break;
2211 case CTRL_CF_END:
2212 ND_PRINT((ndo, "RA:%s BSSID:%s ",
2213 etheraddr_string(ndo, ((const struct ctrl_end_t *)p)->ra),
2214 etheraddr_string(ndo, ((const struct ctrl_end_t *)p)->bssid)));
2215 break;
2216 case CTRL_END_ACK:
2217 ND_PRINT((ndo, "RA:%s BSSID:%s ",
2218 etheraddr_string(ndo, ((const struct ctrl_end_ack_t *)p)->ra),
2219 etheraddr_string(ndo, ((const struct ctrl_end_ack_t *)p)->bssid)));
2220 break;
2221 default:
2222 ND_PRINT((ndo, "(H) Unknown Ctrl Subtype"));
2223 break;
2224 }
2225 }
2226
2227 static int
2228 extract_header_length(netdissect_options *ndo,
2229 u_int16_t fc)
2230 {
2231 int len;
2232
2233 switch (FC_TYPE(fc)) {
2234 case T_MGMT:
2235 return MGMT_HDRLEN;
2236 case T_CTRL:
2237 switch (FC_SUBTYPE(fc)) {
2238 case CTRL_BAR:
2239 return CTRL_BAR_HDRLEN;
2240 case CTRL_PS_POLL:
2241 return CTRL_PS_POLL_HDRLEN;
2242 case CTRL_RTS:
2243 return CTRL_RTS_HDRLEN;
2244 case CTRL_CTS:
2245 return CTRL_CTS_HDRLEN;
2246 case CTRL_ACK:
2247 return CTRL_ACK_HDRLEN;
2248 case CTRL_CF_END:
2249 return CTRL_END_HDRLEN;
2250 case CTRL_END_ACK:
2251 return CTRL_END_ACK_HDRLEN;
2252 default:
2253 return 0;
2254 }
2255 case T_DATA:
2256 len = (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24;
2257 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc)))
2258 len += 2;
2259 return len;
2260 default:
2261 ND_PRINT((ndo, "unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)));
2262 return 0;
2263 }
2264 }
2265
2266 static int
2267 extract_mesh_header_length(const u_char *p)
2268 {
2269 return (p[0] &~ 3) ? 0 : 6*(1 + (p[0] & 3));
2270 }
2271
2272 /*
2273 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
2274 * to point to the source and destination MAC addresses in any case if
2275 * "srcp" and "dstp" aren't null.
2276 */
2277 static void
2278 ieee_802_11_hdr_print(netdissect_options *ndo,
2279 u_int16_t fc, const u_char *p, u_int hdrlen,
2280 u_int meshdrlen, const u_int8_t **srcp,
2281 const u_int8_t **dstp)
2282 {
2283 if (ndo->ndo_vflag) {
2284 if (FC_MORE_DATA(fc))
2285 ND_PRINT((ndo, "More Data "));
2286 if (FC_MORE_FLAG(fc))
2287 ND_PRINT((ndo, "More Fragments "));
2288 if (FC_POWER_MGMT(fc))
2289 ND_PRINT((ndo, "Pwr Mgmt "));
2290 if (FC_RETRY(fc))
2291 ND_PRINT((ndo, "Retry "));
2292 if (FC_ORDER(fc))
2293 ND_PRINT((ndo, "Strictly Ordered "));
2294 if (FC_WEP(fc))
2295 ND_PRINT((ndo, "WEP Encrypted "));
2296 if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL)
2297 ND_PRINT((ndo, "%dus ",
2298 EXTRACT_LE_16BITS(
2299 &((const struct mgmt_header_t *)p)->duration)));
2300 }
2301 if (meshdrlen != 0) {
2302 const struct meshcntl_t *mc =
2303 (const struct meshcntl_t *)&p[hdrlen - meshdrlen];
2304 int ae = mc->flags & 3;
2305
2306 ND_PRINT((ndo, "MeshData (AE %d TTL %u seq %u", ae, mc->ttl,
2307 EXTRACT_LE_32BITS(mc->seq)));
2308 if (ae > 0)
2309 ND_PRINT((ndo, " A4:%s", etheraddr_string(ndo, mc->addr4)));
2310 if (ae > 1)
2311 ND_PRINT((ndo, " A5:%s", etheraddr_string(ndo, mc->addr5)));
2312 if (ae > 2)
2313 ND_PRINT((ndo, " A6:%s", etheraddr_string(ndo, mc->addr6)));
2314 ND_PRINT((ndo, ") "));
2315 }
2316
2317 switch (FC_TYPE(fc)) {
2318 case T_MGMT:
2319 mgmt_header_print(ndo, p, srcp, dstp);
2320 break;
2321 case T_CTRL:
2322 ctrl_header_print(ndo, fc, p, srcp, dstp);
2323 break;
2324 case T_DATA:
2325 data_header_print(ndo, fc, p, srcp, dstp);
2326 break;
2327 default:
2328 ND_PRINT((ndo, "(header) unknown IEEE802.11 frame type (%d)",
2329 FC_TYPE(fc)));
2330 *srcp = NULL;
2331 *dstp = NULL;
2332 break;
2333 }
2334 }
2335
2336 #ifndef roundup2
2337 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2338 #endif
2339
2340 static u_int
2341 ieee802_11_print(netdissect_options *ndo,
2342 const u_char *p, u_int length, u_int orig_caplen, int pad,
2343 u_int fcslen)
2344 {
2345 u_int16_t fc;
2346 u_int caplen, hdrlen, meshdrlen;
2347 const u_int8_t *src, *dst;
2348 u_short extracted_ethertype;
2349
2350 caplen = orig_caplen;
2351 /* Remove FCS, if present */
2352 if (length < fcslen) {
2353 ND_PRINT((ndo, "%s", tstr));
2354 return caplen;
2355 }
2356 length -= fcslen;
2357 if (caplen > length) {
2358 /* Amount of FCS in actual packet data, if any */
2359 fcslen = caplen - length;
2360 caplen -= fcslen;
2361 ndo->ndo_snapend -= fcslen;
2362 }
2363
2364 if (caplen < IEEE802_11_FC_LEN) {
2365 ND_PRINT((ndo, "%s", tstr));
2366 return orig_caplen;
2367 }
2368
2369 fc = EXTRACT_LE_16BITS(p);
2370 hdrlen = extract_header_length(ndo, fc);
2371 if (pad)
2372 hdrlen = roundup2(hdrlen, 4);
2373 if (ndo->ndo_Hflag && FC_TYPE(fc) == T_DATA &&
2374 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) {
2375 meshdrlen = extract_mesh_header_length(p+hdrlen);
2376 hdrlen += meshdrlen;
2377 } else
2378 meshdrlen = 0;
2379
2380
2381 if (caplen < hdrlen) {
2382 ND_PRINT((ndo, "%s", tstr));
2383 return hdrlen;
2384 }
2385
2386 ieee_802_11_hdr_print(ndo, fc, p, hdrlen, meshdrlen, &src, &dst);
2387
2388 /*
2389 * Go past the 802.11 header.
2390 */
2391 length -= hdrlen;
2392 caplen -= hdrlen;
2393 p += hdrlen;
2394
2395 switch (FC_TYPE(fc)) {
2396 case T_MGMT:
2397 if (!mgmt_body_print(ndo, fc,
2398 (const struct mgmt_header_t *)(p - hdrlen), p, length)) {
2399 ND_PRINT((ndo, "%s", tstr));
2400 return hdrlen;
2401 }
2402 break;
2403 case T_CTRL:
2404 if (!ctrl_body_print(ndo, fc, p - hdrlen)) {
2405 ND_PRINT((ndo, "%s", tstr));
2406 return hdrlen;
2407 }
2408 break;
2409 case T_DATA:
2410 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc)))
2411 return hdrlen; /* no-data frame */
2412 /* There may be a problem w/ AP not having this bit set */
2413 if (FC_WEP(fc)) {
2414 if (!wep_print(ndo, p)) {
2415 ND_PRINT((ndo, "%s", tstr));
2416 return hdrlen;
2417 }
2418 } else if (llc_print(ndo, p, length, caplen, dst, src,
2419 &extracted_ethertype) == 0) {
2420 /*
2421 * Some kinds of LLC packet we cannot
2422 * handle intelligently
2423 */
2424 if (!ndo->ndo_eflag)
2425 ieee_802_11_hdr_print(ndo, fc, p - hdrlen, hdrlen,
2426 meshdrlen, NULL, NULL);
2427 if (extracted_ethertype)
2428 ND_PRINT((ndo, "(LLC %s) ",
2429 etherproto_string(
2430 htons(extracted_ethertype))));
2431 if (!ndo->ndo_suppress_default_print)
2432 ND_DEFAULTPRINT(p, caplen);
2433 }
2434 break;
2435 default:
2436 ND_PRINT((ndo, "unknown 802.11 frame type (%d)", FC_TYPE(fc)));
2437 break;
2438 }
2439
2440 return hdrlen;
2441 }
2442
2443 /*
2444 * This is the top level routine of the printer. 'p' points
2445 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2446 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2447 * is the number of bytes actually captured.
2448 */
2449 u_int
2450 ieee802_11_if_print(netdissect_options *ndo,
2451 const struct pcap_pkthdr *h, const u_char *p)
2452 {
2453 return ieee802_11_print(ndo, p, h->len, h->caplen, 0, 0);
2454 }
2455
2456 #define IEEE80211_CHAN_FHSS \
2457 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2458 #define IEEE80211_CHAN_A \
2459 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2460 #define IEEE80211_CHAN_B \
2461 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2462 #define IEEE80211_CHAN_PUREG \
2463 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2464 #define IEEE80211_CHAN_G \
2465 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2466
2467 #define IS_CHAN_FHSS(flags) \
2468 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2469 #define IS_CHAN_A(flags) \
2470 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2471 #define IS_CHAN_B(flags) \
2472 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2473 #define IS_CHAN_PUREG(flags) \
2474 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2475 #define IS_CHAN_G(flags) \
2476 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2477 #define IS_CHAN_ANYG(flags) \
2478 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2479
2480 static void
2481 print_chaninfo(netdissect_options *ndo,
2482 int freq, int flags)
2483 {
2484 ND_PRINT((ndo, "%u MHz", freq));
2485 if (IS_CHAN_FHSS(flags))
2486 ND_PRINT((ndo, " FHSS"));
2487 if (IS_CHAN_A(flags)) {
2488 if (flags & IEEE80211_CHAN_HALF)
2489 ND_PRINT((ndo, " 11a/10Mhz"));
2490 else if (flags & IEEE80211_CHAN_QUARTER)
2491 ND_PRINT((ndo, " 11a/5Mhz"));
2492 else
2493 ND_PRINT((ndo, " 11a"));
2494 }
2495 if (IS_CHAN_ANYG(flags)) {
2496 if (flags & IEEE80211_CHAN_HALF)
2497 ND_PRINT((ndo, " 11g/10Mhz"));
2498 else if (flags & IEEE80211_CHAN_QUARTER)
2499 ND_PRINT((ndo, " 11g/5Mhz"));
2500 else
2501 ND_PRINT((ndo, " 11g"));
2502 } else if (IS_CHAN_B(flags))
2503 ND_PRINT((ndo, " 11b"));
2504 if (flags & IEEE80211_CHAN_TURBO)
2505 ND_PRINT((ndo, " Turbo"));
2506 if (flags & IEEE80211_CHAN_HT20)
2507 ND_PRINT((ndo, " ht/20"));
2508 else if (flags & IEEE80211_CHAN_HT40D)
2509 ND_PRINT((ndo, " ht/40-"));
2510 else if (flags & IEEE80211_CHAN_HT40U)
2511 ND_PRINT((ndo, " ht/40+"));
2512 ND_PRINT((ndo, " "));
2513 }
2514
2515 static int
2516 print_radiotap_field(netdissect_options *ndo,
2517 struct cpack_state *s, u_int32_t bit, u_int8_t *flags,
2518 struct radiotap_state *state, u_int32_t presentflags)
2519 {
2520 union {
2521 int8_t i8;
2522 u_int8_t u8;
2523 int16_t i16;
2524 u_int16_t u16;
2525 u_int32_t u32;
2526 u_int64_t u64;
2527 } u, u2, u3, u4;
2528 int rc;
2529
2530 switch (bit) {
2531 case IEEE80211_RADIOTAP_FLAGS:
2532 rc = cpack_uint8(s, &u.u8);
2533 if (rc != 0)
2534 break;
2535 *flags = u.u8;
2536 break;
2537 case IEEE80211_RADIOTAP_RATE:
2538 rc = cpack_uint8(s, &u.u8);
2539 if (rc != 0)
2540 break;
2541
2542 /* Save state rate */
2543 state->rate = u.u8;
2544 break;
2545 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
2546 case IEEE80211_RADIOTAP_DB_ANTNOISE:
2547 case IEEE80211_RADIOTAP_ANTENNA:
2548 rc = cpack_uint8(s, &u.u8);
2549 break;
2550 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
2551 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
2552 rc = cpack_int8(s, &u.i8);
2553 break;
2554 case IEEE80211_RADIOTAP_CHANNEL:
2555 rc = cpack_uint16(s, &u.u16);
2556 if (rc != 0)
2557 break;
2558 rc = cpack_uint16(s, &u2.u16);
2559 break;
2560 case IEEE80211_RADIOTAP_FHSS:
2561 case IEEE80211_RADIOTAP_LOCK_QUALITY:
2562 case IEEE80211_RADIOTAP_TX_ATTENUATION:
2563 case IEEE80211_RADIOTAP_RX_FLAGS:
2564 rc = cpack_uint16(s, &u.u16);
2565 break;
2566 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
2567 rc = cpack_uint8(s, &u.u8);
2568 break;
2569 case IEEE80211_RADIOTAP_DBM_TX_POWER:
2570 rc = cpack_int8(s, &u.i8);
2571 break;
2572 case IEEE80211_RADIOTAP_TSFT:
2573 rc = cpack_uint64(s, &u.u64);
2574 break;
2575 case IEEE80211_RADIOTAP_XCHANNEL:
2576 rc = cpack_uint32(s, &u.u32);
2577 if (rc != 0)
2578 break;
2579 rc = cpack_uint16(s, &u2.u16);
2580 if (rc != 0)
2581 break;
2582 rc = cpack_uint8(s, &u3.u8);
2583 if (rc != 0)
2584 break;
2585 rc = cpack_uint8(s, &u4.u8);
2586 break;
2587 case IEEE80211_RADIOTAP_MCS:
2588 rc = cpack_uint8(s, &u.u8);
2589 if (rc != 0)
2590 break;
2591 rc = cpack_uint8(s, &u2.u8);
2592 if (rc != 0)
2593 break;
2594 rc = cpack_uint8(s, &u3.u8);
2595 break;
2596 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: {
2597 u_int8_t vns[3];
2598 u_int16_t length;
2599 u_int8_t subspace;
2600
2601 if ((cpack_align_and_reserve(s, 2)) == NULL) {
2602 rc = -1;
2603 break;
2604 }
2605
2606 rc = cpack_uint8(s, &vns[0]);
2607 if (rc != 0)
2608 break;
2609 rc = cpack_uint8(s, &vns[1]);
2610 if (rc != 0)
2611 break;
2612 rc = cpack_uint8(s, &vns[2]);
2613 if (rc != 0)
2614 break;
2615 rc = cpack_uint8(s, &subspace);
2616 if (rc != 0)
2617 break;
2618 rc = cpack_uint16(s, &length);
2619 if (rc != 0)
2620 break;
2621
2622 /* Skip up to length */
2623 s->c_next += length;
2624 break;
2625 }
2626 default:
2627 /* this bit indicates a field whose
2628 * size we do not know, so we cannot
2629 * proceed. Just print the bit number.
2630 */
2631 ND_PRINT((ndo, "[bit %u] ", bit));
2632 return -1;
2633 }
2634
2635 if (rc != 0) {
2636 ND_PRINT((ndo, "%s", tstr));
2637 return rc;
2638 }
2639
2640 /* Preserve the state present flags */
2641 state->present = presentflags;
2642
2643 switch (bit) {
2644 case IEEE80211_RADIOTAP_CHANNEL:
2645 /*
2646 * If CHANNEL and XCHANNEL are both present, skip
2647 * CHANNEL.
2648 */
2649 if (presentflags & (1 << IEEE80211_RADIOTAP_XCHANNEL))
2650 break;
2651 print_chaninfo(ndo, u.u16, u2.u16);
2652 break;
2653 case IEEE80211_RADIOTAP_FHSS:
2654 ND_PRINT((ndo, "fhset %d fhpat %d ", u.u16 & 0xff, (u.u16 >> 8) & 0xff));
2655 break;
2656 case IEEE80211_RADIOTAP_RATE:
2657 /*
2658 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2659 * Linux and AirPcap it does not. (What about
2660 * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
2661 *
2662 * This is an issue either for proprietary extensions
2663 * to 11a or 11g, which do exist, or for 11n
2664 * implementations that stuff a rate value into
2665 * this field, which also appear to exist.
2666 *
2667 * We currently handle that by assuming that
2668 * if the 0x80 bit is set *and* the remaining
2669 * bits have a value between 0 and 15 it's
2670 * an MCS value, otherwise it's a rate. If
2671 * there are cases where systems that use
2672 * "0x80 + MCS index" for MCS indices > 15,
2673 * or stuff a rate value here between 64 and
2674 * 71.5 Mb/s in here, we'll need a preference
2675 * setting. Such rates do exist, e.g. 11n
2676 * MCS 7 at 20 MHz with a long guard interval.
2677 */
2678 if (u.u8 >= 0x80 && u.u8 <= 0x8f) {
2679 /*
2680 * XXX - we don't know the channel width
2681 * or guard interval length, so we can't
2682 * convert this to a data rate.
2683 *
2684 * If you want us to show a data rate,
2685 * use the MCS field, not the Rate field;
2686 * the MCS field includes not only the
2687 * MCS index, it also includes bandwidth
2688 * and guard interval information.
2689 *
2690 * XXX - can we get the channel width
2691 * from XChannel and the guard interval
2692 * information from Flags, at least on
2693 * FreeBSD?
2694 */
2695 ND_PRINT((ndo, "MCS %u ", u.u8 & 0x7f));
2696 } else
2697 ND_PRINT((ndo, "%2.1f Mb/s ", .5 * u.u8));
2698 break;
2699 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
2700 ND_PRINT((ndo, "%ddB signal ", u.i8));
2701 break;
2702 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
2703 ND_PRINT((ndo, "%ddB noise ", u.i8));
2704 break;
2705 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
2706 ND_PRINT((ndo, "%ddB signal ", u.u8));
2707 break;
2708 case IEEE80211_RADIOTAP_DB_ANTNOISE:
2709 ND_PRINT((ndo, "%ddB noise ", u.u8));
2710 break;
2711 case IEEE80211_RADIOTAP_LOCK_QUALITY:
2712 ND_PRINT((ndo, "%u sq ", u.u16));
2713 break;
2714 case IEEE80211_RADIOTAP_TX_ATTENUATION:
2715 ND_PRINT((ndo, "%d tx power ", -(int)u.u16));
2716 break;
2717 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
2718 ND_PRINT((ndo, "%ddB tx power ", -(int)u.u8));
2719 break;
2720 case IEEE80211_RADIOTAP_DBM_TX_POWER:
2721 ND_PRINT((ndo, "%ddBm tx power ", u.i8));
2722 break;
2723 case IEEE80211_RADIOTAP_FLAGS:
2724 if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
2725 ND_PRINT((ndo, "cfp "));
2726 if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
2727 ND_PRINT((ndo, "short preamble "));
2728 if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
2729 ND_PRINT((ndo, "wep "));
2730 if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
2731 ND_PRINT((ndo, "fragmented "));
2732 if (u.u8 & IEEE80211_RADIOTAP_F_BADFCS)
2733 ND_PRINT((ndo, "bad-fcs "));
2734 break;
2735 case IEEE80211_RADIOTAP_ANTENNA:
2736 ND_PRINT((ndo, "antenna %d ", u.u8));
2737 break;
2738 case IEEE80211_RADIOTAP_TSFT:
2739 ND_PRINT((ndo, "%" PRIu64 "us tsft ", u.u64));
2740 break;
2741 case IEEE80211_RADIOTAP_RX_FLAGS:
2742 /* Do nothing for now */
2743 break;
2744 case IEEE80211_RADIOTAP_XCHANNEL:
2745 print_chaninfo(ndo, u2.u16, u.u32);
2746 break;
2747 case IEEE80211_RADIOTAP_MCS: {
2748 static const char *bandwidth[4] = {
2749 "20 MHz",
2750 "40 MHz",
2751 "20 MHz (L)",
2752 "20 MHz (U)"
2753 };
2754 float htrate;
2755
2756 if (u.u8 & IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN) {
2757 /*
2758 * We know the MCS index.
2759 */
2760 if (u3.u8 <= MAX_MCS_INDEX) {
2761 /*
2762 * And it's in-range.
2763 */
2764 if (u.u8 & (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN)) {
2765 /*
2766 * And we know both the bandwidth and
2767 * the guard interval, so we can look
2768 * up the rate.
2769 */
2770 htrate =
2771 ieee80211_float_htrates \
2772 [u3.u8] \
2773 [((u2.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 ? 1 : 0)] \
2774 [((u2.u8 & IEEE80211_RADIOTAP_MCS_SHORT_GI) ? 1 : 0)];
2775 } else {
2776 /*
2777 * We don't know both the bandwidth
2778 * and the guard interval, so we can
2779 * only report the MCS index.
2780 */
2781 htrate = 0.0;
2782 }
2783 } else {
2784 /*
2785 * The MCS value is out of range.
2786 */
2787 htrate = 0.0;
2788 }
2789 if (htrate != 0.0) {
2790 /*
2791 * We have the rate.
2792 * Print it.
2793 */
2794 ND_PRINT((ndo, "%.1f Mb/s MCS %u ", htrate, u3.u8));
2795 } else {
2796 /*
2797 * We at least have the MCS index.
2798 * Print it.
2799 */
2800 ND_PRINT((ndo, "MCS %u ", u3.u8));
2801 }
2802 }
2803 if (u.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN) {
2804 ND_PRINT((ndo, "%s ",
2805 bandwidth[u2.u8 & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK]));
2806 }
2807 if (u.u8 & IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN) {
2808 ND_PRINT((ndo, "%s GI ",
2809 (u2.u8 & IEEE80211_RADIOTAP_MCS_SHORT_GI) ?
2810 "short" : "lon"));
2811 }
2812 if (u.u8 & IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN) {
2813 ND_PRINT((ndo, "%s ",
2814 (u2.u8 & IEEE80211_RADIOTAP_MCS_HT_GREENFIELD) ?
2815 "greenfield" : "mixed"));
2816 }
2817 if (u.u8 & IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN) {
2818 ND_PRINT((ndo, "%s FEC ",
2819 (u2.u8 & IEEE80211_RADIOTAP_MCS_FEC_LDPC) ?
2820 "LDPC" : "BCC"));
2821 }
2822 if (u.u8 & IEEE80211_RADIOTAP_MCS_STBC_KNOWN) {
2823 ND_PRINT((ndo, "RX-STBC%u ",
2824 (u2.u8 & IEEE80211_RADIOTAP_MCS_STBC_MASK) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT));
2825 }
2826
2827 break;
2828 }
2829 }
2830 return 0;
2831 }
2832
2833 static u_int
2834 ieee802_11_radio_print(netdissect_options *ndo,
2835 const u_char *p, u_int length, u_int caplen)
2836 {
2837 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
2838 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
2839 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
2840 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
2841 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
2842 #define BIT(n) (1U << n)
2843 #define IS_EXTENDED(__p) \
2844 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
2845
2846 struct cpack_state cpacker;
2847 struct ieee80211_radiotap_header *hdr;
2848 u_int32_t present, next_present;
2849 u_int32_t presentflags = 0;
2850 u_int32_t *presentp, *last_presentp;
2851 enum ieee80211_radiotap_type bit;
2852 int bit0;
2853 u_int len;
2854 u_int8_t flags;
2855 int pad;
2856 u_int fcslen;
2857 struct radiotap_state state;
2858
2859 if (caplen < sizeof(*hdr)) {
2860 ND_PRINT((ndo, "%s", tstr));
2861 return caplen;
2862 }
2863
2864 hdr = (struct ieee80211_radiotap_header *)p;
2865
2866 len = EXTRACT_LE_16BITS(&hdr->it_len);
2867
2868 if (caplen < len) {
2869 ND_PRINT((ndo, "%s", tstr));
2870 return caplen;
2871 }
2872 cpack_init(&cpacker, (u_int8_t *)hdr, len); /* align against header start */
2873 cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */
2874 for (last_presentp = &hdr->it_present;
2875 IS_EXTENDED(last_presentp) &&
2876 (u_char*)(last_presentp + 1) <= p + len;
2877 last_presentp++)
2878 cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */
2879
2880 /* are there more bitmap extensions than bytes in header? */
2881 if (IS_EXTENDED(last_presentp)) {
2882 ND_PRINT((ndo, "%s", tstr));
2883 return caplen;
2884 }
2885
2886 /* Assume no flags */
2887 flags = 0;
2888 /* Assume no Atheros padding between 802.11 header and body */
2889 pad = 0;
2890 /* Assume no FCS at end of frame */
2891 fcslen = 0;
2892 for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp;
2893 presentp++, bit0 += 32) {
2894 presentflags = EXTRACT_LE_32BITS(presentp);
2895
2896 /* Clear state. */
2897 memset(&state, 0, sizeof(state));
2898
2899 for (present = EXTRACT_LE_32BITS(presentp); present;
2900 present = next_present) {
2901 /* clear the least significant bit that is set */
2902 next_present = present & (present - 1);
2903
2904 /* extract the least significant bit that is set */
2905 bit = (enum ieee80211_radiotap_type)
2906 (bit0 + BITNO_32(present ^ next_present));
2907
2908 if (print_radiotap_field(ndo, &cpacker, bit, &flags, &state, presentflags) != 0)
2909 goto out;
2910 }
2911 }
2912
2913 out:
2914 if (flags & IEEE80211_RADIOTAP_F_DATAPAD)
2915 pad = 1; /* Atheros padding */
2916 if (flags & IEEE80211_RADIOTAP_F_FCS)
2917 fcslen = 4; /* FCS at end of packet */
2918 return len + ieee802_11_print(ndo, p + len, length - len, caplen - len, pad,
2919 fcslen);
2920 #undef BITNO_32
2921 #undef BITNO_16
2922 #undef BITNO_8
2923 #undef BITNO_4
2924 #undef BITNO_2
2925 #undef BIT
2926 }
2927
2928 static u_int
2929 ieee802_11_avs_radio_print(netdissect_options *ndo,
2930 const u_char *p, u_int length, u_int caplen)
2931 {
2932 u_int32_t caphdr_len;
2933
2934 if (caplen < 8) {
2935 ND_PRINT((ndo, "%s", tstr));
2936 return caplen;
2937 }
2938
2939 caphdr_len = EXTRACT_32BITS(p + 4);
2940 if (caphdr_len < 8) {
2941 /*
2942 * Yow! The capture header length is claimed not
2943 * to be large enough to include even the version
2944 * cookie or capture header length!
2945 */
2946 ND_PRINT((ndo, "%s", tstr));
2947 return caplen;
2948 }
2949
2950 if (caplen < caphdr_len) {
2951 ND_PRINT((ndo, "%s", tstr));
2952 return caplen;
2953 }
2954
2955 return caphdr_len + ieee802_11_print(ndo, p + caphdr_len,
2956 length - caphdr_len, caplen - caphdr_len, 0, 0);
2957 }
2958
2959 #define PRISM_HDR_LEN 144
2960
2961 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
2962 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
2963 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
2964
2965 /*
2966 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
2967 * containing information such as radio information, which we
2968 * currently ignore.
2969 *
2970 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
2971 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
2972 * (currently, on Linux, there's no ARPHRD_ type for
2973 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
2974 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
2975 * the AVS header, and the first 4 bytes of the header are used to
2976 * indicate whether it's a Prism header or an AVS header).
2977 */
2978 u_int
2979 prism_if_print(netdissect_options *ndo,
2980 const struct pcap_pkthdr *h, const u_char *p)
2981 {
2982 u_int caplen = h->caplen;
2983 u_int length = h->len;
2984 u_int32_t msgcode;
2985
2986 if (caplen < 4) {
2987 ND_PRINT((ndo, "%s", tstr));
2988 return caplen;
2989 }
2990
2991 msgcode = EXTRACT_32BITS(p);
2992 if (msgcode == WLANCAP_MAGIC_COOKIE_V1 ||
2993 msgcode == WLANCAP_MAGIC_COOKIE_V2)
2994 return ieee802_11_avs_radio_print(ndo, p, length, caplen);
2995
2996 if (caplen < PRISM_HDR_LEN) {
2997 ND_PRINT((ndo, "%s", tstr));
2998 return caplen;
2999 }
3000
3001 return PRISM_HDR_LEN + ieee802_11_print(ndo, p + PRISM_HDR_LEN,
3002 length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN, 0, 0);
3003 }
3004
3005 /*
3006 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
3007 * header, containing information such as radio information.
3008 */
3009 u_int
3010 ieee802_11_radio_if_print(netdissect_options *ndo,
3011 const struct pcap_pkthdr *h, const u_char *p)
3012 {
3013 return ieee802_11_radio_print(ndo, p, h->len, h->caplen);
3014 }
3015
3016 /*
3017 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
3018 * extra header, containing information such as radio information,
3019 * which we currently ignore.
3020 */
3021 u_int
3022 ieee802_11_radio_avs_if_print(netdissect_options *ndo,
3023 const struct pcap_pkthdr *h, const u_char *p)
3024 {
3025 return ieee802_11_avs_radio_print(ndo, p, h->len, h->caplen);
3026 }