]>
Commit | Line | Data |
---|---|---|
1 | //-----------------------------------------------------------------------------\r | |
2 | // Routines to compute the CRCs (two different flavours, just for confusion)\r | |
3 | // required for ISO 14443, swiped directly from the spec.\r | |
4 | //-----------------------------------------------------------------------------\r | |
5 | \r | |
6 | #define CRC_14443_A 0x6363 /* ITU-V.41 */\r | |
7 | #define CRC_14443_B 0xFFFF /* ISO/IEC 13239 (formerly ISO/IEC 3309) */\r | |
8 | \r | |
9 | static unsigned short UpdateCrc14443(unsigned char ch, unsigned short *lpwCrc)\r | |
10 | {\r | |
11 | ch = (ch ^ (unsigned char) ((*lpwCrc) & 0x00FF));\r | |
12 | ch = (ch ^ (ch << 4));\r | |
13 | *lpwCrc = (*lpwCrc >> 8) ^ ((unsigned short) ch << 8) ^\r | |
14 | ((unsigned short) ch << 3) ^ ((unsigned short) ch >> 4);\r | |
15 | return (*lpwCrc);\r | |
16 | }\r | |
17 | \r | |
18 | static void ComputeCrc14443(int CrcType, unsigned char *Data, int Length,\r | |
19 | unsigned char *TransmitFirst, unsigned char *TransmitSecond)\r | |
20 | {\r | |
21 | unsigned char chBlock;\r | |
22 | unsigned short wCrc=CrcType;\r | |
23 | \r | |
24 | do {\r | |
25 | chBlock = *Data++;\r | |
26 | UpdateCrc14443(chBlock, &wCrc);\r | |
27 | } while (--Length);\r | |
28 | \r | |
29 | if (CrcType == CRC_14443_B)\r | |
30 | wCrc = ~wCrc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */\r | |
31 | \r | |
32 | *TransmitFirst = (unsigned char) (wCrc & 0xFF);\r | |
33 | *TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);\r | |
34 | return;\r | |
35 | }\r |