Harald Welte | cdbcff9 | 2018-05-12 09:44:03 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * Functions and types for CRC checks. |
| 4 | * |
| 5 | * Generated on Sat May 12 09:39:22 2018 |
| 6 | * by pycrc v0.9.1, https://pycrc.org |
| 7 | * using the configuration: |
| 8 | * - Width = 4 |
| 9 | * - Poly = 0x3 |
| 10 | * - XorIn = 0x0 |
| 11 | * - ReflectIn = False |
| 12 | * - XorOut = 0x0 |
| 13 | * - ReflectOut = False |
| 14 | * - Algorithm = table-driven |
| 15 | */ |
| 16 | #include "crc4itu.h" /* include the header file generated with pycrc */ |
| 17 | #include <stdlib.h> |
Harald Welte | 0c756eb | 2018-05-06 16:01:29 +0200 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | |
Harald Welte | cdbcff9 | 2018-05-12 09:44:03 +0200 | [diff] [blame] | 20 | |
| 21 | |
| 22 | /** |
| 23 | * Static table used for the table_driven implementation. |
| 24 | */ |
| 25 | static const crc_t crc_table[256] = { |
| 26 | 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, |
| 27 | 0x05, 0x06, 0x03, 0x00, 0x09, 0x0a, 0x0f, 0x0c, 0x0e, 0x0d, 0x08, 0x0b, 0x02, 0x01, 0x04, 0x07, |
| 28 | 0x0a, 0x09, 0x0c, 0x0f, 0x06, 0x05, 0x00, 0x03, 0x01, 0x02, 0x07, 0x04, 0x0d, 0x0e, 0x0b, 0x08, |
| 29 | 0x0f, 0x0c, 0x09, 0x0a, 0x03, 0x00, 0x05, 0x06, 0x04, 0x07, 0x02, 0x01, 0x08, 0x0b, 0x0e, 0x0d, |
| 30 | 0x07, 0x04, 0x01, 0x02, 0x0b, 0x08, 0x0d, 0x0e, 0x0c, 0x0f, 0x0a, 0x09, 0x00, 0x03, 0x06, 0x05, |
| 31 | 0x02, 0x01, 0x04, 0x07, 0x0e, 0x0d, 0x08, 0x0b, 0x09, 0x0a, 0x0f, 0x0c, 0x05, 0x06, 0x03, 0x00, |
| 32 | 0x0d, 0x0e, 0x0b, 0x08, 0x01, 0x02, 0x07, 0x04, 0x06, 0x05, 0x00, 0x03, 0x0a, 0x09, 0x0c, 0x0f, |
| 33 | 0x08, 0x0b, 0x0e, 0x0d, 0x04, 0x07, 0x02, 0x01, 0x03, 0x00, 0x05, 0x06, 0x0f, 0x0c, 0x09, 0x0a, |
| 34 | 0x0e, 0x0d, 0x08, 0x0b, 0x02, 0x01, 0x04, 0x07, 0x05, 0x06, 0x03, 0x00, 0x09, 0x0a, 0x0f, 0x0c, |
| 35 | 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, |
| 36 | 0x04, 0x07, 0x02, 0x01, 0x08, 0x0b, 0x0e, 0x0d, 0x0f, 0x0c, 0x09, 0x0a, 0x03, 0x00, 0x05, 0x06, |
| 37 | 0x01, 0x02, 0x07, 0x04, 0x0d, 0x0e, 0x0b, 0x08, 0x0a, 0x09, 0x0c, 0x0f, 0x06, 0x05, 0x00, 0x03, |
| 38 | 0x09, 0x0a, 0x0f, 0x0c, 0x05, 0x06, 0x03, 0x00, 0x02, 0x01, 0x04, 0x07, 0x0e, 0x0d, 0x08, 0x0b, |
| 39 | 0x0c, 0x0f, 0x0a, 0x09, 0x00, 0x03, 0x06, 0x05, 0x07, 0x04, 0x01, 0x02, 0x0b, 0x08, 0x0d, 0x0e, |
| 40 | 0x03, 0x00, 0x05, 0x06, 0x0f, 0x0c, 0x09, 0x0a, 0x08, 0x0b, 0x0e, 0x0d, 0x04, 0x07, 0x02, 0x01, |
| 41 | 0x06, 0x05, 0x00, 0x03, 0x0a, 0x09, 0x0c, 0x0f, 0x0d, 0x0e, 0x0b, 0x08, 0x01, 0x02, 0x07, 0x04 |
Harald Welte | 0c756eb | 2018-05-06 16:01:29 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Harald Welte | cdbcff9 | 2018-05-12 09:44:03 +0200 | [diff] [blame] | 44 | |
| 45 | crc_t crc4itu_update(crc_t crc, const void *data, size_t data_len) |
Harald Welte | 0c756eb | 2018-05-06 16:01:29 +0200 | [diff] [blame] | 46 | { |
Harald Welte | cdbcff9 | 2018-05-12 09:44:03 +0200 | [diff] [blame] | 47 | const unsigned char *d = (const unsigned char *)data; |
| 48 | unsigned int tbl_idx; |
| 49 | |
| 50 | while (data_len--) { |
| 51 | tbl_idx = (crc << 4) ^ *d; |
| 52 | crc = crc_table[tbl_idx] & 0xf; |
| 53 | d++; |
| 54 | } |
| 55 | return crc & 0xf; |
Harald Welte | 0c756eb | 2018-05-06 16:01:29 +0200 | [diff] [blame] | 56 | } |