opa: Add dissectors for Intel’s Omni-Path Architecture (OPA)
[metze/wireshark/wip.git] / wiretap / peekclassic.c
index 613018e2dd7715339515780c58d0794020bf68ff..5cbefbb3944f819e5c7f4378a6d527de9af04208 100644 (file)
@@ -1,9 +1,9 @@
 /* peekclassic.c
- * Routines for opening files in what WildPackets calls the classic file
- * format in the description of their "PeekRdr Sample Application" (C++
- * source code to read their capture files, downloading of which requires
- * a maintenance contract, so it's not free as in beer and probably not
- * as in speech, either).
+ * Routines for opening files in what Savvius (formerly WildPackets) calls
+ * the classic file format in the description of their "PeekRdr Sample
+ * Application" (C++ source code to read their capture files, downloading
+ * of which requires a maintenance contract, so it's not free as in beer
+ * and probably not as in speech, either).
  *
  * As that description says, it's used by AiroPeek and AiroPeek NX prior
  * to 2.0, EtherPeek prior to 6.0, and EtherPeek NX prior to 3.0.  It
@@ -257,7 +257,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info)
                                 * some radio information.  Presumably
                                 * this is from AiroPeek.
                                 */
-                               file_encap = WTAP_ENCAP_IEEE_802_11_AIROPEEK;
+                               file_encap = WTAP_ENCAP_IEEE_802_11_WITH_RADIO;
                                break;
 
                        default:
@@ -395,6 +395,8 @@ static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
        return TRUE;
 }
 
+#define RADIO_INFO_SIZE        4
+
 static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
     struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
 {
@@ -411,6 +413,7 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
        guint64 timestamp;
        time_t tsecs;
        guint32 tusecs;
+       guint8 radio_info[RADIO_INFO_SIZE];
 
        if (!wtap_read_bytes_or_eof(fh, ep_pkt, sizeof(ep_pkt), err, err_info))
                return -1;
@@ -431,6 +434,11 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
        if (0 == sliceLength) {
                sliceLength = length;
        }
+       /*
+        * The maximum value of sliceLength and length are 65535, which
+        * are less than WTAP_MAX_PACKET_SIZE will ever be, so we don't
+        * need to check them.
+        */
 
        /* fill in packet header values */
        phdr->rec_type = REC_TYPE_PACKET;
@@ -444,10 +452,54 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
 
        switch (wth->file_encap) {
 
-       case WTAP_ENCAP_IEEE_802_11_AIROPEEK:
-               phdr->pseudo_header.ieee_802_11.presence_flags = 0;     /* not present */
+       case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
+               memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11));
                phdr->pseudo_header.ieee_802_11.fcs_len = 0;            /* no FCS */
                phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
+               phdr->pseudo_header.ieee_802_11.datapad = FALSE;
+               phdr->pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN;
+
+               /*
+                * Now process the radio information pseudo-header.
+                * It's a 4-byte pseudo-header, consisting of:
+                *
+                *   1 byte of data rate, in units of 500 kb/s;
+                *
+                *   1 byte of channel number;
+                *
+                *   1 byte of signal strength as a percentage of
+                *   the maximum, i.e. (RXVECTOR RSSI/RXVECTOR RSSI_Max)*100,
+                *   or, at least, that's what I infer it is, given what
+                *   the WildPackets note "Converting Signal Strength
+                *   Percentage to dBm Values" says (it also says that
+                *   the conversion the percentage to a dBm value is
+                *   an adapter-dependent process, so, as we don't know
+                *   what type of adapter was used to do the capture,
+                *   we can't do the conversion);
+                *
+                *   1 byte of unknown content (padding?).
+                */
+               if (phdr->len < RADIO_INFO_SIZE || phdr->caplen < RADIO_INFO_SIZE) {
+                       *err = WTAP_ERR_BAD_FILE;
+                       *err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 4");
+                       return -1;
+               }
+               phdr->len -= RADIO_INFO_SIZE;
+               phdr->caplen -= RADIO_INFO_SIZE;
+               sliceLength -= RADIO_INFO_SIZE;
+
+               /* read the pseudo-header */
+               if (!wtap_read_bytes(fh, radio_info, RADIO_INFO_SIZE, err, err_info))
+                       return -1;
+
+               phdr->pseudo_header.ieee_802_11.has_data_rate = TRUE;
+               phdr->pseudo_header.ieee_802_11.data_rate = radio_info[0];
+
+               phdr->pseudo_header.ieee_802_11.has_channel = TRUE;
+               phdr->pseudo_header.ieee_802_11.channel = radio_info[1];
+
+               phdr->pseudo_header.ieee_802_11.has_signal_percent = TRUE;
+               phdr->pseudo_header.ieee_802_11.signal_percent = radio_info[2];
 
                /*
                 * The last 4 bytes appear to be random data - the length
@@ -459,7 +511,7 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
                 */
                if (phdr->len < 4 || phdr->caplen < 4) {
                        *err = WTAP_ERR_BAD_FILE;
-                       *err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 4");
+                       *err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 8");
                        return -1;
                }
                phdr->len -= 4;
@@ -566,6 +618,11 @@ static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
        if (0 == sliceLength) {
                sliceLength = length;
        }
+       /*
+        * The maximum value of sliceLength and length are 65535, which
+        * are less than WTAP_MAX_PACKET_SIZE will ever be, so we don't
+        * need to check them.
+        */
 
        /* fill in packet header values */
        phdr->rec_type = REC_TYPE_PACKET;