]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/hitag2.c
Added mifare trailer block decoding for sector commands (#734)
[proxmark3-svn] / armsrc / hitag2.c
index 7702025b130a57aeca1c62f3cf18e106b56e6c15..8e690a7b556d2cf11be72baff5202bf1afca2569 100644 (file)
@@ -813,13 +813,13 @@ void SnoopHitag(uint32_t type) {
        int lastbit;
        bool bSkip;
        int tag_sof;
-       byte_t rx[HITAG_FRAME_LEN];
+       byte_t rx[HITAG_FRAME_LEN] = {0};
        size_t rxlen=0;
        
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 
        // Clean up trace and prepare it for storing frames
-       set_tracing(TRUE);
+       set_tracing(true);
        clear_trace();
        
        auth_table_len = 0;
@@ -1032,7 +1032,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 
        // Clean up trace and prepare it for storing frames
-       set_tracing(TRUE);
+       set_tracing(true);
        clear_trace();
 
        auth_table_len = 0;
@@ -1217,7 +1217,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
        int reset_sof; 
        int tag_sof;
        int t_wait = HITAG_T_WAIT_MAX;
-       bool bStop;
+       bool bStop = false;
        bool bQuitTraceFull = false;
   
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
@@ -1225,7 +1225,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
        bSuccessful = false;
   
        // Clean up trace and prepare it for storing frames
-       set_tracing(TRUE);
+       set_tracing(true);
        clear_trace();
 
        //DbpString("Starting Hitag reader family");
@@ -1324,7 +1324,6 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
        frame_count = 0;
        response = 0;
        lastbit = 1;
-       bStop = false;
 
        // Tag specific configuration settings (sof, timings, etc.)
        if (htf < 10){
@@ -1369,46 +1368,46 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
                // By default reset the transmission buffer
                tx = txbuf;
                switch(htf) {
-               case RHT2F_PASSWORD: {
-                       bStop = !hitag2_password(rx,rxlen,tx,&txlen);
-               } break;
-               case RHT2F_AUTHENTICATE: {
-                       bStop = !hitag2_authenticate(rx,rxlen,tx,&txlen);
-               } break;
-               case RHT2F_CRYPTO: {
-                       bStop = !hitag2_crypto(rx,rxlen,tx,&txlen, false);
-               } break;
-               case RHT2F_TEST_AUTH_ATTEMPTS: {
-                       bStop = !hitag2_test_auth_attempts(rx,rxlen,tx,&txlen);
-               } break;
-               case RHT2F_UID_ONLY: {
-                       bStop = !hitag2_read_uid(rx, rxlen, tx, &txlen);
-                       attempt_count++; //attempt 3 times to get uid then quit
-                       if (!bStop && attempt_count == 3) bStop = true;
-               } break;
-               default: {
-                       Dbprintf("Error, unknown function: %d",htf);
-                       return;
-               } break;
+                       case RHT2F_PASSWORD: {
+                               bStop = !hitag2_password(rx,rxlen,tx,&txlen);
+                       } break;
+                       case RHT2F_AUTHENTICATE: {
+                               bStop = !hitag2_authenticate(rx,rxlen,tx,&txlen);
+                       } break;
+                       case RHT2F_CRYPTO: {
+                               bStop = !hitag2_crypto(rx,rxlen,tx,&txlen, false);
+                       } break;
+                       case RHT2F_TEST_AUTH_ATTEMPTS: {
+                               bStop = !hitag2_test_auth_attempts(rx,rxlen,tx,&txlen);
+                       } break;
+                       case RHT2F_UID_ONLY: {
+                               bStop = !hitag2_read_uid(rx, rxlen, tx, &txlen);
+                               attempt_count++; //attempt 3 times to get uid then quit
+                               if (!bStop && attempt_count == 3) bStop = true;
+                       } break;
+                       default: {
+                               Dbprintf("Error, unknown function: %d",htf);
+                               return;
+                       } break;
                }
-               
+
                // Send and store the reader command
                // Disable timer 1 with external trigger to avoid triggers during our own modulation
                AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
-                       
+
                // Wait for HITAG_T_WAIT_2 carrier periods after the last tag bit before transmitting,
                // Since the clock counts since the last falling edge, a 'one' means that the
                // falling edge occured halfway the period. with respect to this falling edge,
                // we need to wait (T_Wait2 + half_tag_period) when the last was a 'one'.
                // All timer values are in terms of T0 units
                while(AT91C_BASE_TC0->TC_CV < T0*(t_wait+(HITAG_T_TAG_HALF_PERIOD*lastbit)));
-                       
+
                //Dbprintf("DEBUG: Sending reader frame");
                
                // Transmit the reader frame
                hitag_reader_send_frame(tx,txlen);
 
-                // Enable and reset external trigger in timer for capturing future frames
+               // Enable and reset external trigger in timer for capturing future frames
                AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
 
                // Add transmitted frame to total count
@@ -1521,7 +1520,11 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
        //Dbprintf("frame received: %d",frame_count);
        //DbpString("All done");
-       cmd_send(CMD_ACK,bSuccessful,0,0,(byte_t*)tag.sectors,48);
+       if (bSuccessful)
+               cmd_send(CMD_ACK,bSuccessful,0,0,(byte_t*)tag.sectors,48);
+       else
+               cmd_send(CMD_ACK,bSuccessful,0,0,0,0);
+
 }
 
 void WriterHitag(hitag_function htf, hitag_data* htd, int page) {
@@ -1545,7 +1548,7 @@ void WriterHitag(hitag_function htf, hitag_data* htd, int page) {
        bSuccessful = false;
   
        // Clean up trace and prepare it for storing frames
-       set_tracing(TRUE);
+       set_tracing(true);
        clear_trace();
 
        //DbpString("Starting Hitag reader family");
Impressum, Datenschutz