27 #ifndef __DESFIRE_ISO14443_SUPPORT_H__ 28 #define __DESFIRE_ISO14443_SUPPORT_H__ 30 #include "DESFireFirmwareSettings.h" 32 #include "../ISO14443-3A.h" 33 #include "../../Codec/ISO14443-2A.h" 43 #define ISO14443A_CMD_RATS 0xE0 44 #define ISO14443A_RATS_FRAME_SIZE (6 * BITS_PER_BYTE) //(4 * 8) 45 #define ISO14443A_CMD_RNAK 0xB2 46 #define ISO14443A_CRC_FRAME_SIZE (ISO14443A_CRCA_SIZE * BITS_PER_BYTE) 48 #define ISO14443_PCB_BLOCK_TYPE_MASK 0xC0 49 #define ISO14443_PCB_I_BLOCK 0x00 50 #define ISO14443_PCB_R_BLOCK 0x80 51 #define ISO14443_PCB_S_BLOCK 0xC0 53 #define ISO14443_PCB_I_BLOCK_STATIC 0x02 54 #define ISO14443_PCB_R_BLOCK_STATIC 0xA2 55 #define ISO14443_PCB_S_BLOCK_STATIC 0xC2 57 #define ISO14443_PCB_BLOCK_NUMBER_MASK 0x01 58 #define ISO14443_PCB_HAS_NAD_MASK 0x04 59 #define ISO14443_PCB_HAS_CID_MASK 0x08 60 #define ISO14443_PCB_I_BLOCK_CHAINING_MASK 0x10 61 #define ISO14443_PCB_R_BLOCK_ACKNAK_MASK 0x10 62 #define ISO14443_PCB_R_BLOCK_ACK 0x00 63 #define ISO14443_PCB_R_BLOCK_NAK 0x10 65 #define ISO14443_R_BLOCK_SIZE 1 67 #define ISO14443_PCB_S_DESELECT (ISO14443_PCB_S_BLOCK_STATIC) 68 #define ISO14443_PCB_S_DESELECT_V2 0xCA 69 #define ISO14443_PCB_S_WTX (ISO14443_PCB_S_BLOCK_STATIC | 0x30) 70 #define ISO14443A_CMD_PPS 0xD0 72 #define IS_ISO14443A_4_COMPLIANT(buf) (buf[0] & 0x20) 73 #define MAKE_ISO14443A_4_COMPLIANT(buf) (buf[0] |= 0x20) 84 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
85 ISO14443_4_STATE_EXPECT_RATS,
86 ISO14443_4_STATE_ACTIVE,
87 ISO14443_4_STATE_LAST,
90 extern Iso144434StateType Iso144434State;
91 extern uint8_t Iso144434BlockNumber;
92 extern uint8_t Iso144434CardID;
93 extern uint8_t LastReaderSentCmd;
96 #define MAX_STATE_RETRY_COUNT (4) 97 extern uint8_t StateRetryCount;
98 bool CheckStateRetryCount(
bool resetByDefault);
99 bool CheckStateRetryCount2(
bool resetByDefault,
bool performLogging);
101 #define IGNORE_ACK_BYTE (0x92) 104 void ISO144434SwitchState(Iso144434StateType NewState);
105 void ISO144434SwitchState2(Iso144434StateType NewState,
bool performLogging);
107 void ISO144434Reset(
void);
108 static uint16_t ISO144434ProcessBlock(uint8_t *Buffer, uint16_t ByteCount, uint16_t BitCount);
113 #define ISO14443A_CRCA_INIT ((uint16_t) 0x6363) 115 #define GetAndSetBufferCRCA(Buffer, ByteCount) ({ \ 116 uint16_t fullReturnBits = 0; \ 117 ISO14443AAppendCRCA(Buffer, ByteCount); \ 118 fullReturnBits = ByteCount * BITS_PER_BYTE + ISO14443A_CRC_FRAME_SIZE; \ 122 #define GetAndSetNoResponseCRCA(Buffer) ({ \ 123 uint16_t fullReturnBits = 0; \ 124 ISO14443AAppendCRCA(Buffer, 0); \ 125 fullReturnBits = ISO14443A_CRC_FRAME_SIZE; \ 129 uint16_t ISO14443AUpdateCRCA(
const uint8_t *Buffer, uint16_t ByteCount, uint16_t InitCRCA);
131 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
133 ISO14443_3A_STATE_IDLE = ISO14443_4_STATE_LAST,
135 ISO14443_3A_STATE_READY1,
136 ISO14443_3A_STATE_READY2,
138 ISO14443_3A_STATE_ACTIVE,
140 ISO14443_3A_STATE_HALT,
141 } Iso144433AStateType;
143 extern Iso144433AStateType Iso144433AState;
144 extern Iso144433AStateType Iso144433AIdleState;
147 void ISO144433ASwitchState(Iso144433AStateType NewState);
148 void ISO144433AReset(
void);
149 void ISO144433AHalt(
void);
150 bool ISO144433AIsHalt(
const uint8_t *Buffer, uint16_t BitCount);
151 uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount);