smb2-dissector: learn the "REPLAY_OPERATION" flag
[obnox/wireshark/wip.git] / epan / dissectors / packet-ppi.c
1 /*
2  * packet-ppi.c
3  * Routines for PPI Packet Header dissection
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 2007 Gerald Combs
10  *
11  * Copyright (c) 2006 CACE Technologies, Davis (California)
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the project nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  *
42  *
43  * Dustin Johnson - Dustin@Dustinj.us, Dustin.Johnson@cacetech.com
44  *     May 7, 2008 - Added 'Aggregation Extension' and '802.3 Extension'
45  */
46
47
48 #ifdef HAVE_CONFIG_H
49 # include "config.h"
50 #endif
51
52 #include <glib.h>
53
54 #include <epan/packet.h>
55 #include <epan/ptvcursor.h>
56 #include <epan/prefs.h>
57 #include <epan/reassemble.h>
58 #include <epan/frequency-utils.h>
59
60 /* Needed for wtap_pcap_encap_to_wtap_encap(). */
61 #include <wiretap/pcap-encap.h>
62
63 #include "packet-frame.h"
64 #include "packet-eth.h"
65 #include "packet-ieee80211.h"
66
67 /*
68  * Per-Packet Information (PPI) header.
69  * See the PPI Packet Header documentation at http://www.cacetech.com/documents
70  * for details.
71  */
72
73 /*
74  * PPI headers have the following format:
75  *
76  * ,---------------------------------------------------------.
77  * | PPH | PFH 1 | Field data 1 | PFH 2 | Field data 2 | ... |
78  * `---------------------------------------------------------'
79  *
80  * The PPH struct has the following format:
81  *
82  * typedef struct ppi_packetheader {
83  *     guint8  pph_version;     // Version.  Currently 0
84  *     guint8  pph_flags;       // Flags.
85  *     guint16 pph_len; // Length of entire message, including this header and TLV payload.
86  *     guint32 pph_dlt; // libpcap Data Link Type of the captured packet data.
87  * } ppi_packetheader_t;
88  *
89  * The PFH struct has the following format:
90  *
91  * typedef struct ppi_fieldheader {
92  *     guint16 pfh_type;        // Type
93  *     guint16 pfh_datalen;     // Length of data
94  * } ppi_fieldheader_t;
95  *
96  * Anyone looking to add their own PPI dissector would probably do well to imitate the GPS
97  * ones separation into a distinct file.  Here is a step by step guide:
98  * 1) add the number you received to the enum ppi_field_type declaration.
99  * 2) Add a value string for your number into vs_ppi_field_type
100  * 3) declare a dissector handle by the ppi_gps_handle, and initialize it inside proto_reg_handoff
101  * 4) add  case inside dissect_ppi to call your new handle.
102  * 5) Write your parser, and get it loaded.
103  * Following these steps will result in less churn inside the ppi proper parser, and avoid namespace issues.
104  */
105
106
107 #define PPI_PADDED (1 << 0)
108
109 #define PPI_V0_HEADER_LEN 8
110 #define PPI_80211_COMMON_LEN 20
111 #define PPI_80211N_MAC_LEN 12
112 #define PPI_80211N_MAC_PHY_OFF 9
113 #define PPI_80211N_MAC_PHY_LEN 48
114 #define PPI_AGGREGATION_EXTENSION_LEN 4
115 #define PPI_8023_EXTENSION_LEN 8
116
117 #define PPI_FLAG_ALIGN 0x01
118 #define IS_PPI_FLAG_ALIGN(x) ((x) & PPI_FLAG_ALIGN)
119
120 #define DOT11_FLAG_HAVE_FCS 0x0001
121
122 #define DOT11N_FLAG_IS_AGGREGATE 0x0010
123 #define DOT11N_FLAG_MORE_AGGREGATES 0x0020
124 #define DOT11N_FLAG_AGG_CRC_ERROR 0x0040
125
126 #define DOT11N_IS_AGGREGATE(flags)      (flags & DOT11N_FLAG_IS_AGGREGATE)
127 #define DOT11N_MORE_AGGREGATES(flags)   ( \
128     (flags & DOT11N_FLAG_MORE_AGGREGATES) && \
129     !(flags & DOT11N_FLAG_AGG_CRC_ERROR))
130 #define AGGREGATE_MAX 65535
131 #define AMPDU_MAX 16383
132
133 /* XXX - Start - Copied from packet-radiotap.c */
134 /* Channel flags. */
135 #define IEEE80211_CHAN_TURBO    0x0010  /* Turbo channel */
136 #define IEEE80211_CHAN_CCK      0x0020  /* CCK channel */
137 #define IEEE80211_CHAN_OFDM     0x0040  /* OFDM channel */
138 #define IEEE80211_CHAN_2GHZ     0x0080  /* 2 GHz spectrum channel. */
139 #define IEEE80211_CHAN_5GHZ     0x0100  /* 5 GHz spectrum channel */
140 #define IEEE80211_CHAN_PASSIVE  0x0200  /* Only passive scan allowed */
141 #define IEEE80211_CHAN_DYN      0x0400  /* Dynamic CCK-OFDM channel */
142 #define IEEE80211_CHAN_GFSK     0x0800  /* GFSK channel (FHSS PHY) */
143
144 /*
145  * Useful combinations of channel characteristics.
146  */
147 #define IEEE80211_CHAN_FHSS \
148         (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
149 #define IEEE80211_CHAN_A \
150         (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
151 #define IEEE80211_CHAN_B \
152         (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
153 #define IEEE80211_CHAN_PUREG \
154         (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
155 #define IEEE80211_CHAN_G \
156         (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
157 #define IEEE80211_CHAN_T \
158         (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
159 #define IEEE80211_CHAN_108G \
160         (IEEE80211_CHAN_G | IEEE80211_CHAN_TURBO)
161 #define IEEE80211_CHAN_108PUREG \
162         (IEEE80211_CHAN_PUREG | IEEE80211_CHAN_TURBO)
163 /* XXX - End - Copied from packet-radiotap.c */
164
165 typedef enum {
166     /* 0 - 29999: Public types */
167     PPI_80211_COMMON          =  2,
168     PPI_80211N_MAC            =  3,
169     PPI_80211N_MAC_PHY        =  4,
170     PPI_SPECTRUM_MAP          =  5,
171     PPI_PROCESS_INFO          =  6,
172     PPI_CAPTURE_INFO          =  7,
173     PPI_AGGREGATION_EXTENSION =  8,
174     PPI_8023_EXTENSION        =  9,
175     /* 11 - 29999: RESERVED */
176
177     /* 30000 - 65535: Private types */
178     INTEL_CORP_PRIVATE           = 30000,
179     MOHAMED_THAGA_PRIVATE        = 30001,
180     PPI_GPS_INFO                 = 30002, /* 30002 - 30005 described in PPI-GEOLOCATION specifcation */
181     PPI_VECTOR_INFO              = 30003, /* currently available in draft from. jellch@harris.com */
182     PPI_SENSOR_INFO              = 30004, 
183     PPI_ANTENNA_INFO             = 30005,
184     CACE_PRIVATE                 = 0xCACE
185     /* All others RESERVED.  Contact the WinPcap team for an assignment */
186 } ppi_field_type;
187
188 /* Protocol */
189 static int proto_ppi = -1;
190
191 /* Packet header */
192 static int hf_ppi_head_version = -1;
193 static int hf_ppi_head_flags = -1;
194 static int hf_ppi_head_flag_alignment = -1;
195 static int hf_ppi_head_flag_reserved = -1;
196 static int hf_ppi_head_len = -1;
197 static int hf_ppi_head_dlt = -1;
198
199 /* Field header */
200 static int hf_ppi_field_type = -1;
201 static int hf_ppi_field_len = -1;
202
203 /* 802.11 Common */
204 static int hf_80211_common_tsft = -1;
205 static int hf_80211_common_flags = -1;
206 static int hf_80211_common_flags_fcs = -1;
207 static int hf_80211_common_flags_tsft = -1;
208 static int hf_80211_common_flags_fcs_valid = -1;
209 static int hf_80211_common_flags_phy_err = -1;
210 static int hf_80211_common_rate = -1;
211 static int hf_80211_common_chan_freq = -1;
212 static int hf_80211_common_chan_flags = -1;
213
214 static int hf_80211_common_chan_flags_turbo = -1;
215 static int hf_80211_common_chan_flags_cck = -1;
216 static int hf_80211_common_chan_flags_ofdm = -1;
217 static int hf_80211_common_chan_flags_2ghz = -1;
218 static int hf_80211_common_chan_flags_5ghz = -1;
219 static int hf_80211_common_chan_flags_passive = -1;
220 static int hf_80211_common_chan_flags_dynamic = -1;
221 static int hf_80211_common_chan_flags_gfsk = -1;
222
223 static int hf_80211_common_fhss_hopset = -1;
224 static int hf_80211_common_fhss_pattern = -1;
225 static int hf_80211_common_dbm_antsignal = -1;
226 static int hf_80211_common_dbm_antnoise = -1;
227
228 /* 802.11n MAC */
229 static int hf_80211n_mac_flags = -1;
230 static int hf_80211n_mac_flags_greenfield = -1;
231 static int hf_80211n_mac_flags_ht20_40 = -1;
232 static int hf_80211n_mac_flags_rx_guard_interval = -1;
233 static int hf_80211n_mac_flags_duplicate_rx = -1;
234 static int hf_80211n_mac_flags_more_aggregates = -1;
235 static int hf_80211n_mac_flags_aggregate = -1;
236 static int hf_80211n_mac_flags_delimiter_crc_after = -1;
237 static int hf_80211n_mac_ampdu_id = -1;
238 static int hf_80211n_mac_num_delimiters = -1;
239 static int hf_80211n_mac_reserved = -1;
240
241 /* 802.11n MAC+PHY */
242 static int hf_80211n_mac_phy_mcs = -1;
243 static int hf_80211n_mac_phy_num_streams = -1;
244 static int hf_80211n_mac_phy_rssi_combined = -1;
245 static int hf_80211n_mac_phy_rssi_ant0_ctl = -1;
246 static int hf_80211n_mac_phy_rssi_ant1_ctl = -1;
247 static int hf_80211n_mac_phy_rssi_ant2_ctl = -1;
248 static int hf_80211n_mac_phy_rssi_ant3_ctl = -1;
249 static int hf_80211n_mac_phy_rssi_ant0_ext = -1;
250 static int hf_80211n_mac_phy_rssi_ant1_ext = -1;
251 static int hf_80211n_mac_phy_rssi_ant2_ext = -1;
252 static int hf_80211n_mac_phy_rssi_ant3_ext = -1;
253 static int hf_80211n_mac_phy_ext_chan_freq = -1;
254 static int hf_80211n_mac_phy_ext_chan_flags = -1;
255 static int hf_80211n_mac_phy_ext_chan_flags_turbo = -1;
256 static int hhf_80211n_mac_phy_ext_chan_flags_cck = -1;
257 static int hf_80211n_mac_phy_ext_chan_flags_ofdm = -1;
258 static int hhf_80211n_mac_phy_ext_chan_flags_2ghz = -1;
259 static int hf_80211n_mac_phy_ext_chan_flags_5ghz = -1;
260 static int hf_80211n_mac_phy_ext_chan_flags_passive = -1;
261 static int hf_80211n_mac_phy_ext_chan_flags_dynamic = -1;
262 static int hf_80211n_mac_phy_ext_chan_flags_gfsk = -1;
263 static int hf_80211n_mac_phy_dbm_ant0signal = -1;
264 static int hf_80211n_mac_phy_dbm_ant0noise = -1;
265 static int hf_80211n_mac_phy_dbm_ant1signal = -1;
266 static int hf_80211n_mac_phy_dbm_ant1noise = -1;
267 static int hf_80211n_mac_phy_dbm_ant2signal = -1;
268 static int hf_80211n_mac_phy_dbm_ant2noise = -1;
269 static int hf_80211n_mac_phy_dbm_ant3signal = -1;
270 static int hf_80211n_mac_phy_dbm_ant3noise = -1;
271 static int hf_80211n_mac_phy_evm0 = -1;
272 static int hf_80211n_mac_phy_evm1 = -1;
273 static int hf_80211n_mac_phy_evm2 = -1;
274 static int hf_80211n_mac_phy_evm3 = -1;
275
276 /* 802.11n-Extensions A-MPDU fragments */
277 static int hf_ampdu_reassembled_in = -1;
278 static int hf_ampdu_segments = -1;
279 static int hf_ampdu_segment = -1;
280 static int hf_ampdu_count  = -1;
281
282 /* Spectrum-Map */
283 static int hf_spectrum_map = -1;
284
285 /* Process-Info */
286 static int hf_process_info = -1;
287
288 /* Capture-Info */
289 static int hf_capture_info = -1;
290
291 /* Aggregation Extension */
292 static int hf_aggregation_extension_interface_id = -1;
293
294 /* 802.3 Extension */
295 static int hf_8023_extension_flags = -1;
296 static int hf_8023_extension_flags_fcs_present = -1;
297 static int hf_8023_extension_errors = -1;
298 static int hf_8023_extension_errors_fcs = -1;
299 static int hf_8023_extension_errors_sequence = -1;
300 static int hf_8023_extension_errors_symbol = -1;
301 static int hf_8023_extension_errors_data = -1;
302
303 static gint ett_ppi_pph = -1;
304 static gint ett_ppi_flags = -1;
305 static gint ett_dot11_common = -1;
306 static gint ett_dot11_common_flags = -1;
307 static gint ett_dot11_common_channel_flags = -1;
308 static gint ett_dot11n_mac = -1;
309 static gint ett_dot11n_mac_flags = -1;
310 static gint ett_dot11n_mac_phy = -1;
311 static gint ett_dot11n_mac_phy_ext_channel_flags = -1;
312 static gint ett_ampdu_segments = -1;
313 static gint ett_ampdu = -1;
314 static gint ett_ampdu_segment  = -1;
315 static gint ett_aggregation_extension = -1;
316 static gint ett_8023_extension = -1;
317 static gint ett_8023_extension_flags = -1;
318 static gint ett_8023_extension_errors = -1;
319
320 static dissector_handle_t data_handle;
321 static dissector_handle_t ieee80211_ht_handle;
322 static dissector_handle_t ppi_gps_handle, ppi_vector_handle, ppi_sensor_handle, ppi_antenna_handle;
323
324
325 static const true_false_string tfs_ppi_head_flag_alignment = { "32-bit aligned", "Not aligned" };
326 static const true_false_string tfs_tsft_ms = { "milliseconds", "microseconds" };
327 static const true_false_string tfs_ht20_40 = { "HT40", "HT20" };
328 static const true_false_string tfs_invalid_valid = { "Invalid", "Valid" };
329 static const true_false_string tfs_phy_error = { "PHY error", "No errors"};
330
331 static const value_string vs_ppi_field_type[] = {
332     {PPI_80211_COMMON, "802.11-Common"},
333     {PPI_80211N_MAC, "802.11n MAC Extensions"},
334     {PPI_80211N_MAC_PHY, "802.11n MAC+PHY Extensions"},
335     {PPI_SPECTRUM_MAP, "Spectrum-Map"},
336     {PPI_PROCESS_INFO, "Process-Info"},
337     {PPI_CAPTURE_INFO, "Capture-Info"},
338     {PPI_AGGREGATION_EXTENSION, "Aggregation Extension"},
339     {PPI_8023_EXTENSION, "802.3 Extension"},
340
341     {INTEL_CORP_PRIVATE, "Intel Corporation (private)"},
342     {MOHAMED_THAGA_PRIVATE, "Mohamed Thaga (private)"},
343     {PPI_GPS_INFO, "GPS Tagging"},
344     {PPI_VECTOR_INFO, "Vector Tagging"},
345     {PPI_SENSOR_INFO, "Sensor tagging"},
346     {PPI_ANTENNA_INFO, "Antenna Tagging"},
347     {CACE_PRIVATE, "CACE Technologies (private)"},
348     {0, NULL}
349 };
350
351 /* XXX - Start - Copied from packet-radiotap.c */
352 static const value_string vs_80211_common_phy_type[] = {
353     { 0, "Unknown" },
354     { IEEE80211_CHAN_A,         "802.11a" },
355     { IEEE80211_CHAN_B,         "802.11b" },
356     { IEEE80211_CHAN_PUREG,     "802.11g (pure-g)" },
357     { IEEE80211_CHAN_G,         "802.11g" },
358     { IEEE80211_CHAN_T,         "802.11a (turbo)" },
359     { IEEE80211_CHAN_108PUREG,  "802.11g (pure-g, turbo)" },
360     { IEEE80211_CHAN_108G,      "802.11g (turbo)" },
361     { IEEE80211_CHAN_FHSS,      "FHSS" },
362     { 0, NULL },
363 };
364 /* XXX - End - Copied from packet-radiotap.c */
365
366 /* Tables for A-MPDU reassembly */
367 static GHashTable *ampdu_fragment_table = NULL;
368 static GHashTable *ampdu_reassembled_table = NULL;
369
370 /* Reassemble A-MPDUs? */
371 static gboolean ppi_ampdu_reassemble = TRUE;
372
373
374 void
375 capture_ppi(const guchar *pd, int len, packet_counts *ld)
376 {
377     guint32 dlt;
378     guint ppi_len, data_type, data_len;
379     guint offset = PPI_V0_HEADER_LEN;
380     gboolean is_htc = FALSE;
381
382     ppi_len = pletohs(pd+2);
383     if(ppi_len < PPI_V0_HEADER_LEN || !BYTES_ARE_IN_FRAME(0, len, ppi_len)) {
384         ld->other++;
385         return;
386     }
387
388     dlt = pletohl(pd+4);
389
390     /* Figure out if we're +HTC */
391     while (offset < ppi_len) {
392         data_type = pletohs(pd+offset);
393         data_len = pletohs(pd+offset+2) + 4;
394         offset += data_len;
395
396         if (data_type == PPI_80211N_MAC || data_type == PPI_80211N_MAC_PHY) {
397             is_htc = TRUE;
398             break;
399         }
400     }
401
402     /* XXX - We should probably combine this with capture_info.c:capture_info_packet() */
403     switch(dlt) {
404         case 1: /* DLT_EN10MB */
405             capture_eth(pd, ppi_len, len, ld);
406             return;
407         case 105: /* DLT_DLT_IEEE802_11 */
408             if (is_htc)
409                 capture_ieee80211_ht(pd, ppi_len, len, ld);
410             else
411                 capture_ieee80211(pd, ppi_len, len, ld);
412             return;
413         default:
414             break;
415     }
416
417     ld->other++;
418 }
419
420 static void
421 ptvcursor_add_invalid_check(ptvcursor_t *csr, int hf, gint len, guint64 invalid_val) {
422     proto_item *ti;
423     guint64 val = invalid_val;
424
425     switch (len) {
426         case 8:
427             val = tvb_get_letoh64(ptvcursor_tvbuff(csr),
428                 ptvcursor_current_offset(csr));
429             break;
430         case 4:
431             val = tvb_get_letohl(ptvcursor_tvbuff(csr),
432                 ptvcursor_current_offset(csr));
433             break;
434         case 2:
435             val = tvb_get_letohs(ptvcursor_tvbuff(csr),
436                 ptvcursor_current_offset(csr));
437             break;
438         case 1:
439             val = tvb_get_guint8(ptvcursor_tvbuff(csr),
440                 ptvcursor_current_offset(csr));
441             break;
442         default:
443             DISSECTOR_ASSERT_NOT_REACHED();
444     }
445
446     ti = ptvcursor_add(csr, hf, len, ENC_LITTLE_ENDIAN);
447     if (val == invalid_val)
448         proto_item_append_text(ti, " [invalid]");
449 }
450
451 static void
452 add_ppi_field_header(tvbuff_t *tvb, proto_tree *tree, int *offset)
453 {
454     ptvcursor_t *csr = NULL;
455
456     csr = ptvcursor_new(tree, tvb, *offset);
457     ptvcursor_add(csr, hf_ppi_field_type, 2, ENC_LITTLE_ENDIAN);
458     ptvcursor_add(csr, hf_ppi_field_len, 2, ENC_LITTLE_ENDIAN);
459     ptvcursor_free(csr);
460     *offset=ptvcursor_current_offset(csr);
461 }
462
463 /* XXX - The main dissection function in the 802.11 dissector has the same name. */
464 static void
465 dissect_80211_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int data_len)
466 {
467     proto_tree *ftree = NULL;
468     proto_item *ti = NULL;
469     ptvcursor_t *csr = NULL;
470     gint rate_kbps;
471     guint32 common_flags;
472     guint16 common_frequency;
473     gchar *chan_str;
474
475     ti = proto_tree_add_text(tree, tvb, offset, data_len, "802.11-Common");
476     ftree = proto_item_add_subtree(ti, ett_dot11_common);
477     add_ppi_field_header(tvb, ftree, &offset);
478     data_len -= 4; /* Subtract field header length */
479
480     if (data_len != PPI_80211_COMMON_LEN) {
481         proto_tree_add_text(ftree, tvb, offset, data_len, "Invalid length: %u", data_len);
482         THROW(ReportedBoundsError);
483     }
484
485     common_flags = tvb_get_letohs(tvb, offset + 8);
486     if (common_flags & DOT11_FLAG_HAVE_FCS)
487         pinfo->pseudo_header->ieee_802_11.fcs_len = 4;
488     else
489         pinfo->pseudo_header->ieee_802_11.fcs_len = 0;
490
491     csr = ptvcursor_new(ftree, tvb, offset);
492
493     ptvcursor_add_invalid_check(csr, hf_80211_common_tsft, 8, 0);
494
495     ptvcursor_add_with_subtree(csr, hf_80211_common_flags, 2, ENC_LITTLE_ENDIAN,
496                                ett_dot11_common_flags);
497     ptvcursor_add_no_advance(csr, hf_80211_common_flags_fcs, 2, ENC_LITTLE_ENDIAN);
498     ptvcursor_add_no_advance(csr, hf_80211_common_flags_tsft, 2, ENC_LITTLE_ENDIAN);
499     ptvcursor_add_no_advance(csr, hf_80211_common_flags_fcs_valid, 2, ENC_LITTLE_ENDIAN);
500     ptvcursor_add(csr, hf_80211_common_flags_phy_err, 2, ENC_LITTLE_ENDIAN);
501     ptvcursor_pop_subtree(csr);
502
503     rate_kbps = tvb_get_letohs(tvb, ptvcursor_current_offset(csr)) * 500;
504     ti = proto_tree_add_uint_format(ftree, hf_80211_common_rate, tvb,
505                                     ptvcursor_current_offset(csr), 2, rate_kbps, "Rate: %.1f Mbps",
506                                     rate_kbps / 1000.0);
507     if (rate_kbps == 0)
508         proto_item_append_text(ti, " [invalid]");
509     if (check_col(pinfo->cinfo, COL_TX_RATE)) {
510         col_add_fstr(pinfo->cinfo, COL_TX_RATE, "%.1f Mbps", rate_kbps / 1000.0);
511     }
512     ptvcursor_advance(csr, 2);
513
514     common_frequency = tvb_get_letohs(ptvcursor_tvbuff(csr), ptvcursor_current_offset(csr));
515     chan_str = ieee80211_mhz_to_str(common_frequency);
516     proto_tree_add_uint_format(ptvcursor_tree(csr), hf_80211_common_chan_freq, ptvcursor_tvbuff(csr),
517                                ptvcursor_current_offset(csr), 2, common_frequency, "Channel frequency: %s", chan_str);
518     if (check_col(pinfo->cinfo, COL_FREQ_CHAN)) {
519         col_add_fstr(pinfo->cinfo, COL_FREQ_CHAN, "%s", chan_str);
520     }
521     g_free(chan_str);
522     ptvcursor_advance(csr, 2);
523
524     ptvcursor_add_with_subtree(csr, hf_80211_common_chan_flags, 2, ENC_LITTLE_ENDIAN,
525                                ett_dot11_common_channel_flags);
526     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_turbo, 2, ENC_LITTLE_ENDIAN);
527     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_cck, 2, ENC_LITTLE_ENDIAN);
528     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_ofdm, 2, ENC_LITTLE_ENDIAN);
529     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_2ghz, 2, ENC_LITTLE_ENDIAN);
530     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_5ghz, 2, ENC_LITTLE_ENDIAN);
531     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_passive, 2, ENC_LITTLE_ENDIAN);
532     ptvcursor_add_no_advance(csr, hf_80211_common_chan_flags_dynamic, 2, ENC_LITTLE_ENDIAN);
533     ptvcursor_add(csr, hf_80211_common_chan_flags_gfsk, 2, ENC_LITTLE_ENDIAN);
534     ptvcursor_pop_subtree(csr);
535
536
537     ptvcursor_add(csr, hf_80211_common_fhss_hopset, 1, ENC_LITTLE_ENDIAN);
538     ptvcursor_add(csr, hf_80211_common_fhss_pattern, 1, ENC_LITTLE_ENDIAN);
539
540     if (check_col(pinfo->cinfo, COL_RSSI)) {
541         col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
542             (gint8) tvb_get_guint8(tvb, ptvcursor_current_offset(csr)));
543     }
544     ptvcursor_add_invalid_check(csr, hf_80211_common_dbm_antsignal, 1, 0x80); /* -128 */
545     ptvcursor_add_invalid_check(csr, hf_80211_common_dbm_antnoise, 1, 0x80);
546
547     ptvcursor_free(csr);
548 }
549
550 static void
551 dissect_80211n_mac(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, int data_len, gboolean add_subtree, guint32 *n_mac_flags, guint32 *ampdu_id)
552 {
553     proto_tree *ftree = tree;
554     proto_item *ti = NULL;
555     ptvcursor_t *csr = NULL;
556     int subtree_off = add_subtree ? 4 : 0;
557
558     *n_mac_flags = tvb_get_letohl(tvb, offset + subtree_off);
559     *ampdu_id = tvb_get_letohl(tvb, offset + 4 + subtree_off);
560
561     if (add_subtree) {
562         ti = proto_tree_add_text(tree, tvb, offset, data_len, "802.11n MAC");
563         ftree = proto_item_add_subtree(ti, ett_dot11n_mac);
564         add_ppi_field_header(tvb, ftree, &offset);
565         data_len -= 4; /* Subtract field header length */
566     }
567
568     if (data_len != PPI_80211N_MAC_LEN) {
569         proto_tree_add_text(ftree, tvb, offset, data_len, "Invalid length: %u", data_len);
570         THROW(ReportedBoundsError);
571     }
572
573     csr = ptvcursor_new(ftree, tvb, offset);
574
575     ptvcursor_add_with_subtree(csr, hf_80211n_mac_flags, 4, ENC_LITTLE_ENDIAN,
576                                ett_dot11n_mac_flags);
577     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_greenfield, 4, ENC_LITTLE_ENDIAN);
578     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_ht20_40, 4, ENC_LITTLE_ENDIAN);
579     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_rx_guard_interval, 4, ENC_LITTLE_ENDIAN);
580     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_duplicate_rx, 4, ENC_LITTLE_ENDIAN);
581     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_aggregate, 4, ENC_LITTLE_ENDIAN);
582     ptvcursor_add_no_advance(csr, hf_80211n_mac_flags_more_aggregates, 4, ENC_LITTLE_ENDIAN);
583     ptvcursor_add(csr, hf_80211n_mac_flags_delimiter_crc_after, 4, ENC_LITTLE_ENDIAN); /* Last */
584     ptvcursor_pop_subtree(csr);
585
586     ptvcursor_add(csr, hf_80211n_mac_ampdu_id, 4, ENC_LITTLE_ENDIAN);
587     ptvcursor_add(csr, hf_80211n_mac_num_delimiters, 1, ENC_LITTLE_ENDIAN);
588
589     if (add_subtree) {
590         ptvcursor_add(csr, hf_80211n_mac_reserved, 3, ENC_LITTLE_ENDIAN);
591     }
592
593     ptvcursor_free(csr);
594 }
595
596 static void
597 dissect_80211n_mac_phy(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int data_len, guint32 *n_mac_flags, guint32 *ampdu_id)
598 {
599     proto_tree *ftree = NULL;
600     proto_item *ti = NULL;
601     ptvcursor_t *csr = NULL;
602     guint16 ext_frequency;
603     gchar *chan_str;
604
605     ti = proto_tree_add_text(tree, tvb, offset, data_len, "802.11n MAC+PHY");
606     ftree = proto_item_add_subtree(ti, ett_dot11n_mac_phy);
607     add_ppi_field_header(tvb, ftree, &offset);
608     data_len -= 4; /* Subtract field header length */
609
610     if (data_len != PPI_80211N_MAC_PHY_LEN) {
611         proto_tree_add_text(ftree, tvb, offset, data_len, "Invalid length: %u", data_len);
612         THROW(ReportedBoundsError);
613     }
614
615     dissect_80211n_mac(tvb, pinfo, ftree, offset, PPI_80211N_MAC_LEN,
616                        FALSE, n_mac_flags, ampdu_id);
617     offset += PPI_80211N_MAC_PHY_OFF;
618
619     csr = ptvcursor_new(ftree, tvb, offset);
620
621     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_mcs, 1, 255);
622     ti = ptvcursor_add(csr, hf_80211n_mac_phy_num_streams, 1, ENC_LITTLE_ENDIAN);
623     if (tvb_get_guint8(tvb, ptvcursor_current_offset(csr) - 1) == 0)
624         proto_item_append_text(ti, " (unknown)");
625     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_combined, 1, 255);
626     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant0_ctl, 1, 255);
627     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant1_ctl, 1, 255);
628     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant2_ctl, 1, 255);
629     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant3_ctl, 1, 255);
630     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant0_ext, 1, 255);
631     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant1_ext, 1, 255);
632     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant2_ext, 1, 255);
633     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_rssi_ant3_ext, 1, 255);
634
635     ext_frequency = tvb_get_letohs(ptvcursor_tvbuff(csr), ptvcursor_current_offset(csr));
636     chan_str = ieee80211_mhz_to_str(ext_frequency);
637     proto_tree_add_uint_format(ptvcursor_tree(csr), hf_80211n_mac_phy_ext_chan_freq, ptvcursor_tvbuff(csr),
638                                ptvcursor_current_offset(csr), 2, ext_frequency, "Ext. Channel frequency: %s", chan_str);
639     g_free(chan_str);
640     ptvcursor_advance(csr, 2);
641
642     ptvcursor_add_with_subtree(csr, hf_80211n_mac_phy_ext_chan_flags, 2, ENC_LITTLE_ENDIAN,
643                                ett_dot11n_mac_phy_ext_channel_flags);
644     ptvcursor_add_no_advance(csr, hf_80211n_mac_phy_ext_chan_flags_turbo, 2, ENC_LITTLE_ENDIAN);
645     ptvcursor_add_no_advance(csr, hhf_80211n_mac_phy_ext_chan_flags_cck, 2, ENC_LITTLE_ENDIAN);
646     ptvcursor_add_no_advance(csr, hf_80211n_mac_phy_ext_chan_flags_ofdm, 2, ENC_LITTLE_ENDIAN);
647     ptvcursor_add_no_advance(csr, hhf_80211n_mac_phy_ext_chan_flags_2ghz, 2, ENC_LITTLE_ENDIAN);
648     ptvcursor_add_no_advance(csr, hf_80211n_mac_phy_ext_chan_flags_5ghz, 2, ENC_LITTLE_ENDIAN);
649     ptvcursor_add_no_advance(csr, hf_80211n_mac_phy_ext_chan_flags_passive, 2, ENC_LITTLE_ENDIAN);
650     ptvcursor_add_no_advance(csr, hf_80211n_mac_phy_ext_chan_flags_dynamic, 2, ENC_LITTLE_ENDIAN);
651     ptvcursor_add(csr, hf_80211n_mac_phy_ext_chan_flags_gfsk, 2, ENC_LITTLE_ENDIAN);
652     ptvcursor_pop_subtree(csr);
653
654     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant0signal, 1, 0x80); /* -128 */
655     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant0noise, 1, 0x80);
656     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant1signal, 1, 0x80);
657     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant1noise, 1, 0x80);
658     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant2signal, 1, 0x80);
659     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant2noise, 1, 0x80);
660     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant3signal, 1, 0x80);
661     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_dbm_ant3noise, 1, 0x80);
662     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_evm0, 4, 0);
663     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_evm1, 4, 0);
664     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_evm2, 4, 0);
665     ptvcursor_add_invalid_check(csr, hf_80211n_mac_phy_evm3, 4, 0);
666
667     ptvcursor_free(csr);
668 }
669
670 static void
671 dissect_aggregation_extension(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, int data_len)
672 {
673     proto_tree *ftree = tree;
674     proto_item *ti = NULL;
675     ptvcursor_t *csr = NULL;
676
677     ti = proto_tree_add_text(tree, tvb, offset, data_len, "Aggregation Extension");
678     ftree = proto_item_add_subtree(ti, ett_aggregation_extension);
679     add_ppi_field_header(tvb, ftree, &offset);
680     data_len -= 4; /* Subtract field header length */
681
682     if (data_len != PPI_AGGREGATION_EXTENSION_LEN) {
683         proto_tree_add_text(ftree, tvb, offset, data_len, "Invalid length: %u", data_len);
684         THROW(ReportedBoundsError);
685     }
686
687     csr = ptvcursor_new(ftree, tvb, offset);
688
689     ptvcursor_add(csr, hf_aggregation_extension_interface_id, 4, ENC_LITTLE_ENDIAN); /* Last */
690     ptvcursor_free(csr);
691 }
692
693 static void
694 dissect_8023_extension(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, int data_len)
695 {
696     proto_tree *ftree = tree;
697     proto_item *ti = NULL;
698     ptvcursor_t *csr = NULL;
699
700     ti = proto_tree_add_text(tree, tvb, offset, data_len, "802.3 Extension");
701     ftree = proto_item_add_subtree(ti, ett_8023_extension);
702     add_ppi_field_header(tvb, ftree, &offset);
703     data_len -= 4; /* Subtract field header length */
704
705     if (data_len != PPI_8023_EXTENSION_LEN) {
706         proto_tree_add_text(ftree, tvb, offset, data_len, "Invalid length: %u", data_len);
707         THROW(ReportedBoundsError);
708     }
709
710     csr = ptvcursor_new(ftree, tvb, offset);
711
712     ptvcursor_add_with_subtree(csr, hf_8023_extension_flags, 4, ENC_LITTLE_ENDIAN, ett_8023_extension_flags);
713     ptvcursor_add(csr, hf_8023_extension_flags_fcs_present, 4, ENC_LITTLE_ENDIAN);
714     ptvcursor_pop_subtree(csr);
715
716     ptvcursor_add_with_subtree(csr, hf_8023_extension_errors, 4, ENC_LITTLE_ENDIAN, ett_8023_extension_errors);
717     ptvcursor_add_no_advance(csr, hf_8023_extension_errors_fcs, 4, ENC_LITTLE_ENDIAN);
718     ptvcursor_add_no_advance(csr, hf_8023_extension_errors_sequence, 4, ENC_LITTLE_ENDIAN);
719     ptvcursor_add_no_advance(csr, hf_8023_extension_errors_symbol, 4, ENC_LITTLE_ENDIAN);
720     ptvcursor_add(csr, hf_8023_extension_errors_data, 4, ENC_LITTLE_ENDIAN);
721     ptvcursor_pop_subtree(csr);
722
723     ptvcursor_free(csr);
724 }
725
726
727 #define PADDING4(x) ((((x + 3) >> 2) << 2) - x)
728 #define ADD_BASIC_TAG(hf_tag) \
729     if (tree)   \
730         proto_tree_add_item(ppi_tree, hf_tag, tvb, offset, data_len, FALSE)
731
732 static void
733 dissect_ppi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
734 {
735     proto_tree *ppi_tree = NULL, *ppi_flags_tree = NULL, *seg_tree = NULL, *ampdu_tree = NULL;
736     proto_tree *agg_tree = NULL;
737     proto_item *ti = NULL;
738     tvbuff_t *next_tvb;
739     int offset = 0;
740     guint version, flags;
741     gint tot_len, data_len;
742     guint data_type;
743     guint32 dlt;
744     guint32 n_ext_flags = 0;
745     guint32 ampdu_id = 0;
746     fragment_data *fd_head = NULL, *ft_fdh = NULL;
747     gint len_remain, /*pad_len = 0,*/ ampdu_len = 0;
748     gint mpdu_count = 0;
749     gchar *mpdu_str;
750     gboolean first_mpdu = TRUE;
751     guint last_frame = 0;
752     gboolean is_ht = FALSE;
753
754     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPI");
755     col_clear(pinfo->cinfo, COL_INFO);
756
757     version = tvb_get_guint8(tvb, offset);
758     flags = tvb_get_guint8(tvb, offset + 1);
759
760     tot_len = tvb_get_letohs(tvb, offset+2);
761     dlt = tvb_get_letohl(tvb, offset+4);
762
763     col_add_fstr(pinfo->cinfo, COL_INFO, "PPI version %u, %u bytes",
764                  version, tot_len);
765
766     /* Dissect the packet */
767     if (tree) {
768         ti = proto_tree_add_protocol_format(tree, proto_ppi,
769                                             tvb, 0, tot_len, "PPI version %u, %u bytes", version, tot_len);
770         ppi_tree = proto_item_add_subtree(ti, ett_ppi_pph);
771         proto_tree_add_item(ppi_tree, hf_ppi_head_version,
772                             tvb, offset, 1, ENC_LITTLE_ENDIAN);
773
774         ti = proto_tree_add_item(ppi_tree, hf_ppi_head_flags,
775                                  tvb, offset + 1, 1, ENC_LITTLE_ENDIAN);
776         ppi_flags_tree = proto_item_add_subtree(ti, ett_ppi_flags);
777         proto_tree_add_item(ppi_flags_tree, hf_ppi_head_flag_alignment,
778                             tvb, offset + 1, 1, ENC_LITTLE_ENDIAN);
779         proto_tree_add_item(ppi_flags_tree, hf_ppi_head_flag_reserved,
780                             tvb, offset + 1, 1, ENC_LITTLE_ENDIAN);
781
782         proto_tree_add_item(ppi_tree, hf_ppi_head_len,
783                                  tvb, offset + 2, 2, ENC_LITTLE_ENDIAN);
784         proto_tree_add_item(ppi_tree, hf_ppi_head_dlt,
785                                  tvb, offset + 4, 4, ENC_LITTLE_ENDIAN);
786     }
787
788     tot_len -= PPI_V0_HEADER_LEN;
789     offset += 8;
790
791     while (tot_len > 0) {
792         data_type = tvb_get_letohs(tvb, offset);
793         data_len = tvb_get_letohs(tvb, offset + 2) + 4;
794         tot_len -= data_len;
795
796         switch (data_type) {
797             case PPI_80211_COMMON:
798                 dissect_80211_common(tvb, pinfo, ppi_tree, offset, data_len);
799                 break;
800
801             case PPI_80211N_MAC:
802                 dissect_80211n_mac(tvb, pinfo, ppi_tree, offset, data_len,
803                     TRUE, &n_ext_flags, &ampdu_id);
804                 is_ht = TRUE;
805                 break;
806
807             case PPI_80211N_MAC_PHY:
808                 dissect_80211n_mac_phy(tvb, pinfo, ppi_tree, offset,
809                     data_len, &n_ext_flags, &ampdu_id);
810                 is_ht = TRUE;
811                 break;
812
813             case PPI_SPECTRUM_MAP:
814                 ADD_BASIC_TAG(hf_spectrum_map);
815                 break;
816
817             case PPI_PROCESS_INFO:
818                 ADD_BASIC_TAG(hf_process_info);
819                 break;
820
821             case PPI_CAPTURE_INFO:
822                 ADD_BASIC_TAG(hf_capture_info);
823                 break;
824
825             case PPI_AGGREGATION_EXTENSION:
826                 dissect_aggregation_extension(tvb, pinfo, ppi_tree, offset, data_len);
827                 break;
828
829         case PPI_8023_EXTENSION:
830             dissect_8023_extension(tvb, pinfo, ppi_tree, offset, data_len);
831             break;
832         case PPI_GPS_INFO:
833             if (ppi_gps_handle == NULL)
834             {
835                 proto_tree_add_text(ppi_tree, tvb, offset, data_len,
836                                     "%s (%u bytes)", val_to_str(data_type, (value_string *)&vs_ppi_field_type, "GPS: "), data_len);
837             }
838             else /* we found a suitable dissector */
839             {
840                 /* skip over the ppi_fieldheader, and pass it off to the dedicated GPS dissetor */
841                 next_tvb = tvb_new_subset(tvb, offset + 4, data_len - 4 , -1);
842                 call_dissector(ppi_gps_handle, next_tvb, pinfo, ppi_tree);
843             }
844             break;
845         case PPI_VECTOR_INFO:
846             if (ppi_vector_handle == NULL)
847             {
848                 proto_tree_add_text(ppi_tree, tvb, offset, data_len,
849                                     "%s (%u bytes)", val_to_str(data_type, (value_string *)&vs_ppi_field_type, "VECTOR: "), data_len);
850             }
851             else /* we found a suitable dissector */
852             {
853                 /* skip over the ppi_fieldheader, and pass it off to the dedicated VECTOR dissetor */
854                 next_tvb = tvb_new_subset(tvb, offset + 4, data_len - 4 , -1);
855                 call_dissector(ppi_vector_handle, next_tvb, pinfo, ppi_tree);
856             }
857             break;
858         case PPI_SENSOR_INFO:
859             if (ppi_sensor_handle == NULL)
860             {
861                 proto_tree_add_text(ppi_tree, tvb, offset, data_len,
862                                     "%s (%u bytes)", val_to_str(data_type, (value_string *)&vs_ppi_field_type, "HARRIS: "), data_len);
863             }
864             else /* we found a suitable dissector */
865             {
866                 /* skip over the ppi_fieldheader, and pass it off to the dedicated SENSOR dissetor */
867                 next_tvb = tvb_new_subset(tvb, offset + 4, data_len - 4 , -1);
868                 call_dissector(ppi_sensor_handle, next_tvb, pinfo, ppi_tree);
869             }
870             break;
871         case PPI_ANTENNA_INFO:
872             if (ppi_antenna_handle == NULL)
873             {
874                 proto_tree_add_text(ppi_tree, tvb, offset, data_len,
875                                     "%s (%u bytes)", val_to_str(data_type, (value_string *)&vs_ppi_field_type, "ANTENNA: "), data_len);
876             }
877             else /* we found a suitable dissector */
878             {
879                 /* skip over the ppi_fieldheader, and pass it off to the dedicated ANTENNA dissetor */
880                 next_tvb = tvb_new_subset(tvb, offset + 4, data_len - 4 , -1);
881                 call_dissector(ppi_antenna_handle, next_tvb, pinfo, ppi_tree);
882             }
883             break;
884
885         default:
886             if (tree)
887                 proto_tree_add_text(ppi_tree, tvb, offset, data_len,
888                                     "%s (%u bytes)", val_to_str(data_type, (value_string *)&vs_ppi_field_type, "Reserved"), data_len);
889         }
890
891         offset += data_len;
892         if (IS_PPI_FLAG_ALIGN(flags)){
893             offset += PADDING4(offset);
894         }
895     }
896
897     if (ppi_ampdu_reassemble && DOT11N_IS_AGGREGATE(n_ext_flags)) {
898         len_remain = tvb_length_remaining(tvb, offset);
899 #if 0 /* XXX: pad_len never actually used ?? */
900         if (DOT11N_MORE_AGGREGATES(n_ext_flags)) {
901             pad_len = PADDING4(len_remain);
902         }
903 #endif
904         pinfo->fragmented = TRUE;
905
906         /* Make sure we aren't going to go past AGGREGATE_MAX
907          * and caclulate our full A-MPDU length */
908         fd_head = fragment_get(pinfo, ampdu_id, ampdu_fragment_table);
909         while (fd_head) {
910             ampdu_len += fd_head->len + PADDING4(fd_head->len) + 4;
911             fd_head = fd_head->next;
912         }
913         if (ampdu_len > AGGREGATE_MAX) {
914             if (tree) {
915                 proto_tree_add_text(ppi_tree, tvb, offset, -1,
916                     "[Aggregate length greater than maximum (%u)]", AGGREGATE_MAX);
917                 THROW(ReportedBoundsError);
918             } else {
919                 return;
920             }
921         }
922
923         /*
924          * Note that we never actually reassemble our A-MPDUs.  Doing
925          * so would require prepending each MPDU with an A-MPDU delimiter
926          * and appending it with padding, only to hand it off to some
927          * routine which would un-do the work we just did.  We're using
928          * the reassembly code to track MPDU sizes and frame numbers.
929          */
930         /*??fd_head = */fragment_add_seq_next(tvb, offset, pinfo, ampdu_id,
931             ampdu_fragment_table, ampdu_reassembled_table,
932             len_remain, TRUE);
933         pinfo->fragmented = TRUE;
934
935         /* Do reassembly? */
936         fd_head = fragment_get(pinfo, ampdu_id, ampdu_fragment_table);
937
938         /* Show our fragments */
939         if (fd_head && tree) {
940             ft_fdh = fd_head;
941             /* List our fragments */
942             ti = proto_tree_add_text(ppi_tree, tvb, offset, -1, "A-MPDU (%u bytes w/hdrs):", ampdu_len);
943             PROTO_ITEM_SET_GENERATED(ti);
944             seg_tree = proto_item_add_subtree(ti, ett_ampdu_segments);
945
946             while (ft_fdh) {
947                 if (ft_fdh->data && ft_fdh->len) {
948                     last_frame = ft_fdh->frame;
949                     if (!first_mpdu)
950                         proto_item_append_text(ti, ",");
951                     first_mpdu = FALSE;
952                     proto_item_append_text(ti, " #%u(%u)",
953                         ft_fdh->frame, ft_fdh->len);
954                     proto_tree_add_uint_format(seg_tree, hf_ampdu_segment,
955                         tvb, 0, 0, last_frame,
956                         "Frame: %u (%u byte%s)",
957                         last_frame,
958                         ft_fdh->len,
959                         plurality(ft_fdh->len, "", "s"));
960                 }
961                 ft_fdh = ft_fdh->next;
962             }
963             if (last_frame && last_frame != pinfo->fd->num)
964                 proto_tree_add_uint(seg_tree, hf_ampdu_reassembled_in,
965                     tvb, 0, 0, last_frame);
966         }
967
968         if (fd_head && !DOT11N_MORE_AGGREGATES(n_ext_flags)) {
969             if (tree) {
970                 ti = proto_tree_add_protocol_format(tree,
971                     proto_get_id_by_filter_name("wlan_aggregate"),
972                     tvb, 0, tot_len, "IEEE 802.11 Aggregate MPDU");
973                 agg_tree = proto_item_add_subtree(ti, ett_ampdu);
974             }
975
976             while (fd_head) {
977                 if (fd_head->data && fd_head->len) {
978                     mpdu_count++;
979                     mpdu_str = ep_strdup_printf("MPDU #%d", mpdu_count);
980
981                     next_tvb = tvb_new_child_real_data(tvb, fd_head->data,
982                         fd_head->len, fd_head->len);
983                     add_new_data_source(pinfo, next_tvb, mpdu_str);
984
985                     if (agg_tree) {
986                         ti = proto_tree_add_text(agg_tree, next_tvb, 0, -1, "%s", mpdu_str);
987                         ampdu_tree = proto_item_add_subtree(ti, ett_ampdu_segment);
988                     }
989                     call_dissector(ieee80211_ht_handle, next_tvb, pinfo, ampdu_tree);
990                 }
991                 fd_head = fd_head->next;
992             }
993             proto_tree_add_uint(seg_tree, hf_ampdu_count, tvb, 0, 0, mpdu_count);
994             pinfo->fragmented=FALSE;
995         } else {
996             next_tvb = tvb_new_subset_remaining(tvb, offset);
997             col_set_str(pinfo->cinfo, COL_PROTOCOL, "IEEE 802.11n");
998             col_set_str(pinfo->cinfo, COL_INFO, "Unreassembled A-MPDU data");
999             call_dissector(data_handle, next_tvb, pinfo, tree);
1000         }
1001         return;
1002     }
1003
1004     next_tvb = tvb_new_subset_remaining(tvb, offset);
1005     if (is_ht) { /* We didn't hit the reassembly code */
1006         call_dissector(ieee80211_ht_handle, next_tvb, pinfo, tree);
1007     } else {
1008         dissector_try_uint(wtap_encap_dissector_table,
1009             wtap_pcap_encap_to_wtap_encap(dlt), next_tvb, pinfo, tree);
1010     }
1011 }
1012
1013 /* Establish our beachead */
1014
1015 static void
1016 ampdu_reassemble_init(void)
1017 {
1018     fragment_table_init(&ampdu_fragment_table);
1019     reassembled_table_init(&ampdu_reassembled_table);
1020 }
1021
1022 void
1023 proto_register_ppi(void)
1024 {
1025     static hf_register_info hf[] = {
1026     { &hf_ppi_head_version,
1027       { "Version", "ppi.version",
1028         FT_UINT8, BASE_DEC, NULL, 0x0,
1029         "PPI header format version", HFILL } },
1030     { &hf_ppi_head_flags,
1031       { "Flags", "ppi.flags",
1032         FT_UINT8, BASE_HEX, NULL, 0x0,
1033         "PPI header flags", HFILL } },
1034     { &hf_ppi_head_flag_alignment,
1035       { "Alignment", "ppi.flags.alignment",
1036         FT_BOOLEAN, 8, TFS(&tfs_ppi_head_flag_alignment), 0x01,
1037         "PPI header flags - 32bit Alignment", HFILL } },
1038     { &hf_ppi_head_flag_reserved,
1039       { "Reserved", "ppi.flags.reserved",
1040         FT_UINT8, BASE_HEX, NULL, 0xFE,
1041         "PPI header flags - Reserved Flags", HFILL } },
1042     { &hf_ppi_head_len,
1043        { "Header length", "ppi.length",
1044          FT_UINT16, BASE_DEC, NULL, 0x0,
1045          "Length of header including payload", HFILL } },
1046     { &hf_ppi_head_dlt,
1047        { "DLT", "ppi.dlt",
1048          FT_UINT32, BASE_DEC, NULL, 0x0, "libpcap Data Link Type (DLT) of the payload", HFILL } },
1049
1050     { &hf_ppi_field_type,
1051        { "Field type", "ppi.field_type",
1052          FT_UINT16, BASE_DEC, VALS(vs_ppi_field_type), 0x0, "PPI data field type", HFILL } },
1053     { &hf_ppi_field_len,
1054        { "Field length", "ppi.field_len",
1055          FT_UINT16, BASE_DEC, NULL, 0x0, "PPI data field length", HFILL } },
1056
1057     { &hf_80211_common_tsft,
1058        { "TSFT", "ppi.80211-common.tsft",
1059          FT_UINT64, BASE_DEC, NULL, 0x0, "PPI 802.11-Common Timing Synchronization Function Timer (TSFT)", HFILL } },
1060     { &hf_80211_common_flags,
1061        { "Flags", "ppi.80211-common.flags",
1062          FT_UINT16, BASE_HEX, NULL, 0x0, "PPI 802.11-Common Flags", HFILL } },
1063     { &hf_80211_common_flags_fcs,
1064        { "FCS present flag", "ppi.80211-common.flags.fcs",
1065          FT_BOOLEAN, 16, TFS(&tfs_present_absent), 0x0001, "PPI 802.11-Common Frame Check Sequence (FCS) Present Flag", HFILL } },
1066     { &hf_80211_common_flags_tsft,
1067        { "TSFT flag", "ppi.80211-common.flags.tsft",
1068          FT_BOOLEAN, 16, TFS(&tfs_tsft_ms), 0x0002, "PPI 802.11-Common Timing Synchronization Function Timer (TSFT) msec/usec flag", HFILL } },
1069     { &hf_80211_common_flags_fcs_valid,
1070        { "FCS validity", "ppi.80211-common.flags.fcs-invalid",
1071          FT_BOOLEAN, 16, TFS(&tfs_invalid_valid), 0x0004, "PPI 802.11-Common Frame Check Sequence (FCS) Validity flag", HFILL } },
1072     { &hf_80211_common_flags_phy_err,
1073        { "PHY error flag", "ppi.80211-common.flags.phy-err",
1074          FT_BOOLEAN, 16, TFS(&tfs_phy_error), 0x0008, "PPI 802.11-Common Physical level (PHY) Error", HFILL } },
1075     { &hf_80211_common_rate,
1076        { "Data rate", "ppi.80211-common.rate",
1077          FT_UINT16, BASE_DEC, NULL, 0x0, "PPI 802.11-Common Data Rate (x 500 Kbps)", HFILL } },
1078     { &hf_80211_common_chan_freq,
1079        { "Channel frequency", "ppi.80211-common.chan.freq",
1080          FT_UINT16, BASE_DEC, NULL, 0x0,
1081         "PPI 802.11-Common Channel Frequency", HFILL } },
1082     { &hf_80211_common_chan_flags,
1083        { "Channel type", "ppi.80211-common.chan.type",
1084          FT_UINT16, BASE_HEX, VALS(vs_80211_common_phy_type), 0x0, "PPI 802.11-Common Channel Type", HFILL } },
1085
1086     { &hf_80211_common_chan_flags_turbo,
1087        { "Turbo", "ppi.80211-common.chan.type.turbo",
1088          FT_BOOLEAN, 16, NULL, 0x0010, "PPI 802.11-Common Channel Type Turbo", HFILL } },
1089     { &hf_80211_common_chan_flags_cck,
1090        { "Complementary Code Keying (CCK)", "ppi.80211-common.chan.type.cck",
1091          FT_BOOLEAN, 16, NULL, 0x0020, "PPI 802.11-Common Channel Type Complementary Code Keying (CCK) Modulation", HFILL } },
1092     { &hf_80211_common_chan_flags_ofdm,
1093        { "Orthogonal Frequency-Division Multiplexing (OFDM)", "ppi.80211-common.chan.type.ofdm",
1094          FT_BOOLEAN, 16, NULL, 0x0040, "PPI 802.11-Common Channel Type Orthogonal Frequency-Division Multiplexing (OFDM)", HFILL } },
1095     { &hf_80211_common_chan_flags_2ghz,
1096        { "2 GHz spectrum", "ppi.80211-common.chan.type.2ghz",
1097          FT_BOOLEAN, 16, NULL, 0x0080, "PPI 802.11-Common Channel Type 2 GHz spectrum", HFILL } },
1098     { &hf_80211_common_chan_flags_5ghz,
1099        { "5 GHz spectrum", "ppi.80211-common.chan.type.5ghz",
1100          FT_BOOLEAN, 16, NULL, 0x0100, "PPI 802.11-Common Channel Type 5 GHz spectrum", HFILL } },
1101     { &hf_80211_common_chan_flags_passive,
1102        { "Passive", "ppi.80211-common.chan.type.passive",
1103          FT_BOOLEAN, 16, NULL, 0x0200, "PPI 802.11-Common Channel Type Passive", HFILL } },
1104     { &hf_80211_common_chan_flags_dynamic,
1105        { "Dynamic CCK-OFDM", "ppi.80211-common.chan.type.dynamic",
1106          FT_BOOLEAN, 16, NULL, 0x0400, "PPI 802.11-Common Channel Type Dynamic CCK-OFDM Channel", HFILL } },
1107     { &hf_80211_common_chan_flags_gfsk,
1108        { "Gaussian Frequency Shift Keying (GFSK)", "ppi.80211-common.chan.type.gfsk",
1109          FT_BOOLEAN, 16, NULL, 0x0800, "PPI 802.11-Common Channel Type Gaussian Frequency Shift Keying (GFSK) Modulation", HFILL } },
1110
1111     { &hf_80211_common_fhss_hopset,
1112        { "FHSS hopset", "ppi.80211-common.fhss.hopset",
1113          FT_UINT8, BASE_HEX, NULL, 0x0, "PPI 802.11-Common Frequency-Hopping Spread Spectrum (FHSS) Hopset", HFILL } },
1114     { &hf_80211_common_fhss_pattern,
1115        { "FHSS pattern", "ppi.80211-common.fhss.pattern",
1116          FT_UINT8, BASE_HEX, NULL, 0x0, "PPI 802.11-Common Frequency-Hopping Spread Spectrum (FHSS) Pattern", HFILL } },
1117     { &hf_80211_common_dbm_antsignal,
1118        { "dBm antenna signal", "ppi.80211-common.dbm.antsignal",
1119          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11-Common dBm Antenna Signal", HFILL } },
1120     { &hf_80211_common_dbm_antnoise,
1121        { "dBm antenna noise", "ppi.80211-common.dbm.antnoise",
1122          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11-Common dBm Antenna Noise", HFILL } },
1123
1124     /* 802.11n MAC */
1125     { &hf_80211n_mac_flags,
1126        { "MAC flags", "ppi.80211n-mac.flags",
1127          FT_UINT32, BASE_HEX, NULL, 0x0, "PPI 802.11n MAC flags", HFILL } },
1128     { &hf_80211n_mac_flags_greenfield,
1129        { "Greenfield flag", "ppi.80211n-mac.flags.greenfield",
1130          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0001, "PPI 802.11n MAC Greenfield Flag", HFILL } },
1131     { &hf_80211n_mac_flags_ht20_40,
1132        { "HT20/HT40 flag", "ppi.80211n-mac.flags.ht20_40",
1133          FT_BOOLEAN, 32, TFS(&tfs_ht20_40), 0x0002, "PPI 802.11n MAC HT20/HT40 Flag", HFILL } },
1134     { &hf_80211n_mac_flags_rx_guard_interval,
1135        { "RX Short Guard Interval (SGI) flag", "ppi.80211n-mac.flags.rx.short_guard_interval",
1136          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0004, "PPI 802.11n MAC RX Short Guard Interval (SGI) Flag", HFILL } },
1137     { &hf_80211n_mac_flags_duplicate_rx,
1138        { "Duplicate RX flag", "ppi.80211n-mac.flags.rx.duplicate",
1139          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0008, "PPI 802.11n MAC Duplicate RX Flag", HFILL } },
1140     { &hf_80211n_mac_flags_aggregate,
1141        { "Aggregate flag", "ppi.80211n-mac.flags.agg",
1142          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0010, "PPI 802.11 MAC Aggregate Flag", HFILL } },
1143     { &hf_80211n_mac_flags_more_aggregates,
1144        { "More aggregates flag", "ppi.80211n-mac.flags.more_agg",
1145          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0020, "PPI 802.11n MAC More Aggregates Flag", HFILL } },
1146     { &hf_80211n_mac_flags_delimiter_crc_after,
1147        { "A-MPDU Delimiter CRC error after this frame flag", "ppi.80211n-mac.flags.delim_crc_error_after",
1148          FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0040, "PPI 802.11n MAC A-MPDU Delimiter CRC Error After This Frame Flag", HFILL } },
1149     { &hf_80211n_mac_ampdu_id,
1150        { "AMPDU-ID", "ppi.80211n-mac.ampdu_id",
1151          FT_UINT32, BASE_HEX, NULL, 0x0, "PPI 802.11n MAC AMPDU-ID", HFILL } },
1152     { &hf_80211n_mac_num_delimiters,
1153        { "Num-Delimiters", "ppi.80211n-mac.num_delimiters",
1154          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC number of zero-length pad delimiters", HFILL } },
1155     { &hf_80211n_mac_reserved,
1156        { "Reserved", "ppi.80211n-mac.reserved",
1157          FT_UINT24, BASE_HEX, NULL, 0x0, "PPI 802.11n MAC Reserved", HFILL } },
1158
1159
1160     /* 802.11n MAC+PHY */
1161     { &hf_80211n_mac_phy_mcs,
1162        { "MCS", "ppi.80211n-mac-phy.mcs",
1163          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Modulation Coding Scheme (MCS)", HFILL } },
1164     { &hf_80211n_mac_phy_num_streams,
1165        { "Number of spatial streams", "ppi.80211n-mac-phy.num_streams",
1166          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY number of spatial streams", HFILL } },
1167     { &hf_80211n_mac_phy_rssi_combined,
1168        { "RSSI combined", "ppi.80211n-mac-phy.rssi.combined",
1169          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Received Signal Strength Indication (RSSI) Combined", HFILL } },
1170     { &hf_80211n_mac_phy_rssi_ant0_ctl,
1171        { "Antenna 0 control RSSI", "ppi.80211n-mac-phy.rssi.ant0ctl",
1172          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 0 Control Channel Received Signal Strength Indication (RSSI)", HFILL } },
1173     { &hf_80211n_mac_phy_rssi_ant1_ctl,
1174        { "Antenna 1 control RSSI", "ppi.80211n-mac-phy.rssi.ant1ctl",
1175          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 1 Control Channel Received Signal Strength Indication (RSSI)", HFILL } },
1176     { &hf_80211n_mac_phy_rssi_ant2_ctl,
1177        { "Antenna 2 control RSSI", "ppi.80211n-mac-phy.rssi.ant2ctl",
1178          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 2 Control Channel Received Signal Strength Indication (RSSI)", HFILL } },
1179     { &hf_80211n_mac_phy_rssi_ant3_ctl,
1180        { "Antenna 3 control RSSI", "ppi.80211n-mac-phy.rssi.ant3ctl",
1181          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 3 Control Channel Received Signal Strength Indication (RSSI)", HFILL } },
1182     { &hf_80211n_mac_phy_rssi_ant0_ext,
1183        { "Antenna 0 extension RSSI", "ppi.80211n-mac-phy.rssi.ant0ext",
1184          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 0 Extension Channel Received Signal Strength Indication (RSSI)", HFILL } },
1185     { &hf_80211n_mac_phy_rssi_ant1_ext,
1186        { "Antenna 1 extension RSSI", "ppi.80211n-mac-phy.rssi.ant1ext",
1187          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 1 Extension Channel Received Signal Strength Indication (RSSI)", HFILL } },
1188     { &hf_80211n_mac_phy_rssi_ant2_ext,
1189        { "Antenna 2 extension RSSI", "ppi.80211n-mac-phy.rssi.ant2ext",
1190          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 2 Extension Channel Received Signal Strength Indication (RSSI)", HFILL } },
1191     { &hf_80211n_mac_phy_rssi_ant3_ext,
1192        { "Antenna 3 extension RSSI", "ppi.80211n-mac-phy.rssi.ant3ext",
1193          FT_UINT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Antenna 3 Extension Channel Received Signal Strength Indication (RSSI)", HFILL } },
1194     { &hf_80211n_mac_phy_ext_chan_freq,
1195        { "Extended channel frequency", "ppi.80211-mac-phy.ext-chan.freq",
1196          FT_UINT16, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Extended Channel Frequency", HFILL } },
1197     { &hf_80211n_mac_phy_ext_chan_flags,
1198        { "Channel type", "ppi.80211-mac-phy.ext-chan.type",
1199          FT_UINT16, BASE_HEX, VALS(vs_80211_common_phy_type), 0x0, "PPI 802.11n MAC+PHY Channel Type", HFILL } },
1200     { &hf_80211n_mac_phy_ext_chan_flags_turbo,
1201        { "Turbo", "ppi.80211-mac-phy.ext-chan.type.turbo",
1202          FT_BOOLEAN, 16, NULL, 0x0010, "PPI 802.11n MAC+PHY Channel Type Turbo", HFILL } },
1203     { &hhf_80211n_mac_phy_ext_chan_flags_cck,
1204        { "Complementary Code Keying (CCK)", "ppi.80211-mac-phy.ext-chan.type.cck",
1205          FT_BOOLEAN, 16, NULL, 0x0020, "PPI 802.11n MAC+PHY Channel Type Complementary Code Keying (CCK) Modulation", HFILL } },
1206     { &hf_80211n_mac_phy_ext_chan_flags_ofdm,
1207        { "Orthogonal Frequency-Division Multiplexing (OFDM)", "ppi.80211-mac-phy.ext-chan.type.ofdm",
1208          FT_BOOLEAN, 16, NULL, 0x0040, "PPI 802.11n MAC+PHY Channel Type Orthogonal Frequency-Division Multiplexing (OFDM)", HFILL } },
1209     { &hhf_80211n_mac_phy_ext_chan_flags_2ghz,
1210        { "2 GHz spectrum", "ppi.80211-mac-phy.ext-chan.type.2ghz",
1211          FT_BOOLEAN, 16, NULL, 0x0080, "PPI 802.11n MAC+PHY Channel Type 2 GHz spectrum", HFILL } },
1212     { &hf_80211n_mac_phy_ext_chan_flags_5ghz,
1213        { "5 GHz spectrum", "ppi.80211-mac-phy.ext-chan.type.5ghz",
1214          FT_BOOLEAN, 16, NULL, 0x0100, "PPI 802.11n MAC+PHY Channel Type 5 GHz spectrum", HFILL } },
1215     { &hf_80211n_mac_phy_ext_chan_flags_passive,
1216        { "Passive", "ppi.80211-mac-phy.ext-chan.type.passive",
1217          FT_BOOLEAN, 16, NULL, 0x0200, "PPI 802.11n MAC+PHY Channel Type Passive", HFILL } },
1218     { &hf_80211n_mac_phy_ext_chan_flags_dynamic,
1219        { "Dynamic CCK-OFDM", "ppi.80211-mac-phy.ext-chan.type.dynamic",
1220          FT_BOOLEAN, 16, NULL, 0x0400, "PPI 802.11n MAC+PHY Channel Type Dynamic CCK-OFDM Channel", HFILL } },
1221     { &hf_80211n_mac_phy_ext_chan_flags_gfsk,
1222        { "Gaussian Frequency Shift Keying (GFSK)", "ppi.80211-mac-phy.ext-chan.type.gfsk",
1223          FT_BOOLEAN, 16, NULL, 0x0800, "PPI 802.11n MAC+PHY Channel Type Gaussian Frequency Shift Keying (GFSK) Modulation", HFILL } },
1224     { &hf_80211n_mac_phy_dbm_ant0signal,
1225        { "dBm antenna 0 signal", "ppi.80211n-mac-phy.dbmant0.signal",
1226          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 0 Signal", HFILL } },
1227     { &hf_80211n_mac_phy_dbm_ant0noise,
1228        { "dBm antenna 0 noise", "ppi.80211n-mac-phy.dbmant0.noise",
1229          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 0 Noise", HFILL } },
1230     { &hf_80211n_mac_phy_dbm_ant1signal,
1231        { "dBm antenna 1 signal", "ppi.80211n-mac-phy.dbmant1.signal",
1232          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 1 Signal", HFILL } },
1233     { &hf_80211n_mac_phy_dbm_ant1noise,
1234        { "dBm antenna 1 noise", "ppi.80211n-mac-phy.dbmant1.noise",
1235          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 1 Noise", HFILL } },
1236     { &hf_80211n_mac_phy_dbm_ant2signal,
1237        { "dBm antenna 2 signal", "ppi.80211n-mac-phy.dbmant2.signal",
1238          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 2 Signal", HFILL } },
1239     { &hf_80211n_mac_phy_dbm_ant2noise,
1240        { "dBm antenna 2 noise", "ppi.80211n-mac-phy.dbmant2.noise",
1241          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 2 Noise", HFILL } },
1242     { &hf_80211n_mac_phy_dbm_ant3signal,
1243        { "dBm antenna 3 signal", "ppi.80211n-mac-phy.dbmant3.signal",
1244          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 3 Signal", HFILL } },
1245     { &hf_80211n_mac_phy_dbm_ant3noise,
1246        { "dBm antenna 3 noise", "ppi.80211n-mac-phy.dbmant3.noise",
1247          FT_INT8, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY dBm Antenna 3 Noise", HFILL } },
1248     { &hf_80211n_mac_phy_evm0,
1249        { "EVM-0", "ppi.80211n-mac-phy.evm0",
1250          FT_UINT32, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Error Vector Magnitude (EVM) for chain 0", HFILL } },
1251     { &hf_80211n_mac_phy_evm1,
1252        { "EVM-1", "ppi.80211n-mac-phy.evm1",
1253          FT_UINT32, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Error Vector Magnitude (EVM) for chain 1", HFILL } },
1254     { &hf_80211n_mac_phy_evm2,
1255        { "EVM-2", "ppi.80211n-mac-phy.evm2",
1256          FT_UINT32, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Error Vector Magnitude (EVM) for chain 2", HFILL } },
1257     { &hf_80211n_mac_phy_evm3,
1258        { "EVM-3", "ppi.80211n-mac-phy.evm3",
1259          FT_UINT32, BASE_DEC, NULL, 0x0, "PPI 802.11n MAC+PHY Error Vector Magnitude (EVM) for chain 3", HFILL } },
1260
1261     { &hf_ampdu_segment,
1262         { "A-MPDU", "ppi.80211n-mac.ampdu",
1263             FT_FRAMENUM, BASE_NONE, NULL, 0x0, "802.11n Aggregated MAC Protocol Data Unit (A-MPDU)", HFILL }},
1264     { &hf_ampdu_segments,
1265         { "Reassembled A-MPDU", "ppi.80211n-mac.ampdu.reassembled",
1266             FT_NONE, BASE_NONE, NULL, 0x0, "Reassembled Aggregated MAC Protocol Data Unit (A-MPDU)", HFILL }},
1267     { &hf_ampdu_reassembled_in,
1268         { "Reassembled A-MPDU in frame", "ppi.80211n-mac.ampdu.reassembled_in",
1269             FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1270             "The A-MPDU that doesn't end in this segment is reassembled in this frame",
1271             HFILL }},
1272     { &hf_ampdu_count,
1273         { "MPDU count", "ppi.80211n-mac.ampdu.count",
1274             FT_UINT16, BASE_DEC, NULL, 0x0, "The number of aggregated MAC Protocol Data Units (MPDUs)", HFILL }},
1275
1276     { &hf_spectrum_map,
1277        { "Radio spectrum map", "ppi.spectrum-map",
1278             FT_BYTES, BASE_NONE, NULL, 0x0, "PPI Radio spectrum map", HFILL } },
1279     { &hf_process_info,
1280        { "Process information", "ppi.proc-info",
1281             FT_BYTES, BASE_NONE, NULL, 0x0, "PPI Process information", HFILL } },
1282     { &hf_capture_info,
1283        { "Capture information", "ppi.cap-info",
1284             FT_BYTES, BASE_NONE, NULL, 0x0, "PPI Capture information", HFILL } },
1285
1286     /* Aggregtion Extension */
1287     { &hf_aggregation_extension_interface_id,
1288        { "Interface ID", "ppi.aggregation_extension.interface_id",
1289             FT_UINT32, BASE_DEC, NULL, 0x0, "Zero-based index of the physical interface the packet was captured from", HFILL } },
1290
1291     /* 802.3 Extension */
1292     { &hf_8023_extension_flags,
1293        { "Flags", "ppi.8023_extension.flags",
1294             FT_UINT32, BASE_HEX, NULL, 0x0, "PPI 802.3 Extension Flags", HFILL } },
1295     { &hf_8023_extension_flags_fcs_present,
1296        { "FCS Present Flag", "ppi.8023_extension.flags.fcs_present",
1297             FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0001, "FCS (4 bytes) is present at the end of the packet", HFILL } },
1298     { &hf_8023_extension_errors,
1299        { "Errors", "ppi.8023_extension.errors",
1300             FT_UINT32, BASE_HEX, NULL, 0x0, "PPI 802.3 Extension Errors", HFILL } },
1301     { &hf_8023_extension_errors_fcs,
1302        { "FCS Error", "ppi.8023_extension.errors.fcs",
1303             FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0001,
1304             "PPI 802.3 Extension FCS Error", HFILL } },
1305     { &hf_8023_extension_errors_sequence,
1306        { "Sequence Error", "ppi.8023_extension.errors.sequence",
1307             FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0002,
1308             "PPI 802.3 Extension Sequence Error", HFILL } },
1309     { &hf_8023_extension_errors_symbol,
1310        { "Symbol Error", "ppi.8023_extension.errors.symbol",
1311             FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0004,
1312             "PPI 802.3 Extension Symbol Error", HFILL } },
1313     { &hf_8023_extension_errors_data,
1314        { "Data Error", "ppi.8023_extension.errors.data",
1315             FT_BOOLEAN, 32, TFS(&tfs_true_false), 0x0008,
1316             "PPI 802.3 Extension Data Error", HFILL } },
1317
1318     };
1319
1320     static gint *ett[] = {
1321         &ett_ppi_pph,
1322         &ett_ppi_flags,
1323         &ett_dot11_common,
1324         &ett_dot11_common_flags,
1325         &ett_dot11_common_channel_flags,
1326         &ett_dot11n_mac,
1327         &ett_dot11n_mac_flags,
1328         &ett_dot11n_mac_phy,
1329         &ett_dot11n_mac_phy_ext_channel_flags,
1330         &ett_ampdu_segments,
1331         &ett_ampdu,
1332         &ett_ampdu_segment,
1333         &ett_aggregation_extension,
1334         &ett_8023_extension,
1335         &ett_8023_extension_flags,
1336         &ett_8023_extension_errors
1337     };
1338
1339     module_t *ppi_module;
1340
1341     proto_ppi = proto_register_protocol("PPI Packet Header", "PPI", "ppi");
1342     proto_register_field_array(proto_ppi, hf, array_length(hf));
1343     proto_register_subtree_array(ett, array_length(ett));
1344     register_dissector("ppi", dissect_ppi, proto_ppi);
1345
1346     register_init_routine(ampdu_reassemble_init);
1347
1348     /* Configuration options */
1349     ppi_module = prefs_register_protocol(proto_ppi, NULL);
1350     prefs_register_bool_preference(ppi_module, "reassemble",
1351                                    "Reassemble fragmented 802.11 A-MPDUs",
1352                                    "Whether fragmented 802.11 aggregated MPDUs should be reassembled",
1353                                    &ppi_ampdu_reassemble);
1354 }
1355
1356 void
1357 proto_reg_handoff_ppi(void)
1358 {
1359     dissector_handle_t ppi_handle;
1360
1361     ppi_handle = create_dissector_handle(dissect_ppi, proto_ppi);
1362     data_handle = find_dissector("data");
1363     ieee80211_ht_handle = find_dissector("wlan_ht");
1364     ppi_gps_handle = find_dissector("ppi_gps");
1365     ppi_vector_handle = find_dissector("ppi_vector");
1366     ppi_sensor_handle = find_dissector("ppi_sensor");
1367     ppi_antenna_handle = find_dissector("ppi_antenna");
1368
1369     dissector_add_uint("wtap_encap", WTAP_ENCAP_PPI, ppi_handle);
1370 }
1371
1372 /*
1373  * Editor modelines
1374  *
1375  * Local Variables:
1376  * c-basic-offset: 4
1377  * tab-width: 8
1378  * indent-tabs-mode: nil
1379  * End:
1380  *
1381  * ex: set shiftwidth=4 tabstop=8 expandtab:
1382  * :indentSize=4:tabSize=8:noTabs=true:
1383  */