Skip to contentSkip to conversation

CRC ITU-T V.41

PATCH Superseded Ivo van Doorn 3 participants 7 messages Jun 12, 2006

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

PATCH 1/1 CRC ITU-T V.41

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.

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

include/linux/crc-itu-t.h new file +28 -0
new file mode 100644
index 0000000..84920f3
@@ -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  0x0x1021 (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 +68 -0

68 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · On Mon, 12 Jun 2006 16:17:04 +0200 Ivo van Doorn wrote:

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.

so the rt2x00 driver will be converted to use this lib/ code?

Quoted 9 lines

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

include/linux/crc-itu-t.h new file +0 -0
new file mode 100644
index 0000000..84920f3

include/linux/crc-itu-t.h line 6

Quoted 6 lines
include/linux/crc-itu-t.h new file +6 -0
@@ -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  0x0x1021 (x^16 + x^12 + x^15 + 1)

what does 0x0x.... mean? and aren't poly exponents usually listed in descending order? or should the 15 be 5?

Quoted 12 lines
include/linux/crc-itu-t.h new file +5 -0
+ *   Init  0
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
lib/crc-itu-t.c new file +0 -0
new file mode 100644
index 0000000..b4d4a21

lib/crc-itu-t.c line 3

Quoted 3 lines
lib/crc-itu-t.c new file +3 -0
@@ -0,0 +1,68 @@
+
+/**
+ * Compute the CRC-ITU-T for the data buffer

Please use Linux kernel-doc format. See Documentation/kernel-doc-nano-HOWTO.txt. Basically:

* crc_itu_t - compute the CRC-ITU-T for the data buffer

and make parameter changes below:

lib/crc-itu-t.c line 55

Quoted 4 lines
lib/crc-itu-t.c new file +4 -0
+ *
+ * @param crc     previous CRC value
+ * @param buffer  data pointer
+ * @param len     number of bytes in the buffer

* @crc: previous CRC value
* @buffer: data pointer
* @len: number of bytes in the buffer
*
* Returns the updated CRC value.

lib/crc-itu-t.c line 59

Quoted 4 lines
lib/crc-itu-t.c new file +4 -0
+ * @return        the updated CRC value
+ */
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{

---
~Randy

#2 lore raw
Quoted 11 lines · Randy.Dunlap
Quoted 7 lines · On Mon, 12 Jun 2006 16:17:04 +0200 Ivo van Doorn wrote:

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.

so the rt2x00 driver will be converted to use this lib/ code?

Yes. But since rt2x00 is only in the wireless-dev tree at the moment I didn't want to send the patch to convert rt2x00 to this list. And since other (non network) drivers also might want to use this CRC library, I thought it best to seperate the 2 patches completely.
If this patch is is applied I'll immediately send the patch to netdev to make rt2x00 use this library.

Quoted 18 lines
Quoted 9 lines

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

include/linux/crc-itu-t.h new file +0 -0
new file mode 100644
index 0000000..84920f3

include/linux/crc-itu-t.h line 6

Quoted 6 lines
include/linux/crc-itu-t.h new file +6 -0
@@ -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  0x0x1021 (x^16 + x^12 + x^15 + 1)

what does 0x0x.... mean? and aren't poly exponents usually listed in descending order? or should the 15 be 5?

The 0x0x is a typo. :(
The ordering of the exponents came from another driver
which uses the same CRC method, namely tehe udf crc.
I used the information from their comment to get the exact naming of the CRC calculation and the plynomial. The crc code that came from Ralink for the rt2x00 didn't contain any of such information, and I did want to at least provide it with the correct information.

---- [From fs/udf/crc.c]
/*
* udf_crc
*
* PURPOSE
* Calculate a 16-bit CRC checksum using ITU-T V.41 polynomial.
*
* DESCRIPTION
* The OSTA-UDF(tm) 1.50 standard states that using CRCs is mandatory.
* The polynomial used is: x^16 + x^12 + x^15 + 1
*
* PRE-CONDITIONS

  *      data            Pointer to the data block.
  *      size            Size of the data block.

*
* POST-CONDITIONS
* <return> CRC of the data block.
*
* HISTORY
* July 21, 1997 - Andrew E. Mileski
* Adapted from OSTA-UDF(tm) 1.50 standard.
*/
--- [/From fs/udf/crc.c]

Note that I am currently looking into some drivers with their own implementation of CRC to make them use the crc libraries, but I haven't got any patches yet.

Quoted 6 lines
Quoted 5 lines
include/linux/crc-itu-t.h new file +5 -0
+ *   Init  0
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
Quoted 12 lines

lib/crc-itu-t.c line 3

Quoted 9 lines
lib/crc-itu-t.c new file +3 -0
new file mode 100644
index 0000000..b4d4a21
@@ -0,0 +1,68 @@
+
+/**
+ * Compute the CRC-ITU-T for the data buffer

Please use Linux kernel-doc format. See Documentation/kernel-doc-nano-HOWTO.txt. Basically:

Ah ok. I just followed the crc16 approach.

Quoted 15 lines

* crc_itu_t - compute the CRC-ITU-T for the data buffer

and make parameter changes below:

lib/crc-itu-t.c line 7

Quoted 4 lines
lib/crc-itu-t.c new file +4 -0
+ *
+ * @param crc     previous CRC value
+ * @param buffer  data pointer
+ * @param len     number of bytes in the buffer

* @crc: previous CRC value
* @buffer: data pointer
* @len: number of bytes in the buffer
*
* Returns the updated CRC value.

Quoted 4 lines

lib/crc-itu-t.c line 11

Quoted 4 lines
lib/crc-itu-t.c new file +4 -0
+ * @return        the updated CRC value
+ */
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{

The updated patch would then become:

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

#3 lore raw
Quoted 11 lines · On Mon, 12 Jun 2006 19:32:34 +0200 Ivo van Doorn wrote:
Quoted 8 lines · Randy.Dunlap
Quoted 2 lines · On Mon, 12 Jun 2006 16:17:04 +0200 Ivo van Doorn wrote:

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

Please use Linux kernel-doc format. See Documentation/kernel-doc-nano-HOWTO.txt. Basically:

Ah ok. I just followed the crc16 approach.

OK, I'll plan to fix that file's kernel-doc then.

Quoted 24 lines
Quoted 15 lines

* crc_itu_t - compute the CRC-ITU-T for the data buffer

and make parameter changes below:

Quoted 4 lines

+ *

+ * @param crc     previous CRC value
+ * @param buffer  data pointer
+ * @param len     number of bytes in the buffer

* @crc: previous CRC value
* @buffer: data pointer
* @len: number of bytes in the buffer
*
* Returns the updated CRC value.

Quoted 4 lines

lib/crc-itu-t.c line 60

Quoted 4 lines

+ * @return the updated CRC value
+ */

lib/crc-itu-t.c new file +2 -0
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{

The updated patch would then become:

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

Quoted 8 lines

---

+/**
+ * crc_itu_t - Compute the CRC-ITU-T for the data buffer
+ *
+ * @crc previous CRC value
+ * @buffer data pointer
+ * @len number of bytes in the buffer

The kernel-doc doc. says to put a colon after each parameter name, so please do that too. Otherwise looks good, thanks.

lib/crc-itu-t.c line 60

Quoted 5 lines

+ *
+ * Returns the updated CRC value
+ */

lib/crc-itu-t.c new file +2 -0
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{

---
~Randy

#4 lore raw
Quoted 49 lines · Randy.Dunlap
Quoted 11 lines · On Mon, 12 Jun 2006 19:32:34 +0200 Ivo van Doorn wrote:
Quoted 8 lines · Randy.Dunlap
Quoted 2 lines · On Mon, 12 Jun 2006 16:17:04 +0200 Ivo van Doorn wrote:

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

Please use Linux kernel-doc format. See Documentation/kernel-doc-nano-HOWTO.txt. Basically:

Ah ok. I just followed the crc16 approach.

OK, I'll plan to fix that file's kernel-doc then.

Quoted 24 lines
Quoted 15 lines

* crc_itu_t - compute the CRC-ITU-T for the data buffer

and make parameter changes below:

Quoted 4 lines

+ *

+ * @param crc     previous CRC value
+ * @param buffer  data pointer
+ * @param len     number of bytes in the buffer

* @crc: previous CRC value
* @buffer: data pointer
* @len: number of bytes in the buffer
*
* Returns the updated CRC value.

Quoted 4 lines

Review

Quoted 4 lines

+ * @return the updated CRC value
+ */

(quoted diff) +2 -0
+u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+{

The updated patch would then become:

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

Quoted 8 lines

---

+/**
+ * crc_itu_t - Compute the CRC-ITU-T for the data buffer
+ *
+ * @crc previous CRC value
+ * @buffer data pointer
+ * @len number of bytes in the buffer

Quoted 2 lines

The kernel-doc doc. says to put a colon after each parameter name, so please do that too. Otherwise looks good, thanks.

Updated version. :)

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

#5 lore raw
In reply to Ivo van Doorn
Quoted 6 lines
Quoted 1 line

so the rt2x00 driver will be converted to use this lib/ code?

Yes. [...]
If this patch is is applied I'll immediately send the patch to netdev to make rt2x00 use this library.

Is rt2x00 already in-kernel? AFAIK no, but correct me if I am wrong.

Jan Engelhardt

#6 lore raw
Quoted 7 lines · Jan Engelhardt
Quoted 6 lines
Quoted 1 line

so the rt2x00 driver will be converted to use this lib/ code?

Yes. [...]
If this patch is is applied I'll immediately send the patch to netdev to make rt2x00 use this library.

Is rt2x00 already in-kernel? AFAIK no, but correct me if I am wrong.

No not yet. It is only located in the wireless-dev tree from John Linville. It has the d80211 stack as a dependency, and that stack is also only found in the wireless-dev tree.

Ivo