opa: Add dissectors for Intel’s Omni-Path Architecture (OPA)
[metze/wireshark/wip.git] / wiretap / k12.c
index 934e8d4ec5d05157a26ec5e867f9e0ad612c6543..b5558a0cf44667c9b78f47be4a715cd1cf234360 100644 (file)
@@ -29,9 +29,7 @@
 #include <errno.h>
 
 #include "wtap-int.h"
-#include "wtap.h"
 #include "file_wrappers.h"
-#include <wsutil/buffer.h>
 #include "k12.h"
 
 #include <wsutil/str_util.h>
@@ -71,9 +69,9 @@ void k12_fprintf(const char* fmt, ...) {
 
 #define CAT(a,b) a##b
 #define K12_DBG(level,args) do { if (level <= debug_level) { \
-       fprintf(dbg_out,"%s:%d: ",CAT(__FI,LE__),CAT(__LI,NE__)); \
-       k12_fprintf args ; \
-       fprintf(dbg_out,"\n"); \
+            fprintf(dbg_out,"%s:%d: ",CAT(__FI,LE__),CAT(__LI,NE__));   \
+            k12_fprintf args ;                                          \
+            fprintf(dbg_out,"\n");                                      \
 } } while(0)
 
 void k12_hex_ascii_dump(guint level, gint64 offset, const char* label, const unsigned char* b, unsigned int len) {
@@ -240,30 +238,30 @@ typedef struct _k12_src_desc_t {
  * with the "group" code followe by the "type" code.  The "group" values
  * are:
  *
- *     0x0001 - "data event"
- *     0x0002 - "text or L1 event"
- *     0x0007 - "configuration event"
+ *      0x0001 - "data event"
+ *      0x0002 - "text or L1 event"
+ *      0x0007 - "configuration event"
  *
  * and the "type" values are:
  *
  *  data events:
- *     0x0020 - "frame" (i.e., "an actual packet")
- *     0x0021 - "transparent frame"
- *     0x0022 - "bit data (TRAU frame)"
- *     0x0024 - "used to mark the frame which is a fragment"
- *     0x0026 - "used to mark the frame which is a fragment"
- *     0x0028 - "used to mark the frame which is generated by the LSA"
- *     0x002A - "used to mark the frame which is generated by the LSA"
+ *      0x0020 - "frame" (i.e., "an actual packet")
+ *      0x0021 - "transparent frame"
+ *      0x0022 - "bit data (TRAU frame)"
+ *      0x0024 - "used to mark the frame which is a fragment"
+ *      0x0026 - "used to mark the frame which is a fragment"
+ *      0x0028 - "used to mark the frame which is generated by the LSA"
+ *      0x002A - "used to mark the frame which is generated by the LSA"
  *
  *  text or L1 events:
- *     0x0030 - "text event"
- *     0x0031 - "L1 event"
- *     0x0032 - "L1 event (BAI)"
- *     0x0033 - "L1 event (VX)"
+ *      0x0030 - "text event"
+ *      0x0031 - "L1 event"
+ *      0x0032 - "L1 event (BAI)"
+ *      0x0033 - "L1 event (VX)"
  *
  *  configuration events:
- *     0x0040 - Logical Data Source configuration event
- *     0x0041 - Logical Link configuration event
+ *      0x0040 - Logical Data Source configuration event
+ *      0x0041 - Logical Link configuration event
  */
 /* so far we've seen these types of records */
 #define K12_REC_PACKET        0x00010020 /* an actual packet */
@@ -567,10 +565,10 @@ memiszero(const void *ptr, size_t count)
     const guint8 *p = (const guint8 *)ptr;
 
     while (count != 0) {
-       if (*p != 0)
-           return FALSE;
-       p++;
-       count--;
+        if (*p != 0)
+            return FALSE;
+        p++;
+        count--;
     }
     return TRUE;
 }
@@ -801,7 +799,7 @@ static void k12_close(wtap *wth) {
     k12_t *k12 = (k12_t *)wth->priv;
 
     destroy_k12_file_data(k12);
-    wth->priv = NULL;  /* destroy_k12_file_data freed it */
+    wth->priv = NULL;   /* destroy_k12_file_data freed it */
 #ifdef DEBUG_K12
     K12_DBG(5,("k12_close: CLOSED"));
     if (env_file) fclose(dbg_out);
@@ -828,14 +826,14 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
     gchar* env_level = getenv("K12_DEBUG_LEVEL");
     env_file = getenv("K12_DEBUG_FILENAME");
     if ( env_file ) {
-       dbg_out = ws_fopen(env_file,"w");
-       if (dbg_out == NULL) {
-               dbg_out = stderr;
-               K12_DBG(1,("unable to open K12 DEBUG FILENAME for writing!  Logging to standard error"));
-       }
+        dbg_out = ws_fopen(env_file,"w");
+        if (dbg_out == NULL) {
+                dbg_out = stderr;
+                K12_DBG(1,("unable to open K12 DEBUG FILENAME for writing!  Logging to standard error"));
+        }
     }
     else
-       dbg_out = stderr;
+        dbg_out = stderr;
     if ( env_level ) debug_level = (unsigned int)strtoul(env_level,NULL,10);
     K12_DBG(1,("k12_open: ENTER debug_level=%u",debug_level));
 #endif
@@ -861,8 +859,8 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
     if (memiszero(header_buffer + 0x10, K12_FILE_HDR_LEN - 0x10)) {
         /*
          * The rest of the file header is all zeroes.  That means
-        * this is a file written by the old Wireshark code, and
-        * a count of records in the file is at an offset of 0x0C.
+         * this is a file written by the old Wireshark code, and
+         * a count of records in the file is at an offset of 0x0C.
          */
         file_data->num_of_records = pntoh32( header_buffer + 0x0C );
     } else {
@@ -1009,7 +1007,7 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
                         rec->input_info.ds0mask = 0x00000000;
                         if (hwpart_len > K12_SRCDESC_DS0_MASK) {
                             for (i = 0; i < hwpart_len - K12_SRCDESC_DS0_MASK; i++) {
-                                rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 0x1<<(31-i) : 0x0;
+                                rec->input_info.ds0mask |= ( *(read_buffer + K12_SRCDESC_HWPART + K12_SRCDESC_DS0_MASK + i) == 0xff ) ? 1U<<(31-i) : 0x0;
                             }
                         }
                         break;
@@ -1094,9 +1092,9 @@ wtap_open_return_val k12_open(wtap *wth, int *err, gchar **err_info) {
 }
 
 typedef struct {
-       guint32 file_len;
-       guint32 num_of_records;
-       guint32 file_offset;
+    guint32 file_len;
+    guint32 num_of_records;
+    guint32 file_offset;
 } k12_dump_t;
 
 int k12_dump_can_write_encap(int encap) {
@@ -1249,7 +1247,7 @@ static void k12_dump_src_setting(gpointer k _U_, gpointer v, gpointer p) {
 }
 
 static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
-                         const guint8 *pd, int *err) {
+                         const guint8 *pd, int *err, gchar **err_info _U_) {
     const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
     k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
     guint32 len;
@@ -1271,7 +1269,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
 
     /* We can only write packet records. */
     if (phdr->rec_type != REC_TYPE_PACKET) {
-        *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
+        *err = WTAP_ERR_UNWRITABLE_REC_TYPE;
         return FALSE;
     }
 
@@ -1304,7 +1302,7 @@ static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
 
 static const guint8 k12_eof[] = {0xff,0xff};
 
-static gboolean k12_dump_close(wtap_dumper *wdh, int *err) {
+static gboolean k12_dump_finish(wtap_dumper *wdh, int *err) {
     k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
     union {
         guint8 b[sizeof(guint32)];
@@ -1362,7 +1360,7 @@ gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
         return FALSE;
 
     wdh->subtype_write = k12_dump;
-    wdh->subtype_close = k12_dump_close;
+    wdh->subtype_finish = k12_dump_finish;
 
     k12 = (k12_dump_t *)g_malloc(sizeof(k12_dump_t));
     wdh->priv = (void *)k12;
@@ -1372,3 +1370,16 @@ gboolean k12_dump_open(wtap_dumper *wdh, int *err) {
 
     return TRUE;
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */