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