1 // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2 package edu.uci.iotproject;
4 import io.kaitai.struct.ByteBufferKaitaiStream;
5 import io.kaitai.struct.KaitaiStruct;
6 import io.kaitai.struct.KaitaiStream;
7 import java.io.IOException;
9 import java.util.HashMap;
10 import java.util.ArrayList;
14 * PPI is a standard for link layer packet encapsulation, proposed as
15 * generic extensible container to store both captured in-band data and
16 * out-of-band data. Originally it was developed to provide 802.11n
17 * radio information, but can be used for other purposes as well.
19 * Sample capture: https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=Http.cap
20 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 3</a>
22 public class PacketPpi extends KaitaiStruct {
23 public static PacketPpi fromFile(String fileName) throws IOException {
24 return new PacketPpi(new ByteBufferKaitaiStream(fileName));
28 RADIO_802_11_COMMON(2),
29 RADIO_802_11N_MAC_EXT(3),
30 RADIO_802_11N_MAC_PHY_EXT(4),
35 private final long id;
36 PfhType(long id) { this.id = id; }
37 public long id() { return id; }
38 private static final Map<Long, PfhType> byId = new HashMap<Long, PfhType>(6);
40 for (PfhType e : PfhType.values())
43 public static PfhType byId(long id) { return byId.get(id); }
46 public enum Linktype {
66 IEEE802_11_PRISM(119),
69 IEEE802_11_RADIOTAP(127),
71 APPLE_IP_OVER_IEEE1394(138),
101 BLUETOOTH_HCI_H4(187),
107 BLUETOOTH_HCI_H4_WITH_PHDR(201),
111 C_HDLC_WITH_DIR(205),
112 FRELAY_WITH_DIR(206),
114 IEEE802_15_4_NONASK_PHY(215),
115 USB_LINUX_MMAPPED(220),
117 FC_2_WITH_FRAME_DELIMS(225),
122 IEEE802_15_4_NOFCS(230),
126 STANAG_5066_D_PDU(237),
129 NETANALYZER_TRANSPARENT(241),
138 BLUETOOTH_LE_LL(251),
140 BLUETOOTH_LINUX_MONITOR(254),
141 BLUETOOTH_BREDR_BB(255),
142 BLUETOOTH_LE_LL_WITH_PHDR(256),
149 WATTSTOPPER_DLM(263),
152 private final long id;
153 Linktype(long id) { this.id = id; }
154 public long id() { return id; }
155 private static final Map<Long, Linktype> byId = new HashMap<Long, Linktype>(104);
157 for (Linktype e : Linktype.values())
160 public static Linktype byId(long id) { return byId.get(id); }
163 public PacketPpi(KaitaiStream _io) {
164 this(_io, null, null);
167 public PacketPpi(KaitaiStream _io, KaitaiStruct _parent) {
168 this(_io, _parent, null);
171 public PacketPpi(KaitaiStream _io, KaitaiStruct _parent, PacketPpi _root) {
173 this._parent = _parent;
174 this._root = _root == null ? this : _root;
177 private void _read() {
178 this.header = new PacketPpiHeader(this._io, this, _root);
179 this._raw_fields = this._io.readBytes((header().pphLen() - 8));
180 KaitaiStream _io__raw_fields = new ByteBufferKaitaiStream(_raw_fields);
181 this.fields = new PacketPpiFields(_io__raw_fields, this, _root);
182 switch (header().pphDlt()) {
184 this._raw_body = this._io.readBytesFull();
185 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
186 this.body = new PacketPpi(_io__raw_body);
190 this._raw_body = this._io.readBytesFull();
191 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
192 this.body = new EthernetFrame(_io__raw_body);
196 this.body = this._io.readBytesFull();
201 public static class PacketPpiFields extends KaitaiStruct {
202 public static PacketPpiFields fromFile(String fileName) throws IOException {
203 return new PacketPpiFields(new ByteBufferKaitaiStream(fileName));
206 public PacketPpiFields(KaitaiStream _io) {
207 this(_io, null, null);
210 public PacketPpiFields(KaitaiStream _io, PacketPpi _parent) {
211 this(_io, _parent, null);
214 public PacketPpiFields(KaitaiStream _io, PacketPpi _parent, PacketPpi _root) {
216 this._parent = _parent;
220 private void _read() {
221 this.entries = new ArrayList<PacketPpiField>();
224 while (!this._io.isEof()) {
225 this.entries.add(new PacketPpiField(this._io, this, _root));
230 private ArrayList<PacketPpiField> entries;
231 private PacketPpi _root;
232 private PacketPpi _parent;
233 public ArrayList<PacketPpiField> entries() { return entries; }
234 public PacketPpi _root() { return _root; }
235 public PacketPpi _parent() { return _parent; }
239 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 4.1.3</a>
241 public static class Radio80211nMacExtBody extends KaitaiStruct {
242 public static Radio80211nMacExtBody fromFile(String fileName) throws IOException {
243 return new Radio80211nMacExtBody(new ByteBufferKaitaiStream(fileName));
246 public Radio80211nMacExtBody(KaitaiStream _io) {
247 this(_io, null, null);
250 public Radio80211nMacExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) {
251 this(_io, _parent, null);
254 public Radio80211nMacExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) {
256 this._parent = _parent;
260 private void _read() {
261 this.flags = new MacFlags(this._io, this, _root);
262 this.aMpduId = this._io.readU4le();
263 this.numDelimiters = this._io.readU1();
264 this.reserved = this._io.readBytes(3);
266 private MacFlags flags;
267 private long aMpduId;
268 private int numDelimiters;
269 private byte[] reserved;
270 private PacketPpi _root;
271 private PacketPpi.PacketPpiField _parent;
272 public MacFlags flags() { return flags; }
273 public long aMpduId() { return aMpduId; }
274 public int numDelimiters() { return numDelimiters; }
275 public byte[] reserved() { return reserved; }
276 public PacketPpi _root() { return _root; }
277 public PacketPpi.PacketPpiField _parent() { return _parent; }
279 public static class MacFlags extends KaitaiStruct {
280 public static MacFlags fromFile(String fileName) throws IOException {
281 return new MacFlags(new ByteBufferKaitaiStream(fileName));
284 public MacFlags(KaitaiStream _io) {
285 this(_io, null, null);
288 public MacFlags(KaitaiStream _io, KaitaiStruct _parent) {
289 this(_io, _parent, null);
292 public MacFlags(KaitaiStream _io, KaitaiStruct _parent, PacketPpi _root) {
294 this._parent = _parent;
298 private void _read() {
299 this.unused1 = this._io.readBitsInt(1) != 0;
300 this.aggregateDelimiter = this._io.readBitsInt(1) != 0;
301 this.moreAggregates = this._io.readBitsInt(1) != 0;
302 this.aggregate = this._io.readBitsInt(1) != 0;
303 this.dupRx = this._io.readBitsInt(1) != 0;
304 this.rxShortGuard = this._io.readBitsInt(1) != 0;
305 this.isHt40 = this._io.readBitsInt(1) != 0;
306 this.greenfield = this._io.readBitsInt(1) != 0;
307 this._io.alignToByte();
308 this.unused2 = this._io.readBytes(3);
310 private boolean unused1;
311 private boolean aggregateDelimiter;
312 private boolean moreAggregates;
313 private boolean aggregate;
314 private boolean dupRx;
315 private boolean rxShortGuard;
316 private boolean isHt40;
317 private boolean greenfield;
318 private byte[] unused2;
319 private PacketPpi _root;
320 private KaitaiStruct _parent;
321 public boolean unused1() { return unused1; }
324 * Aggregate delimiter CRC error after this frame
326 public boolean aggregateDelimiter() { return aggregateDelimiter; }
331 public boolean moreAggregates() { return moreAggregates; }
336 public boolean aggregate() { return aggregate; }
341 public boolean dupRx() { return dupRx; }
344 * RX short guard interval (SGI)
346 public boolean rxShortGuard() { return rxShortGuard; }
349 * true = HT40, false = HT20
351 public boolean isHt40() { return isHt40; }
356 public boolean greenfield() { return greenfield; }
357 public byte[] unused2() { return unused2; }
358 public PacketPpi _root() { return _root; }
359 public KaitaiStruct _parent() { return _parent; }
363 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 3.1</a>
365 public static class PacketPpiHeader extends KaitaiStruct {
366 public static PacketPpiHeader fromFile(String fileName) throws IOException {
367 return new PacketPpiHeader(new ByteBufferKaitaiStream(fileName));
370 public PacketPpiHeader(KaitaiStream _io) {
371 this(_io, null, null);
374 public PacketPpiHeader(KaitaiStream _io, PacketPpi _parent) {
375 this(_io, _parent, null);
378 public PacketPpiHeader(KaitaiStream _io, PacketPpi _parent, PacketPpi _root) {
380 this._parent = _parent;
384 private void _read() {
385 this.pphVersion = this._io.readU1();
386 this.pphFlags = this._io.readU1();
387 this.pphLen = this._io.readU2le();
388 this.pphDlt = PacketPpi.Linktype.byId(this._io.readU4le());
390 private int pphVersion;
391 private int pphFlags;
393 private Linktype pphDlt;
394 private PacketPpi _root;
395 private PacketPpi _parent;
396 public int pphVersion() { return pphVersion; }
397 public int pphFlags() { return pphFlags; }
398 public int pphLen() { return pphLen; }
399 public Linktype pphDlt() { return pphDlt; }
400 public PacketPpi _root() { return _root; }
401 public PacketPpi _parent() { return _parent; }
405 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 4.1.2</a>
407 public static class Radio80211CommonBody extends KaitaiStruct {
408 public static Radio80211CommonBody fromFile(String fileName) throws IOException {
409 return new Radio80211CommonBody(new ByteBufferKaitaiStream(fileName));
412 public Radio80211CommonBody(KaitaiStream _io) {
413 this(_io, null, null);
416 public Radio80211CommonBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) {
417 this(_io, _parent, null);
420 public Radio80211CommonBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) {
422 this._parent = _parent;
426 private void _read() {
427 this.tsfTimer = this._io.readU8le();
428 this.flags = this._io.readU2le();
429 this.rate = this._io.readU2le();
430 this.channelFreq = this._io.readU2le();
431 this.channelFlags = this._io.readU2le();
432 this.fhssHopset = this._io.readU1();
433 this.fhssPattern = this._io.readU1();
434 this.dbmAntsignal = this._io.readS1();
435 this.dbmAntnoise = this._io.readS1();
437 private long tsfTimer;
440 private int channelFreq;
441 private int channelFlags;
442 private int fhssHopset;
443 private int fhssPattern;
444 private byte dbmAntsignal;
445 private byte dbmAntnoise;
446 private PacketPpi _root;
447 private PacketPpi.PacketPpiField _parent;
448 public long tsfTimer() { return tsfTimer; }
449 public int flags() { return flags; }
450 public int rate() { return rate; }
451 public int channelFreq() { return channelFreq; }
452 public int channelFlags() { return channelFlags; }
453 public int fhssHopset() { return fhssHopset; }
454 public int fhssPattern() { return fhssPattern; }
455 public byte dbmAntsignal() { return dbmAntsignal; }
456 public byte dbmAntnoise() { return dbmAntnoise; }
457 public PacketPpi _root() { return _root; }
458 public PacketPpi.PacketPpiField _parent() { return _parent; }
462 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 3.1</a>
464 public static class PacketPpiField extends KaitaiStruct {
465 public static PacketPpiField fromFile(String fileName) throws IOException {
466 return new PacketPpiField(new ByteBufferKaitaiStream(fileName));
469 public PacketPpiField(KaitaiStream _io) {
470 this(_io, null, null);
473 public PacketPpiField(KaitaiStream _io, PacketPpi.PacketPpiFields _parent) {
474 this(_io, _parent, null);
477 public PacketPpiField(KaitaiStream _io, PacketPpi.PacketPpiFields _parent, PacketPpi _root) {
479 this._parent = _parent;
483 private void _read() {
484 this.pfhType = PacketPpi.PfhType.byId(this._io.readU2le());
485 this.pfhDatalen = this._io.readU2le();
487 case RADIO_802_11_COMMON: {
488 this._raw_body = this._io.readBytes(pfhDatalen());
489 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
490 this.body = new Radio80211CommonBody(_io__raw_body, this, _root);
493 case RADIO_802_11N_MAC_EXT: {
494 this._raw_body = this._io.readBytes(pfhDatalen());
495 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
496 this.body = new Radio80211nMacExtBody(_io__raw_body, this, _root);
499 case RADIO_802_11N_MAC_PHY_EXT: {
500 this._raw_body = this._io.readBytes(pfhDatalen());
501 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
502 this.body = new Radio80211nMacPhyExtBody(_io__raw_body, this, _root);
506 this.body = this._io.readBytes(pfhDatalen());
511 private PfhType pfhType;
512 private int pfhDatalen;
514 private PacketPpi _root;
515 private PacketPpi.PacketPpiFields _parent;
516 private byte[] _raw_body;
517 public PfhType pfhType() { return pfhType; }
518 public int pfhDatalen() { return pfhDatalen; }
519 public Object body() { return body; }
520 public PacketPpi _root() { return _root; }
521 public PacketPpi.PacketPpiFields _parent() { return _parent; }
522 public byte[] _raw_body() { return _raw_body; }
526 * @see <a href="https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf">PPI header format spec, section 4.1.4</a>
528 public static class Radio80211nMacPhyExtBody extends KaitaiStruct {
529 public static Radio80211nMacPhyExtBody fromFile(String fileName) throws IOException {
530 return new Radio80211nMacPhyExtBody(new ByteBufferKaitaiStream(fileName));
533 public Radio80211nMacPhyExtBody(KaitaiStream _io) {
534 this(_io, null, null);
537 public Radio80211nMacPhyExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent) {
538 this(_io, _parent, null);
541 public Radio80211nMacPhyExtBody(KaitaiStream _io, PacketPpi.PacketPpiField _parent, PacketPpi _root) {
543 this._parent = _parent;
547 private void _read() {
548 this.flags = new MacFlags(this._io, this, _root);
549 this.aMpduId = this._io.readU4le();
550 this.numDelimiters = this._io.readU1();
551 this.mcs = this._io.readU1();
552 this.numStreams = this._io.readU1();
553 this.rssiCombined = this._io.readU1();
554 rssiAntCtl = new ArrayList<Integer>((int) (4));
555 for (int i = 0; i < 4; i++) {
556 this.rssiAntCtl.add(this._io.readU1());
558 rssiAntExt = new ArrayList<Integer>((int) (4));
559 for (int i = 0; i < 4; i++) {
560 this.rssiAntExt.add(this._io.readU1());
562 this.extChannelFreq = this._io.readU2le();
563 this.extChannelFlags = new ChannelFlags(this._io, this, _root);
564 rfSignalNoise = new ArrayList<SignalNoise>((int) (4));
565 for (int i = 0; i < 4; i++) {
566 this.rfSignalNoise.add(new SignalNoise(this._io, this, _root));
568 evm = new ArrayList<Long>((int) (4));
569 for (int i = 0; i < 4; i++) {
570 this.evm.add(this._io.readU4le());
573 public static class ChannelFlags extends KaitaiStruct {
574 public static ChannelFlags fromFile(String fileName) throws IOException {
575 return new ChannelFlags(new ByteBufferKaitaiStream(fileName));
578 public ChannelFlags(KaitaiStream _io) {
579 this(_io, null, null);
582 public ChannelFlags(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent) {
583 this(_io, _parent, null);
586 public ChannelFlags(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent, PacketPpi _root) {
588 this._parent = _parent;
592 private void _read() {
593 this.spectrum2ghz = this._io.readBitsInt(1) != 0;
594 this.ofdm = this._io.readBitsInt(1) != 0;
595 this.cck = this._io.readBitsInt(1) != 0;
596 this.turbo = this._io.readBitsInt(1) != 0;
597 this.unused = this._io.readBitsInt(8);
598 this.gfsk = this._io.readBitsInt(1) != 0;
599 this.dynCckOfdm = this._io.readBitsInt(1) != 0;
600 this.onlyPassiveScan = this._io.readBitsInt(1) != 0;
601 this.spectrum5ghz = this._io.readBitsInt(1) != 0;
603 private boolean spectrum2ghz;
604 private boolean ofdm;
606 private boolean turbo;
608 private boolean gfsk;
609 private boolean dynCckOfdm;
610 private boolean onlyPassiveScan;
611 private boolean spectrum5ghz;
612 private PacketPpi _root;
613 private PacketPpi.Radio80211nMacPhyExtBody _parent;
618 public boolean spectrum2ghz() { return spectrum2ghz; }
621 * OFDM (Orthogonal Frequency-Division Multiplexing)
623 public boolean ofdm() { return ofdm; }
626 * CCK (Complementary Code Keying)
628 public boolean cck() { return cck; }
629 public boolean turbo() { return turbo; }
630 public long unused() { return unused; }
633 * Gaussian Frequency Shift Keying
635 public boolean gfsk() { return gfsk; }
640 public boolean dynCckOfdm() { return dynCckOfdm; }
643 * Only passive scan allowed
645 public boolean onlyPassiveScan() { return onlyPassiveScan; }
650 public boolean spectrum5ghz() { return spectrum5ghz; }
651 public PacketPpi _root() { return _root; }
652 public PacketPpi.Radio80211nMacPhyExtBody _parent() { return _parent; }
656 * RF signal + noise pair at a single antenna
658 public static class SignalNoise extends KaitaiStruct {
659 public static SignalNoise fromFile(String fileName) throws IOException {
660 return new SignalNoise(new ByteBufferKaitaiStream(fileName));
663 public SignalNoise(KaitaiStream _io) {
664 this(_io, null, null);
667 public SignalNoise(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent) {
668 this(_io, _parent, null);
671 public SignalNoise(KaitaiStream _io, PacketPpi.Radio80211nMacPhyExtBody _parent, PacketPpi _root) {
673 this._parent = _parent;
677 private void _read() {
678 this.signal = this._io.readS1();
679 this.noise = this._io.readS1();
683 private PacketPpi _root;
684 private PacketPpi.Radio80211nMacPhyExtBody _parent;
689 public byte signal() { return signal; }
694 public byte noise() { return noise; }
695 public PacketPpi _root() { return _root; }
696 public PacketPpi.Radio80211nMacPhyExtBody _parent() { return _parent; }
698 private MacFlags flags;
699 private long aMpduId;
700 private int numDelimiters;
702 private int numStreams;
703 private int rssiCombined;
704 private ArrayList<Integer> rssiAntCtl;
705 private ArrayList<Integer> rssiAntExt;
706 private int extChannelFreq;
707 private ChannelFlags extChannelFlags;
708 private ArrayList<SignalNoise> rfSignalNoise;
709 private ArrayList<Long> evm;
710 private PacketPpi _root;
711 private PacketPpi.PacketPpiField _parent;
712 public MacFlags flags() { return flags; }
713 public long aMpduId() { return aMpduId; }
714 public int numDelimiters() { return numDelimiters; }
717 * Modulation Coding Scheme (MCS)
719 public int mcs() { return mcs; }
722 * Number of spatial streams (0 = unknown)
724 public int numStreams() { return numStreams; }
727 * RSSI (Received Signal Strength Indication), combined from all active antennas / channels
729 public int rssiCombined() { return rssiCombined; }
732 * RSSI (Received Signal Strength Indication) for antennas 0-3, control channel
734 public ArrayList<Integer> rssiAntCtl() { return rssiAntCtl; }
737 * RSSI (Received Signal Strength Indication) for antennas 0-3, extension channel
739 public ArrayList<Integer> rssiAntExt() { return rssiAntExt; }
742 * Extension channel frequency (MHz)
744 public int extChannelFreq() { return extChannelFreq; }
747 * Extension channel flags
749 public ChannelFlags extChannelFlags() { return extChannelFlags; }
752 * Signal + noise values for antennas 0-3
754 public ArrayList<SignalNoise> rfSignalNoise() { return rfSignalNoise; }
757 * EVM (Error Vector Magnitude) for chains 0-3
759 public ArrayList<Long> evm() { return evm; }
760 public PacketPpi _root() { return _root; }
761 public PacketPpi.PacketPpiField _parent() { return _parent; }
763 private PacketPpiHeader header;
764 private PacketPpiFields fields;
766 private PacketPpi _root;
767 private KaitaiStruct _parent;
768 private byte[] _raw_fields;
769 private byte[] _raw_body;
770 public PacketPpiHeader header() { return header; }
771 public PacketPpiFields fields() { return fields; }
772 public Object body() { return body; }
773 public PacketPpi _root() { return _root; }
774 public KaitaiStruct _parent() { return _parent; }
775 public byte[] _raw_fields() { return _raw_fields; }
776 public byte[] _raw_body() { return _raw_body; }