Add support for verifying CIP Safety CRC values.
authorMichael Mann <mmann78@netscape.net>
Mon, 13 Mar 2017 19:20:49 +0000 (15:20 -0400)
committerAnders Broman <a.broman58@gmail.com>
Thu, 16 Mar 2017 05:51:04 +0000 (05:51 +0000)
Change-Id: I44f7ff6980f27b1a0d4199a91f9b217aec7e4652
Reviewed-on: https://code.wireshark.org/review/20557
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
13 files changed:
debian/libwsutil0.symbols
epan/dissectors/packet-cip.c
epan/dissectors/packet-cip.h
epan/dissectors/packet-cipsafety.c
epan/dissectors/packet-cipsafety.h
epan/dissectors/packet-enip.c
epan/dissectors/packet-enip.h
wsutil/crc16.c
wsutil/crc16.h
wsutil/crc32.c
wsutil/crc32.h
wsutil/crc8.c
wsutil/crc8.h

index 9c2bb43437b377e6a3d34e27060788fd6f80c100..5da393df84afa329d46153a57a3a193d984dcdc8 100644 (file)
@@ -14,6 +14,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
  copy_file_binary_mode@Base 1.12.0~rc1
  copy_persconffile_profile@Base 1.12.0~rc1
  crc11_307_noreflect_noxor@Base 1.10.0
+ crc16_0x080F_seed@Base 2.3.0
  crc16_0x3D65_seed@Base 1.99.0
  crc16_0x5935@Base 1.10.0
  crc16_0x755B@Base 1.12.0~rc1
@@ -24,6 +25,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
  crc16_iso14443a@Base 2.1.0
  crc16_plain_update@Base 1.10.0
  crc16_x25_ccitt_seed@Base 1.99.3
+ crc32_0x5D6DCB_seed@Base 2.3.0
  crc32_0x0AA725CF_seed@Base 1.12.0~rc1
  crc32_ccitt@Base 1.10.0
  crc32_ccitt_seed@Base 1.10.0
@@ -35,6 +37,8 @@ libwsutil.so.0 libwsutil0 #MINVER#
  crc6_compute@Base 1.12.0~rc1
  crc7update@Base 1.10.0
  crc8_0x2F@Base 1.10.0
+ crc8_0x37@Base 2.3.0
+ crc8_0x3B@Base 2.3.0
  create_persconffile_dir@Base 1.12.0~rc1
  create_persconffile_profile@Base 1.12.0~rc1
  create_tempdir@Base 1.12.0~rc1
