10 //#define FELICA_SUPPORT
11 //#define TOPAZ_SUPPORT
12 //#define PCSC_SUPPORT
13 //#define MIRARE_SUPPORT
16 #define PICC_ABSENT 0xCC
17 #define PICC_TYPEA_TCL 0x20 // typeA which support ISO/IEC 14443-4
18 #define PICC_MIFARE 0x10
19 #define PICC_TYPEB_TCL 0x23 // typeB which support ISO/IEC 14443-4
20 #define PICC_ST_MEMERY 0x24
21 #define PICC_TOPAZ 0x04
22 #define PICC_FELICA212 0x11
23 #define PICC_FELICA424 0x12
26 #define PICC_ERRORCODE_NONE RDR_TO_PC_SLOTERROR_NONE
27 #define PICC_ERRORCODE_CMD_ABORTED RDR_TO_PC_SLOTERROR_CMD_ABORTED
28 #define PICC_ERRORCODE_MUTE RDR_TO_PC_SLOTERROR_ICC_MUTE
29 #define PICC_ERRORCODE_XFR_PARITY_ERROR RDR_TO_PC_SLOTERROR_XFR_PARITY_ERROR
30 #define PICC_ERRORCODE_XFR_OVERRUN RDR_TO_PC_SLOTERROR_XFR_OVERRUN
31 #define PICC_ERRORCODE_HW_ERROR RDR_TO_PC_SLOTERROR_XFR_OVERRUN
33 #define PICC_ICCSTATUS_ACTIVE RDR_TO_PC_ICCSTATUS_ACTIVE
34 #define PICC_ICCSTATUS_INACTIVE RDR_TO_PC_ICCSTATUS_INACTIVE
35 #define PICC_ICCSTATUS_NOICC RDR_TO_PC_ICCSTATUS_NOICC
42 #define TYPEA (1<<0) // bit 0: typeA
43 #define TYPEB (1<<1) // bit 1: typeB
44 #define FELICA212 (1<<2) // bit 2: felica212
45 #define FELICA414 (1<<3) // bit 3: felica414
46 #define TOPAZ (1<<4) // bit 4: topaz
47 uint8_t support_card_type
;
49 uint8_t FSDI
; // codes FSD, FSD defines the maximum size of a fram the PCD is able to receive, default 8, 256 bytes( refer to FSCConvertTbl[])
50 uint8_t max_speed
; // Maximum communication speed supported by the IFD
51 uint8_t current_speed
;
54 // describes prologue filed in Block Format, ISO/IEC 14443-4
60 #define AUTO_RATS (1<<0) // bit 0: Auto RATS
61 #define AUTO_POLLING (1<<1) // bit 1: Auto poll
62 #define POLLING_CARD_ENABLE (1<<2) // bit 2: poll card
63 uint8_t flags_polling
;
67 uint16_t poll_interval
;
69 uint8_t mifare_key
[2][6];
71 struct picc_device
*picc
;
72 }/* __attribute__((packed, aligned(1)))*/;
86 enum picc_state states
; // picc states
88 #define PRESENT (1<<0) // bit 0: present
89 #define ACTIVATED (1<<1) // bit 1: activated
90 #define CONNECTED (1<<2) // bit 2: connected
91 #define FIRST_INSERT (1<<3) // bit 3: first insert
92 #define SLOT_CHANGE (1<<4) // bit 4: slot change
93 volatile uint8_t status
;
95 uint8_t type
; // picc type
96 uint8_t support_part4
; // if support ISO14443-4
99 uint8_t sn
[10]; // used to stored UID(type A, MAX 10 bytes), PUPI(type B, 4 bytes), NFCID2(felica, 8 bytes)
115 uint8_t attrib_param
[4];
116 uint8_t attrib_response
[7];
121 uint8_t PAD
[8]; // used to stored PMm(manufacture parameter, 8 bytes) of felica
122 uint8_t system_code
[2];
124 // the struct defines these parameter of the PICC which supports ISO14443-4
125 uint8_t FWI
; // codes FWT, Frame waiting Time Integer, defines the maximum time for a PICC to start its response after the end of a PCD frame
126 uint8_t SFGI
; // codes amultiplier value used to define the SFGT, SFGT defines guard time needed by the PICC before it is ready to receive the next fram after it has sent the ATS
128 uint8_t FSCI
; // codes FSC, FSC defines the maximum size of a fram accepted by the PICC, default 2, 32 bytes( refer to FSCConvertTbl[])
129 uint8_t speed
; // stored TA(1), specify the divisor D for each direction
133 uint8_t ATS
[20]; // an array used to stores the ATS send from PICC
136 #define PCD_BLOCK_NUMBER (1<<0) // bit 0: pcd block number
137 #define CID_PRESENT (1<<1) // bit 1: cid present
138 #define PCD_CHAINING (1<<2) // bit 2: pcd chaining
139 #define PICC_CHAINING (1<<3) // bit 3: picc chaning
140 #define WTX_REQUEST (1<<4) // bit 4: wtx request
141 #define TYPEB_ATTRIB (1<<5) // bit 5: typeB attrib
142 #define WTX_REQ_BEFORE (1<<6) // bit 6: wtx request before
143 #define NAD_PRESENT (1<<7) // bit 7: NAD present
144 uint8_t flags_TCL
; // flag for 14443-4
147 // prologue filed in Block Format, ISO/IEC 14443-4
155 volatile uint8_t work_key
[6];
156 volatile uint8_t key_valid
;
157 volatile uint8_t key_type
;
159 volatile uint8_t key_No
;
160 volatile uint8_t authen_need
;
161 volatile uint8_t block
;
164 #define TXCRC (1<<0) // bit 0: TxCRC bit
165 #define RXCRC (1<<1) // bit 1: RxCRC bit
166 #define TXPARITY (1<<2) // bit 2: TxParity bit
167 #define RXPARITY (1<<3) // bit 3: RxParity bit
168 #define PROLOGUE (1<<4) // bit 4: prologue bit
169 #define VENDORSPEC (1<<5) // bit 5: vendor specify bit
170 volatile uint8_t flags_tx_rx
;
172 volatile uint8_t previous_cmd
;
173 volatile uint8_t transfer_status
;
174 volatile uint8_t flags_status
;
175 volatile uint8_t last_rx_valid_bits
;
177 volatile uint8_t last_tx_valid_bits
;
178 volatile uint8_t next_cmd
;
181 struct pn51x_request
*request
;
182 struct pcd_device
*pcd
;
183 } /*__attribute__((packed, aligned(1)))*/;
186 extern const uint8_t IFDVersion
[];
188 extern const uint16_t FSCConvertTbl
[9];
191 void picc_wait_for_req(struct pn51x_request
*req
);
192 uint8_t get_cid(uint8_t *uid
);
193 void picc_reset(struct picc_device
*picc
);
195 int picc_power_on(struct picc_device
*picc
, uint8_t *atrBuf
, uint32_t *atrLen
);
196 void picc_power_off(struct picc_device
*picc
);
198 int picc_command_exchange(struct picc_device
*picc
, uint8_t *cmdBuf
, uint32_t cmdLen
, uint8_t *resBuf
, uint32_t *resLen
, uint8_t *level
);