linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
	davem@davemloft.net, Stephen Rothwell <sfr@canb.auug.org.au>,
	Sergey Lapin <slapin@ossfans.org>,
	Darren Salt <linux@youmustbejoking.demon.co.uk>
Subject: [PATCH 1/6] crc-itu-t: add bit-reversed calculation
Date: Wed,  3 Jun 2009 13:33:44 +0400	[thread overview]
Message-ID: <1244021629-18409-2-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1244021629-18409-1-git-send-email-dbaryshkov@gmail.com>

From: Darren Salt <linux@youmustbejoking.demon.co.uk>

Signed-off-by: Darren Salt <linux@youmustbejoking.demon.co.uk>
---
 include/linux/crc-itu-t.h |   10 ++++++++++
 lib/crc-itu-t.c           |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/linux/crc-itu-t.h b/include/linux/crc-itu-t.h
index 84920f3..7b2b7ba 100644
--- a/include/linux/crc-itu-t.h
+++ b/include/linux/crc-itu-t.h
@@ -6,6 +6,9 @@
  *   Poly  0x0x1021 (x^16 + x^12 + x^15 + 1)
  *   Init  0
  *
+ * The bit-reversed buffer variants may be non-standard, but some firmware
+ * loaders require them.
+ *
  * This source code is licensed under the GNU General Public License,
  * Version 2. See the file COPYING for more details.
  */
@@ -14,15 +17,22 @@
 #define CRC_ITU_T_H
 
 #include <linux/types.h>
+#include <linux/bitrev.h>
 
 extern u16 const crc_itu_t_table[256];
 
 extern u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len);
+extern u16 crc_itu_t_bitreversed(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];
 }
 
+static inline u16 crc_itu_t_bitreversed_byte(u16 crc, const u8 data)
+{
+	return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ bitrev8(data)) & 0xff];
+}
+
 #endif /* CRC_ITU_T_H */
 
diff --git a/lib/crc-itu-t.c b/lib/crc-itu-t.c
index a63472b..5562fdd 100644
--- a/lib/crc-itu-t.c
+++ b/lib/crc-itu-t.c
@@ -64,6 +64,24 @@ u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
 }
 EXPORT_SYMBOL(crc_itu_t);
 
+/**
+ * crc_itu_t_bitreversed - Compute the CRC-ITU-T for the data buffer;
+ * the buffer content is assumed to be bit-reversed
+ *
+ * @crc:     previous CRC value
+ * @buffer:  data pointer
+ * @len:     number of bytes in the buffer
+ *
+ * Returns the updated CRC value
+ */
+u16 crc_itu_t_bitreversed(u16 crc, const u8 *buffer, size_t len)
+{
+	while (len--)
+		crc = crc_itu_t_bitreversed_byte(crc, *buffer++);
+	return crc;
+}
+EXPORT_SYMBOL(crc_itu_t_bitreversed);
+
 MODULE_DESCRIPTION("CRC ITU-T V.41 calculations");
 MODULE_LICENSE("GPL");
 
-- 
1.6.3.1


  reply	other threads:[~2009-06-03  9:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-03  9:33 [MERGE REQUEST] IEEE 802.15.4 stack: generic parts Dmitry Eremin-Solenikov
2009-06-03  9:33 ` Dmitry Eremin-Solenikov [this message]
2009-06-03  9:33   ` [PATCH 2/6] Add constants for the ieee 802.15.4/ZigBee stack Dmitry Eremin-Solenikov
2009-06-03  9:33     ` [PATCH 3/6] net: add IEEE 802.15.4 socket family implementation Dmitry Eremin-Solenikov
2009-06-03  9:33       ` [PATCH 4/6] net: add NL802154 interface for configuration of 802.15.4 devices Dmitry Eremin-Solenikov
2009-06-03  9:33         ` [PATCH 5/6] ieee802154: add documentation about our stack Dmitry Eremin-Solenikov
2009-06-03  9:33           ` [PATCH 6/6] ieee802154: add simple HardMAC driver sample Dmitry Eremin-Solenikov
2009-06-03  9:39         ` [PATCH 4/6] net: add NL802154 interface for configuration of 802.15.4 devices Johannes Berg
2009-06-03 10:09           ` David Miller
2009-06-03 10:52             ` Dmitry Eremin-Solenikov
2009-06-03 11:05               ` Johannes Berg
2009-06-03 12:27                 ` Dmitry Eremin-Solenikov
2009-06-04 14:12                   ` Johannes Berg
2009-06-04 14:51                     ` Dmitry Eremin-Solenikov
2009-06-04 15:12                       ` Patrick McHardy
2009-06-04 15:14                         ` Dmitry Eremin-Solenikov
2009-06-04 15:15                           ` Patrick McHardy
2009-06-03 12:55                 ` Sergey Lapin
2009-06-03 14:21                   ` Patrick McHardy
2009-06-03 23:12                 ` Dmitry Eremin-Solenikov
2009-06-03 10:08     ` [PATCH 2/6] Add constants for the ieee 802.15.4/ZigBee stack David Miller
2009-06-03 10:51       ` Dmitry Eremin-Solenikov
2009-06-03 21:19         ` David Miller
2009-06-03 23:15           ` Dmitry Eremin-Solenikov
2009-06-04  0:49             ` David Miller
2009-06-03 12:43   ` [PATCH 1/6] crc-itu-t: add bit-reversed calculation Ben Hutchings
2009-06-03 12:48     ` Dmitry Eremin-Solenikov
2009-06-04  0:49     ` Dmitry Eremin-Solenikov
2009-06-21  8:29     ` Dmitry Eremin-Solenikov
2009-06-21 10:18       ` Ivo van Doorn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244021629-18409-2-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@youmustbejoking.demon.co.uk \
    --cc=netdev@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=slapin@ossfans.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).