index 6b522ee8ad93cd4b9225fd16a745d161693f82bf..9ecca50882f20441ee7af19fb75850fcc592d374 100644 (file)
@@ -6106,8 +6106,9 @@ dissect_cip_cm_fwd_open_rsp_success(cip_req_info_t *preq_info, proto_tree *tree,
 {
    int temp_data;
    unsigned char app_rep_size;
-   guint32 O2TConnID, T2OConnID, DeviceSerialNumber;
-   guint16 ConnSerialNumber, VendorID;
+   guint32 O2TConnID, T2OConnID, DeviceSerialNumber, target_device_sn;
+   guint16 ConnSerialNumber, VendorID, init_rollover_value = 0, init_timestamp_value = 0,
+           target_conn_sn = 0, target_vendorID = 0;
    proto_tree *pid_tree, *safety_tree;
 
    /* Display originator to target connection ID */
@@ -6157,8 +6158,10 @@ dissect_cip_cm_fwd_open_rsp_success(cip_req_info_t *preq_info, proto_tree *tree,
          proto_tree_add_item( safety_tree, hf_cip_cm_consumer_number, tvb, offset+26, 2, ENC_LITTLE_ENDIAN);
          pid_tree = proto_tree_add_subtree( safety_tree, tvb, offset+28, 8, ett_cip_cm_pid, NULL, "PID/CID");
          proto_tree_add_item( pid_tree, hf_cip_cm_targ_vendor_id, tvb, offset+28, 2, ENC_LITTLE_ENDIAN);
-         proto_tree_add_item( pid_tree, hf_cip_cm_targ_dev_serial_num, tvb, offset+30, 4, ENC_LITTLE_ENDIAN);
+         target_vendorID = tvb_get_letohs(tvb, offset+28);
+         proto_tree_add_item_ret_uint( pid_tree, hf_cip_cm_targ_dev_serial_num, tvb, offset+30, 4, ENC_LITTLE_ENDIAN, &target_device_sn);
          proto_tree_add_item( pid_tree, hf_cip_cm_targ_conn_serial_num, tvb, offset+34, 2, ENC_LITTLE_ENDIAN);
+         target_conn_sn = tvb_get_letohs(tvb, offset+34);
 
          if (app_rep_size > 10)
             proto_tree_add_item(tree, hf_cip_cm_app_reply_data, tvb, offset+36, app_rep_size-10, ENC_NA );
@@ -6169,10 +6172,15 @@ dissect_cip_cm_fwd_open_rsp_success(cip_req_info_t *preq_info, proto_tree *tree,
          proto_tree_add_item( safety_tree, hf_cip_cm_consumer_number, tvb, offset+26, 2, ENC_LITTLE_ENDIAN);
          pid_tree = proto_tree_add_subtree( safety_tree, tvb, offset+28, 12, ett_cip_cm_pid, NULL, "PID/CID");
          proto_tree_add_item( pid_tree, hf_cip_cm_targ_vendor_id, tvb, offset+28, 2, ENC_LITTLE_ENDIAN);
-         proto_tree_add_item( pid_tree, hf_cip_cm_targ_dev_serial_num, tvb, offset+30, 4, ENC_LITTLE_ENDIAN);
+         target_vendorID = tvb_get_letohs(tvb, offset+28);
+         proto_tree_add_item_ret_uint( pid_tree, hf_cip_cm_targ_dev_serial_num, tvb, offset+30, 4, ENC_LITTLE_ENDIAN, &target_device_sn);
          proto_tree_add_item( pid_tree, hf_cip_cm_targ_conn_serial_num, tvb, offset+34, 2, ENC_LITTLE_ENDIAN);
+         target_conn_sn = tvb_get_letohs(tvb, offset+34);
+
          proto_tree_add_item( pid_tree, hf_cip_cm_initial_timestamp, tvb, offset+36, 2, ENC_LITTLE_ENDIAN);
+         init_timestamp_value = tvb_get_letohs(tvb, offset+36);
          proto_tree_add_item( pid_tree, hf_cip_cm_initial_rollover, tvb, offset+38, 2, ENC_LITTLE_ENDIAN);
+         init_rollover_value = tvb_get_letohs(tvb, offset+38);
 
          if (app_rep_size > 14)
             proto_tree_add_item(tree, hf_cip_cm_app_reply_data, tvb, offset+40, app_rep_size-14, ENC_NA );
@@ -6195,6 +6203,14 @@ dissect_cip_cm_fwd_open_rsp_success(cip_req_info_t *preq_info, proto_tree *tree,
             the ForwardOpen request */
          preq_info->connInfo->O2T.connID = O2TConnID;
          preq_info->connInfo->T2O.connID = T2OConnID;
+         if (preq_info->connInfo->safety.safety_seg == TRUE)
+         {
+             preq_info->connInfo->safety.running_rollover_value = init_rollover_value;
+             preq_info->connInfo->safety.running_timestamp_value = init_timestamp_value;
+             preq_info->connInfo->safety.target_conn_sn = target_conn_sn;
+             preq_info->connInfo->safety.target_vendorID = target_vendorID;
+             preq_info->connInfo->safety.target_device_sn = target_device_sn;
+         }
       }
    }
 }
index 37aa723dff1bc0632c853e9c6d255c588170c2a7..3c18d72366ebd9308a186fa62c2dcd5650bd4e6c 100644 (file)
@@ -298,6 +298,11 @@ enum cip_safety_format_type {CIP_SAFETY_BASE_FORMAT, CIP_SAFETY_EXTENDED_FORMAT}
 typedef struct cip_safety_epath_info {
    gboolean safety_seg;
    enum cip_safety_format_type format;
+   guint16 running_rollover_value;  /* Keep track of the rollover value over the course of the connection */
+   guint16 running_timestamp_value; /* Keep track of the timestamp value over the course of the connection */
+   guint16 target_conn_sn;
+   guint16 target_vendorID;
+   guint32 target_device_sn;
 } cip_safety_epath_info_t;
 
 typedef struct cip_conn_info {
index 2bcd1b8dd7939ce2711f895185b9cf0f9ebe74a8..53062ca53afd24aa6c3c5455d21e85af13d38b8a 100644 (file)
@@ -31,6 +31,9 @@
 #include <epan/proto_data.h>
 
 #include <wsutil/pint.h>
+#include <wsutil/crc8.h>
+#include <wsutil/crc16.h>
+#include <wsutil/crc32.h>
 #include "packet-cip.h"
 #include "packet-cipsafety.h"
 
@@ -59,8 +62,13 @@ static int hf_cipsafety_mode_byte_ping_count      = -1;
 static int hf_cipsafety_mode_byte_tbd             = -1;
 static int hf_cipsafety_mode_byte_not_tbd         = -1;
 static int hf_cipsafety_crc_s1                    = -1;
+static int hf_cipsafety_crc_s1_status             = -1;
 static int hf_cipsafety_crc_s2                    = -1;
+static int hf_cipsafety_crc_s2_status             = -1;
 static int hf_cipsafety_crc_s3                    = -1;
+static int hf_cipsafety_crc_s3_status             = -1;
+static int hf_cipsafety_complement_crc_s3         = -1;
+static int hf_cipsafety_complement_crc_s3_status  = -1;
 static int hf_cipsafety_timestamp                 = -1;
 static int hf_cipsafety_ack_byte                  = -1;
 static int hf_cipsafety_ack_byte_ping_count_reply = -1;
@@ -81,6 +89,7 @@ static int hf_cipsafety_time_correction           = -1;
 static int hf_cipsafety_crc_s5_0                  = -1;
 static int hf_cipsafety_crc_s5_1                  = -1;
 static int hf_cipsafety_crc_s5_2                  = -1;
+static int hf_cipsafety_crc_s5_status             = -1;
 static int hf_cipsafety_complement_data           = -1;
 
 /* CIP Safety header field identifiers */
@@ -281,6 +290,12 @@ static expert_field ei_cipsafety_tbd_not_copied = EI_INIT;
 static expert_field ei_cipsafety_run_idle_not_complemented = EI_INIT;
 static expert_field ei_mal_io = EI_INIT;
 static expert_field ei_mal_sercosiii_link_error_count_p1p2 = EI_INIT;
+static expert_field ei_cipsafety_not_complement_data = EI_INIT;
+static expert_field ei_cipsafety_crc_s1 = EI_INIT;
+static expert_field ei_cipsafety_crc_s2 = EI_INIT;
+static expert_field ei_cipsafety_crc_s3 = EI_INIT;
+static expert_field ei_cipsafety_complement_crc_s3 = EI_INIT;
+static expert_field ei_cipsafety_crc_s5 = EI_INIT;
 
 static expert_field ei_mal_ssupervisor_exception_detail_ced = EI_INIT;
 static expert_field ei_mal_ssupervisor_exception_detail_ded = EI_INIT;
@@ -302,6 +317,17 @@ static expert_field ei_mal_svalidator_prod_cons_fault_count = EI_INIT;
 
 static dissector_handle_t cipsafety_handle;
 
+typedef struct cip_safety_packet_data {
+   guint16 rollover_value;
+   guint16 timestamp_value;
+} cip_safety_packet_data_t;
+
+#define MODE_BYTE_CRC_S1_MASK  0xE0
+#define MODE_BYTE_CRC_S1_TIME_STAMP_MASK  0x1F
+#define MODE_BYTE_CRC_S3_MASK  0xE0
+#define MODE_BYTE_CRC_S5_BASE_MASK  0xE0
+#define MODE_BYTE_CRC_S5_EXTENDED_MASK  0x1F
+
 const value_string cipsafety_ssn_date_vals[8] = {
 
    { 0,     "NULL SSN" },
@@ -1229,6 +1255,146 @@ dissect_class_svalidator_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
    return FALSE;
 }
 
+/************************************************
+ *
+ * CRC handling
+ *
+ ************************************************/
+static guint8 compute_crc_s1_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
+{
+    guint8 temp_buf[8];
+    memcpy(temp_buf, &vendor_id, 2);
+    memcpy(&temp_buf[2], &device_serial_number, 4);
+    memcpy(&temp_buf[6], &conn_serial_number, 2);
+
+    return crc8_0x37(temp_buf, 8, 0);
+}
+
+static guint8 compute_crc_s1_timestamp(guint8 pid_seed, guint8 mode_byte_mask, guint16 timestamp)
+{
+    guint8 mode_byte_crc = crc8_0x37(&mode_byte_mask, 1, pid_seed);
+    guint8 timestamp_crc = crc8_0x37((guint8*)&timestamp, 2, mode_byte_crc);
+
+    return timestamp_crc;
+}
+
+static guint8 compute_crc_s1_data(guint8 pid_seed, guint8 mode_byte_mask, guint8 *buf, int len)
+{
+    guint8 mode_byte_crc = crc8_0x37(&mode_byte_mask, 1, pid_seed);
+
+    return crc8_0x37(buf, len, mode_byte_crc);
+}
+
+static guint8 compute_crc_s2_data(guint8 pid_seed, guint8 mode_byte_mask, guint8 *comp_buf, int len)
+{
+    int i;
+    guint8 mode_byte_crc = crc8_0x3B(&mode_byte_mask, 1, pid_seed);
+
+    for (i = 0; i < len; i++)
+        comp_buf[i] ^= 0xFF;
+
+    return crc8_0x3B(comp_buf, len, mode_byte_crc);
+}
+
+static guint16 compute_crc_s3_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
+{
+    guint8 temp_buf[8];
+    memcpy(temp_buf, &vendor_id, 2);
+    memcpy(&temp_buf[2], &device_serial_number, 4);
+    memcpy(&temp_buf[6], &conn_serial_number, 2);
+
+    return crc16_0x080F_seed(temp_buf, 8, 0);
+}
+
+static guint16 compute_crc_s3_base_data(guint16 pid_seed, guint8 mode_byte_mask, guint8 *buf, int len)
+{
+    guint16 mode_byte_crc = crc16_0x080F_seed(&mode_byte_mask, 1, pid_seed);
+
+    return crc16_0x080F_seed(buf, len, mode_byte_crc);
+}
+
+static guint16 compute_crc_s3_extended_data(guint16 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint8 *buf, int len)
+{
+    guint16 rollover_crc = crc16_0x080F_seed((guint8*)&rollover_value, 2, pid_seed);
+    guint16 mode_byte_crc = crc16_0x080F_seed(&mode_byte_mask, 1, rollover_crc);
+
+    return crc16_0x080F_seed(buf, len, mode_byte_crc);
+}
+
+static guint16 compute_crc_s3_time(guint16 pid_seed, guint8 ack_mcast_byte, guint16 timestamp_value)
+{
+    guint16 mode_byte_crc = crc16_0x080F_seed(&ack_mcast_byte, 1, pid_seed);
+    guint16 timestamp_crc;
+
+    timestamp_crc = crc16_0x080F_seed((guint8*)&timestamp_value, 2, mode_byte_crc);
+
+    return timestamp_crc;
+}
+
+static guint32 compute_crc_s5_pid(guint16 conn_serial_number, guint16 vendor_id, guint32 device_serial_number)
+{
+    guint8 temp_buf[8];
+    memcpy(temp_buf, &vendor_id, 2);
+    memcpy(&temp_buf[2], &device_serial_number, 4);
+    memcpy(&temp_buf[6], &conn_serial_number, 2);
+
+    return crc32_0x5D6DCB_seed(temp_buf, 8, 0);
+}
+
+static guint32 compute_crc_s5_short_data(guint32 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint16 timestamp_value, guint8 *buf, int len)
+{
+    guint32 rollover_crc = crc32_0x5D6DCB_seed((guint8*)&rollover_value, 2, pid_seed);
+    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&mode_byte_mask, 1, rollover_crc);
+    guint32 data_crc, timestamp_crc;
+
+    data_crc = crc32_0x5D6DCB_seed(buf, len, mode_byte_crc);
+    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, data_crc);
+
+    return timestamp_crc;
+}
+
+static guint32 compute_crc_s5_long_data(guint32 pid_seed, guint16 rollover_value, guint8 mode_byte_mask, guint16 timestamp_value, guint8 *comp_buf, int len)
+{
+    int i;
+    guint32 rollover_crc = crc32_0x5D6DCB_seed((guint8*)&rollover_value, 2, pid_seed);
+    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&mode_byte_mask, 1, rollover_crc);
+    guint32 comp_data_crc, timestamp_crc;
+
+    for (i = 0; i < len; i++)
+        comp_buf[i] ^= 0xFF;
+
+    comp_data_crc = crc32_0x5D6DCB_seed(comp_buf, len, mode_byte_crc);
+    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, comp_data_crc);
+
+    return timestamp_crc;
+}
+
+static guint32 compute_crc_s5_time(guint32 pid_seed, guint8 ack_mcast_byte, guint16 timestamp_value)
+{
+    guint32 mode_byte_crc = crc32_0x5D6DCB_seed(&ack_mcast_byte, 1, pid_seed);
+    guint32 timestamp_crc;
+
+    timestamp_crc = crc32_0x5D6DCB_seed((guint8*)&timestamp_value, 2, mode_byte_crc);
+
+    return timestamp_crc;
+}
+
+static gboolean verify_compliment_data(tvbuff_t *tvb, int data_offset, int complement_data_offset, int data_size)
+{
+    const guint8 *data = tvb_get_ptr(tvb, data_offset, data_size);
+    const guint8 *complement_data = tvb_get_ptr(tvb, complement_data_offset, data_size);
+    int i;
+
+    for (i = 0; i < data_size; i++)
+    {
+        if ((data[i] ^ complement_data[i])!= 0xFF)
+            return FALSE;
+    }
+
+    return TRUE;
+}
+
+
 /************************************************
  *
  * Dissector for CIP Safety I/O Data
@@ -1315,14 +1481,21 @@ dissect_mcast_byte( proto_tree *tree, tvbuff_t *tvb, int offset, packet_info *pi
 }
 
 static void
-dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int item_length, packet_info *pinfo)
+dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int item_length, packet_info *pinfo, cip_safety_info_t* safety_info)
 {
    int base_length, io_data_size;
    gboolean multicast = (((pntoh32(pinfo->dst.data)) & 0xf0000000) == 0xe0000000);
    gboolean server_dir = FALSE;
    enum enip_connid_type conn_type = ECIDT_UNKNOWN;
    enum cip_safety_format_type format = CIP_SAFETY_BASE_FORMAT;
-   cip_safety_info_t* safety_info = (cip_safety_info_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0 );
+   guint16 timestamp, conn_sn = 0, vendorID = 0;
+   guint8 mode_byte;
+   guint32 device_sn = 0;
+   cip_safety_packet_data_t* packet_data = NULL;
+   guint32 test_crc_c5, value_c5 = 0, tmp_c5;
+   proto_item *complement_item, *crc_s5_item, *crc_s5_status_item;
+   gboolean short_format = TRUE;
+   gboolean compute_crc = ((safety_info != NULL) && (safety_info->eip_conn_info != NULL));
 
    /* Make entries in Protocol column and Info column on summary display */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "CIP Safety");
