aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/CMakeLists.txt1
-rw-r--r--epan/Makefile.common2
-rw-r--r--epan/crc10-tvb.c40
-rw-r--r--epan/crc10-tvb.h38
-rw-r--r--epan/dissectors/packet-atm.c66
-rw-r--r--epan/dissectors/packet-iuup.c21
-rw-r--r--wsutil/crc10.c22
-rw-r--r--wsutil/crc10.h2
8 files changed, 110 insertions, 82 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index 69670faa54..4ca89f8e42 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -1531,6 +1531,7 @@ set(LIBWIRESHARK_FILES
column-utils.c
conversation.c
conversation_table.c
+ crc10-tvb.c
crc16-tvb.c
crc32-tvb.c
crc8-tvb.c
diff --git a/epan/Makefile.common b/epan/Makefile.common
index 675d740428..ef925bf63e 100644
--- a/epan/Makefile.common
+++ b/epan/Makefile.common
@@ -36,6 +36,7 @@ LIBWIRESHARK_SRC = \
column-utils.c \
conversation.c \
conversation_table.c \
+ crc10-tvb.c \
crc16-tvb.c \
crc32-tvb.c \
crc8-tvb.c \
@@ -166,6 +167,7 @@ LIBWIRESHARK_INCLUDES = \
conversation_debug.h \
conversation_table.h \
conv_id.h \
+ crc10-tvb.h \
crc16-tvb.h \
crc32-tvb.h \
crc8-tvb.h \
diff --git a/epan/crc10-tvb.c b/epan/crc10-tvb.c
new file mode 100644
index 0000000000..072feb8e64
--- /dev/null
+++ b/epan/crc10-tvb.c
@@ -0,0 +1,40 @@
+/* crc10-tvb.c
+ * CRC-10 tvb routines
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <epan/tvbuff.h>
+#include <wsutil/crc10.h>
+#include <epan/crc10-tvb.h>
+
+/* update the data block's CRC-10 remainder one byte at a time */
+guint16
+update_crc10_by_bytes_tvb(guint16 crc10, tvbuff_t *tvb, int offset, int len)
+{
+ const guint8 *buf;
+
+ tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
+ buf = tvb_get_ptr(tvb, offset, len);
+
+ return update_crc10_by_bytes(crc10, buf, len);
+}
diff --git a/epan/crc10-tvb.h b/epan/crc10-tvb.h
new file mode 100644
index 0000000000..d090062e3d
--- /dev/null
+++ b/epan/crc10-tvb.h
@@ -0,0 +1,38 @@
+/* crc10-tvb.h
+ * Declaration of CRC-10 tvbuff routines
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef __CRC10_TVB_H__
+#define __CRC10_TVB_H__
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+WS_DLL_PUBLIC guint16 update_crc10_by_bytes_tvb(guint16 crc10, tvbuff_t *tvb, int offset, int len);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* crc10-tvb.h */
diff --git a/epan/dissectors/packet-atm.c b/epan/dissectors/packet-atm.c
index 96e4b8674b..c8cec768bc 100644
--- a/epan/dissectors/packet-atm.c
+++ b/epan/dissectors/packet-atm.c
@@ -29,6 +29,7 @@
#include <epan/addr_resolv.h>
#include <epan/ppptypes.h>
#include <epan/expert.h>
+#include <epan/crc10-tvb.h>
#include "packet-atm.h"
#include "packet-snmp.h"
@@ -1476,65 +1477,6 @@ const value_string atm_pt_vals[] = {
{ 0, NULL }
};
-/*
- * Charles Michael Heard's CRC-10 code, from
- *
- * http://web.archive.org/web/20061005231950/http://cell-relay.indiana.edu/cell-relay/publications/software/CRC/crc10.html
- *
- * with the CRC table initialized with values computed by
- * his "gen_byte_crc10_table()" routine, rather than by calling that
- * routine at run time, and with various data type cleanups.
- */
-static const guint16 byte_crc10_table[256] = {
- 0x0000, 0x0233, 0x0255, 0x0066, 0x0299, 0x00aa, 0x00cc, 0x02ff,
- 0x0301, 0x0132, 0x0154, 0x0367, 0x0198, 0x03ab, 0x03cd, 0x01fe,
- 0x0031, 0x0202, 0x0264, 0x0057, 0x02a8, 0x009b, 0x00fd, 0x02ce,
- 0x0330, 0x0103, 0x0165, 0x0356, 0x01a9, 0x039a, 0x03fc, 0x01cf,
- 0x0062, 0x0251, 0x0237, 0x0004, 0x02fb, 0x00c8, 0x00ae, 0x029d,
- 0x0363, 0x0150, 0x0136, 0x0305, 0x01fa, 0x03c9, 0x03af, 0x019c,
- 0x0053, 0x0260, 0x0206, 0x0035, 0x02ca, 0x00f9, 0x009f, 0x02ac,
- 0x0352, 0x0161, 0x0107, 0x0334, 0x01cb, 0x03f8, 0x039e, 0x01ad,
- 0x00c4, 0x02f7, 0x0291, 0x00a2, 0x025d, 0x006e, 0x0008, 0x023b,
- 0x03c5, 0x01f6, 0x0190, 0x03a3, 0x015c, 0x036f, 0x0309, 0x013a,
- 0x00f5, 0x02c6, 0x02a0, 0x0093, 0x026c, 0x005f, 0x0039, 0x020a,
- 0x03f4, 0x01c7, 0x01a1, 0x0392, 0x016d, 0x035e, 0x0338, 0x010b,
- 0x00a6, 0x0295, 0x02f3, 0x00c0, 0x023f, 0x000c, 0x006a, 0x0259,
- 0x03a7, 0x0194, 0x01f2, 0x03c1, 0x013e, 0x030d, 0x036b, 0x0158,
- 0x0097, 0x02a4, 0x02c2, 0x00f1, 0x020e, 0x003d, 0x005b, 0x0268,
- 0x0396, 0x01a5, 0x01c3, 0x03f0, 0x010f, 0x033c, 0x035a, 0x0169,
- 0x0188, 0x03bb, 0x03dd, 0x01ee, 0x0311, 0x0122, 0x0144, 0x0377,
- 0x0289, 0x00ba, 0x00dc, 0x02ef, 0x0010, 0x0223, 0x0245, 0x0076,
- 0x01b9, 0x038a, 0x03ec, 0x01df, 0x0320, 0x0113, 0x0175, 0x0346,
- 0x02b8, 0x008b, 0x00ed, 0x02de, 0x0021, 0x0212, 0x0274, 0x0047,
- 0x01ea, 0x03d9, 0x03bf, 0x018c, 0x0373, 0x0140, 0x0126, 0x0315,
- 0x02eb, 0x00d8, 0x00be, 0x028d, 0x0072, 0x0241, 0x0227, 0x0014,
- 0x01db, 0x03e8, 0x038e, 0x01bd, 0x0342, 0x0171, 0x0117, 0x0324,
- 0x02da, 0x00e9, 0x008f, 0x02bc, 0x0043, 0x0270, 0x0216, 0x0025,
- 0x014c, 0x037f, 0x0319, 0x012a, 0x03d5, 0x01e6, 0x0180, 0x03b3,
- 0x024d, 0x007e, 0x0018, 0x022b, 0x00d4, 0x02e7, 0x0281, 0x00b2,
- 0x017d, 0x034e, 0x0328, 0x011b, 0x03e4, 0x01d7, 0x01b1, 0x0382,
- 0x027c, 0x004f, 0x0029, 0x021a, 0x00e5, 0x02d6, 0x02b0, 0x0083,
- 0x012e, 0x031d, 0x037b, 0x0148, 0x03b7, 0x0184, 0x01e2, 0x03d1,
- 0x022f, 0x001c, 0x007a, 0x0249, 0x00b6, 0x0285, 0x02e3, 0x00d0,
- 0x011f, 0x032c, 0x034a, 0x0179, 0x0386, 0x01b5, 0x01d3, 0x03e0,
- 0x021e, 0x002d, 0x004b, 0x0278, 0x0087, 0x02b4, 0x02d2, 0x00e1,
-};
-
-/* update the data block's CRC-10 remainder one byte at a time */
-static guint16
-update_crc10_by_bytes(guint16 crc10_accum, const guint8 *data_blk_ptr,
- int data_blk_size)
-{
- register int i;
-
- for (i = 0; i < data_blk_size; i++) {
- crc10_accum = ((crc10_accum << 8) & 0x3ff)
- ^ byte_crc10_table[( crc10_accum >> 2) & 0xff]
- ^ *data_blk_ptr++;
- }
- return crc10_accum;
-}
-
static const value_string st_vals[] = {
{ 2, "BOM" },
{ 0, "COM" },
@@ -1743,8 +1685,7 @@ dissect_atm_cell(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree_add_item(aal_tree, hf_atm_aal3_4_multiplex_id, tvb, offset, 2, ENC_BIG_ENDIAN);
length = tvb_length_remaining(tvb, offset);
- crc10 = update_crc10_by_bytes(0, tvb_get_ptr(tvb, offset, length),
- length);
+ crc10 = update_crc10_by_bytes_tvb(0, tvb, offset, length);
offset += 2;
proto_tree_add_item(aal_tree, hf_atm_aal3_4_information, tvb, offset, 44, ENC_NA);
@@ -1790,8 +1731,7 @@ dissect_atm_cell(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
break;
}
length = tvb_length_remaining(tvb, offset);
- crc10 = update_crc10_by_bytes(0, tvb_get_ptr(tvb, offset, length),
- length);
+ crc10 = update_crc10_by_bytes_tvb(0, tvb, offset, length);
offset += 1;
proto_tree_add_item(aal_tree, hf_atm_aal_oamcell_func_spec, tvb, offset, 45, ENC_NA);
diff --git a/epan/dissectors/packet-iuup.c b/epan/dissectors/packet-iuup.c
index 5c5820be65..d5315a8d6e 100644
--- a/epan/dissectors/packet-iuup.c
+++ b/epan/dissectors/packet-iuup.c
@@ -36,6 +36,7 @@
#include <epan/prefs.h>
#include <epan/wmem/wmem.h>
#include <epan/expert.h>
+#include <epan/crc10-tvb.h>
#include <wsutil/crc10.h>
#include <wsutil/crc6.h>
@@ -574,12 +575,26 @@ static void add_hdr_crc(tvbuff_t* tvb, packet_info* pinfo, proto_item* iuup_tree
}
}
+guint16
+update_crc10_by_bytes_iuup(tvbuff_t *tvb, int offset, int length)
+{
+ guint16 crc10;
+ guint16 extra_16bits;
+ guint8 extra_8bits[2];
+
+ crc10 = update_crc10_by_bytes_tvb(0, tvb, offset + 2, length - 4);
+ extra_16bits = tvb_get_ntohs(tvb, offset) & 0x3FF;
+ extra_8bits[0] = extra_16bits >> 2;
+ extra_8bits[1] = (extra_16bits << 6) & 0xFF;
+ crc10 = update_crc10_by_bytes(crc10, extra_8bits, 2);
+ return crc10;
+}
+
static void add_payload_crc(tvbuff_t* tvb, packet_info* pinfo, proto_item* iuup_tree)
{
proto_item *crc_item;
int length = tvb_length(tvb);
- guint16 crc10 = tvb_get_ntohs(tvb, 2) & 0x3FF;
- guint16 crccheck = update_crc10_by_bytes(crc10, tvb_get_ptr(tvb, 4, length - 4), length - 4);
+ guint16 crccheck = update_crc10_by_bytes_iuup(tvb, 2, length - 4);
crc_item = proto_tree_add_item(iuup_tree,hf_iuup_payload_crc,tvb,2,2,ENC_BIG_ENDIAN);
if (crccheck) {
@@ -789,7 +804,7 @@ static gboolean dissect_iuup_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree
switch ( first_octet & 0xf0 ) {
case 0x00: {
if (len<7) return FALSE;
- if (update_crc10_by_bytes((guint16)(tvb_get_ntohs(tvb, 4) & 0x3FF), tvb_get_ptr(tvb, 6, len-4), len-4) ) return FALSE;
+ if (update_crc10_by_bytes_iuup(tvb, 4, len-4) ) return FALSE;
break;
}
case 0x10:
diff --git a/wsutil/crc10.c b/wsutil/crc10.c
index 9f04d93c04..17d6f1a291 100644
--- a/wsutil/crc10.c
+++ b/wsutil/crc10.c
@@ -69,25 +69,17 @@ static const guint16 byte_crc10_table[256] = {
0x021e, 0x002d, 0x004b, 0x0278, 0x0087, 0x02b4, 0x02d2, 0x00e1
};
-/* update the data block's CRC-10 remainder one byte at a time */
-guint16 update_crc10_by_bytes(guint16 crc10, const guint8 *data_blk_ptr,
- int data_blk_size)
+/* Update the data block's CRC-10 remainder one byte at a time */
+guint16
+update_crc10_by_bytes(guint16 crc10_accum, const guint8 *data_blk_ptr,
+ int data_blk_size)
{
register int i;
- guint16 crc10_accum = 0;
for (i = 0; i < data_blk_size; i++) {
- crc10_accum = ((crc10_accum << 8) & 0x3ff)
- ^ byte_crc10_table[( crc10_accum >> 2) & 0xff]
- ^ *data_blk_ptr++;
+ crc10_accum = ((crc10_accum << 8) & 0x3ff)
+ ^ byte_crc10_table[( crc10_accum >> 2) & 0xff]
+ ^ *data_blk_ptr++;
}
- crc10_accum = ((crc10_accum << 8) & 0x3ff)
- ^ byte_crc10_table[( crc10_accum >> 2) & 0xff]
- ^ (crc10>>2);
- crc10_accum = ((crc10_accum << 8) & 0x3ff)
- ^ byte_crc10_table[( crc10_accum >> 2) & 0xff]
- ^ ((crc10<<6) & 0xFF);
-
return crc10_accum;
}
-
diff --git a/wsutil/crc10.h b/wsutil/crc10.h
index 41b631962b..f881f3bda9 100644
--- a/wsutil/crc10.h
+++ b/wsutil/crc10.h
@@ -26,7 +26,7 @@
#include "ws_symbol_export.h"
-/* update the data block's CRC-10 remainder one byte at a time */
+/* Update the data block's CRC-10 remainder one byte at a time */
WS_DLL_PUBLIC guint16 update_crc10_by_bytes(guint16 crc10, const guint8 *data_blk_ptr, int data_blk_size);
#endif /* __CRC10_H__ */