From bf25b1c9baa577bcebe20972d16895dc592c7dae Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 30 Jan 2018 03:31:11 +0100 Subject: [PATCH] chg: crc16 got a compute_crc function --- client/cmdanalyse.c | 11 ++++++----- common/crc16.c | 17 +++++++++++++++++ common/crc16.h | 3 +++ common/iso15693tools.c | 1 - common/protocols.h | 18 +++++++++++++++--- include/common.h | 1 - 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index d1adf18fc..7cab35499 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -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)); diff --git a/common/crc16.c b/common/crc16.c index 91dcf8504..70b0c9d4c 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -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); diff --git a/common/crc16.h b/common/crc16.h index 7202e74de..a4face22d 100644 --- a/common/crc16.h +++ b/common/crc16.h @@ -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); diff --git a/common/iso15693tools.c b/common/iso15693tools.c index 03d0892cb..42937e5a8 100644 --- a/common/iso15693tools.c +++ b/common/iso15693tools.c @@ -5,7 +5,6 @@ //----------------------------------------------------------------------------- // ISO15693 CRC & other commons //----------------------------------------------------------------------------- - #include "iso15693tools.h" // The CRC as described in ISO 15693-Part 3-Annex C diff --git a/common/protocols.h b/common/protocols.h index 041b8893a..9d5334c67 100644 --- a/common/protocols.h +++ b/common/protocols.h @@ -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 diff --git a/include/common.h b/include/common.h index 434f050e8..fe5eaeb59 100644 --- a/include/common.h +++ b/include/common.h @@ -50,5 +50,4 @@ extern int MF_DBGLEVEL; #ifdef __cplusplus } #endif - #endif \ No newline at end of file