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);
}