iwanders / MFRC630

A library for NXP's MFRC630 NFC IC.
MIT License
59 stars 22 forks source link

Desfire commands #15

Open minabf opened 3 years ago

minabf commented 3 years ago

Hi all,

My RFID project is with CLRC663 using stm32l0. So far with the help of the code here I managed to get ATQA, UID, SAK, ATS and also read and write to Mifare classic card, work. However I can not get it work with desfire commands! I need to create application, select it, create file and so on but I could not get the native commands work, I even tried to wrap it with ISO 7816 but still no gain. Is their any library that i can download? Nxp's library is so complicated . Many thanks in advance.

alansbor commented 3 years ago

Hi, see to this : https://www.mifare.net/support/forum/topic/desfire-ev1-selectapplication-command/

minabf commented 3 years ago

Thanks for the help. However my problem is beyond this. No command works after ATS! I think I am not sending the commands right! So I got an array like Send_Re[4]= {0x5A, 0x01,0x01,0x01}; which th3 three byte 0x01 is my AID which is created using nxp app. Now I am trying to select this app so I write Send_Re into fifo and afterwards I transieve it and once the communication finished(IRQ0 clears) I read the fifo again. Is there anything wrong with this?

minabf commented 3 years ago

This is my ATS function which works fine. uint64_t PICC_RequestATS(uint8_t* ats){ CLRC663_write_reg(CLRC663_REG_COMMAND,CLRC663_CMD_LOADPROTOCOL); //write_reg(0x00,0x0D); CLRC663_flush_fifo(); // Flush_FiFo CLRC663_write_reg(CLRC663_REG_TXCRCPRESET, 0x19);
CLRC663_write_reg(CLRC663_REG_RXCRCCON, 0x19); // CRC auto calculation is activated for CRC16

uint8_t Send_req1[]= {0xE0, 0x80};  
CLRC663_write_fifo(Send_req1, 2);          //RATS,E0
CLRC663_write_reg(CLRC663_REG_COMMAND, CLRC663_CMD_TRANSCEIVE);     //Start tranceive command
Clrc663_irq_wait(0x18, 0x2);                                        // Wait for irq0 to clear, showing the
uint8_t len = CLRC663_fifo_length();//read FIFO length
CLRC663_read_fifo((uint8_t*) &ats, len);   // Read FIFO,Expecting ATS,after receiving the ATS the PICC enters protocol 
return ats;

}

However for selecting the App I do exactly the same thing and got different response each time which is neither of the response specified in the AN. Here is my code:

uint8_t PICC_SelectApp(uint8_t* result){ CLRC663_write_reg(CLRC663_REG_COMMAND,CLRC663_CMD_LOADPROTOCOL); //write_reg(0x00,0x0D); CLRC663_flush_fifo(); // Flush_FiFo CLRC663_write_reg(CLRC663_REG_TXCRCPRESET, 0x19);
CLRC663_write_reg(CLRC663_REG_RXCRCCON, 0x19); // CRC auto calculation is activated for CRC16

uint8_t Send_req1[]= {0x5A, 0x01, 0x01, 0x01};  
CLRC663_write_fifo(Send_req1, 4);          //RATS,E0
CLRC663_write_reg(CLRC663_REG_COMMAND, CLRC663_CMD_TRANSCEIVE);     //Start tranceive command
Clrc663_irq_wait(0x18, 0x2);                                        // Wait for irq0 to clear, showing the
uint8_t len = CLRC663_fifo_length();//read FIFO length
CLRC663_read_fifo((uint8_t*) &result, len);   // Read FIFO,Expecting ATS,after receiving the ATS the PICC enters protocol 
return result;

} I even tried sending {0x02, 0x5A, 0x01, 0x01, 0x01} or {0x90, 0x5A, 0x01, 0x01, 0x01} but still does not work. I do not know what the problem might be. Any help really appreciated.

alansbor commented 3 years ago

Ok. AN11022 has a description for the Appids acquisition sequence Fig 14. NFC Cockpit with CLEV6630A / CLEV6630B: Activation of a MIFARE DESFire EV1 card + Get Version Compare with your algorithm of work.

minabf commented 2 years ago

Thanks alansbor, I got PPS and application select work . Now I am working on authentication . Is it exactly the same process?

alansbor commented 2 years ago

I was glad to help. Read all the manuals from the chip manufacturer and everything will be fine.