chg: crc16 got a compute_crc function

This commit is contained in:
iceman1001 2018-01-30 03:31:11 +01:00
commit bf25b1c9ba
6 changed files with 41 additions and 10 deletions

View file

@ -277,16 +277,17 @@ int CmdAnalyseCRC(const char *Cmd) {
}
len >>= 1;
PrintAndLog("\nTests with | %s", sprint_hex(data, len));
PrintAndLog("\nTests with (%d) | %s",len, sprint_hex(data, len));
init_table(CRC_LEGIC);
// 51 f5 7a d6
uint8_t uid[] = {0x51, 0xf5, 0x7a, 0xd6}; //12 34 56
init_table(CRC_LEGIC);
uint8_t legic8 = CRC8Legic(uid, sizeof(uid));
PrintAndLog("LEGIC | %X (EF6F expected) %02x", crc16_legic(data, sizeof(len), legic8), legic8);
PrintAndLog("Legic 16 | %X (EF6F expected) [legic8 = %02x]", crc16_legic(data, len, legic8), legic8);
init_table(CRC_FELICA);
PrintAndLog("FeliCa | %X ", crc16_xmodem(data, len));
return 0;
PrintAndLog("\nTests of reflection. Current methods in source code");
PrintAndLog(" reflect(0x3e23L,3) is %04X == 0x3e26", reflect(0x3e23L,3) );
PrintAndLog(" reflect8(0x80) is %02X == 0x01", reflect8(0x80));

View file

@ -146,6 +146,23 @@ uint16_t crc16(uint8_t const *d, size_t length, uint16_t remainder, uint16_t pol
return remainder;
}
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second) {
uint16_t crc = 0;
switch (ct) {
case CRC_14A: crc = crc16_a(d, n); break;
case CRC_14B:
case CRC_15: crc = crc16_x25(d, n); break;
case CRC_15_ICLASS: crc = crc16_iclass(d, n); break;
case CRC_FELICA:crc = crc16_xmodem(d, n); break;
//case CRC_LEGIC:
case CRC_DNP: crc = crc16_dnp(d, n); break;
case CRC_CCITT: crc = crc16_ccitt(d, n); break;
default: break;
}
*first = (crc & 0xFF);
*second = ((crc >> 8) & 0xFF);
}
//poly=0x1021 init=0xffff refin=false refout=false xorout=0x0000 check=0x29b1 residue=0x0000 name="CRC-16/CCITT-FALSE"
uint16_t crc16_ccitt(uint8_t const *d, size_t n) {
return crc16_fast(d, n, 0xffff, false, false);

View file

@ -32,6 +32,9 @@ uint16_t update_crc16_ex( uint16_t crc, uint8_t c, uint16_t polynomial );
uint16_t update_crc16(uint16_t crc, uint8_t c);
uint16_t crc16(uint8_t const *message, size_t length, uint16_t remainder, uint16_t polynomial, bool refin, bool refout);
//
void compute_crc(CrcType_t ct, const uint8_t *d, size_t n, uint8_t *first, uint8_t *second);
// Calculate CRC-16/CCITT-FALSE checksum
uint16_t crc16_ccitt(uint8_t const *d, size_t n);

View file

@ -5,7 +5,6 @@
//-----------------------------------------------------------------------------
// ISO15693 CRC & other commons
//-----------------------------------------------------------------------------
#include "iso15693tools.h"
// The CRC as described in ISO 15693-Part 3-Annex C

View file

@ -438,9 +438,6 @@ uint32_t GetT55xxClockBit(uint32_t clock);
// FeliCa protocol
#define FLITE_SERVICE_RO 0x000B
#define FLITE_SERVICE_RW 0x0009
#define FELICA_POLL_REQ 0x00
#define FELICA_POLL_ACK 0x01
@ -497,6 +494,21 @@ uint32_t GetT55xxClockBit(uint32_t clock);
#define FELICA_UPDATE_RNDID_REQ 0x4C
#define FELICA_UPDATE_RNDID_ACK 0x4D
// FeliCa SYSTEM list
#define SYSTEMCODE_ANY 0xffff // ANY
#define SYSTEMCODE_FELICA_LITE 0x88b4 // FeliCa Lite
#define SYSTEMCODE_COMMON 0xfe00 // Common
#define SYSTEMCODE_EDY 0xfe00 // Edy
#define SYSTEMCODE_CYBERNE 0x0003 // Cyberne
#define SYSTEMCODE_SUICA 0x0003 // Suica
#define SYSTEMCODE_PASMO 0x0003 // Pasmo
//FeliCa Service list Suica/pasmo (little endian)
#define SERVICE_SUICA_INOUT 0x108f // SUICA/PASMO
#define SERVICE_SUICA_HISTORY 0x090f // SUICA/PASMO
#define SERVICE_FELICA_LITE_READONLY 0x0b00 // FeliCa Lite RO
#define SERVICE_FELICA_LITE_READWRITE 0x0900 // FeliCa Lite RW
// Calypso protocol
#define CALYPSO_GET_RESPONSE 0xC0
#define CALYPSO_SELECT 0xA4

View file

@ -50,5 +50,4 @@ extern int MF_DBGLEVEL;
#ifdef __cplusplus
}
#endif
#endif