chg: rename

This commit is contained in:
iceman1001 2018-01-28 11:01:29 +01:00
commit 1f5477491f
2 changed files with 28 additions and 34 deletions

View file

@ -8,41 +8,37 @@
#include "iso14443crc.h" #include "iso14443crc.h"
unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc) uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc) {
{ b = (b ^ (uint8_t)((*crc) & 0x00FF));
ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF)); b = (b ^ (b << 4));
ch = (ch ^ (ch << 4)); *crc = (*crc >> 8) ^ ((uint16_t) b << 8) ^ ((uint16_t) b << 3) ^ ((uint16_t) b >> 4);
*lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^ return (*crc);
((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);
return (*lpwCrc);
} }
void ComputeCrc14443(int CrcType, void ComputeCrc14443(uint16_t CrcType, const uint8_t *data, int length,
const unsigned char *Data, int Length, uint8_t *TransmitFirst, uint8_t *TransmitSecond)
unsigned char *TransmitFirst,
unsigned char *TransmitSecond)
{ {
unsigned char chBlock; uint8_t b;
unsigned short wCrc=CrcType; uint16_t crc = CrcType;
do { do {
chBlock = *Data++; b = *data++;
UpdateCrc14443(chBlock, &wCrc); UpdateCrc14443(b, &crc);
} while (--Length); } while (--length);
if (CrcType == CRC_14443_B) if (CrcType == CRC_14443_B)
wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
*TransmitFirst = (unsigned char) (wCrc & 0xFF); *TransmitFirst = (uint8_t) (crc & 0xFF);
*TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF); *TransmitSecond = (uint8_t)((crc >> 8) & 0xFF);
return; return;
} }
int CheckCrc14443(int CrcType, const unsigned char *Data, int Length) { bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length) {
unsigned char b1; if (length < 3) return false;
unsigned char b2; uint8_t b1, b2;
if (Length < 3) return 0; ComputeCrc14443(CrcType, data, length - 2, &b1, &b2);
ComputeCrc14443(CrcType, Data, Length - 2, &b1, &b2); if ((b1 == data[length - 2]) && (b2 == data[length - 1]))
if ((b1 == Data[Length - 2]) && (b2 == Data[Length - 1])) return 1; return true;
return 0; return false;
} }

View file

@ -18,11 +18,9 @@
#define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */ #define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
#define CRC_ICLASS 0xE012 /* ICLASS PREFIX */ #define CRC_ICLASS 0xE012 /* ICLASS PREFIX */
unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc); uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc);
void ComputeCrc14443(int CrcType, void ComputeCrc14443(uint16_t CrcType, const uint8_t *data, int length,
const unsigned char *Data, int Length, uint8_t *TransmitFirst, uint8_t *TransmitSecond);
unsigned char *TransmitFirst, bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length);
unsigned char *TransmitSecond);
int CheckCrc14443(int CrcType, const unsigned char *Data, int Length);
#endif #endif