add legic crc16 to lua

This commit is contained in:
iceman1001 2021-10-23 23:53:59 +02:00
commit 644da79a50
4 changed files with 56 additions and 15 deletions

View file

@ -41,6 +41,9 @@ void init_table(CrcType_t crctype) {
case CRC_LEGIC:
generate_table(CRC16_POLY_LEGIC, true);
break;
case CRC_LEGIC_16:
generate_table(CRC16_POLY_LEGIC_16, true);
break;
case CRC_CCITT:
generate_table(CRC16_POLY_CCITT, false);
break;
@ -194,6 +197,7 @@ void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8
crc = crc16_fdxb(d, n);
break;
case CRC_LEGIC:
case CRC_LEGIC_16:
// TODO
return;
case CRC_NONE:
@ -227,6 +231,7 @@ uint16_t Crc16ex(CrcType_t ct, const uint8_t *d, size_t n) {
case CRC_11784:
return crc16_fdxb(d, n);
case CRC_LEGIC:
case CRC_LEGIC_16:
// TODO
return 0;
case CRC_NONE:
@ -272,6 +277,7 @@ bool check_crc(CrcType_t ct, const uint8_t *d, size_t n) {
case CRC_11784:
return (crc16_fdxb(d, n) == 0);
case CRC_LEGIC:
case CRC_LEGIC_16:
// TODO
return false;
case CRC_NONE:
@ -330,7 +336,7 @@ uint16_t crc16_iclass(uint8_t const *d, size_t n) {
// This CRC-16 is used in Legic Advant systems.
// poly=0xB400, init=depends refin=true refout=true xorout=0x0000 check= name="CRC-16/LEGIC"
uint16_t crc16_legic(uint8_t const *d, size_t n, uint8_t uidcrc) {
uint16_t initial = uidcrc << 8 | uidcrc;
return crc16_fast(d, n, initial, true, true);
uint16_t initial = (uidcrc << 8 | uidcrc);
return crc16_fast(d, n, initial, true, false);
}

View file

@ -10,10 +10,11 @@
#include "common.h"
#define CRC16_POLY_CCITT 0x1021
#define CRC16_POLY_KERMIT 0x8408
#define CRC16_POLY_LEGIC 0xc6c6 //0x6363
#define CRC16_POLY_DNP 0x3d65
#define CRC16_POLY_CCITT 0x1021
#define CRC16_POLY_KERMIT 0x8408
#define CRC16_POLY_LEGIC 0xc6c6 //0x6363
#define CRC16_POLY_LEGIC_16 0x002d
#define CRC16_POLY_DNP 0x3d65
#define X25_CRC_CHECK ((uint16_t)(~0xF0B8 & 0xFFFF)) // use this for checking of a correct crc
@ -26,6 +27,7 @@ typedef enum {
CRC_ICLASS,
CRC_FELICA,
CRC_LEGIC,
CRC_LEGIC_16,
CRC_CCITT,
CRC_KERMIT,
CRC_XMODEM,