@@ -1331,8 +1504,8 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
    if (safety_info != NULL)
    {
       conn_type = safety_info->conn_type;
-      format = safety_info->format;
-      server_dir = safety_info->server_dir;
+      format = safety_info->eip_conn_info->safety.format;
+      server_dir = (safety_info->eip_conn_info->TransportClass_trigger & CI_PRODUCTION_DIR_MASK) ? TRUE : FALSE;
    }
 
    /* compute the base packet length to determine what is actual I/O data */
@@ -1341,40 +1514,165 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
    if (((conn_type == ECIDT_O2T) && (server_dir == FALSE)) ||
        ((conn_type == ECIDT_T2O) && (server_dir == TRUE)))
    {
+      if (compute_crc)
+      {
+         if ((conn_type == ECIDT_O2T) && (server_dir == FALSE))
+         {
+            conn_sn = safety_info->eip_conn_info->ConnSerialNumber;
+            vendorID = safety_info->eip_conn_info->VendorID;
+            device_sn = safety_info->eip_conn_info->DeviceSerialNumber;
+         }
+         else
+         {
+            conn_sn = safety_info->eip_conn_info->safety.target_conn_sn;
+            vendorID = safety_info->eip_conn_info->safety.target_vendorID;
+            device_sn = safety_info->eip_conn_info->safety.target_device_sn;
+         }
+      }
+
       /* consumer data */
       dissect_ack_byte(tree, tvb, 0, pinfo);
       proto_tree_add_item(tree, hf_cipsafety_consumer_time_value, tvb, 1, 2, ENC_LITTLE_ENDIAN);
+      timestamp = tvb_get_letohs(tvb, 1);
 
       switch (format)
       {
       case CIP_SAFETY_BASE_FORMAT:
          proto_tree_add_item(tree, hf_cipsafety_ack_byte2, tvb, 3, 1, ENC_LITTLE_ENDIAN);
-         proto_tree_add_item(tree, hf_cipsafety_crc_s3, tvb, 4, 2, ENC_LITTLE_ENDIAN);
+         if (compute_crc)
+         {
+            proto_tree_add_checksum(tree, tvb, 4,
+                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
+                        compute_crc_s3_time(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
+                                                                tvb_get_guint8(tvb, 0), /* ack byte */
+                                                                timestamp),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+         }
+         else
+         {
+            proto_tree_add_checksum(tree, tvb, 4,
+                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+         }
          break;
       case CIP_SAFETY_EXTENDED_FORMAT:
          proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, 3, 1, ENC_LITTLE_ENDIAN);
          proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, 4, 1, ENC_LITTLE_ENDIAN);
-         proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, 5, 1, ENC_LITTLE_ENDIAN);
+         crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, 5, 1, ENC_LITTLE_ENDIAN);
+
+         /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up into multiple fields */
+         if (compute_crc)
+         {
+            test_crc_c5 = compute_crc_s5_time(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
+                                    tvb_get_guint8(tvb, 0), /* ack byte */
+                                    timestamp);
+
+            tmp_c5 = tvb_get_guint8(tvb, 3);
+            value_c5 = tmp_c5;
+            tmp_c5 = tvb_get_guint8(tvb, 4);
+            value_c5 += ((tmp_c5 << 8) & 0xFF00);
+            tmp_c5 = tvb_get_guint8(tvb, 5);
+            value_c5 += ((tmp_c5 << 16) & 0xFF0000);
+
+            if (test_crc_c5 == value_c5)
+            {
+               proto_item_append_text(crc_s5_item, " [correct]");
+               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_GOOD);
+            }
+            else
+            {
+               proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
+               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_BAD);
+               expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
+            }
+         }
+         else
+         {
+            crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, 5, 0, PROTO_CHECKSUM_E_UNVERIFIED);
+         }
+         PROTO_ITEM_SET_GENERATED(crc_s5_status_item);
+
          break;
       }
    }
    else if (((conn_type == ECIDT_O2T) && (server_dir == TRUE)) ||
             ((conn_type == ECIDT_T2O) && (server_dir == FALSE)))
    {
+      if (compute_crc)
+      {
+         if ((conn_type == ECIDT_O2T) && (server_dir == TRUE))
+         {
+            conn_sn = safety_info->eip_conn_info->ConnSerialNumber;
+            vendorID = safety_info->eip_conn_info->VendorID;
+            device_sn = safety_info->eip_conn_info->DeviceSerialNumber;
+         }
+         else
+         {
+            conn_sn = safety_info->eip_conn_info->safety.target_conn_sn;
+            vendorID = safety_info->eip_conn_info->safety.target_vendorID;
+            device_sn = safety_info->eip_conn_info->safety.target_device_sn;
+         }
+      }
+
+      if (item_length-base_length > 2)
+         short_format = FALSE;
+
       /* producer data */
       switch (format)
       {
       case CIP_SAFETY_BASE_FORMAT:
-         if (item_length-base_length <= 2)
+         if (short_format)
          {
+            io_data_size = item_length-base_length;
+
             /* Short Format (1-2 bytes I/O data) */
-            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, item_length-base_length, ENC_NA);
-            dissect_mode_byte(tree, tvb, item_length-base_length, pinfo);
+            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
+            dissect_mode_byte(tree, tvb, io_data_size, pinfo);
+            mode_byte = tvb_get_guint8(tvb, io_data_size);
 
-            proto_tree_add_item(tree, hf_cipsafety_crc_s1,    tvb, item_length-base_length+1, 1, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s2,    tvb, item_length-base_length+2, 1, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, item_length-base_length+3, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s1,    tvb, item_length-base_length+5, 1, ENC_LITTLE_ENDIAN);
+            if (compute_crc)
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
+                        compute_crc_s1_data(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
+                                (mode_byte & MODE_BYTE_CRC_S1_MASK),
+                                (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+
+               proto_tree_add_checksum(tree, tvb, io_data_size+2,
+                        hf_cipsafety_crc_s2, hf_cipsafety_crc_s2_status, &ei_cipsafety_crc_s2, pinfo,
+                        compute_crc_s2_data(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
+                                ((mode_byte ^ 0xFF) & MODE_BYTE_CRC_S1_MASK),
+                                /* I/O data is duplicated because it will be complemented inline */
+                                (guint8*)tvb_memdup(wmem_packet_scope(), tvb, 0, io_data_size), io_data_size),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+               proto_tree_add_checksum(tree, tvb, io_data_size+2,
+                        hf_cipsafety_crc_s2, hf_cipsafety_crc_s2_status, &ei_cipsafety_crc_s2,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+            }
+            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, io_data_size+3, 2, ENC_LITTLE_ENDIAN);
+            timestamp = tvb_get_letohs(tvb, io_data_size+3);
+            if (compute_crc)
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+5,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
+                        compute_crc_s1_timestamp(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
+                                (mode_byte & MODE_BYTE_CRC_S1_TIME_STAMP_MASK),
+                                timestamp),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+5,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+            }
 
             if (multicast)
             {
@@ -1398,11 +1696,59 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
 
             proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
             dissect_mode_byte(tree, tvb, io_data_size, pinfo);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s3, tvb, io_data_size+1, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s3, tvb, (io_data_size*2)+3, 2, ENC_LITTLE_ENDIAN);
+            mode_byte = tvb_get_guint8(tvb, io_data_size);
+
+            if (compute_crc)
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
+                        compute_crc_s3_base_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
+                                mode_byte & MODE_BYTE_CRC_S3_MASK, (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+            }
+
+            complement_item = proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
+            if (!verify_compliment_data(tvb, 0, io_data_size+3, io_data_size))
+                expert_add_info(pinfo, complement_item, &ei_cipsafety_not_complement_data);
+
+            if (compute_crc)
+            {
+               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+3,
+                        hf_cipsafety_complement_crc_s3, hf_cipsafety_complement_crc_s3_status, &ei_cipsafety_complement_crc_s3, pinfo,
+                        compute_crc_s3_base_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
+                                ((mode_byte ^ 0xFF) & MODE_BYTE_CRC_S3_MASK),
+                                (guint8*)tvb_get_ptr(tvb, io_data_size+3, io_data_size), io_data_size),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+3,
+                        hf_cipsafety_complement_crc_s3, hf_cipsafety_complement_crc_s3_status, &ei_cipsafety_complement_crc_s3,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+            }
             proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, (io_data_size*2)+5, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s1, tvb, (io_data_size*2)+7, 1, ENC_LITTLE_ENDIAN);
+            timestamp = tvb_get_letohs(tvb, (io_data_size*2)+5);
+            if (compute_crc)
+            {
+               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+7,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1, pinfo,
+                        compute_crc_s1_timestamp(compute_crc_s1_pid(conn_sn, vendorID, device_sn),
+                                (mode_byte & MODE_BYTE_CRC_S1_TIME_STAMP_MASK),
+                                timestamp),
+                        ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, (io_data_size*2)+7,
+                        hf_cipsafety_crc_s1, hf_cipsafety_crc_s1_status, &ei_cipsafety_crc_s1,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+            }
 
             if (multicast)
             {
@@ -1414,16 +1760,84 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
          }
          break;
       case CIP_SAFETY_EXTENDED_FORMAT:
-         if (item_length-base_length <= 2)
+         if (short_format)
+         {
+            io_data_size = item_length-base_length;
+            timestamp = tvb_get_letohs(tvb, io_data_size+3);
+         }
+         else
+         {
+            io_data_size = multicast ? ((item_length-14)/2) : ((item_length-8)/2);
+            timestamp = tvb_get_letohs(tvb, (io_data_size*2)+5);
+         }
+         mode_byte = tvb_get_guint8(tvb, io_data_size);
+
+         if (compute_crc)
+         {
+            /* Determine if packet timestamp results in rollover count increment */
+            if (!pinfo->fd->flags.visited)
+            {
+               if ((timestamp != 0) && (timestamp < safety_info->eip_conn_info->safety.running_timestamp_value))
+               {
+                  safety_info->eip_conn_info->safety.running_rollover_value++;
+               }
+
+               safety_info->eip_conn_info->safety.running_timestamp_value = timestamp;
+
+               /* Save the rollover value for CRC calculations */
+               packet_data = wmem_new0(wmem_file_scope(), cip_safety_packet_data_t);
+               packet_data->rollover_value = safety_info->eip_conn_info->safety.running_rollover_value;
+
+               p_add_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0, packet_data);
+            }
+            else
+            {
+               packet_data = (cip_safety_packet_data_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0);
+            }
+         }
+
+         if (short_format)
          {
             /* Short Format (1-2 bytes I/O data) */
-            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, item_length-base_length, ENC_NA);
-            dissect_mode_byte(tree, tvb, item_length-base_length, pinfo);
+            proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
+            dissect_mode_byte(tree, tvb, io_data_size, pinfo);
+
+            proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, io_data_size+1, 1, ENC_LITTLE_ENDIAN);
+            proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, io_data_size+2, 1, ENC_LITTLE_ENDIAN);
+            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, io_data_size+3, 2, ENC_LITTLE_ENDIAN);
+            crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, io_data_size+5, 1, ENC_LITTLE_ENDIAN);
 
