]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/mifaredesfire.c
fixup code
[proxmark3-svn] / armsrc / mifaredesfire.c
index 57681d716933a59edda9277c117454a552b64631..530b797d888f6a294e95852be62c1f396ad5b350 100644 (file)
@@ -19,17 +19,13 @@ static  uint8_t deselect_cmd[] = {0xc2,0xe0,0xb4};
 
 bool InitDesfireCard(){
 
 
 bool InitDesfireCard(){
 
+       iso14a_card_select_t card;
+       
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
        set_tracing(TRUE);
 
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
        set_tracing(TRUE);
 
-       byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
-       iso14a_card_select_t *card = (iso14a_card_select_t*)cardbuf;
-       
-       int len = iso14443a_select_card(NULL,card,NULL);
-
-       if (!len) {
-               if (MF_DBGLEVEL >= MF_DBG_ERROR)
-                       Dbprintf("Can't select card");
+       if (!iso14443a_select_card(NULL, &card, NULL, true, 0)) {
+               if (MF_DBGLEVEL >= MF_DBG_ERROR) DbpString("Can't select card");
                OnError(1);
                return false;
        }
                OnError(1);
                return false;
        }
@@ -63,9 +59,8 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain){
                print_result(" RX    : ", datain, datalen);
        }
        
                print_result(" RX    : ", datain, datalen);
        }
        
-       if ( flags & CLEARTRACE ){
+       if ( flags & CLEARTRACE )
                clear_trace();
                clear_trace();
-       }
        
        if ( flags & INIT ){
                if ( !InitDesfireCard() )
        
        if ( flags & INIT ){
                if ( !InitDesfireCard() )
@@ -73,9 +68,8 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain){
        }
        
        int len = DesfireAPDU(datain, datalen, resp);
        }
        
        int len = DesfireAPDU(datain, datalen, resp);
-       if (MF_DBGLEVEL >= 4) {
+       if (MF_DBGLEVEL >= 4)
                print_result("ERR <--: ", resp, len);
                print_result("ERR <--: ", resp, len);
-       }
 
        if ( !len ) {
                OnError(2);
 
        if ( !len ) {
                OnError(2);
@@ -85,9 +79,8 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain){
        // reset the pcb_blocknum,
        pcb_blocknum = 0;
        
        // reset the pcb_blocknum,
        pcb_blocknum = 0;
        
-       if ( flags & DISCONNECT ){
+       if ( flags & DISCONNECT )
                OnSuccess();
                OnSuccess();
-       }
        
        cmd_send(CMD_ACK,1,len,0,resp,len);
 }
        
        cmd_send(CMD_ACK,1,len,0,resp,len);
 }
@@ -95,9 +88,9 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain){
 void MifareDesfireGetInformation(){
                
        int len = 0;
 void MifareDesfireGetInformation(){
                
        int len = 0;
+       iso14a_card_select_t card;
        uint8_t resp[USB_CMD_DATA_SIZE] = {0x00};
        uint8_t dataout[USB_CMD_DATA_SIZE] = {0x00};
        uint8_t resp[USB_CMD_DATA_SIZE] = {0x00};
        uint8_t dataout[USB_CMD_DATA_SIZE] = {0x00};
-       byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
        
        /*
                1 = PCB                                 1
        
        /*
                1 = PCB                                 1
@@ -113,17 +106,13 @@ void MifareDesfireGetInformation(){
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
 
        // card select - information
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
 
        // card select - information
-       iso14a_card_select_t *card = (iso14a_card_select_t*)cardbuf;
-       byte_t isOK = iso14443a_select_card(NULL, card, NULL);
-       if ( isOK == 0) {
-               if (MF_DBGLEVEL >= MF_DBG_ERROR) {
-                       Dbprintf("Can't select card");
-               }
+       if ( !iso14443a_select_card(NULL, &card, NULL, true, 0) ) {
+               if (MF_DBGLEVEL >= MF_DBG_ERROR) DbpString("Can't select card");
                OnError(1);
                return;
        }
 
                OnError(1);
                return;
        }
 
-       memcpy(dataout,card->uid,7);
+       memcpy(dataout, card.uid, 7);
 
        LED_A_ON();
        LED_B_OFF();
 
        LED_A_ON();
        LED_B_OFF();
@@ -510,20 +499,18 @@ int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout){
        size_t len = 0;
        size_t wrappedLen = 0;
        uint8_t wCmd[USB_CMD_DATA_SIZE] = {0x00};
        size_t len = 0;
        size_t wrappedLen = 0;
        uint8_t wCmd[USB_CMD_DATA_SIZE] = {0x00};
-       
        uint8_t resp[MAX_FRAME_SIZE];
     uint8_t par[MAX_PARITY_SIZE];
        
        wrappedLen = CreateAPDU( cmd, cmd_len, wCmd);
        
        uint8_t resp[MAX_FRAME_SIZE];
     uint8_t par[MAX_PARITY_SIZE];
        
        wrappedLen = CreateAPDU( cmd, cmd_len, wCmd);
        
-       if (MF_DBGLEVEL >= 4) {
+       if (MF_DBGLEVEL >= 4)
                print_result("WCMD <--: ", wCmd, wrappedLen);   
                print_result("WCMD <--: ", wCmd, wrappedLen);   
-       }
+
        ReaderTransmit( wCmd, wrappedLen, NULL);
 
        len = ReaderReceive(resp, par);
        ReaderTransmit( wCmd, wrappedLen, NULL);
 
        len = ReaderReceive(resp, par);
-       
-       if( len == 0x00 ){
+       if ( !len ) {
                if (MF_DBGLEVEL >= 4) Dbprintf("fukked");
                return FALSE; //DATA LINK ERROR
        }
                if (MF_DBGLEVEL >= 4) Dbprintf("fukked");
                return FALSE; //DATA LINK ERROR
        }
@@ -569,17 +556,13 @@ size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout){
 void OnSuccess(){
        pcb_blocknum = 0;
        ReaderTransmit(deselect_cmd, 3 , NULL);
 void OnSuccess(){
        pcb_blocknum = 0;
        ReaderTransmit(deselect_cmd, 3 , NULL);
+       mifare_ultra_halt();
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
        LEDsoff();
        set_tracing(FALSE);     
 }
 
 void OnError(uint8_t reason){
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
        LEDsoff();
        set_tracing(FALSE);     
 }
 
 void OnError(uint8_t reason){
-       pcb_blocknum = 0;
-       ReaderTransmit(deselect_cmd, 3 , NULL);
-       
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
        cmd_send(CMD_ACK,0,reason,0,0,0);
        cmd_send(CMD_ACK,0,reason,0,0,0);
-       LEDsoff();
-       set_tracing(FALSE);     
+       OnSuccess();
 }
 }
Impressum, Datenschutz