]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/epa.c
Merge remote-tracking branch 'origin/DESFireAuth'
[proxmark3-svn] / armsrc / epa.c
index 565019ce22ec621285b77d5f2334fae24ec7e1a1..0bbd2dd786e18af9a43a927dcf66c5b6618a9446 100644 (file)
@@ -108,9 +108,9 @@ size_t EPA_Parse_CardAccess(uint8_t *data,
                if (data[index] == 0x31 || data[index] == 0x30) {
                        // enter the set (skip tag + length)
                        index += 2;
                if (data[index] == 0x31 || data[index] == 0x30) {
                        // enter the set (skip tag + length)
                        index += 2;
-                       // extended length
+                       // check for extended length
                        if ((data[index - 1] & 0x80) != 0) {
                        if ((data[index - 1] & 0x80) != 0) {
-                               index += (data[index] & 0x7F);
+                               index += (data[index-1] & 0x7F);
                        }
                }
                // OID
                        }
                }
                // OID
@@ -185,6 +185,7 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
            || response_apdu[rapdu_length - 4] != 0x90
            || response_apdu[rapdu_length - 3] != 0x00)
        {
            || response_apdu[rapdu_length - 4] != 0x90
            || response_apdu[rapdu_length - 3] != 0x00)
        {
+               Dbprintf("epa - no select cardaccess");
                return -1;
        }
        
                return -1;
        }
        
@@ -196,6 +197,7 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
            || response_apdu[rapdu_length - 4] != 0x90
            || response_apdu[rapdu_length - 3] != 0x00)
        {
            || response_apdu[rapdu_length - 4] != 0x90
            || response_apdu[rapdu_length - 3] != 0x00)
        {
+               Dbprintf("epa - no read cardaccess");
                return -1;
        }
        
                return -1;
        }
        
@@ -222,8 +224,7 @@ static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return)
        EPA_Finish();
        
        // send the USB packet
        EPA_Finish();
        
        // send the USB packet
-  cmd_send(CMD_ACK,step,func_return,0,0,0);
-//UsbSendPacket((void *)ack, sizeof(UsbCommand));
+       cmd_send(CMD_ACK,step,func_return,0,0,0);
 }
 
 //-----------------------------------------------------------------------------
 }
 
 //-----------------------------------------------------------------------------
@@ -243,7 +244,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
         */
 
        // return value of a function
         */
 
        // return value of a function
-       int func_return;
+       int func_return = 0;
 
 //     // initialize ack with 0s
 //     memset(ack->arg, 0, 12);
 
 //     // initialize ack with 0s
 //     memset(ack->arg, 0, 12);
@@ -251,13 +252,15 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
        
        // set up communication
        func_return = EPA_Setup();
        
        // set up communication
        func_return = EPA_Setup();
-       if (func_return != 0) {
+       if (func_return != 0) { 
                EPA_PACE_Collect_Nonce_Abort(1, func_return);
                EPA_PACE_Collect_Nonce_Abort(1, func_return);
+               Dbprintf("epa: setup fucked up! %d", func_return);
                return;
        }
 
        // increase the timeout (at least some cards really do need this!)
        iso14a_set_timeout(0x0002FFFF);
                return;
        }
 
        // increase the timeout (at least some cards really do need this!)
        iso14a_set_timeout(0x0002FFFF);
+       Dbprintf("epa: Epic!");
        
        // read the CardAccess file
        // this array will hold the CardAccess file
        
        // read the CardAccess file
        // this array will hold the CardAccess file
@@ -265,10 +268,13 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
        int card_access_length = EPA_Read_CardAccess(card_access, 256);
        // the response has to be at least this big to hold the OID
        if (card_access_length < 18) {
        int card_access_length = EPA_Read_CardAccess(card_access, 256);
        // the response has to be at least this big to hold the OID
        if (card_access_length < 18) {
+               Dbprintf("epa: Too small!");
                EPA_PACE_Collect_Nonce_Abort(2, card_access_length);
                return;
        }
 
                EPA_PACE_Collect_Nonce_Abort(2, card_access_length);
                return;
        }
 
+       Dbprintf("epa: foo!");
+       
        // this will hold the PACE info of the card
        pace_version_info_t pace_version_info;
        // search for the PACE OID
        // this will hold the PACE info of the card
        pace_version_info_t pace_version_info;
        // search for the PACE OID
@@ -280,6 +286,8 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
                return;
        }
        
                return;
        }
        
+       Dbprintf("epa: bar!");
+       
        // initiate the PACE protocol
        // use the CAN for the password since that doesn't change
        func_return = EPA_PACE_MSE_Set_AT(pace_version_info, 2);
        // initiate the PACE protocol
        // use the CAN for the password since that doesn't change
        func_return = EPA_PACE_MSE_Set_AT(pace_version_info, 2);
@@ -301,8 +309,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
        // save received information
 //     ack->arg[1] = func_return;
 //     memcpy(ack->d.asBytes, nonce, func_return);
        // save received information
 //     ack->arg[1] = func_return;
 //     memcpy(ack->d.asBytes, nonce, func_return);
-//     UsbSendPacket((void *)ack, sizeof(UsbCommand));
-  cmd_send(CMD_ACK,0,func_return,0,nonce,func_return);
+       cmd_send(CMD_ACK,0,func_return,0,nonce,func_return);
 }
 
 //-----------------------------------------------------------------------------
 }
 
 //-----------------------------------------------------------------------------
@@ -416,25 +423,28 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
 //-----------------------------------------------------------------------------
 int EPA_Setup()
 {
 //-----------------------------------------------------------------------------
 int EPA_Setup()
 {
-       // return code
+
        int return_code = 0;
        int return_code = 0;
-       // card UID
-       uint8_t uid[8];
-       // card select information
+       uint8_t uid[10];
+       uint8_t pps_response[3];
+       uint8_t pps_response_par[1];
        iso14a_card_select_t card_select_info;
        iso14a_card_select_t card_select_info;
+
        // power up the field
        iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
        // power up the field
        iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
-
+       
+       iso14a_set_timeout(10500);
+       
        // select the card
        return_code = iso14443a_select_card(uid, &card_select_info, NULL);
        if (return_code != 1) {
        // select the card
        return_code = iso14443a_select_card(uid, &card_select_info, NULL);
        if (return_code != 1) {
+               Dbprintf("Epa: Can't select card");
                return 1;
        }
 
        // send the PPS request
        ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
                return 1;
        }
 
        // send the PPS request
        ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
-       uint8_t pps_response[3];
-       return_code = ReaderReceive(pps_response);
+       return_code = ReaderReceive(pps_response, pps_response_par);
        if (return_code != 3 || pps_response[0] != 0xD0) {
                return return_code == 0 ? 2 : return_code;
        }
        if (return_code != 3 || pps_response[0] != 0xD0) {
                return return_code == 0 ? 2 : return_code;
        }
Impressum, Datenschutz