Skip to content

Commit 1f54774

Browse files
committed
chg: rename
1 parent e580464 commit 1f54774

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

common/iso14443crc.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,37 @@
88

99
#include "iso14443crc.h"
1010

11-
unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)
12-
{
13-
ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));
14-
ch = (ch ^ (ch << 4));
15-
*lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^
16-
((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);
17-
return (*lpwCrc);
11+
uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc) {
12+
b = (b ^ (uint8_t)((*crc) & 0x00FF));
13+
b = (b ^ (b << 4));
14+
*crc = (*crc >> 8) ^ ((uint16_t) b << 8) ^ ((uint16_t) b << 3) ^ ((uint16_t) b >> 4);
15+
return (*crc);
1816
}
1917

20-
void ComputeCrc14443(int CrcType,
21-
const unsigned char *Data, int Length,
22-
unsigned char *TransmitFirst,
23-
unsigned char *TransmitSecond)
18+
void ComputeCrc14443(uint16_t CrcType, const uint8_t *data, int length,
19+
uint8_t *TransmitFirst, uint8_t *TransmitSecond)
2420
{
25-
unsigned char chBlock;
26-
unsigned short wCrc=CrcType;
21+
uint8_t b;
22+
uint16_t crc = CrcType;
2723

28-
do {
29-
chBlock = *Data++;
30-
UpdateCrc14443(chBlock, &wCrc);
31-
} while (--Length);
24+
do {
25+
b = *data++;
26+
UpdateCrc14443(b, &crc);
27+
} while (--length);
3228

3329
if (CrcType == CRC_14443_B)
34-
wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
30+
crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
3531

36-
*TransmitFirst = (unsigned char) (wCrc & 0xFF);
37-
*TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
32+
*TransmitFirst = (uint8_t) (crc & 0xFF);
33+
*TransmitSecond = (uint8_t)((crc >> 8) & 0xFF);
3834
return;
3935
}
4036

41-
int CheckCrc14443(int CrcType, const unsigned char *Data, int Length) {
42-
unsigned char b1;
43-
unsigned char b2;
44-
if (Length < 3) return 0;
45-
ComputeCrc14443(CrcType, Data, Length - 2, &b1, &b2);
46-
if ((b1 == Data[Length - 2]) && (b2 == Data[Length - 1])) return 1;
47-
return 0;
48-
}
37+
bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length) {
38+
if (length < 3) return false;
39+
uint8_t b1, b2;
40+
ComputeCrc14443(CrcType, data, length - 2, &b1, &b2);
41+
if ((b1 == data[length - 2]) && (b2 == data[length - 1]))
42+
return true;
43+
return false;
44+
}

common/iso14443crc.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
#define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
1919
#define CRC_ICLASS 0xE012 /* ICLASS PREFIX */
2020

21-
unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc);
22-
void ComputeCrc14443(int CrcType,
23-
const unsigned char *Data, int Length,
24-
unsigned char *TransmitFirst,
25-
unsigned char *TransmitSecond);
26-
int CheckCrc14443(int CrcType, const unsigned char *Data, int Length);
21+
uint16_t UpdateCrc14443(uint8_t b, uint16_t *crc);
22+
void ComputeCrc14443(uint16_t CrcType, const uint8_t *data, int length,
23+
uint8_t *TransmitFirst, uint8_t *TransmitSecond);
24+
bool CheckCrc14443(uint16_t CrcType, const uint8_t *data, int length);
2725

2826
#endif

0 commit comments

Comments
 (0)