-
-// desfire_cmd = enum DESFIRE_CMD in desfire.h
-// cmd = pointer to
-// dataout = point to array for response data.
-int SendDesfireCommand(enum DESFIRE_CMD desfire_cmd,uint8_t *dataout, uint8_t fromscratch){
-
- uint8_t resp[80];
- uint8_t len;
-
- if ( fromscratch){
-
- FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-
- // power up the field
- iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
- // select the card
- iso14443a_select_card(NULL, NULL, NULL);
- }
-
- // 3 olika ISO sätt att skicka data till DESFIRE (direkt, inkapslat, inkapslat ISO)
- uint8_t real_cmd[4];
- real_cmd[0] = 0x02;
- real_cmd[1] = desfire_cmd;
- AppendCrc14443a(real_cmd, 2);
- ReaderTransmit(real_cmd, sizeof(real_cmd), NULL);
- len = ReaderReceive(resp);
- if(!len)
- return -1; //DATA LINK ERROR
-
- if ( fromscratch){
- FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
- }
-
- enum DESFIRE_STATUS status = resp[1];
- //1 bytes iso, 1 byte status, in the end: 2 bytes crc
- if ( status == OPERATION_OK || status == ADDITIONAL_FRAME) {
- memcpy(dataout, resp+2, 2);
- return len;
- }
- else {
- Dbprintf("unexpected desfire response: %X (to %X)", status, desfire_cmd);
- return -status;
- }
-}
-
- // crc_update(&desfire_crc32, 0, 1); /* CMD_WRITE */
- // crc_update(&desfire_crc32, addr, addr_sz);
- // crc_update(&desfire_crc32, byte, 8);
- // uint32_t crc = crc_finish(&desfire_crc32);
-
-
- /* Version
-
- //uint8_t versionCmd1[] = {0x02, 0x60};
- //uint8_t versionCmd2[] = {0x03, 0xaf};
- //uint8_t versionCmd3[] = {0x02, 0xaf};
-
- // AUTH 1 - CMD: 0x02, 0x0A, 0x00 = Auth
- // 0x02 = status byte för simpla svar?!?
- // 0x0a = krypto typ
- // 0x00 = key nr
- //uint8_t initAuthCmdDES[] = {0x02, 0x0a, 0x00}; // DES
- //uint8_t initAuthCmd3DES[] = {0x02, 0x1a, 0x00}; // 3DES
- //uint8_t initAuthCmdAES[] = {0x02, 0xaa, 0x00}; // AES
- // auth 1 - answer command
- // 0x03 = status byte för komplexa typer?
- // 0xaf = additional frame
- // LEN = 1+1+32+2 = 36
- //uint8_t answerAuthCmd[34] = {0x03, 0xaf};
-
- // Lägg till CRC
- //AppendCrc14443a(versionCmd1,sizeof(versionCmd1));
-*/
-
- // Sending commands
- /*ReaderTransmit(versionCmd1,sizeof(versionCmd1)+2, NULL);
- len = ReaderReceive(buffer);
- print_result("Get Version 3", buffer, 9);
- */
-
- // for( int i = 0; i < 8; i++){
- // // Auth 1 - Request authentication
- // ReaderTransmit(initAuthCmdAES,sizeof(initAuthCmdAES)+2, NULL);
- // //len = ReaderReceive(buffer);
-
- // // 0xAE = authentication error
- // if (buffer[1] == 0xae) {
- // Dbprintf("Cmd Error: %02x", buffer[1]);
- // OnError();
- // return;
- // }
-
- // // tags enc nonce
- // memcpy(encRndB, buffer+2, 16);
-
- // // dekryptera svaret från tag.
- // AesDecrypt(&ctx, encRndB, decRndB, 16);
-
- // rol8(decRndB,16);
- // memcpy(RndARndB, RndA,16);
- // memcpy(RndARndB+16, decRndB ,16 );
-
- // AesEncrypt(&ctx, RndARndB, encRndARndB, 32 );
-
- // memcpy(answerAuthCmd+2, encRndARndB, 32);
- // AppendCrc14443a(answerAuthCmd,sizeof(answerAuthCmd));
-
- // ReaderTransmit(answerAuthCmd,sizeof(answerAuthCmd)+2, NULL);
-
- // len = ReaderReceive(buffer);
-
- // print_result("Auth1a ", buffer, 8);
- // Dbprintf("Rx len: %02x", len);