56 #ifndef ISO14443_3A_H_
57 #define ISO14443_3A_H_
59 #include "../Common.h"
61 #define ISO14443A_UID_SIZE_SINGLE 4
62 #define ISO14443A_UID_SIZE_DOUBLE 7
63 #define ISO14443A_UID_SIZE_TRIPLE 10
65 #define ISO14443A_CMD_REQA 0x26
66 #define ISO14443A_CMD_WUPA 0x52
67 #define ISO14443A_CMD_SELECT_CL1 0x93
68 #define ISO14443A_CMD_SELECT_CL2 0x95
69 #define ISO14443A_CMD_SELECT_CL3 0x97
70 #define ISO14443A_CMD_HLTA 0x50
72 #define ISO14443A_NVB_AC_START 0x20
73 #define ISO14443A_NVB_AC_END 0x70
75 #define ISO14443A_CL_UID_OFFSET 0
76 #define ISO14443A_CL_UID_SIZE 4
77 #define ISO14443A_CL_BCC_OFFSET 4
78 #define ISO14443A_CL_BCC_SIZE 1
79 #define ISO14443A_CL_FRAME_SIZE ((ISO14443A_CL_UID_SIZE + ISO14443A_CL_BCC_SIZE) * 8)
80 #define ISO14443A_SAK_INCOMPLETE 0x04
81 #define ISO14443A_SAK_COMPLETE_COMPLIANT 0x20
82 #define ISO14443A_SAK_COMPLETE_NOT_COMPLIANT 0x00
84 #define ISO14443A_ATQA_FRAME_SIZE (2 * 8)
85 #define ISO14443A_SAK_FRAME_SIZE (3 * 8)
87 #define ISO14443A_UID0_RANDOM 0x08
88 #define ISO14443A_UID0_CT 0x88
90 #define ISO14443A_CRCA_SIZE 2
92 #define ISO14443A_CALC_BCC(ByteBuffer) \
93 ( ByteBuffer[0] ^ ByteBuffer[1] ^ ByteBuffer[2] ^ ByteBuffer[3] )
95 void ISO14443AAppendCRCA(
void* Buffer, uint16_t ByteCount);
96 bool ISO14443ACheckCRCA(
void* Buffer, uint16_t ByteCount);
98 INLINE
bool ISO14443ASelect(
void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t SAKValue);
99 INLINE
bool ISO14443AWakeUp(
void* Buffer, uint16_t* BitCount, uint16_t ATQAValue);
102 bool ISO14443ASelect(
void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t SAKValue)
104 uint8_t* DataPtr = (uint8_t*) Buffer;
105 uint8_t NVB = DataPtr[1];
110 case ISO14443A_NVB_AC_START:
113 DataPtr[0] = UidCL[0];
114 DataPtr[1] = UidCL[1];
115 DataPtr[2] = UidCL[2];
116 DataPtr[3] = UidCL[3];
117 DataPtr[4] = ISO14443A_CALC_BCC(DataPtr);
119 *BitCount = ISO14443A_CL_FRAME_SIZE;
123 case ISO14443A_NVB_AC_END:
126 if ( (DataPtr[2] == UidCL[0]) &&
127 (DataPtr[3] == UidCL[1]) &&
128 (DataPtr[4] == UidCL[2]) &&
129 (DataPtr[5] == UidCL[3]) ) {
131 DataPtr[0] = SAKValue;
132 ISO14443AAppendCRCA(Buffer, 1);
134 *BitCount = ISO14443A_SAK_FRAME_SIZE;
149 bool ISO14443AWakeUp(
void* Buffer, uint16_t* BitCount, uint16_t ATQAValue)
151 uint8_t* DataPtr = (uint8_t*) Buffer;
153 if ( (DataPtr[0] == ISO14443A_CMD_REQA) || (DataPtr[0] == ISO14443A_CMD_WUPA) ){
154 DataPtr[0] = (ATQAValue >> 0) & 0x00FF;
155 DataPtr[1] = (ATQAValue >> 8) & 0x00FF;
157 *BitCount = ISO14443A_ATQA_FRAME_SIZE;