2 * Routines for Wireless LAN (IEEE 802.11) dissection
3 * Copyright 2000, Axis Communications AB
4 * Inquiries/bugreports should be sent to Johan.Jorgensen@axis.com
6 * $Id: packet-ieee80211.c,v 1.31 2001/06/20 23:58:57 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * Copied from README.developer
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * The following people helped me by pointing out bugs etc. Thank you!
34 * Magnus Hultman-Persson
45 #ifdef HAVE_SYS_TYPES_H
46 # include <sys/types.h>
49 #ifdef HAVE_NETINET_IN_H
50 # include <netinet/in.h>
53 #ifdef NEED_SNPRINTF_H
59 # include "snprintf.h"
68 #include "packet-llc.h"
69 #include "packet-ieee80211.h"
72 /* ************************************************************************* */
73 /* Miscellaneous Constants */
74 /* ************************************************************************* */
76 #define MGT_FRAME_LEN 24
78 /* ************************************************************************* */
79 /* Define some very useful macros that are used to analyze frame types etc. */
80 /* ************************************************************************* */
81 #define COMPOSE_FRAME_TYPE(x) (((x & 0x0C)<< 2)+((x & 0xF0) >> 4)) /* Create key to (sub)type */
82 #define COOK_PROT_VERSION(x) ((x) & 0x3)
83 #define COOK_FRAME_TYPE(x) (((x) & 0xC) >> 2)
84 #define COOK_FRAME_SUBTYPE(x) (((x) & 0xF0) >> 4)
85 #define COOK_ADDR_SELECTOR(x) ((x) & 0x300)
86 #define COOK_ASSOC_ID(x) ((x) & 0x3FFF)
87 #define COOK_FRAGMENT_NUMBER(x) ((x) & 0x000F)
88 #define COOK_SEQUENCE_NUMBER(x) (((x) & 0xFFF0) >> 4)
89 #define COOK_FLAGS(x) (((x) & 0xFF00) >> 8)
90 #define COOK_DS_STATUS(x) ((x) & 0x3)
91 #define COOK_WEP_IV(x) ((x) & 0xFFFFFF)
92 #define COOK_WEP_KEY(x) (((x) & 0xC0000000) >> 30)
93 #define COL_SHOW_INFO(fd,info) if (check_col(fd,COL_INFO)) \
94 col_add_str(fd,COL_INFO,info);
95 #define COL_SHOW_INFO_CONST(fd,info) if (check_col(fd,COL_INFO)) \
96 col_set_str(fd,COL_INFO,info);
98 #define IS_TO_DS(x) ((x) & 0x01)
99 #define IS_FROM_DS(x) ((x) & 0x02)
100 #define HAVE_FRAGMENTS(x) ((x) & 0x04)
101 #define IS_RETRY(x) ((x) & 0x08)
102 #define POWER_MGT_STATUS(x) ((x) & 0x10)
103 #define HAS_MORE_DATA(x) ((x) & 0x20)
104 #define IS_WEP(x) ((x) & 0x40)
105 #define IS_STRICTLY_ORDERED(x) ((x) & 0x80)
107 #define MGT_RESERVED_RANGE(x) (((x>=0x06)&&(x<=0x07))||((x>=0x0D)&&(x<=0x0F)))
108 #define CTRL_RESERVED_RANGE(x) ((x>=0x10)&&(x<=0x19))
109 #define DATA_RESERVED_RANGE(x) ((x>=0x28)&&(x<=0x2f))
110 #define SPEC_RESERVED_RANGE(x) ((x>=0x30)&&(x<=0x3f))
113 /* ************************************************************************* */
114 /* Constants used to identify cooked frame types */
115 /* ************************************************************************* */
116 #define MGT_FRAME 0x00 /* Frame type is management */
117 #define CONTROL_FRAME 0x01 /* Frame type is control */
118 #define DATA_FRAME 0x02 /* Frame type is Data */
120 #define DATA_SHORT_HDR_LEN 24
121 #define DATA_LONG_HDR_LEN 30
122 #define MGT_FRAME_HDR_LEN 24 /* Length of Managment frame-headers */
124 #define MGT_ASSOC_REQ 0x00 /* Management - association request */
125 #define MGT_ASSOC_RESP 0x01 /* Management - association response */
126 #define MGT_REASSOC_REQ 0x02 /* Management - reassociation request */
127 #define MGT_REASSOC_RESP 0x03 /* Management - reassociation response */
128 #define MGT_PROBE_REQ 0x04 /* Management - Probe request */
129 #define MGT_PROBE_RESP 0x05 /* Management - Probe response */
130 #define MGT_BEACON 0x08 /* Management - Beacon frame */
131 #define MGT_ATIM 0x09 /* Management - ATIM */
132 #define MGT_DISASS 0x0A /* Management - Disassociation */
133 #define MGT_AUTHENTICATION 0x0B /* Management - Authentication */
134 #define MGT_DEAUTHENTICATION 0x0C /* Management - Deauthentication */
136 #define CTRL_PS_POLL 0x1A /* Control - power-save poll */
137 #define CTRL_RTS 0x1B /* Control - request to send */
138 #define CTRL_CTS 0x1C /* Control - clear to send */
139 #define CTRL_ACKNOWLEDGEMENT 0x1D /* Control - acknowledgement */
140 #define CTRL_CFP_END 0x1E /* Control - contention-free period end */
141 #define CTRL_CFP_ENDACK 0x1F /* Control - contention-free period end/ack */
143 #define DATA 0x20 /* Data - Data */
144 #define DATA_CF_ACK 0x21 /* Data - Data + CF acknowledge */
145 #define DATA_CF_POLL 0x22 /* Data - Data + CF poll */
146 #define DATA_CF_ACK_POLL 0x23 /* Data - Data + CF acknowledge + CF poll */
147 #define DATA_NULL_FUNCTION 0x24 /* Data - Null function (no data) */
148 #define DATA_CF_ACK_NOD 0x25 /* Data - CF ack (no data) */
149 #define DATA_CF_POLL_NOD 0x26 /* Data - Data + CF poll (No data) */
150 #define DATA_CF_ACK_POLL_NOD 0x27 /* Data - CF ack + CF poll (no data) */
152 #define DATA_ADDR_T1 0x0000
153 #define DATA_ADDR_T2 0x0100
154 #define DATA_ADDR_T3 0x0200
155 #define DATA_ADDR_T4 0x0300
158 /* ************************************************************************* */
159 /* Macros used to extract information about fixed fields */
160 /* ************************************************************************* */
161 #define ESS_SET(x) ((x) & 0x0001)
162 #define IBSS_SET(x) ((x) & 0x0002)
166 /* ************************************************************************* */
167 /* Logical field codes (dissector's encoding of fixed fields) */
168 /* ************************************************************************* */
169 #define FIELD_TIMESTAMP 0x01 /* 64-bit timestamp */
170 #define FIELD_BEACON_INTERVAL 0x02 /* 16-bit beacon interval */
171 #define FIELD_CAP_INFO 0x03 /* Add capability information tree */
172 #define FIELD_AUTH_ALG 0x04 /* Authentication algorithm used */
173 #define FIELD_AUTH_TRANS_SEQ 0x05 /* Authentication sequence number */
174 #define FIELD_CURRENT_AP_ADDR 0x06
175 #define FIELD_LISTEN_IVAL 0x07
176 #define FIELD_REASON_CODE 0x08
177 #define FIELD_ASSOC_ID 0x09
178 #define FIELD_STATUS_CODE 0x0A
180 /* ************************************************************************* */
181 /* Logical field codes (IEEE 802.11 encoding of tags) */
182 /* ************************************************************************* */
183 #define TAG_SSID 0x00
184 #define TAG_SUPP_RATES 0x01
185 #define TAG_FH_PARAMETER 0x02
186 #define TAG_DS_PARAMETER 0x03
187 #define TAG_CF_PARAMETER 0x04
189 #define TAG_IBSS_PARAMETER 0x06
190 #define TAG_CHALLENGE_TEXT 0x10
192 /* ************************************************************************* */
193 /* Frame types, and their names */
194 /* ************************************************************************* */
195 static const value_string frame_type_subtype_vals[] = {
196 {MGT_ASSOC_REQ, "Association Request"},
197 {MGT_ASSOC_RESP, "Association Response"},
198 {MGT_REASSOC_REQ, "Reassociation Request"},
199 {MGT_REASSOC_RESP, "Reassociation Response"},
200 {MGT_PROBE_REQ, "Probe Request"},
201 {MGT_PROBE_RESP, "Probe Response"},
202 {MGT_BEACON, "Beacon frame"},
204 {MGT_DISASS, "Dissassociate"},
205 {MGT_AUTHENTICATION, "Authentication"},
206 {MGT_DEAUTHENTICATION, "Deauthentication"},
207 {CTRL_PS_POLL, "Power-Save poll"},
208 {CTRL_RTS, "Request-to-send"},
209 {CTRL_CTS, "Clear-to-send"},
210 {CTRL_ACKNOWLEDGEMENT, "Acknowledgement"},
211 {CTRL_CFP_END, "CF-End (Control-frame)"},
212 {CTRL_CFP_ENDACK, "CF-End + CF-Ack (Control-frame)"},
214 {DATA_CF_ACK, "Data + CF-Acknowledgement"},
215 {DATA_CF_POLL, "Data + CF-Poll"},
216 {DATA_CF_ACK_POLL, "Data + CF-Acknowledgement/Poll"},
217 {DATA_NULL_FUNCTION, "Null function (No data)"},
218 {DATA_CF_ACK_NOD, "Data + Acknowledgement (No data)"},
219 {DATA_CF_POLL_NOD, "Data + CF-Poll (No data)"},
220 {DATA_CF_ACK_POLL_NOD, "Data + CF-Acknowledgement/Poll (No data)"},
224 static int proto_wlan = -1;
225 /* ************************************************************************* */
226 /* Header field info values for FC-field */
227 /* ************************************************************************* */
228 static int hf_fc_field = -1;
229 static int hf_fc_proto_version = -1;
230 static int hf_fc_frame_type = -1;
231 static int hf_fc_frame_subtype = -1;
232 static int hf_fc_frame_type_subtype = -1;
234 static int hf_fc_flags = -1;
235 static int hf_fc_to_ds = -1;
236 static int hf_fc_from_ds = -1;
237 static int hf_fc_data_ds = -1;
239 static int hf_fc_more_frag = -1;
240 static int hf_fc_retry = -1;
241 static int hf_fc_pwr_mgt = -1;
242 static int hf_fc_more_data = -1;
243 static int hf_fc_wep = -1;
244 static int hf_fc_order = -1;
247 /* ************************************************************************* */
248 /* Header values for Duration/ID field */
249 /* ************************************************************************* */
250 static int hf_did_duration = -1;
251 static int hf_assoc_id = -1;
254 /* ************************************************************************* */
255 /* Header values for different address-fields (all 4 of them) */
256 /* ************************************************************************* */
257 static int hf_addr_da = -1; /* Destination address subfield */
258 static int hf_addr_sa = -1; /* Source address subfield */
259 static int hf_addr_ra = -1; /* Receiver address subfield */
260 static int hf_addr_ta = -1; /* Transmitter address subfield */
261 static int hf_addr_bssid = -1; /* address is bssid */
265 /* ************************************************************************* */
266 /* Header values for sequence number field */
267 /* ************************************************************************* */
268 static int hf_frag_number = -1;
269 static int hf_seq_number = -1;
271 /* ************************************************************************* */
272 /* Header values for Frame Check field */
273 /* ************************************************************************* */
274 static int hf_fcs = -1;
277 /* ************************************************************************* */
278 /* Fixed fields found in mgt frames */
279 /* ************************************************************************* */
280 static int ff_auth_alg = -1; /* Authentication algorithm field */
281 static int ff_auth_seq = -1; /* Authentication transaction sequence */
282 static int ff_current_ap = -1; /* Current AP MAC address */
283 static int ff_listen_ival = -1; /* Listen interval fixed field */
284 static int ff_timestamp = -1; /* 64 bit timestamp */
285 static int ff_beacon_interval = -1; /* 16 bit Beacon interval */
286 static int ff_assoc_id = -1; /* 16 bit AID field */
287 static int ff_reason = -1; /* 16 bit reason code */
288 static int ff_status_code = -1; /* Status code */
290 /* ************************************************************************* */
291 /* Flags found in the capability field (fixed field) */
292 /* ************************************************************************* */
293 static int ff_capture = -1;
294 static int ff_cf_sta_poll = -1; /* CF pollable status for a STA */
295 static int ff_cf_ap_poll = -1; /* CF pollable status for an AP */
296 static int ff_cf_ess = -1;
297 static int ff_cf_ibss = -1;
298 static int ff_cf_privacy = -1;
299 static int ff_cf_preamble = -1;
300 static int ff_cf_pbcc = -1;
301 static int ff_cf_agility = -1;
303 /* ************************************************************************* */
304 /* Tagged value format fields */
305 /* ************************************************************************* */
306 static int tag_number = -1;
307 static int tag_length = -1;
308 static int tag_interpretation = -1;
312 static int hf_fixed_parameters = -1; /* Protocol payload for management frames */
313 static int hf_tagged_parameters = -1; /* Fixed payload item */
314 static int hf_wep_parameters = -1;
315 static int hf_wep_iv = -1;
316 static int hf_wep_key = -1;
317 static int hf_wep_crc = -1;
319 /* ************************************************************************* */
321 /* ************************************************************************* */
322 static gint ett_80211 = -1;
323 static gint ett_proto_flags = -1;
324 static gint ett_cap_tree = -1;
325 static gint ett_fc_tree = -1;
326 static gint ett_fixed_parameters = -1;
327 static gint ett_tagged_parameters = -1;
328 static gint ett_wep_parameters = -1;
330 static dissector_handle_t llc_handle;
332 /* ************************************************************************* */
333 /* Return the length of the current header (in bytes) */
334 /* ************************************************************************* */
336 find_header_length (guint16 fcf)
338 return (COOK_ADDR_SELECTOR(fcf) == DATA_ADDR_T4) ? 30 : 24;
342 /* ************************************************************************* */
343 /* This is the capture function used to update packet counts */
344 /* ************************************************************************* */
346 capture_ieee80211 (const u_char * pd, int offset, packet_counts * ld)
348 guint16 fcf, hdr_length;
350 fcf = pletohs (&pd[0]);
352 if (IS_WEP(COOK_FLAGS(fcf)))
358 switch (COMPOSE_FRAME_TYPE (fcf))
361 case DATA: /* We got a data frame */
362 case DATA_CF_ACK: /* Data with ACK */
364 case DATA_CF_ACK_POLL:
365 hdr_length = find_header_length (fcf);
366 capture_llc (pd, offset + hdr_length, ld);
377 /* ************************************************************************* */
378 /* Add the subtree used to store the fixed parameters */
379 /* ************************************************************************* */
381 get_fixed_parameter_tree (proto_tree * tree, tvbuff_t *tvb, int start, int size)
383 proto_item *fixed_fields;
385 proto_tree_add_uint_format (tree, hf_fixed_parameters, tvb, start,
386 size, size, "Fixed parameters (%d bytes)",
389 return proto_item_add_subtree (fixed_fields, ett_fixed_parameters);
393 /* ************************************************************************* */
394 /* Add the subtree used to store tagged parameters */
395 /* ************************************************************************* */
397 get_tagged_parameter_tree (proto_tree * tree, tvbuff_t *tvb, int start, int size)
399 proto_item *tagged_fields;
401 tagged_fields = proto_tree_add_uint_format (tree, hf_tagged_parameters,
406 "Tagged parameters (%d bytes)",
409 return proto_item_add_subtree (tagged_fields, ett_tagged_parameters);
413 /* ************************************************************************* */
414 /* Add the subtree used to store WEP parameters */
415 /* ************************************************************************* */
417 get_wep_parameter_tree (proto_tree * tree, tvbuff_t *tvb, int start, int size)
419 proto_item *wep_fields;
420 proto_tree *wep_tree;
421 int crc_offset = size - 4;
423 wep_fields = proto_tree_add_string_format(tree, hf_wep_parameters, tvb,
424 0, 4, 0, "WEP parameters");
426 wep_tree = proto_item_add_subtree (wep_fields, ett_wep_parameters);
427 proto_tree_add_uint (wep_tree, hf_wep_iv, tvb, start, 3,
428 COOK_WEP_IV (tvb_get_letohl (tvb, start)));
430 proto_tree_add_uint (wep_tree, hf_wep_key, tvb, start + 3, 1,
431 COOK_WEP_KEY (tvb_get_letohl (tvb, start)));
433 if (tvb_bytes_exist(tvb, start + crc_offset, 4))
434 proto_tree_add_uint (wep_tree, hf_wep_crc, tvb, start + crc_offset, 4,
435 tvb_get_ntohl (tvb, start + crc_offset));
438 /* ************************************************************************* */
439 /* Dissect and add fixed mgmt fields to protocol tree */
440 /* ************************************************************************* */
442 add_fixed_field (proto_tree * tree, tvbuff_t * tvb, int offset, int lfcode)
444 const guint8 *dataptr;
445 char out_buff[SHORT_STR];
447 proto_item *cap_item;
448 static proto_tree *cap_tree;
453 case FIELD_TIMESTAMP:
454 dataptr = tvb_get_ptr (tvb, offset, 8);
455 memset (out_buff, 0, SHORT_STR);
456 snprintf (out_buff, SHORT_STR, "0x%02X%02X%02X%02X%02X%02X%02X%02X",
466 proto_tree_add_string (tree, ff_timestamp, tvb, offset, 8, out_buff);
470 case FIELD_BEACON_INTERVAL:
471 dataptr = tvb_get_ptr (tvb, offset, 2);
472 temp_double = ((double) *((guint16 *) dataptr));
473 temp_double = temp_double * 1024 / 1000000;
474 proto_tree_add_double_format (tree, ff_beacon_interval, tvb, offset, 2,
475 temp_double,"Beacon Interval: %f [Seconds]",
481 dataptr = tvb_get_ptr (tvb, offset, 2);
482 temp16 = (guint16 *) dataptr;
484 cap_item = proto_tree_add_uint_format (tree, ff_capture,
487 "Capability Information: 0x%04X",
489 cap_tree = proto_item_add_subtree (cap_item, ett_cap_tree);
490 proto_tree_add_boolean (cap_tree, ff_cf_ess, tvb, offset, 1,
492 proto_tree_add_boolean (cap_tree, ff_cf_ibss, tvb, offset, 1,
494 proto_tree_add_boolean (cap_tree, ff_cf_privacy, tvb, offset, 1,
496 proto_tree_add_boolean (cap_tree, ff_cf_preamble, tvb, offset, 1,
498 proto_tree_add_boolean (cap_tree, ff_cf_pbcc, tvb, offset, 1,
500 proto_tree_add_boolean (cap_tree, ff_cf_agility, tvb, offset, 1,
502 if (ESS_SET (pletohs (temp16)) != 0) /* This is an AP */
503 proto_tree_add_uint (cap_tree, ff_cf_ap_poll, tvb, offset, 2,
504 ((pletohs (temp16) & 0xC) >> 2));
506 else /* This is a STA */
507 proto_tree_add_uint (cap_tree, ff_cf_sta_poll, tvb, offset, 2,
508 ((pletohs (temp16) & 0xC) >> 2));
513 dataptr = tvb_get_ptr (tvb, offset, 2);
514 temp16 =(guint16 *) dataptr;
515 proto_tree_add_uint (tree, ff_auth_alg, tvb, offset, 2,
520 case FIELD_AUTH_TRANS_SEQ:
521 dataptr = tvb_get_ptr (tvb, offset, 2);
522 temp16 = (guint16 *)dataptr;
523 proto_tree_add_uint (tree, ff_auth_seq, tvb, offset, 2,
528 case FIELD_CURRENT_AP_ADDR:
529 dataptr = tvb_get_ptr (tvb, offset, 6);
530 proto_tree_add_ether (tree, ff_current_ap, tvb, offset, 6, dataptr);
534 case FIELD_LISTEN_IVAL:
535 dataptr = tvb_get_ptr (tvb, offset, 2);
536 temp16 = (guint16 *) dataptr;
537 proto_tree_add_uint (tree, ff_listen_ival, tvb, offset, 2,
542 case FIELD_REASON_CODE:
543 dataptr = tvb_get_ptr (tvb, offset, 2);
544 temp16 = (guint16 *) dataptr;
545 proto_tree_add_uint (tree, ff_reason, tvb, offset, 2, pletohs (temp16));
550 dataptr = tvb_get_ptr (tvb, offset, 2);
551 temp16 = (guint16 *) dataptr;
552 proto_tree_add_uint (tree, ff_assoc_id, tvb, offset, 2, pletohs (temp16));
555 case FIELD_STATUS_CODE:
556 dataptr = tvb_get_ptr (tvb, offset, 2);
557 temp16 = (guint16 *) dataptr;
558 proto_tree_add_uint (tree, ff_status_code, tvb, offset, 2,
565 /* ************************************************************************* */
566 /* Dissect and add tagged (optional) fields to proto tree */
567 /* ************************************************************************* */
569 add_tagged_field (proto_tree * tree, tvbuff_t * tvb, int offset)
571 const guint8 *tag_info_ptr;
572 const guint8 *tag_data_ptr;
573 guint32 tag_no, tag_len;
576 char out_buff[SHORT_STR];
579 tag_info_ptr = tvb_get_ptr (tvb, offset, 2);
580 tag_no = tag_info_ptr[0];
581 tag_len = tag_info_ptr[1];
583 tag_data_ptr = tvb_get_ptr (tvb, offset + 2, tag_len);
586 if ((tag_no >= 17) && (tag_no <= 31))
587 { /* Reserved for challenge text */
588 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
589 "Tag Number: %u (Reserved for challenge text)",
592 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
593 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
594 tag_len, "Not interpreted");
595 return (int) tag_len + 2;
598 /* Next See if tag is reserved - if true, skip it! */
599 if (((tag_no >= 7) && (tag_no <= 15))
600 || ((tag_no >= 32) && (tag_no <= 255)))
602 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
603 "Tag Number: %u (Reserved tag number)",
606 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
608 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
609 tag_len, "Not interpreted");
610 return (int) tag_len + 2;
614 switch (tag_info_ptr[0])
619 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
620 "Tag Number: %u (SSID parameter set)",
623 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
625 memset (out_buff, 0, SHORT_STR);
627 memcpy (out_buff, tag_data_ptr, (size_t) tag_len);
628 out_buff[tag_len + 1] = 0;
630 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
637 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
638 "Tag Number: %u (Supported Rates)", tag_no);
640 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
642 memset (out_buff, 0, SHORT_STR);
643 strcpy (out_buff, "Supported rates: ");
644 n = strlen (out_buff);
646 for (i = 0; i < tag_len; i++)
648 n += snprintf (out_buff + n, SHORT_STR - n, "%2.1f%s ",
649 (tag_data_ptr[i] & 0x7F) * 0.5,
650 (tag_data_ptr[i] & 0x80) ? "(B)" : "");
652 snprintf (out_buff + n, SHORT_STR - n, "[Mbit/sec]");
654 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
660 case TAG_FH_PARAMETER:
661 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
662 "Tag Number: %u (FH Parameter set)",
665 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
666 memset (out_buff, 0, SHORT_STR);
668 snprintf (out_buff, SHORT_STR,
669 "Dwell time 0x%04X, Hop Set %2d, Hop Pattern %2d, "
670 "Hop Index %2d", pletohs (tag_data_ptr), tag_data_ptr[2],
671 tag_data_ptr[3], tag_data_ptr[4]);
673 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
679 case TAG_DS_PARAMETER:
680 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
681 "Tag Number: %u (DS Parameter set)",
684 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
685 memset (out_buff, 0, SHORT_STR);
687 snprintf (out_buff, SHORT_STR, "Current Channel: %u", tag_data_ptr[0]);
688 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
693 case TAG_CF_PARAMETER:
694 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
695 "Tag Number: %u (CF Parameter set)",
698 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
699 memset (out_buff, 0, SHORT_STR);
701 snprintf (out_buff, SHORT_STR,
702 "CFP count %u, CFP period %u, CFP max duration %u, "
703 "CFP Remaining %u", tag_data_ptr[0], tag_data_ptr[1],
704 pletohs (tag_data_ptr + 2), pletohs (tag_data_ptr + 4));
706 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
712 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
713 "Tag Number: %u ((TIM) Traffic Indication Map)",
716 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
717 memset (out_buff, 0, SHORT_STR);
718 snprintf (out_buff, SHORT_STR,
719 "DTIM count %u, DTIM period %u, Bitmap control 0x%X, "
720 "(Bitmap suppressed)", tag_data_ptr[0], tag_data_ptr[1],
722 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
728 case TAG_IBSS_PARAMETER:
729 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
730 "Tag Number: %u (IBSS Parameter set)",
733 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
734 memset (out_buff, 0, SHORT_STR);
735 snprintf (out_buff, SHORT_STR, "ATIM window 0x%X",
736 pletohs (tag_data_ptr));
738 proto_tree_add_string (tree, tag_interpretation, tvb, offset + 2,
744 case TAG_CHALLENGE_TEXT:
745 proto_tree_add_uint_format (tree, tag_number, tvb, offset, 1, tag_no,
746 "Tag Number: %u (Challenge text)", tag_no);
748 proto_tree_add_uint (tree, tag_length, tvb, offset + 1, 1, tag_len);
749 memset (out_buff, 0, SHORT_STR);
750 snprintf (out_buff, SHORT_STR, "Challenge text: %.47s", tag_data_ptr);
751 proto_tree_add_string (tree, tag_interpretation, tvb, offset, tag_len,
764 set_src_addr_cols(packet_info *pinfo, const guint8 *addr, char *type)
766 if (check_col(pinfo->fd, COL_RES_DL_SRC))
767 col_add_fstr(pinfo->fd, COL_RES_DL_SRC, "%s (%s)",
768 get_ether_name(addr), type);
769 if (check_col(pinfo->fd, COL_UNRES_DL_SRC))
770 col_add_fstr(pinfo->fd, COL_UNRES_DL_SRC, "%s (%s)",
771 ether_to_str(addr), type);
775 set_dst_addr_cols(packet_info *pinfo, const guint8 *addr, char *type)
777 if (check_col(pinfo->fd, COL_RES_DL_DST))
778 col_add_fstr(pinfo->fd, COL_RES_DL_DST, "%s (%s)",
779 get_ether_name(addr), type);
780 if (check_col(pinfo->fd, COL_UNRES_DL_DST))
781 col_add_fstr(pinfo->fd, COL_UNRES_DL_DST, "%s (%s)",
782 ether_to_str(addr), type);
785 /* ************************************************************************* */
786 /* Dissect 802.11 frame */
787 /* ************************************************************************* */
789 dissect_ieee80211 (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
791 guint16 fcf, flags, frame_type_subtype;
792 const guint8 *src = NULL, *dst = NULL;
793 proto_item *ti = NULL;
794 proto_item *flag_item;
796 static proto_tree *hdr_tree;
797 static proto_tree *flag_tree;
798 static proto_tree *fixed_tree;
799 static proto_tree *tagged_tree;
800 static proto_tree *fc_tree;
801 guint16 cap_len, hdr_len;
806 int tagged_parameter_tree_len;
808 if (check_col (pinfo->fd, COL_PROTOCOL))
809 col_set_str (pinfo->fd, COL_PROTOCOL, "IEEE 802.11");
810 if (check_col (pinfo->fd, COL_INFO))
811 col_clear (pinfo->fd, COL_INFO);
813 cap_len = tvb_length(tvb);
814 fcf = tvb_get_letohs (tvb, 0);
815 hdr_len = find_header_length (fcf);
816 frame_type_subtype = COMPOSE_FRAME_TYPE(fcf);
818 COL_SHOW_INFO_CONST (pinfo->fd,
819 val_to_str(frame_type_subtype, frame_type_subtype_vals,
820 "Unrecognized (Reserved frame)"));
822 /* Add the FC to the current tree */
825 ti = proto_tree_add_protocol_format (tree, proto_wlan, tvb, 0, hdr_len,
827 hdr_tree = proto_item_add_subtree (ti, ett_80211);
829 proto_tree_add_uint (hdr_tree, hf_fc_frame_type_subtype,
833 fc_item = proto_tree_add_uint_format (hdr_tree, hf_fc_field, tvb, 0, 2,
835 "Frame Control: 0x%04X",
838 fc_tree = proto_item_add_subtree (fc_item, ett_fc_tree);
841 proto_tree_add_uint (fc_tree, hf_fc_proto_version, tvb, 0, 1,
842 COOK_PROT_VERSION (fcf));
844 proto_tree_add_uint (fc_tree, hf_fc_frame_type, tvb, 0, 1,
845 COOK_FRAME_TYPE (fcf));
847 proto_tree_add_uint (fc_tree, hf_fc_frame_subtype,
849 COOK_FRAME_SUBTYPE (fcf));
851 flags = COOK_FLAGS (fcf);
854 proto_tree_add_uint_format (fc_tree, hf_fc_flags, tvb, 1, 1,
855 flags, "Flags: 0x%X", flags);
857 flag_tree = proto_item_add_subtree (flag_item, ett_proto_flags);
859 proto_tree_add_uint (flag_tree, hf_fc_data_ds, tvb, 1, 1,
860 COOK_DS_STATUS (flags));
862 proto_tree_add_boolean (flag_tree, hf_fc_more_frag, tvb, 1, 1,
865 proto_tree_add_boolean (flag_tree, hf_fc_retry, tvb, 1, 1, flags);
867 proto_tree_add_boolean (flag_tree, hf_fc_pwr_mgt, tvb, 1, 1, flags);
869 proto_tree_add_boolean (flag_tree, hf_fc_more_data, tvb, 1, 1,
872 proto_tree_add_boolean (flag_tree, hf_fc_wep, tvb, 1, 1, flags);
874 proto_tree_add_boolean (flag_tree, hf_fc_order, tvb, 1, 1, flags);
876 if (frame_type_subtype == CTRL_PS_POLL)
877 proto_tree_add_uint(hdr_tree, hf_assoc_id,tvb,2,2,
878 COOK_ASSOC_ID(tvb_get_letohs(tvb,2)));
881 proto_tree_add_uint (hdr_tree, hf_did_duration, tvb, 2, 2,
882 tvb_get_letohs (tvb, 2));
885 /* Perform tasks which are common to a certain frame type */
886 switch (COOK_FRAME_TYPE (fcf))
889 case MGT_FRAME: /* All management frames share a common header */
891 * Set the top-level item to cover the entire frame.
894 proto_item_set_len(ti, tvb_length(tvb));
895 src = tvb_get_ptr (tvb, 10, 6);
896 dst = tvb_get_ptr (tvb, 4, 6);
898 SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src);
899 SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src);
900 SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dst);
901 SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dst);
905 proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6,
906 tvb_get_ptr (tvb, 4, 6));
908 proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6,
909 tvb_get_ptr (tvb, 10, 6));
911 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 16, 6,
912 tvb_get_ptr (tvb, 16, 6));
914 proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
915 COOK_FRAGMENT_NUMBER (tvb_get_letohs
918 proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
919 COOK_SEQUENCE_NUMBER (tvb_get_letohs
921 cap_len = cap_len - MGT_FRAME_LEN - 4;
933 addr_type = COOK_ADDR_SELECTOR (fcf);
935 /* In order to show src/dst address we must always do the following */
940 src = tvb_get_ptr (tvb, 10, 6);
941 dst = tvb_get_ptr (tvb, 4, 6);
946 src = tvb_get_ptr (tvb, 16, 6);
947 dst = tvb_get_ptr (tvb, 4, 6);
952 src = tvb_get_ptr (tvb, 10, 6);
953 dst = tvb_get_ptr (tvb, 16, 6);
958 src = tvb_get_ptr (tvb, 24, 6);
959 dst = tvb_get_ptr (tvb, 16, 6);
963 SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src);
964 SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src);
965 SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dst);
966 SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dst);
968 /* Now if we have a tree we start adding stuff */
977 proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6,
978 tvb_get_ptr (tvb, 4, 6));
979 proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6,
980 tvb_get_ptr (tvb, 10, 6));
981 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 16, 6,
982 tvb_get_ptr (tvb, 16, 6));
983 proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
984 COOK_FRAGMENT_NUMBER (tvb_get_letohs
986 proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
987 COOK_SEQUENCE_NUMBER (tvb_get_letohs
993 proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 4, 6,
994 tvb_get_ptr (tvb, 4, 6));
995 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 10, 6,
996 tvb_get_ptr (tvb, 10, 6));
997 proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 16, 6,
998 tvb_get_ptr (tvb, 16, 6));
999 proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
1000 COOK_FRAGMENT_NUMBER (tvb_get_letohs
1002 proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
1003 COOK_SEQUENCE_NUMBER (tvb_get_letohs
1009 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 4, 6,
1010 tvb_get_ptr (tvb, 4, 6));
1011 proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 10, 6,
1012 tvb_get_ptr (tvb, 10, 6));
1013 proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 16, 6,
1014 tvb_get_ptr (tvb, 16, 6));
1015 proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
1016 COOK_FRAGMENT_NUMBER (tvb_get_letohs
1018 proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
1019 COOK_SEQUENCE_NUMBER (tvb_get_letohs
1025 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1026 tvb_get_ptr (tvb, 4, 6));
1027 proto_tree_add_ether (hdr_tree, hf_addr_ta, tvb, 10, 6,
1028 tvb_get_ptr (tvb, 10, 6));
1029 proto_tree_add_ether (hdr_tree, hf_addr_da, tvb, 16, 6,
1030 tvb_get_ptr (tvb, 16, 6));
1031 proto_tree_add_uint (hdr_tree, hf_frag_number, tvb, 22, 2,
1032 COOK_FRAGMENT_NUMBER (tvb_get_letohs
1034 proto_tree_add_uint (hdr_tree, hf_seq_number, tvb, 22, 2,
1035 COOK_SEQUENCE_NUMBER (tvb_get_letohs
1037 proto_tree_add_ether (hdr_tree, hf_addr_sa, tvb, 24, 6,
1038 tvb_get_ptr (tvb, 24, 6));
1046 switch (frame_type_subtype)
1052 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 4);
1053 add_fixed_field (fixed_tree, tvb, MGT_FRAME_HDR_LEN,
1055 add_fixed_field (fixed_tree, tvb, MGT_FRAME_HDR_LEN + 2,
1058 next_idx = MGT_FRAME_HDR_LEN + 4; /* Size of fixed fields */
1059 tagged_parameter_tree_len =
1060 tvb_reported_length_remaining(tvb, next_idx + 4);
1061 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1062 tagged_parameter_tree_len);
1064 while (tagged_parameter_tree_len > 0) {
1065 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1067 next_idx +=next_len;
1068 tagged_parameter_tree_len -= next_len;
1075 case MGT_ASSOC_RESP:
1078 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 6);
1079 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_CAP_INFO);
1080 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 2,
1082 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 4,
1085 next_idx = MGT_FRAME_LEN + 6; /* Size of fixed fields */
1087 tagged_parameter_tree_len =
1088 tvb_reported_length_remaining(tvb, next_idx + 4);
1089 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1090 tagged_parameter_tree_len);
1092 while (tagged_parameter_tree_len > 0) {
1093 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1095 next_idx +=next_len;
1096 tagged_parameter_tree_len -= next_len;
1102 case MGT_REASSOC_REQ:
1105 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 10);
1106 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_CAP_INFO);
1107 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 2,
1109 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 4,
1110 FIELD_CURRENT_AP_ADDR);
1112 next_idx = MGT_FRAME_LEN + 10; /* Size of fixed fields */
1113 tagged_parameter_tree_len =
1114 tvb_reported_length_remaining(tvb, next_idx + 4);
1115 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1116 tagged_parameter_tree_len);
1118 while (tagged_parameter_tree_len > 0) {
1119 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1121 next_idx +=next_len;
1122 tagged_parameter_tree_len -= next_len;
1127 case MGT_REASSOC_RESP:
1130 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 10);
1131 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_CAP_INFO);
1132 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 2,
1134 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 4,
1137 next_idx = MGT_FRAME_LEN + 6; /* Size of fixed fields */
1138 tagged_parameter_tree_len =
1139 tvb_reported_length_remaining(tvb, next_idx + 4);
1140 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1141 tagged_parameter_tree_len);
1143 while (tagged_parameter_tree_len > 0) {
1144 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1146 next_idx +=next_len;
1147 tagged_parameter_tree_len -= next_len;
1156 next_idx = MGT_FRAME_LEN;
1157 tagged_parameter_tree_len =
1158 tvb_reported_length_remaining(tvb, next_idx + 4);
1159 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1160 tagged_parameter_tree_len);
1162 while (tagged_parameter_tree_len > 0) {
1163 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1165 next_idx +=next_len;
1166 tagged_parameter_tree_len -= next_len;
1172 case MGT_PROBE_RESP:
1175 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 12);
1176 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_TIMESTAMP);
1177 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 8,
1178 FIELD_BEACON_INTERVAL);
1179 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 10,
1182 next_idx = MGT_FRAME_LEN + 12; /* Size of fixed fields */
1183 tagged_parameter_tree_len =
1184 tvb_reported_length_remaining(tvb, next_idx + 4);
1185 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1186 tagged_parameter_tree_len);
1188 while (tagged_parameter_tree_len > 0) {
1189 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1191 next_idx +=next_len;
1192 tagged_parameter_tree_len -= next_len;
1198 case MGT_BEACON: /* Dissect protocol payload fields */
1201 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 12);
1203 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_TIMESTAMP);
1205 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 8,
1206 FIELD_BEACON_INTERVAL);
1207 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 10,
1210 next_idx = MGT_FRAME_LEN + 12; /* Size of fixed fields */
1211 tagged_parameter_tree_len =
1212 tvb_reported_length_remaining(tvb, next_idx + 4);
1213 tagged_tree = get_tagged_parameter_tree (hdr_tree, tvb, next_idx,
1214 tagged_parameter_tree_len);
1216 while (tagged_parameter_tree_len > 0) {
1217 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1219 next_idx +=next_len;
1220 tagged_parameter_tree_len -= next_len;
1235 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, cap_len);
1236 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_REASON_CODE);
1240 case MGT_AUTHENTICATION:
1241 if (IS_WEP(COOK_FLAGS(fcf)))
1243 int pkt_len = tvb_reported_length (tvb);
1244 int cap_len = tvb_length (tvb);
1247 get_wep_parameter_tree (tree, tvb, MGT_FRAME_LEN, pkt_len);
1248 pkt_len = MAX (pkt_len - 8 - MGT_FRAME_LEN, 0);
1249 cap_len = MIN (pkt_len, MAX (cap_len - 8 - MGT_FRAME_LEN, 0));
1250 next_tvb = tvb_new_subset (tvb, MGT_FRAME_LEN + 4, cap_len, pkt_len);
1251 dissect_data (next_tvb, 0, pinfo, tree);
1257 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 6);
1258 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_AUTH_ALG);
1259 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 2,
1260 FIELD_AUTH_TRANS_SEQ);
1261 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN + 4,
1264 next_idx = MGT_FRAME_LEN + 6; /* Size of fixed fields */
1266 tagged_parameter_tree_len =
1267 tvb_reported_length_remaining(tvb, next_idx + 4);
1268 if (tagged_parameter_tree_len != 0)
1270 tagged_tree = get_tagged_parameter_tree (hdr_tree,
1273 tagged_parameter_tree_len);
1275 while (tagged_parameter_tree_len > 0) {
1276 if ((next_len=add_tagged_field (tagged_tree, tvb, next_idx))==0)
1278 next_idx +=next_len;
1279 tagged_parameter_tree_len -= next_len;
1287 case MGT_DEAUTHENTICATION:
1290 fixed_tree = get_fixed_parameter_tree (hdr_tree, tvb, MGT_FRAME_LEN, 2);
1291 add_fixed_field (fixed_tree, tvb, MGT_FRAME_LEN, FIELD_REASON_CODE);
1297 src = tvb_get_ptr (tvb, 10, 6);
1298 dst = tvb_get_ptr (tvb, 4, 6);
1300 set_src_addr_cols(pinfo, src, "BSSID");
1301 set_dst_addr_cols(pinfo, dst, "BSSID");
1305 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 4, 6,
1306 tvb_get_ptr (tvb, 4, 6));
1308 proto_tree_add_ether (hdr_tree, hf_addr_ta, tvb, 10, 6,
1309 tvb_get_ptr (tvb, 10, 6));
1316 src = tvb_get_ptr (tvb, 10, 6);
1317 dst = tvb_get_ptr (tvb, 4, 6);
1319 set_src_addr_cols(pinfo, src, "TA");
1320 set_dst_addr_cols(pinfo, dst, "RA");
1324 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1325 tvb_get_ptr (tvb, 4, 6));
1327 proto_tree_add_ether (hdr_tree, hf_addr_ta, tvb, 10, 6,
1328 tvb_get_ptr (tvb, 10, 6));
1335 dst = tvb_get_ptr (tvb, 4, 6);
1337 set_dst_addr_cols(pinfo, dst, "RA");
1341 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1342 tvb_get_ptr (tvb, 4, 6));
1348 case CTRL_ACKNOWLEDGEMENT:
1349 dst = tvb_get_ptr (tvb, 4, 6);
1351 set_dst_addr_cols(pinfo, dst, "RA");
1354 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1355 tvb_get_ptr (tvb, 4, 6));
1360 src = tvb_get_ptr (tvb, 10, 6);
1361 dst = tvb_get_ptr (tvb, 4, 6);
1363 set_src_addr_cols(pinfo, src, "BSSID");
1364 set_dst_addr_cols(pinfo, dst, "RA");
1368 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1369 tvb_get_ptr (tvb, 4, 6));
1370 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 10, 6,
1371 tvb_get_ptr (tvb, 10, 6));
1376 case CTRL_CFP_ENDACK:
1377 src = tvb_get_ptr (tvb, 10, 6);
1378 dst = tvb_get_ptr (tvb, 4, 6);
1380 set_src_addr_cols(pinfo, src, "BSSID");
1381 set_dst_addr_cols(pinfo, dst, "RA");
1385 proto_tree_add_ether (hdr_tree, hf_addr_ra, tvb, 4, 6,
1386 tvb_get_ptr (tvb, 4, 6));
1388 proto_tree_add_ether (hdr_tree, hf_addr_bssid, tvb, 10, 6,
1389 tvb_get_ptr (tvb, 10, 6));
1397 case DATA_CF_ACK_POLL:
1398 next_tvb = tvb_new_subset (tvb, hdr_len, -1, -1);
1400 if (IS_WEP(COOK_FLAGS(fcf)))
1402 int pkt_len = tvb_reported_length (next_tvb);
1403 int cap_len = tvb_length (next_tvb);
1406 get_wep_parameter_tree (tree, next_tvb, 0, pkt_len);
1407 pkt_len = MAX (pkt_len - 8, 0);
1408 cap_len = MIN (pkt_len, MAX (cap_len - 8, 0));
1409 next_tvb = tvb_new_subset (tvb, hdr_len + 4, cap_len, pkt_len);
1410 dissect_data (next_tvb, 0, pinfo, tree);
1413 call_dissector (llc_handle, next_tvb, pinfo, tree);
1420 proto_register_wlan (void)
1423 static const value_string frame_type[] = {
1424 {MGT_FRAME, "Management frame"},
1425 {CONTROL_FRAME, "Control frame"},
1426 {DATA_FRAME, "Data frame"},
1430 static const value_string tofrom_ds[] = {
1431 {0, "Not leaving DS or network is operating in AD-HOC mode (To DS: 0 From DS: 0)"},
1432 {1, "Frame is exiting DS (To DS: 0 From DS: 1)"},
1433 {2, "Frame is entering DS (To DS: 1 From DS: 0)"},
1434 {3, "Frame part of WDS (To DS: 1 From DS: 1)"},
1438 static const true_false_string tods_flag = {
1439 "TO DS: Should be false",
1443 static const true_false_string fromds_flag = {
1444 "FROM DS: Should be false",
1448 static const true_false_string more_frags = {
1449 "MSDU/MMPDU is fragmented",
1453 static const true_false_string retry_flags = {
1454 "Frame is being retransmitted",
1455 "Frame is not being retransmitted"
1458 static const true_false_string pm_flags = {
1459 "STA will go to sleep",
1463 static const true_false_string md_flags = {
1464 "Data is buffered for STA at AP",
1468 static const true_false_string wep_flags = {
1473 static const true_false_string order_flags = {
1475 "Not strictly ordered"
1478 static const true_false_string cf_ess_flags = {
1479 "Transmitter is an AP",
1480 "Transmitter is a STA"
1484 static const true_false_string cf_privacy_flags = {
1485 "AP/STA can support WEP",
1486 "AP/STA cannot support WEP"
1489 static const true_false_string cf_preamble_flags = {
1490 "Short preamble allowed",
1491 "Short preamble not allowed"
1494 static const true_false_string cf_pbcc_flags = {
1495 "PBCC modulation allowed",
1496 "PBCC modulation not allowed"
1499 static const true_false_string cf_agility_flags = {
1500 "Channel agility in use",
1501 "Channel agility not in use"
1505 static const true_false_string cf_ibss_flags = {
1506 "Transmitter belongs to an IBSS",
1507 "Transmitter belongs to a BSS"
1510 static const value_string sta_cf_pollable[] = {
1511 {0x00, "Station is not CF-Pollable"},
1512 {0x02, "Station is CF-Pollable, "
1513 "not requesting to be placed on the CF-polling list"},
1514 {0x01, "Station is CF-Pollable, "
1515 "requesting to be placed on the CF-polling list"},
1516 {0x03, "Station is CF-Pollable, requesting never to be polled"},
1520 static const value_string ap_cf_pollable[] = {
1521 {0x00, "No point coordinator at AP"},
1522 {0x02, "Point coordinator at AP for delivery only (no polling)"},
1523 {0x01, "Point coordinator at AP for delivery and polling"},
1529 static const value_string auth_alg[] = {
1530 {0x00, "Open System"},
1531 {0x01, "Shared key"},
1535 static const value_string reason_codes[] = {
1537 {0x01, "Unspecified reason"},
1538 {0x02, "Previous authentication no longer valid"},
1539 {0x03, "Deauthenticated because sending STA is leaving (has left) "
1541 {0x04, "Disassociated due to inactivity"},
1542 {0x05, "Disassociated because AP is unable to handle all currently "
1543 "associated stations"},
1544 {0x06, "Class 2 frame received from nonauthenticated station"},
1545 {0x07, "Class 3 frame received from nonassociated station"},
1546 {0x08, "Disassociated because sending STA is leaving (has left) BSS"},
1547 {0x09, "Station requesting (re)association is not authenticated with "
1548 "responding station"},
1553 static const value_string status_codes[] = {
1554 {0x00, "Successful"},
1555 {0x01, "Unspecified failure"},
1556 {0x0A, "Cannot support all requested capabilities in the "
1557 "Capability information field"},
1558 {0x0B, "Reassociation denied due to inability to confirm that "
1559 "association exists"},
1560 {0x0C, "Association denied due to reason outside the scope of this "
1563 {0x0D, "Responding station does not support the specified authentication "
1565 {0x0E, "Received an Authentication frame with authentication sequence "
1566 "transaction sequence number out of expected sequence"},
1567 {0x0F, "Authentication rejected because of challenge failure"},
1568 {0x10, "Authentication rejected due to timeout waiting for next "
1569 "frame in sequence"},
1570 {0x11, "Association denied because AP is unable to handle additional "
1571 "associated stations"},
1572 {0x12, "Association denied due to requesting station not supporting all "
1573 "of the datarates in the BSSBasicServiceSet Parameter"},
1579 static hf_register_info hf[] = {
1581 {"Frame Control Field", "wlan.fc", FT_UINT16, BASE_HEX, NULL, 0,
1582 "MAC Frame control", HFILL }},
1584 {&hf_fc_proto_version,
1585 {"Version", "wlan.fc.version", FT_UINT8, BASE_DEC, NULL, 0,
1586 "MAC Protocol version", HFILL }}, /* 0 */
1589 {"Type", "wlan.fc.type", FT_UINT8, BASE_DEC, VALS(frame_type), 0,
1590 "Frame type", HFILL }},
1592 {&hf_fc_frame_subtype,
1593 {"Subtype", "wlan.fc.subtype", FT_UINT8, BASE_DEC, NULL, 0,
1594 "Frame subtype", HFILL }}, /* 2 */
1596 {&hf_fc_frame_type_subtype,
1597 {"Type/Subtype", "wlan.fc.type_subtype", FT_UINT16, BASE_DEC, VALS(frame_type_subtype_vals), 0,
1598 "Type and subtype combined", HFILL }},
1601 {"Protocol Flags", "wlan.flags", FT_UINT8, BASE_HEX, NULL, 0,
1602 "Protocol flags", HFILL }},
1605 {"DS status", "wlan.fc.ds", FT_UINT8, BASE_HEX, VALS (&tofrom_ds), 0,
1606 "Data-frame DS-traversal status", HFILL }}, /* 3 */
1609 {"To DS", "wlan.fc.tods", FT_BOOLEAN, 8, TFS (&tods_flag), 0x1,
1610 "To DS flag", HFILL }}, /* 4 */
1613 {"From DS", "wlan.fc.fromds", FT_BOOLEAN, 8, TFS (&fromds_flag), 0x2,
1614 "From DS flag", HFILL }}, /* 5 */
1617 {"Fragments", "wlan.fc.frag", FT_BOOLEAN, 8, TFS (&more_frags), 0x4,
1618 "More Fragments flag", HFILL }}, /* 6 */
1621 {"Retry", "wlan.fc.retry", FT_BOOLEAN, 8, TFS (&retry_flags), 0x8,
1622 "Retransmission flag", HFILL }},
1625 {"PWR MGT", "wlan.fc.pwrmgt", FT_BOOLEAN, 8, TFS (&pm_flags), 0x10,
1626 "Power management status", HFILL }},
1629 {"More Data", "wlan.fc.moredata", FT_BOOLEAN, 8, TFS (&md_flags), 0x20,
1630 "More data flag", HFILL }},
1633 {"WEP flag", "wlan.fc.wep", FT_BOOLEAN, 8, TFS (&wep_flags), 0x40,
1634 "WEP flag", HFILL }},
1637 {"Order flag", "wlan.fc.order", FT_BOOLEAN, 8, TFS (&order_flags), 0x80,
1638 "Strictly ordered flag", HFILL }},
1641 {"Association ID","wlan.aid",FT_UINT16, BASE_DEC,NULL,0,
1642 "Association-ID field", HFILL }},
1645 {"Duration", "wlan.duration", FT_UINT16, BASE_DEC, NULL, 0,
1646 "Duration field", HFILL }},
1649 {"Destination address", "wlan.da", FT_ETHER, BASE_NONE, NULL, 0,
1650 "Destination Hardware address", HFILL }},
1653 {"Source address", "wlan.sa", FT_ETHER, BASE_NONE, NULL, 0,
1654 "Source Hardware address", HFILL }},
1657 {"Receiver address", "wlan.ra", FT_ETHER, BASE_NONE, NULL, 0,
1658 "Receiving Station Hardware Address", HFILL }},
1661 {"Transmitter address", "wlan.ta", FT_ETHER, BASE_NONE, NULL, 0,
1662 "Transmitting Station Hardware Address", HFILL }},
1665 {"BSS Id", "wlan.bssid", FT_ETHER, BASE_NONE, NULL, 0,
1666 "Basic Service Set ID", HFILL }},
1669 {"Fragment number", "wlan.frag", FT_UINT16, BASE_HEX, NULL, 0,
1670 "Fragment number", HFILL }},
1673 {"Sequence number", "wlan.seq", FT_UINT16, BASE_HEX, NULL, 0,
1674 "Fragment number", HFILL }},
1677 {"Frame Check Sequence (not verified)", "wlan.fcs", FT_UINT32, BASE_HEX,
1678 NULL, 0, "", HFILL }},
1681 {"Timestamp", "wlan.fixed.timestamp", FT_STRING, BASE_NONE,
1682 NULL, 0, "", HFILL }},
1685 {"Authentication Algorithm", "wlan.fixed.auth.alg",
1686 FT_UINT16, BASE_DEC, VALS (&auth_alg), 0, "", HFILL }},
1688 {&ff_beacon_interval,
1689 {"Beacon Interval", "wlan.fixed.beacon", FT_DOUBLE, BASE_DEC, NULL, 0,
1692 {&hf_fixed_parameters,
1693 {"Fixed parameters", "wlan.fixed.all", FT_UINT16, BASE_DEC, NULL, 0,
1696 {&hf_tagged_parameters,
1697 {"Tagged parameters", "wlan.tagged.all", FT_UINT16, BASE_DEC, NULL, 0,
1700 {&hf_wep_parameters,
1701 {"WEP parameters", "wlan.wep.all", FT_STRING, BASE_NONE, NULL, 0,
1705 {"Initialization Vector", "wlan.wep.iv", FT_UINT32, BASE_HEX, NULL, 0,
1706 "Initialization Vector", HFILL }},
1709 {"Key", "wlan.wep.key", FT_UINT32, BASE_DEC, NULL, 0,
1713 {"WEP CRC (not verified)", "wlan.wep.crc", FT_UINT32, BASE_HEX, NULL, 0,
1714 "WEP CRC", HFILL }},
1717 {"Capabilities", "wlan.fixed.capabilities", FT_UINT16, BASE_HEX, NULL, 0,
1718 "Capability information", HFILL }},
1721 {"CFP participation capabilities", "wlan.fixed.capabilities.cfpoll.sta",
1722 FT_UINT16, BASE_HEX, VALS (&sta_cf_pollable), 0,
1723 "CF-Poll capabilities for a STA", HFILL }},
1726 {"CFP participation capabilities", "wlan.fixed.capabilities.cfpoll.ap",
1727 FT_UINT16, BASE_HEX, VALS (&ap_cf_pollable), 0,
1728 "CF-Poll capabilities for an AP", HFILL }},
1731 {"ESS capabilities", "wlan.fixed.capabilities.ess",
1732 FT_BOOLEAN, 8, TFS (&cf_ess_flags), 0x0001, "ESS capabilities", HFILL }},
1736 {"IBSS status", "wlan.fixed.capabilities.ibss",
1737 FT_BOOLEAN, 8, TFS (&cf_ibss_flags), 0x0002, "IBSS participation", HFILL }},
1740 {"Privacy", "wlan.fixed.capabilities.privacy",
1741 FT_BOOLEAN, 8, TFS (&cf_privacy_flags), 0x0010, "WEP support", HFILL }},
1744 {"Short Preamble", "wlan.fixed.capabilities.preamble",
1745 FT_BOOLEAN, 8, TFS (&cf_preamble_flags), 0x0020, "Short Preamble", HFILL }},
1748 {"PBCC", "wlan.fixed.capabilities.pbcc",
1749 FT_BOOLEAN, 8, TFS (&cf_pbcc_flags), 0x0040, "PBCC Modulation", HFILL }},
1752 {"Channel Agility", "wlan.fixed.capabilities.agility",
1753 FT_BOOLEAN, 8, TFS (&cf_agility_flags), 0x0080, "Channel Agility", HFILL }},
1757 {"Authentication SEQ", "wlan.fixed.auth_seq",
1758 FT_UINT16, BASE_HEX, NULL, 0, "Authentication sequence number", HFILL }},
1761 {"Association ID", "wlan.fixed.aid",
1762 FT_UINT16, BASE_HEX, NULL, 0, "Association ID", HFILL }},
1765 {"Listen Interval", "wlan.fixed.listen_ival",
1766 FT_UINT16, BASE_HEX, NULL, 0, "Listen Interval", HFILL }},
1769 {"Current AP", "wlan.fixed.current_ap",
1770 FT_ETHER, BASE_NONE, NULL, 0, "MAC address of current AP", HFILL }},
1773 {"Reason code", "wlan.fixed.reason_code",
1774 FT_UINT16, BASE_HEX, VALS (&reason_codes), 0,
1775 "Reason for unsolicited notification", HFILL }},
1778 {"Status code", "wlan.fixed.status_code",
1779 FT_UINT16, BASE_HEX, VALS (&status_codes), 0,
1780 "Status of requested event", HFILL }},
1783 {"Tag", "wlan.tag.number",
1784 FT_UINT16, BASE_DEC, NULL, 0,
1785 "Element ID", HFILL }},
1788 {"Tag length", "wlan.tag.length",
1789 FT_UINT16, BASE_DEC, NULL, 0, "Length of tag", HFILL }},
1791 {&tag_interpretation,
1792 {"Tag interpretation", "wlan.tag.interpretation",
1793 FT_STRING, BASE_NONE, NULL, 0, "Interpretation of tag", HFILL }}
1799 static gint *tree_array[] = { &ett_80211,
1802 &ett_fixed_parameters,
1803 &ett_tagged_parameters,
1804 &ett_wep_parameters,
1808 proto_wlan = proto_register_protocol ("IEEE 802.11 wireless LAN",
1809 "IEEE 802.11", "wlan");
1810 proto_register_field_array (proto_wlan, hf, array_length (hf));
1811 proto_register_subtree_array (tree_array, array_length (tree_array));
1815 proto_reg_handoff_wlan(void)
1818 * Get a handle for the LLC dissector.
1820 llc_handle = find_dissector("llc");
1822 dissector_add("wtap_encap", WTAP_ENCAP_IEEE_802_11, dissect_ieee80211,