aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/crc16.h
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-12-23 22:16:08 +0100
committerHarald Welte <laforge@gnumonks.org>2016-12-23 22:16:08 +0100
commita0f74f218bd5c805d1c190af54d80ed781241148 (patch)
tree6dce29c5ab8f66742b8f0a2b2226943e08bcfb50 /include/osmocom/core/crc16.h
parent5e5954db8b2f340a10877ebabc895f27ad319231 (diff)
add CRC16-CCITT to libosmocore
Use the implementation from Linux lib/crc-ccitt.c (GPLv2) Change-Id: I26bb54038f5ab36bbb34da7f5fb8ae6c0c0386a4
Diffstat (limited to 'include/osmocom/core/crc16.h')
-rw-r--r--include/osmocom/core/crc16.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/osmocom/core/crc16.h b/include/osmocom/core/crc16.h
index 83b2e5f7..f1564bd2 100644
--- a/include/osmocom/core/crc16.h
+++ b/include/osmocom/core/crc16.h
@@ -29,3 +29,15 @@ static inline uint16_t osmo_crc16_byte(uint16_t crc, const uint8_t data)
{
return (crc >> 8) ^ osmo_crc16_table[(crc ^ data) & 0xff];
}
+
+
+/* CCITT polynome 0x8408. This corresponds to x^0 + x^5 + x^12 */
+
+extern uint16_t const osmo_crc16_ccitt_table[256];
+
+extern uint16_t osmo_crc16_ccitt(uint16_t crc, const uint8_t *buffer, size_t len);
+
+static inline uint16_t osmo_crc16_ccitt_byte(uint16_t crc, const uint8_t data)
+{
+ return (crc >> 8) ^ osmo_crc16_ccitt_table[(crc ^ data) & 0xff];
+}