-            proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, item_length-base_length+1, 1, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, item_length-base_length+2, 1, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, item_length-base_length+3, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, item_length-base_length+5, 1, ENC_LITTLE_ENDIAN);
+            /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up in non-consecutive bytes */
+            if (compute_crc && (packet_data != NULL))
+            {
+               test_crc_c5 = compute_crc_s5_short_data(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
+                                        ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S5_BASE_MASK, timestamp,
+                                        (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size);
+
+               tmp_c5 = tvb_get_guint8(tvb, io_data_size+1);
+               value_c5 = tmp_c5;
+               tmp_c5 = tvb_get_guint8(tvb, io_data_size+2);
+               value_c5 += ((tmp_c5 << 8) & 0xFF00);
+               tmp_c5 = tvb_get_guint8(tvb, io_data_size+5);
+               value_c5 += ((tmp_c5 << 16) & 0xFF0000);
+
+               if (test_crc_c5 == value_c5)
+               {
+                  proto_item_append_text(crc_s5_item, " [correct]");
+                  crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_GOOD);
+               }
+               else
+               {
+                   proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
+                   crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_BAD);
+                   expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
+               }
+            }
+            else
+            {
+               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, io_data_size+5, 0, PROTO_CHECKSUM_E_UNVERIFIED);
+            }
+            PROTO_ITEM_SET_GENERATED(crc_s5_status_item);
 
             if (multicast)
             {
@@ -1444,17 +1858,88 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
                return;
             }
 
-            io_data_size = multicast ? ((item_length-14)/2) : ((item_length-8)/2);
-
             proto_tree_add_item(tree, hf_cipsafety_data, tvb, 0, io_data_size, ENC_NA);
             dissect_mode_byte(tree, tvb, io_data_size, pinfo);
 
-            proto_tree_add_item(tree, hf_cipsafety_crc_s3, tvb, io_data_size+1, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
+            if (compute_crc)
+            {
+               /* Determine if packet timestamp results in rollover count increment */
+               if (!pinfo->fd->flags.visited)
+               {
+                  if ((timestamp != 0) && (timestamp < safety_info->eip_conn_info->safety.running_timestamp_value))
+                  {
+                     safety_info->eip_conn_info->safety.running_rollover_value++;
+                  }
+
+                  safety_info->eip_conn_info->safety.running_timestamp_value = timestamp;
+
+                  /* Save the rollover value for CRC calculations */
+                  packet_data = wmem_new0(wmem_file_scope(), cip_safety_packet_data_t);
+                  packet_data->rollover_value = safety_info->eip_conn_info->safety.running_rollover_value;
+
+                  p_add_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0, packet_data);
+               }
+               else
+               {
+                  packet_data = (cip_safety_packet_data_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0);
+               }
+
+               if (packet_data != NULL)
+               {
+                  proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                           hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3, pinfo,
+                           compute_crc_s3_extended_data(compute_crc_s3_pid(conn_sn, vendorID, device_sn),
+                                ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S3_MASK, (guint8*)tvb_get_ptr(tvb, 0, io_data_size), io_data_size),
+                           ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
+               }
+            }
+            else
+            {
+               proto_tree_add_checksum(tree, tvb, io_data_size+1,
+                        hf_cipsafety_crc_s3, hf_cipsafety_crc_s3_status, &ei_cipsafety_crc_s3,
+                        pinfo, 0, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
+
+            }
+            complement_item = proto_tree_add_item(tree, hf_cipsafety_complement_data, tvb, io_data_size+3, io_data_size, ENC_NA);
+            if (!verify_compliment_data(tvb, 0, io_data_size+3, io_data_size))
+                expert_add_info(pinfo, complement_item, &ei_cipsafety_not_complement_data);
             proto_tree_add_item(tree, hf_cipsafety_crc_s5_0, tvb, (io_data_size*2)+3, 1, ENC_LITTLE_ENDIAN);
             proto_tree_add_item(tree, hf_cipsafety_crc_s5_1, tvb, (io_data_size*2)+4, 1, ENC_LITTLE_ENDIAN);
             proto_tree_add_item(tree, hf_cipsafety_timestamp, tvb, (io_data_size*2)+5, 2, ENC_LITTLE_ENDIAN);
-            proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, (io_data_size*2)+7, 1, ENC_LITTLE_ENDIAN);
+            crc_s5_item = proto_tree_add_item(tree, hf_cipsafety_crc_s5_2, tvb, (io_data_size*2)+7, 1, ENC_LITTLE_ENDIAN);
+
+            /* CRC-S5 doesn't use proto_tree_add_checksum because the checksum is broken up in non-consecutive bytes */
+            if (compute_crc && (packet_data != NULL))
+            {
+               test_crc_c5 = compute_crc_s5_long_data(compute_crc_s5_pid(conn_sn, vendorID, device_sn),
+                                        ((timestamp != 0) ? packet_data->rollover_value : 0), mode_byte & MODE_BYTE_CRC_S5_EXTENDED_MASK, timestamp,
+                                        /* I/O data is duplicated because it will be complemented inline */
+                                        (guint8*)tvb_memdup(wmem_packet_scope(), tvb, 0, io_data_size), io_data_size);
+
+               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+3);
+               value_c5 = tmp_c5;
+               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+4);
+               value_c5 += ((tmp_c5 << 8) & 0xFF00);
+               tmp_c5 = tvb_get_guint8(tvb, (io_data_size*2)+7);
+               value_c5 += ((tmp_c5 << 16) & 0xFF0000);
+
+               if (test_crc_c5 == value_c5)
+               {
+                  proto_item_append_text(crc_s5_item, " [correct]");
+                  crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_GOOD);
+               }
+               else
+               {
+                   proto_item_append_text(crc_s5_item, " incorrect, should be 0x%08x", test_crc_c5);
+                   crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_BAD);
+                   expert_add_info_format(pinfo, crc_s5_item, &ei_cipsafety_crc_s5, "Bad checksum [should be 0x%08x]", test_crc_c5);
+               }
+            }
+            else
+            {
+               crc_s5_status_item = proto_tree_add_uint(tree, hf_cipsafety_crc_s5_status, tvb, (io_data_size*2)+7, 0, PROTO_CHECKSUM_E_UNVERIFIED);
+            }
+            PROTO_ITEM_SET_GENERATED(crc_s5_status_item);
 
             if (multicast)
             {
@@ -1476,16 +1961,17 @@ dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int
 }
 
 static int
