2010-02-21 08:12:52 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// CRC16
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef __CRC16_H
|
|
|
|
#define __CRC16_H
|
2016-07-29 03:41:44 +08:00
|
|
|
|
2019-08-08 22:57:33 +08:00
|
|
|
#include "common.h"
|
2016-07-29 03:41:44 +08:00
|
|
|
|
2019-10-30 22:44:57 +08:00
|
|
|
#define CRC16_POLY_CCITT 0x1021
|
|
|
|
#define CRC16_POLY_KERMIT 0x8408
|
|
|
|
#define CRC16_POLY_LEGIC 0xc6c6 //0x6363
|
|
|
|
#define CRC16_POLY_DNP 0x3d65
|
2018-01-28 17:59:57 +08:00
|
|
|
|
2019-03-10 02:19:50 +08:00
|
|
|
#define X25_CRC_CHECK ((uint16_t)(~0xF0B8 & 0xFFFF)) // use this for checking of a correct crc
|
2018-02-01 22:19:47 +08:00
|
|
|
|
2018-01-29 20:42:02 +08:00
|
|
|
typedef enum {
|
2019-03-10 02:19:50 +08:00
|
|
|
CRC_NONE,
|
2019-10-30 22:44:57 +08:00
|
|
|
CRC_11784,
|
2019-03-10 02:19:50 +08:00
|
|
|
CRC_14443_A,
|
|
|
|
CRC_14443_B,
|
|
|
|
CRC_15693,
|
|
|
|
CRC_ICLASS,
|
|
|
|
CRC_FELICA,
|
|
|
|
CRC_LEGIC,
|
|
|
|
CRC_CCITT,
|
|
|
|
CRC_KERMIT,
|
2019-08-05 02:05:30 +08:00
|
|
|
CRC_XMODEM,
|
2020-08-21 20:11:24 +08:00
|
|
|
CRC_CRYPTORF,
|
2018-01-29 20:42:02 +08:00
|
|
|
} CrcType_t;
|
2018-01-28 17:59:57 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
uint16_t update_crc16_ex(uint16_t crc, uint8_t c, uint16_t polynomial);
|
2018-01-28 17:59:57 +08:00
|
|
|
uint16_t update_crc16(uint16_t crc, uint8_t c);
|
2019-04-09 16:12:15 +08:00
|
|
|
uint16_t Crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout);
|
2018-01-28 19:19:04 +08:00
|
|
|
|
2019-04-09 16:12:15 +08:00
|
|
|
uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n);
|
2018-01-30 10:31:11 +08:00
|
|
|
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second);
|
2018-02-01 22:19:47 +08:00
|
|
|
bool check_crc(CrcType_t ct, const uint8_t *d, size_t n);
|
2018-01-30 10:31:11 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/CCITT-FALSE
|
2018-01-28 19:19:04 +08:00
|
|
|
uint16_t crc16_ccitt(uint8_t const *d, size_t n);
|
2018-01-29 20:42:02 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/KERMIT (FDX-B ISO11784/85) LF
|
2019-10-30 22:44:57 +08:00
|
|
|
uint16_t crc16_fdx(uint8_t const *d, size_t n);
|
|
|
|
|
|
|
|
// Calculate CRC-16/KERMIT
|
2018-01-28 19:19:04 +08:00
|
|
|
uint16_t crc16_kermit(uint8_t const *d, size_t n);
|
2018-01-29 20:42:02 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/XMODEM (FeliCa)
|
2018-01-28 19:19:04 +08:00
|
|
|
uint16_t crc16_xmodem(uint8_t const *d, size_t n);
|
2018-01-29 20:42:02 +08:00
|
|
|
|
2019-03-09 15:59:13 +08:00
|
|
|
// Calculate CRC-16/X25 (ISO15693, ISO14443 CRC-B,ISO/IEC 13239)
|
2018-01-28 19:19:04 +08:00
|
|
|
uint16_t crc16_x25(uint8_t const *d, size_t n);
|
2018-01-29 20:42:02 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/CRC-A (ISO14443 CRC-A)
|
2018-01-28 19:19:04 +08:00
|
|
|
uint16_t crc16_a(uint8_t const *d, size_t n);
|
2018-01-29 20:42:02 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/iCLASS
|
2018-01-29 20:42:02 +08:00
|
|
|
uint16_t crc16_iclass(uint8_t const *d, size_t n);
|
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
// Calculate CRC-16/Legic
|
2018-01-29 20:42:02 +08:00
|
|
|
// the initial_value is based on the previous legic_Crc8 of the UID.
|
|
|
|
// ie: uidcrc = 0x78 then initial_value == 0x7878
|
|
|
|
uint16_t crc16_legic(uint8_t const *d, size_t n, uint8_t uidcrc);
|
|
|
|
|
|
|
|
// table implementation
|
|
|
|
void init_table(CrcType_t crctype);
|
|
|
|
void reset_table(void);
|
|
|
|
void generate_table(uint16_t polynomial, bool refin);
|
|
|
|
uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bool refout);
|
2018-01-28 19:19:04 +08:00
|
|
|
|
2019-03-12 07:12:26 +08:00
|
|
|
#endif
|