]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/iso14443a.c
CHG: some textual change and some syntax suger changes.
[proxmark3-svn] / armsrc / iso14443a.c
index dfd167f071bbba2ad5b4f662fdb284174214fbf3..29d70dfc6aed5005938a866d0e352c0b95e298e4 100644 (file)
@@ -17,6 +17,7 @@
 #include "cmd.h"
 #include "iso14443crc.h"
 #include "iso14443a.h"
+#include "iso14443b.h"
 #include "crapto1.h"
 #include "mifareutil.h"
 #include "BigBuf.h"
@@ -187,12 +188,6 @@ void AppendCrc14443a(uint8_t* data, int len)
        ComputeCrc14443(CRC_14443_A,data,len,data+len,data+len+1);
 }
 
-void AppendCrc14443b(uint8_t* data, int len)
-{
-       ComputeCrc14443(CRC_14443_B,data,len,data+len,data+len+1);
-}
-
-
 //=============================================================================
 // ISO 14443 Type A - Miller decoder
 //=============================================================================
@@ -546,7 +541,7 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
        
        // Allocate memory from BigBuf for some buffers
        // free all previous allocations first
-       BigBuf_free();
+       BigBuf_free(); BigBuf_Clear_ext(false);
        
        // init trace buffer
        clear_trace();
@@ -745,13 +740,12 @@ static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *par
        ToSend[++ToSendMax] = SEC_F;
 
        // Convert from last byte pos to length
-       ToSendMax++;
+       ++ToSendMax;
 }
 
 static void CodeIso14443aAsTag(const uint8_t *cmd, uint16_t len)
 {
        uint8_t par[MAX_PARITY_SIZE] = {0};
-       
        GetParity(cmd, len, par);
        CodeIso14443aAsTagPar(cmd, len, par);
 }
@@ -1427,7 +1421,7 @@ void PrepareDelayedTransfer(uint16_t delay)
        for (i = 0; i < delay; ++i)
                bitmask |= (0x01 << i);
 
-               ToSend[++ToSendMax] = 0x00;
+       ToSend[++ToSendMax] = 0x00;
 
        for (i = 0; i < ToSendMax; ++i) {
                        bits_to_shift = ToSend[i] & bitmask;
@@ -2052,20 +2046,22 @@ void iso14443a_setup(uint8_t fpga_minor_mode) {
 
        // Signal field is on with the appropriate LED
        if (fpga_minor_mode == FPGA_HF_ISO14443A_READER_MOD
-               || fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN) {
+               || fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN)
                LED_D_ON();
-       } else {
+       else
                LED_D_OFF();
-       }
+
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | fpga_minor_mode);
 
-       // Start the timer
-       StartCountSspClk();
-       
        DemodReset();
        UartReset();
-       NextTransferTime = 2*DELAY_ARM2AIR_AS_READER;
+
        iso14a_set_timeout(10*106); // 10ms default
+       
+       // Start the timer
+       StartCountSspClk();
+
+       NextTransferTime = 2*DELAY_ARM2AIR_AS_READER;
 }
 
 int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, void *data) {
@@ -2119,13 +2115,14 @@ void ReaderIso14443a(UsbCommand *c)
        if (param & ISO14A_REQUEST_TRIGGER)
                iso14a_set_trigger(TRUE);
 
-
        if (param & ISO14A_CONNECT) {
                iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
                if(!(param & ISO14A_NO_SELECT)) {
                        iso14a_card_select_t *card = (iso14a_card_select_t*)buf;
                        arg0 = iso14443a_select_card(NULL,card,NULL, true, 0);
                        cmd_send(CMD_ACK,arg0,card->uidlen,0,buf,sizeof(iso14a_card_select_t));
+                       // if it fails,  the cmdhf14a.c client quites.. however this one still executes.
+                       if ( arg0 == 0 ) return;
                }
        }
 
@@ -2303,6 +2300,9 @@ void ReaderMifare(bool first_try, uint8_t block )
        #define MAX_SYNC_TRIES          32
        #define MAX_STRATEGY            3
 
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
+       
        clear_trace();
        set_tracing(TRUE);
        
@@ -2310,9 +2310,6 @@ void ReaderMifare(bool first_try, uint8_t block )
        
        if (first_try)
                iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
-       
-       // free eventually allocated BigBuf memory. We want all for tracing.
-       BigBuf_free();
 
        if (first_try) { 
                sync_time = GetCountSspClk() & 0xfffffff8;
@@ -3068,6 +3065,9 @@ void RAMFUNC SniffMifare(uint8_t param) {
        // bit 1 - trigger from first reader 7-bit request
        LEDsoff();
 
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
+       
        // init trace buffer
        clear_trace();
        set_tracing(TRUE);
@@ -3084,9 +3084,6 @@ void RAMFUNC SniffMifare(uint8_t param) {
 
        iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
 
-       // free eventually allocated BigBuf memory
-       BigBuf_free();
-       
        // allocate the DMA buffer, used to stream samples from the FPGA
        uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE);
        uint8_t *data = dmaBuf;
Impressum, Datenschutz