-dissect_cipsafety(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
+dissect_cipsafety(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
 {
    proto_item *ti;
    proto_tree *safety_tree;
+   cip_safety_info_t* safety_info = (cip_safety_info_t*)data;
 
    /* Create display subtree for the protocol */
    ti = proto_tree_add_item(tree, proto_cipsafety, tvb, 0, -1, ENC_NA);
    safety_tree = proto_item_add_subtree( ti, ett_cip_safety);
 
-   dissect_cip_safety_data(safety_tree, ti, tvb, tvb_reported_length(tvb), pinfo );
+   dissect_cip_safety_data(safety_tree, ti, tvb, tvb_reported_length(tvb), pinfo, safety_info);
    return tvb_captured_length(tvb);
 }
 
@@ -1641,17 +2127,37 @@ proto_register_cipsafety(void)
         { "CRC S1", "cipsafety.crc_s1",
           FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
       },
+      { &hf_cipsafety_crc_s1_status,
+        { "CRC S1 Status", "cipsafety.crc_s1.status",
+          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
+      },
       { &hf_cipsafety_crc_s2,
         { "CRC S2", "cipsafety.crc_s2",
           FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
       },
+      { &hf_cipsafety_crc_s2_status,
+        { "CRC S2 Status", "cipsafety.crc_s2.status",
+          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
+      },
       { &hf_cipsafety_crc_s3,
         { "CRC S3", "cipsafety.crc_s3",
           FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
       },
+      { &hf_cipsafety_crc_s3_status,
+        { "CRC S3 Status", "cipsafety.crc_s3.status",
+          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
+      },
+      { &hf_cipsafety_complement_crc_s3,
+        { "Complement CRC S3", "cipsafety.complement_crc_s3",
+          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
+      },
+      { &hf_cipsafety_complement_crc_s3_status,
+        { "Complement CRC S3 Status", "cipsafety.complement_crc_s3.status",
+          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
+      },
       { &hf_cipsafety_timestamp,
         { "Timestamp", "cipsafety.timestamp",
-          FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }
+          FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }
       },
       { &hf_cipsafety_ack_byte,
         { "ACK Byte", "cipsafety.ack_byte",
@@ -1729,6 +2235,10 @@ proto_register_cipsafety(void)
         { "CRC S5_2", "cipsafety.crc_s5_2",
           FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL }
       },
+      { &hf_cipsafety_crc_s5_status,
+        { "CRC S5 Status", "cipsafety.crc_s5.status",
+          FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, NULL, HFILL }
+      },
       { &hf_cipsafety_complement_data,
         { "Complement Data", "cipsafety.complement_data",
           FT_BYTES, BASE_NONE, NULL, 0, "Connection Transport Data", HFILL }
@@ -2349,6 +2859,12 @@ proto_register_cipsafety(void)
       { &ei_cipsafety_run_idle_not_complemented, { "cipsafety.run_idle_not_complemented", PI_PROTOCOL, PI_WARN, "Run/Idle bit not complemented", EXPFILL }},
       { &ei_mal_io, { "cipsafety.malformed.io", PI_MALFORMED, PI_ERROR, "Malformed CIP Safety I/O packet", EXPFILL }},
       { &ei_mal_sercosiii_link_error_count_p1p2, { "cipsafety.malformed.sercosiii_link.error_count_p1p2", PI_MALFORMED, PI_ERROR, "Malformed SERCOS III Attribute 5", EXPFILL }},
+      { &ei_cipsafety_not_complement_data, { "cipsafety.not_complement_data", PI_PROTOCOL, PI_WARN, "Data not complemented", EXPFILL }},
+      { &ei_cipsafety_crc_s1, { "cipsafety.crc_s1.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S1 incorrect", EXPFILL }},
+      { &ei_cipsafety_crc_s2, { "cipsafety.crc_s2.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S2 incorrect", EXPFILL }},
+      { &ei_cipsafety_crc_s3, { "cipsafety.crc_s3.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S3 incorrect", EXPFILL }},
+      { &ei_cipsafety_complement_crc_s3, { "cipsafety.complement_crc_s3.incorrect", PI_PROTOCOL, PI_WARN, "Complement CRC-S3 incorrect", EXPFILL }},
+      { &ei_cipsafety_crc_s5, { "cipsafety.crc_s5.incorrect", PI_PROTOCOL, PI_WARN, "CRC-S5 incorrect", EXPFILL }},
       };
 
    static ei_register_info ei_ssupervisor[] = {
index b17ffa18050166a8a1cd10640e85c4520f23f00a..ddcc2543b553fe26842bf41ab62bcf07792aebd6 100644 (file)
@@ -48,8 +48,7 @@
 
 typedef struct cip_safety_info {
    enum enip_connid_type conn_type;
-   enum cip_safety_format_type format;
-   gboolean server_dir;
+   enip_conn_val_t* eip_conn_info;
 } cip_safety_info_t;
 
 
index 6aec4fba6a73b02059c754900ab541340f41da33..357735b4b76cb4193fac87a7364078746d07c391 100644 (file)
@@ -95,7 +95,6 @@ void proto_reg_handoff_enip(void);
 /* Initialize the protocol and registered fields */
 static int proto_enip = -1;
 static int proto_enipio = -1;
-static int proto_cipsafety = -1;
 
 static int hf_enip_command = -1;
 static int hf_enip_length = -1;
@@ -899,22 +898,6 @@ typedef struct enip_conn_key {
    guint32 T2OConnID;
 } enip_conn_key_t;
 
-typedef struct enip_conn_val {
-   guint16 ConnSerialNumber;
-   guint16 VendorID;
-   guint32 DeviceSerialNumber;
-   guint32 O2TConnID;
-   guint32 T2OConnID;
-   guint8  TransportClass_trigger;
-   guint32 open_frame;
-   guint32 open_reply_frame;
-   guint32 close_frame;
-   guint32 connid;
-   cip_safety_epath_info_t safety;
-   gboolean motion;
-   guint32 ClassID;
-} enip_conn_val_t;
-
 typedef struct _enip_conv_info_t {
    wmem_tree_t *O2TConnIDs;
    wmem_tree_t *T2OConnIDs;
@@ -2196,7 +2179,7 @@ dissect_cpf(enip_request_key_t *request_key, int command, tvbuff_t *tvb,
    gboolean               FwdOpen      = FALSE;
    gboolean               FwdOpenReply = FALSE;
    enum enip_connid_type  connid_type  = ECIDT_UNKNOWN;
-   cip_safety_info_t*     cip_safety;
+   cip_safety_info_t      cip_safety;
    guint32                trans_id, ucmm_request;
    conversation_t        *conversation;
 
@@ -2392,12 +2375,10 @@ dissect_cpf(enip_request_key_t *request_key, int command, tvbuff_t *tvb,
                          if (conn_info->safety.safety_seg == TRUE)
                          {
                             /* Add any possible safety related data */
-                            cip_safety = wmem_new(wmem_file_scope(), cip_safety_info_t);
-                            cip_safety->conn_type = connid_type;
-                            cip_safety->server_dir = (conn_info->TransportClass_trigger & CI_PRODUCTION_DIR_MASK) ? TRUE : FALSE;
-                            cip_safety->format = conn_info->safety.format;
-                            p_add_proto_data(wmem_file_scope(), pinfo, proto_cipsafety, 0, cip_safety);
-                            call_dissector(cipsafety_handle, next_tvb, pinfo, dissector_tree);
+                            cip_safety.conn_type = connid_type;
+                            cip_safety.eip_conn_info = conn_info;
+
+                            call_dissector_with_data(cipsafety_handle, next_tvb, pinfo, dissector_tree, &cip_safety);
                          }
                          else if (conn_info->motion == TRUE)
                          {
@@ -4451,7 +4432,6 @@ proto_reg_handoff_enip(void)
    dlr_handle = create_dissector_handle(dissect_dlr, proto_dlr);
    dissector_add_uint("ethertype", ETHERTYPE_DLR, dlr_handle);
 
-   proto_cipsafety = proto_get_id_by_filter_name( "cipsafety" );
    subdissector_class_table = find_dissector_table("cip.class.iface");
 
 } /* end of proto_reg_handoff_enip() */
index 81ac3897dcdfeb2f798cf70f59b389468b7c9cc0..6010bc01876476754727a60042cb8d1ccdefb920 100644 (file)
@@ -103,6 +103,22 @@ typedef struct {
    cip_req_info_t* cip_info;
 } enip_request_info_t;
 
+typedef struct enip_conn_val {
+   guint16 ConnSerialNumber;
+   guint16 VendorID;
+   guint32 DeviceSerialNumber;
+   guint32 O2TConnID;
+   guint32 T2OConnID;
+   guint8  TransportClass_trigger;
+   guint32 open_frame;
+   guint32 open_reply_frame;
+   guint32 close_frame;
+   guint32 connid;
+   cip_safety_epath_info_t safety;
+   gboolean motion;
+   guint32 ClassID;
+} enip_conn_val_t;
+
 enum enip_connid_type {ECIDT_UNKNOWN, ECIDT_O2T, ECIDT_T2O};
 
 /* proto_data types */
index 2ff576c200f0b2dcec89fa049b12b37cf0880761..3fc09f52ea16c8de46664ee102a0af4ef11541c8 100644 (file)
@@ -293,6 +293,43 @@ static const guint crc16_precompiled_3D65_reverse[] =
     0x91AF, 0xA7F1, 0xFD13, 0xCB4D, 0x48D7, 0x7E89, 0x246B, 0x1235
 };
 
+/* This table was compiled using the polynom: 0x080F */
+static const guint crc16_precompiled_080F[] =
+{
+    0x0000, 0x080F, 0x101E, 0x1811, 0x203C, 0x2833, 0x3022, 0x382D,
+    0x4078, 0x4877, 0x5066, 0x5869, 0x6044, 0x684B, 0x705A, 0x7855,
+    0x80F0, 0x88FF, 0x90EE, 0x98E1, 0xA0CC, 0xA8C3, 0xB0D2, 0xB8DD,
+    0xC088, 0xC887, 0xD096, 0xD899, 0xE0B4, 0xE8BB, 0xF0AA, 0xF8A5,
+    0x09EF, 0x01E0, 0x19F1, 0x11FE, 0x29D3, 0x21DC, 0x39CD, 0x31C2,
+    0x4997, 0x4198, 0x5989, 0x5186, 0x69AB, 0x61A4, 0x79B5, 0x71BA,
+    0x891F, 0x8110, 0x9901, 0x910E, 0xA923, 0xA12C, 0xB93D, 0xB132,
+    0xC967, 0xC168, 0xD979, 0xD176, 0xE95B, 0xE154, 0xF945, 0xF14A,
+    0x13DE, 0x1BD1, 0x03C0, 0x0BCF, 0x33E2, 0x3BED, 0x23FC, 0x2BF3,
+    0x53A6, 0x5BA9, 0x43B8, 0x4BB7, 0x739A, 0x7B95, 0x6384, 0x6B8B,
+    0x932E, 0x9B21, 0x8330, 0x8B3F, 0xB312, 0xBB1D, 0xA30C, 0xAB03,
+    0xD356, 0xDB59, 0xC348, 0xCB47, 0xF36A, 0xFB65, 0xE374, 0xEB7B,
+    0x1A31, 0x123E, 0x0A2F, 0x0220, 0x3A0D, 0x3202, 0x2A13, 0x221C,
+    0x5A49, 0x5246, 0x4A57, 0x4258, 0x7A75, 0x727A, 0x6A6B, 0x6264,
+    0x9AC1, 0x92CE, 0x8ADF, 0x82D0, 0xBAFD, 0xB2F2, 0xAAE3, 0xA2EC,
+    0xDAB9, 0xD2B6, 0xCAA7, 0xC2A8, 0xFA85, 0xF28A, 0xEA9B, 0xE294,
+    0x27BC, 0x2FB3, 0x37A2, 0x3FAD, 0x0780, 0x0F8F, 0x179E, 0x1F91,
+    0x67C4, 0x6FCB, 0x77DA, 0x7FD5, 0x47F8, 0x4FF7, 0x57E6, 0x5FE9,
+    0xA74C, 0xAF43, 0xB752, 0xBF5D, 0x8770, 0x8F7F, 0x976E, 0x9F61,
+    0xE734, 0xEF3B, 0xF72A, 0xFF25, 0xC708, 0xCF07, 0xD716, 0xDF19,
+    0x2E53, 0x265C, 0x3E4D, 0x3642, 0x0E6F, 0x0660, 0x1E71, 0x167E,
+    0x6E2B, 0x6624, 0x7E35, 0x763A, 0x4E17, 0x4618, 0x5E09, 0x5606,
+    0xAEA3, 0xA6AC, 0xBEBD, 0xB6B2, 0x8E9F, 0x8690, 0x9E81, 0x968E,
+    0xEEDB, 0xE6D4, 0xFEC5, 0xF6CA, 0xCEE7, 0xC6E8, 0xDEF9, 0xD6F6,
+    0x3462, 0x3C6D, 0x247C, 0x2C73, 0x145E, 0x1C51, 0x0440, 0x0C4F,
+    0x741A, 0x7C15, 0x6404, 0x6C0B, 0x5426, 0x5C29, 0x4438, 0x4C37,
+    0xB492, 0xBC9D, 0xA48C, 0xAC83, 0x94AE, 0x9CA1, 0x84B0, 0x8CBF,
+    0xF4EA, 0xFCE5, 0xE4F4, 0xECFB, 0xD4D6, 0xDCD9, 0xC4C8, 0xCCC7,
+    0x3D8D, 0x3582, 0x2D93, 0x259C, 0x1DB1, 0x15BE, 0x0DAF, 0x05A0,
+    0x7DF5, 0x75FA, 0x6DEB, 0x65E4, 0x5DC9, 0x55C6, 0x4DD7, 0x45D8,
+    0xBD7D, 0xB572, 0xAD63, 0xA56C, 0x9D41, 0x954E, 0x8D5F, 0x8550,
+    0xFD05, 0xF50A, 0xED1B, 0xE514, 0xDD39, 0xD536, 0xCD27, 0xC528
+};
+
 static const guint16 crc16_ccitt_start = 0xFFFF;
 static const guint16 crc16_ccitt_xorout = 0xFFFF;
 
@@ -374,6 +411,22 @@ guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 seed)
     return crc16_reflected(buf, len, seed, crc16_precompiled_3D65_reverse);
 }
 
+guint16 crc16_0x080F_seed(const guint8 *buf, guint len, guint16 seed)
+{
+    guint16 crc = seed;
+
+    if (len > 0)
+    {
+        while (len-- > 0)
+        {
+            guint8 data = *buf++;
+            crc = crc16_precompiled_080F[((crc >> 8) ^ data)] ^ (crc << 8);
+        }
+    }
+
+    return crc;
+}
+
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
  *
index 11616089cc303b8daeaf8921e7edc03bd0af3a91..b80c012d83c0d685fea051b8e01961e57c6b9be8 100644 (file)
@@ -103,6 +103,15 @@ WS_DLL_PUBLIC guint16 crc16_0x9949_seed(const guint8 *buf, guint len, guint16 se
  */
 WS_DLL_PUBLIC guint16 crc16_0x3D65_seed(const guint8 *buf, guint len, guint16 seed);
 
+/** Computes CRC16 checksum for the given data with the polynom 0x080F using
+ *  precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC16 checksum for the buffer
+ */
+WS_DLL_PUBLIC guint16 crc16_0x080F_seed(const guint8 *buf, guint len, guint16 seed);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 142a457f4411cb6b4f084809d6ea3f258f376cc1..1ce43eb9c1cdc05503ba1445b52929707b47c1e1 100644 (file)
@@ -296,6 +296,75 @@ static const guint32 crc32_0AA725CF_reverse[] = {
                0x53E8BE29U, 0x9D422BE7U, 0x29F45F14U, 0xE75ECADAU
 };
 
+/* This table was compiled using the polynom: 0x5D6DCB */
+static const guint32 crc32_5D6DCB[] =
+{
+               0x00000000, 0x005d6dcb, 0x00badb96, 0x00e7b65d,
+               0x0028dae7, 0x0075b72c, 0x00920171, 0x00cf6cba,
+               0x0051b5ce, 0x000cd805, 0x00eb6e58, 0x00b60393,
+               0x00796f29, 0x002402e2, 0x00c3b4bf, 0x009ed974,
+               0x00a36b9c, 0x00fe0657, 0x0019b00a, 0x0044ddc1,
+               0x008bb17b, 0x00d6dcb0, 0x00316aed, 0x006c0726,
+               0x00f2de52, 0x00afb399, 0x004805c4, 0x0015680f,
+               0x00da04b5, 0x0087697e, 0x0060df23, 0x003db2e8,
+               0x001bbaf3, 0x0046d738, 0x00a16165, 0x00fc0cae,
+               0x00336014, 0x006e0ddf, 0x0089bb82, 0x00d4d649,
+               0x004a0f3d, 0x001762f6, 0x00f0d4ab, 0x00adb960,
+               0x0062d5da, 0x003fb811, 0x00d80e4c, 0x00856387,
+               0x00b8d16f, 0x00e5bca4, 0x00020af9, 0x005f6732,
+               0x00900b88, 0x00cd6643, 0x002ad01e, 0x0077bdd5,
+               0x00e964a1, 0x00b4096a, 0x0053bf37, 0x000ed2fc,
+               0x00c1be46, 0x009cd38d, 0x007b65d0, 0x0026081b,
+               0x003775e6, 0x006a182d, 0x008dae70, 0x00d0c3bb,
+               0x001faf01, 0x0042c2ca, 0x00a57497, 0x00f8195c,
+               0x0066c028, 0x003bade3, 0x00dc1bbe, 0x00817675,
+               0x004e1acf, 0x00137704, 0x00f4c159, 0x00a9ac92,
+               0x00941e7a, 0x00c973b1, 0x002ec5ec, 0x0073a827,
+               0x00bcc49d, 0x00e1a956, 0x00061f0b, 0x005b72c0,
+               0x00c5abb4, 0x0098c67f, 0x007f7022, 0x00221de9,
+               0x00ed7153, 0x00b01c98, 0x0057aac5, 0x000ac70e,
+               0x002ccf15, 0x0071a2de, 0x00961483, 0x00cb7948,
+               0x000415f2, 0x00597839, 0x00bece64, 0x00e3a3af,
+               0x007d7adb, 0x00201710, 0x00c7a14d, 0x009acc86,
+               0x0055a03c, 0x0008cdf7, 0x00ef7baa, 0x00b21661,
+               0x008fa489, 0x00d2c942, 0x00357f1f, 0x006812d4,
+               0x00a77e6e, 0x00fa13a5, 0x001da5f8, 0x0040c833,
+               0x00de1147, 0x00837c8c, 0x0064cad1, 0x0039a71a,
+               0x00f6cba0, 0x00aba66b, 0x004c1036, 0x00117dfd,
+               0x006eebcc, 0x00338607, 0x00d4305a, 0x00895d91,
+               0x0046312b, 0x001b5ce0, 0x00fceabd, 0x00a18776,
+               0x003f5e02, 0x006233c9, 0x00858594, 0x00d8e85f,
+               0x001784e5, 0x004ae92e, 0x00ad5f73, 0x00f032b8,
+               0x00cd8050, 0x0090ed9b, 0x00775bc6, 0x002a360d,
+               0x00e55ab7, 0x00b8377c, 0x005f8121, 0x0002ecea,
+               0x009c359e, 0x00c15855, 0x0026ee08, 0x007b83c3,
+               0x00b4ef79, 0x00e982b2, 0x000e34ef, 0x00535924,
+               0x0075513f, 0x00283cf4, 0x00cf8aa9, 0x0092e762,
+               0x005d8bd8, 0x0000e613, 0x00e7504e, 0x00ba3d85,
+               0x0024e4f1, 0x0079893a, 0x009e3f67, 0x00c352ac,
+               0x000c3e16, 0x005153dd, 0x00b6e580, 0x00eb884b,
+               0x00d63aa3, 0x008b5768, 0x006ce135, 0x00318cfe,
+               0x00fee044, 0x00a38d8f, 0x00443bd2, 0x00195619,
+               0x00878f6d, 0x00dae2a6, 0x003d54fb, 0x00603930,
+               0x00af558a, 0x00f23841, 0x00158e1c, 0x0048e3d7,
+               0x00599e2a, 0x0004f3e1, 0x00e345bc, 0x00be2877,
+               0x007144cd, 0x002c2906, 0x00cb9f5b, 0x0096f290,
+               0x00082be4, 0x0055462f, 0x00b2f072, 0x00ef9db9,
+               0x0020f103, 0x007d9cc8, 0x009a2a95, 0x00c7475e,
+               0x00faf5b6, 0x00a7987d, 0x00402e20, 0x001d43eb,
+               0x00d22f51, 0x008f429a, 0x0068f4c7, 0x0035990c,
+               0x00ab4078, 0x00f62db3, 0x00119bee, 0x004cf625,
+               0x00839a9f, 0x00def754, 0x00394109, 0x00642cc2,
+               0x004224d9, 0x001f4912, 0x00f8ff4f, 0x00a59284,
+               0x006afe3e, 0x003793f5, 0x00d025a8, 0x008d4863,
+               0x00139117, 0x004efcdc, 0x00a94a81, 0x00f4274a,
+               0x003b4bf0, 0x0066263b, 0x00819066, 0x00dcfdad,
+               0x00e14f45, 0x00bc228e, 0x005b94d3, 0x0006f918,
+               0x00c995a2, 0x0094f869, 0x00734e34, 0x002e23ff,
+               0x00b0fa8b, 0x00ed9740, 0x000a211d, 0x00574cd6,
+               0x0098206c, 0x00c54da7, 0x0022fbfa, 0x007f9631
+};
+
 guint32
 crc32c_table_lookup (guchar pos)
 {
@@ -374,6 +443,23 @@ crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint32 seed)
        return (guint32)crc32;
 }
 
+guint32
+crc32_0x5D6DCB_seed(const guint8 *buf, guint len, guint32 seed)
+{
+       guint32 crc = seed;
+       if (len > 0)
+       {
+               while (len-- > 0)
+               {
+                       guint8 data = *buf++;
+                       /* XOR data with CRC2, look up result, then XOR that with CRC; */
+                       crc = crc32_5D6DCB[((crc >> 16) ^ data) & 0xff] ^ (crc << 8);
+               }
+       }
+       return (crc & 0x00ffffff);
+}
+
+
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
  *
index 39cf17798ae479dc566694205fc99329b48b4c2f..02a990206cf678d2e3f8036f9664b7a18d72441c 100644 (file)
@@ -96,6 +96,15 @@ WS_DLL_PUBLIC guint32 crc32_mpeg2_seed(const guint8 *buf, guint len, guint32 see
  */
 WS_DLL_PUBLIC guint32 crc32_0x0AA725CF_seed(const guint8 *buf, guint len, guint32 seed);
 
+/** Computes CRC32 checksum for the given data with the polynom 0x5D6DCB using
+ *  precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC32 checksum for the buffer
+ */
+WS_DLL_PUBLIC guint32 crc32_0x5D6DCB_seed(const guint8 *buf, guint len, guint32 seed);
+
 WS_DLL_PUBLIC int AirPDcapWepDecrypt(
        const guchar *seed,
        const size_t seed_len,
index 1fbf045c7042d1196eb2c757eaad857798ba4052..d667f57e90f98603d9a8f3263e7f026b68ccd14c 100644 (file)
@@ -65,7 +65,79 @@ static const guint8 crc8_precompiled_2F[256] =
     0x8F, 0xA0, 0xD1, 0xFE, 0x33, 0x1C, 0x6D, 0x42
 };
 
+/* @brief Precompiled table for CRC8 values for the polynom 0x37 */
+static const unsigned char crc8_precompiled_37[256] =
+{
+    0x00, 0x37, 0x6e, 0x59, 0xdc, 0xeb, 0xb2, 0x85,
+    0x8f, 0xb8, 0xe1, 0xd6, 0x53, 0x64, 0x3d, 0x0a,
+    0x29, 0x1e, 0x47, 0x70, 0xf5, 0xc2, 0x9b, 0xac,
+    0xa6, 0x91, 0xc8, 0xff, 0x7a, 0x4d, 0x14, 0x23,
+    0x52, 0x65, 0x3c, 0x0b, 0x8e, 0xb9, 0xe0, 0xd7,
+    0xdd, 0xea, 0xb3, 0x84, 0x01, 0x36, 0x6f, 0x58,
+    0x7b, 0x4c, 0x15, 0x22, 0xa7, 0x90, 0xc9, 0xfe,
+    0xf4, 0xc3, 0x9a, 0xad, 0x28, 0x1f, 0x46, 0x71,
+    0xa4, 0x93, 0xca, 0xfd, 0x78, 0x4f, 0x16, 0x21,
+    0x2b, 0x1c, 0x45, 0x72, 0xf7, 0xc0, 0x99, 0xae,
+    0x8d, 0xba, 0xe3, 0xd4, 0x51, 0x66, 0x3f, 0x08,
+    0x02, 0x35, 0x6c, 0x5b, 0xde, 0xe9, 0xb0, 0x87,
+    0xf6, 0xc1, 0x98, 0xaf, 0x2a, 0x1d, 0x44, 0x73,
+    0x79, 0x4e, 0x17, 0x20, 0xa5, 0x92, 0xcb, 0xfc,
+    0xdf, 0xe8, 0xb1, 0x86, 0x03, 0x34, 0x6d, 0x5a,
+    0x50, 0x67, 0x3e, 0x09, 0x8c, 0xbb, 0xe2, 0xd5,
+    0x7f, 0x48, 0x11, 0x26, 0xa3, 0x94, 0xcd, 0xfa,
+    0xf0, 0xc7, 0x9e, 0xa9, 0x2c, 0x1b, 0x42, 0x75,
+    0x56, 0x61, 0x38, 0x0f, 0x8a, 0xbd, 0xe4, 0xd3,
+    0xd9, 0xee, 0xb7, 0x80, 0x05, 0x32, 0x6b, 0x5c,
+    0x2d, 0x1a, 0x43, 0x74, 0xf1, 0xc6, 0x9f, 0xa8,
+    0xa2, 0x95, 0xcc, 0xfb, 0x7e, 0x49, 0x10, 0x27,
+    0x04, 0x33, 0x6a, 0x5d, 0xd8, 0xef, 0xb6, 0x81,
+    0x8b, 0xbc, 0xe5, 0xd2, 0x57, 0x60, 0x39, 0x0e,
+    0xdb, 0xec, 0xb5, 0x82, 0x07, 0x30, 0x69, 0x5e,
+    0x54, 0x63, 0x3a, 0x0d, 0x88, 0xbf, 0xe6, 0xd1,
+    0xf2, 0xc5, 0x9c, 0xab, 0x2e, 0x19, 0x40, 0x77,
+    0x7d, 0x4a, 0x13, 0x24, 0xa1, 0x96, 0xcf, 0xf8,
+    0x89, 0xbe, 0xe7, 0xd0, 0x55, 0x62, 0x3b, 0x0c,
+    0x06, 0x31, 0x68, 0x5f, 0xda, 0xed, 0xb4, 0x83,
+    0xa0, 0x97, 0xce, 0xf9, 0x7c, 0x4b, 0x12, 0x25,
+    0x2f, 0x18, 0x41, 0x76, 0xf3, 0xc4, 0x9d, 0xaa,
+};
 
+/* @brief Precompiled table for CRC8 values for the polynom 0x3B */
+static const unsigned char crc8_precompiled_3b[256] =
+{
+    0x00, 0x3b, 0x76, 0x4d, 0xec, 0xd7, 0x9a, 0xa1,
+    0xe3, 0xd8, 0x95, 0xae, 0x0f, 0x34, 0x79, 0x42,
+    0xfd, 0xc6, 0x8b, 0xb0, 0x11, 0x2a, 0x67, 0x5c,
+    0x1e, 0x25, 0x68, 0x53, 0xf2, 0xc9, 0x84, 0xbf,
+    0xc1, 0xfa, 0xb7, 0x8c, 0x2d, 0x16, 0x5b, 0x60,
+    0x22, 0x19, 0x54, 0x6f, 0xce, 0xf5, 0xb8, 0x83,
+    0x3c, 0x07, 0x4a, 0x71, 0xd0, 0xeb, 0xa6, 0x9d,
+    0xdf, 0xe4, 0xa9, 0x92, 0x33, 0x08, 0x45, 0x7e,
+    0xb9, 0x82, 0xcf, 0xf4, 0x55, 0x6e, 0x23, 0x18,
+    0x5a, 0x61, 0x2c, 0x17, 0xb6, 0x8d, 0xc0, 0xfb,
+    0x44, 0x7f, 0x32, 0x09, 0xa8, 0x93, 0xde, 0xe5,
+    0xa7, 0x9c, 0xd1, 0xea, 0x4b, 0x70, 0x3d, 0x06,
+    0x78, 0x43, 0x0e, 0x35, 0x94, 0xaf, 0xe2, 0xd9,
+    0x9b, 0xa0, 0xed, 0xd6, 0x77, 0x4c, 0x01, 0x3a,
+    0x85, 0xbe, 0xf3, 0xc8, 0x69, 0x52, 0x1f, 0x24,
+    0x66, 0x5d, 0x10, 0x2b, 0x8a, 0xb1, 0xfc, 0xc7,
+    0x49, 0x72, 0x3f, 0x04, 0xa5, 0x9e, 0xd3, 0xe8,
+    0xaa, 0x91, 0xdc, 0xe7, 0x46, 0x7d, 0x30, 0x0b,
+    0xb4, 0x8f, 0xc2, 0xf9, 0x58, 0x63, 0x2e, 0x15,
+    0x57, 0x6c, 0x21, 0x1a, 0xbb, 0x80, 0xcd, 0xf6,
+    0x88, 0xb3, 0xfe, 0xc5, 0x64, 0x5f, 0x12, 0x29,
+    0x6b, 0x50, 0x1d, 0x26, 0x87, 0xbc, 0xf1, 0xca,
+    0x75, 0x4e, 0x03, 0x38, 0x99, 0xa2, 0xef, 0xd4,
+    0x96, 0xad, 0xe0, 0xdb, 0x7a, 0x41, 0x0c, 0x37,
+    0xf0, 0xcb, 0x86, 0xbd, 0x1c, 0x27, 0x6a, 0x51,
+    0x13, 0x28, 0x65, 0x5e, 0xff, 0xc4, 0x89, 0xb2,
+    0x0d, 0x36, 0x7b, 0x40, 0xe1, 0xda, 0x97, 0xac,
+    0xee, 0xd5, 0x98, 0xa3, 0x02, 0x39, 0x74, 0x4f,
+    0x31, 0x0a, 0x47, 0x7c, 0xdd, 0xe6, 0xab, 0x90,
+    0xd2, 0xe9, 0xa4, 0x9f, 0x3e, 0x05, 0x48, 0x73,
+    0xcc, 0xf7, 0xba, 0x81, 0x20, 0x1b, 0x56, 0x6d,
+    0x2f, 0x14, 0x59, 0x62, 0xc3, 0xf8, 0xb5, 0x8e,
+};
 /** Calculates a CRC8 checksum for the given buffer with the polynom
  *  stored in the crc_table
  * @param buf a pointer to a buffer of the given length
@@ -97,6 +169,40 @@ guint8 crc8_0x2F(guint8 *buf, guint32 len, guint8 seed)
     return crc8_precompiled(buf, len, seed, crc8_precompiled_2F);
 }
 
+/** Calculates a CRC8 checksum for the given buffer with the polynom
+ *  0x37 using the precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC8 checksum for the buffer
+ */
+guint8 crc8_0x37(guint8 *buf, guint32 len, guint8 seed)
+{
+    guint8 crc = seed;
+    while (len-- > 0)
+    {
+        crc = crc8_precompiled_37[(crc ^ *buf++)];
+    }
+    return (crc);
+}
+
+/** Calculates a CRC8 checksum for the given buffer with the polynom
+ *  0x3B using the precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC8 checksum for the buffer
+ */
+guint8 crc8_0x3B(guint8 *buf, guint32 len, guint8 seed)
+{
+    guint8 crc = seed;
+    while (len-- > 0)
+    {
+        crc = crc8_precompiled_3b[(crc ^ *buf++)];
+    }
+    return (crc);
+}
+
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
  *
index 52db4fd64b34a52100f57a2d0614f48c65d6b80b..0aaf78e2aeec570dd531d5249cc13b8ad00903c2 100644 (file)
@@ -41,6 +41,24 @@ extern "C" {
  */
 WS_DLL_PUBLIC guint8 crc8_0x2F(guint8 *buf, guint32 len, guint8 seed);
 
+/** Calculates a CRC8 checksum for the given buffer with the polynom
+ *  0x37 using the precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC8 checksum for the buffer
+ */
+WS_DLL_PUBLIC guint8 crc8_0x37(guint8 *buf, guint32 len, guint8 seed);
+
+/** Calculates a CRC8 checksum for the given buffer with the polynom
+ *  0x3B using the precompiled CRC table
+ * @param buf a pointer to a buffer of the given length
+ * @param len the length of the given buffer
+ * @param seed The seed to use.
+ * @return the CRC8 checksum for the buffer
+ */
+WS_DLL_PUBLIC guint8 crc8_0x3B(guint8 *buf, guint32 len, guint8 seed);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */