Skip to contentSkip to conversation

CRC ITU-T V.41

PATCH RESEND In review Ivo van Doorn 2 participants 3 messages Jun 22, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 CRC ITU-T V.41

Patch was send 2 weeks ago, but required some small changes. This is now the correct patch for latest linux-2.6 git tree. Patch is against torvalds/linux-2.6.git

This will add the CRC calculation according
to the CRC ITU-T V.41 to the kernel lib/ folder.

This code has been derived from the rt2x00 driver, currently found only in the wireless-dev tree, but this library is generic and could be used by more drivers who currently use their own implementation.

The rt2x00 driver will be updated to use this library when this lib is merged into the kernel.

Signed-off-by Ivo van Doorn <[email protected]>

---

include/linux/crc-itu-t.h new file +28 -0
new file mode 100644
index 0000000..a9953c7
@@ -0,0 +1,28 @@
+/*
+ *	crc-itu-t.h - CRC ITU-T V.41 routine
+ *
+ * Implements the standard CRC ITU-T V.41:
+ *   Width 16
+ *   Poly  0x1021 (x^16 + x^12 + x^15 + 1)
+ *   Init  0
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+
+#ifndef CRC_ITU_T_H
+#define CRC_ITU_T_H
+
+#include <linux/types.h>
+
+extern u16 const crc_itu_t_table[256];
+
+extern u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len);
+
+static inline u16 crc_itu_t_byte(u16 crc, const u8 data)
+{
+	return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ data) & 0xff];
+}
+
+#endif /* CRC_ITU_T_H */
+
lib/Kconfig +8 -0
index 3de9335..451d821 100644
@@ -20,6 +20,14 @@ config CRC16
 	  the kernel tree does. Such modules that use library CRC16
 	  functions require M here.
 
+config CRC_ITU_T
+	tristate "CRC ITU-T V.41 functions"
+	help
+	  This option is provided for the case where no in-kernel-tree
+	  modules require CRC ITU-T V.41 functions, but a module built outside
+	  the kernel tree does. Such modules that use library CRC ITU-T V.41
+	  functions require M here.
+
 config CRC32
 	tristate "CRC32 functions"
 	default y
lib/Makefile +1 -0
index b830c9a..d2d08ce 100644
@@ -33,6 +33,7 @@ endif
 
 obj-$(CONFIG_CRC_CCITT)	+= crc-ccitt.o
 obj-$(CONFIG_CRC16)	+= crc16.o
+obj-$(CONFIG_CRC_ITU_T)	+= crc-itu-t.o
 obj-$(CONFIG_CRC32)	+= crc32.o
 obj-$(CONFIG_LIBCRC32C)	+= libcrc32c.o
 obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
lib/crc-itu-t.c new file +69 -0

69 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · On Thu, 22 Jun 2006 16:29:02 +0200 Ivo van Doorn wrote:
lib/crc-itu-t.c new file +4 -0
new file mode 100644
index 0000000..15128ae
@@ -0,0 +1,69 @@
+/*
+ *      crc-itu-t.c
+ *
+ * This source code is licensed under the GNU General Public License,

lib/crc-itu-t.c line 14

Quoted 10 lines
lib/crc-itu-t.c new file +10 -0
+ * Version 2. See the file COPYING for more details.
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/crc-itu-t.h>
+
+/**
+ * crc_itu_t - Compute the CRC-ITU-T for the data buffer
+ *

no blank ('*') line here (above), please.
kernel-doc doesn't expect that.

lib/crc-itu-t.c line 64

Quoted 12 lines
lib/crc-itu-t.c new file +12 -0
+ * @crc: previous CRC value
+ * @buffer: data pointer
+ * @len: number of bytes in the buffer
+ *
+ * Returns the updated CRC value
+ */
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{
+	while (len--)
+		crc = crc_itu_t_byte(crc, *buffer++);
+	return crc;
+}

---
~Randy

#2 lore raw

<snip>

Quoted 7 lines
Quoted 3 lines

+/**
+ * crc_itu_t - Compute the CRC-ITU-T for the data buffer
+ *

no blank ('*') line here (above), please.
kernel-doc doesn't expect that.

Hopefully this is completely correct now. :)
And ready to be applied. ;)

Signed-off-by Ivo van Doorn <[email protected]>

---

include/linux/crc-itu-t.h new file +28 -0
new file mode 100644
index 0000000..a9953c7
@@ -0,0 +1,28 @@
+/*
+ *	crc-itu-t.h - CRC ITU-T V.41 routine
+ *
+ * Implements the standard CRC ITU-T V.41:
+ *   Width 16
+ *   Poly  0x1021 (x^16 + x^12 + x^15 + 1)
+ *   Init  0
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+
+#ifndef CRC_ITU_T_H
+#define CRC_ITU_T_H
+
+#include <linux/types.h>
+
+extern u16 const crc_itu_t_table[256];
+
+extern u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len);
+
+static inline u16 crc_itu_t_byte(u16 crc, const u8 data)
+{
+	return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ data) & 0xff];
+}
+
+#endif /* CRC_ITU_T_H */
+
lib/Kconfig +8 -0
index 3de9335..451d821 100644
@@ -20,6 +20,14 @@ config CRC16
 	  the kernel tree does. Such modules that use library CRC16
 	  functions require M here.
 
+config CRC_ITU_T
+	tristate "CRC ITU-T V.41 functions"
+	help
+	  This option is provided for the case where no in-kernel-tree
+	  modules require CRC ITU-T V.41 functions, but a module built outside
+	  the kernel tree does. Such modules that use library CRC ITU-T V.41
+	  functions require M here.
+
 config CRC32
 	tristate "CRC32 functions"
 	default y
lib/Makefile +1 -0
index b830c9a..d2d08ce 100644
@@ -33,6 +33,7 @@ endif
 
 obj-$(CONFIG_CRC_CCITT)	+= crc-ccitt.o
 obj-$(CONFIG_CRC16)	+= crc16.o
+obj-$(CONFIG_CRC_ITU_T)	+= crc-itu-t.o
 obj-$(CONFIG_CRC32)	+= crc32.o
 obj-$(CONFIG_LIBCRC32C)	+= libcrc32c.o
 obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
lib/crc-itu-t.c new file +66 -0

66 lines not on this page · raw message