]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: Added calling clear bigbuff to zero out it also, instead of just "free" it.
authoriceman1001 <iceman@iuse.se>
Sat, 12 Mar 2016 08:03:28 +0000 (09:03 +0100)
committericeman1001 <iceman@iuse.se>
Sat, 12 Mar 2016 08:03:28 +0000 (09:03 +0100)
ADD:  downloading the EML part from BigBuffer specially.

16 files changed:
armsrc/BigBuf.c
armsrc/appmain.c
armsrc/fpgaloader.c
armsrc/hfsnoop.c
armsrc/hitag2.c
armsrc/hitagS.c
armsrc/iso14443a.c
armsrc/mifarecmd.c
armsrc/mifareutil.c
armsrc/util.c
client/cmdmain.c
client/data.c
client/data.h
client/hid-flasher/usb_cmd.h
client/lualibs/commands.lua
include/usb_cmd.h

index 851cf390e795faf4c6d3b3f58411e6d9966a2d5b..407133fdf60b5de431cfe05d6ab5dd523dfcf8a2 100644 (file)
 
 // BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
 // Also used to hold various smaller buffers and the Mifare Emulator Memory.
-
 // declare it as uint32_t to achieve alignment to 4 Byte boundary
 static uint32_t BigBuf[BIGBUF_SIZE/sizeof(uint32_t)];
 
+/* BigBuf memory layout:
+Pointer to highest available memory: BigBuf_hi
+
+    high BIGBUF_SIZE
+    reserved = BigBuf_malloc()  subtracts amount from BigBuf_hi,   
+       low  0x00
+*/
+
 // High memory mark
 static uint16_t BigBuf_hi = BIGBUF_SIZE;
 
@@ -40,9 +47,9 @@ uint8_t *BigBuf_get_addr(void)
 // get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
 uint8_t *BigBuf_get_EM_addr(void)
 {
-       if (emulator_memory == NULL) {          // not yet allocated
+       // not yet allocated
+       if (emulator_memory == NULL)
                emulator_memory = BigBuf_malloc(CARD_MEMORY_SIZE);
-       }
        
        return emulator_memory;
 }
@@ -56,14 +63,14 @@ void BigBuf_Clear(void)
 // clear ALL of BigBuf
 void BigBuf_Clear_ext(bool verbose)
 {
-       memset(BigBuf,0,BIGBUF_SIZE);
+       memset(BigBuf, 0, BIGBUF_SIZE);
        if (verbose) 
                Dbprintf("Buffer cleared (%i bytes)",BIGBUF_SIZE);
 }
 
 void BigBuf_Clear_keep_EM(void)
 {
-       memset(BigBuf,0,BigBuf_hi);
+       memset(BigBuf, 0, BigBuf_hi);
 }
 
 // allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory
@@ -85,30 +92,32 @@ void BigBuf_free(void)
 {
        BigBuf_hi = BIGBUF_SIZE;
        emulator_memory = NULL;
+       
+       // shouldn't this empty BigBuf also?
 }
 
 
 // free allocated chunks EXCEPT the emulator memory
 void BigBuf_free_keep_EM(void)
 {
-       if (emulator_memory != NULL) {
+       if (emulator_memory != NULL)
                BigBuf_hi = emulator_memory - (uint8_t *)BigBuf;
-       } else {
+       else
                BigBuf_hi = BIGBUF_SIZE;
-       }
+       
+       // shouldn't this empty BigBuf also?
 }
 
 void BigBuf_print_status(void)
 {
        Dbprintf("Memory");
        Dbprintf("  BIGBUF_SIZE.............%d", BIGBUF_SIZE);
-       Dbprintf("  BigBuf_hi  .............%d", BigBuf_hi);
+       Dbprintf("  Available memory........%d", BigBuf_hi);
        Dbprintf("Tracing");
        Dbprintf("  tracing ................%d", tracing);
        Dbprintf("  traceLen ...............%d", traceLen);
 }
 
-
 // return the maximum trace length (i.e. the unallocated size of BigBuf)
 uint16_t BigBuf_max_traceLen(void)
 {
@@ -149,9 +158,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
        uint16_t duration = timestamp_end - timestamp_start;
 
        // Return when trace is full
-       uint16_t max_traceLen = BigBuf_max_traceLen();
-
-       if (traceLen + sizeof(iLen) + sizeof(timestamp_start) + sizeof(duration) + num_paritybytes + iLen >= max_traceLen) {
+       if (traceLen + sizeof(iLen) + sizeof(timestamp_start) + sizeof(duration) + num_paritybytes + iLen >= BigBuf_max_traceLen()) {
                tracing = FALSE;        // don't trace any more
                return FALSE;
        }
index e2a1888edfaad3b59e2f433d874b9e416969944f..2ba3d75c8762fcd0475691946a4f69c3d8c91eb1 100644 (file)
@@ -1274,8 +1274,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        LED_D_OFF(); // LED D indicates field ON or OFF
                        break;
 
-               case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
-
+               case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
                        LED_B_ON();
                        uint8_t *BigBuf = BigBuf_get_addr();
                        size_t len = 0;
@@ -1287,13 +1286,26 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        cmd_send(CMD_ACK,1,0,BigBuf_get_traceLen(),getSamplingConfig(),sizeof(sample_config));
                        LED_B_OFF();
                        break;
-
+               }
                case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
                        uint8_t *b = BigBuf_get_addr();
-                       memcpy(b+c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
+                       memcpy( b + c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
                        cmd_send(CMD_ACK,0,0,0,0,0);
                        break;
-               }       
+               }
+               case CMD_DOWNLOAD_EML_BIGBUF: {
+                       LED_B_ON();
+                       uint8_t *cardmem = BigBuf_get_EM_addr();
+                       size_t len = 0;
+                       for(size_t i=0; i < c->arg[1]; i += USB_CMD_DATA_SIZE) {
+                               len = MIN((c->arg[1] - i), USB_CMD_DATA_SIZE);
+                               cmd_send(CMD_DOWNLOADED_EML_BIGBUF, i, len, CARD_MEMORY_SIZE, cardmem + c->arg[0] + i, len);
+                       }
+                       // Trigger a finish downloading signal with an ACK frame
+                       cmd_send(CMD_ACK, 1, 0, CARD_MEMORY_SIZE, 0, 0);
+                       LED_B_OFF();
+                       break;
+               }
                case CMD_READ_MEM:
                        ReadMem(c->arg[0]);
                        break;
index da85c66c1a424233e875ce63e224008d005b1b56..64ddc608dcd6925e9ced586eafdc1b394e1cfd37 100644 (file)
@@ -220,7 +220,8 @@ static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size)
 
 static void fpga_inflate_free(voidpf opaque, voidpf address)
 {
-       BigBuf_free();
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
 }
 
 
@@ -416,7 +417,7 @@ void FpgaDownloadAndGo(int bitstream_version)
                return;
 
        // make sure that we have enough memory to decompress
-       BigBuf_free();
+       BigBuf_free(); BigBuf_Clear_ext(false);
        
        if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
                return;
@@ -430,7 +431,8 @@ void FpgaDownloadAndGo(int bitstream_version)
 
        inflateEnd(&compressed_fpga_stream);
        
-       BigBuf_free();
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
 }      
 
 
@@ -450,7 +452,7 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len)
        dst[0] = '\0';
 
        // ensure that we can allocate enough memory for decompression:
-       BigBuf_free();
+       BigBuf_free(); BigBuf_Clear_ext(false);
 
        if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer))
                return;
index cfded30273d87ba0ba87b2f8330f438c5c44a376..945809cea0c4ce3e3888d3010cf368aa3fc17900 100644 (file)
@@ -28,8 +28,11 @@ static void RAMFUNC optimizedSnoop(void)
 
 void HfSnoop(int samplesToSkip, int triggersToSkip)
 {
+       BigBuf_free(); BigBuf_Clear();
+       
        Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.\n", samplesToSkip, triggersToSkip);
        bool trigger_cnt;
+
        LED_D_ON();
        // Select correct configs
        FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@@ -39,9 +42,6 @@ void HfSnoop(int samplesToSkip, int triggersToSkip)
        SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP);
        SpinDelay(100);
-
-       BigBuf_free();
-       BigBuf_Clear();
        
        AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame Mode For better performance on high speed data transfer.
 
index 1b82c26935969c25243e1c955f3228e072748e53..4596d3f17cfc6005dc58520537b37ff7b8125d05 100644 (file)
@@ -712,7 +712,10 @@ void SnoopHitag(uint32_t type) {
        size_t rxlen=0;
        
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
-
+       
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
+       
        // Clean up trace and prepare it for storing frames
        clear_trace();
        set_tracing(TRUE);
@@ -720,7 +723,6 @@ void SnoopHitag(uint32_t type) {
        auth_table_len = 0;
        auth_table_pos = 0;
 
-       BigBuf_free();
     auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
        memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
        
@@ -927,6 +929,9 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
        
        FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
+
        // Clean up trace and prepare it for storing frames
        clear_trace();
        set_tracing(TRUE);
@@ -934,7 +939,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
        auth_table_len = 0;
        auth_table_pos = 0;
     byte_t* auth_table;
-       BigBuf_free();
+
     auth_table = (byte_t *)BigBuf_malloc(AUTH_TABLE_LENGTH);
        memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
 
index 1b247d19bdee3a6f92f065da22642e68b9f2f064..a5bce4b9c33d1e3f1e57ff04b23e1319508ba403 100644 (file)
@@ -949,14 +949,15 @@ void SimulateHitagSTag(bool tag_mem_supplied, byte_t* data) {
        int i, j;
        byte_t rx[HITAG_FRAME_LEN];
        size_t rxlen = 0;
-//bool bQuitTraceFull = false;
+       //bool bQuitTraceFull = false;
        bQuiet = false;
        byte_t txbuf[HITAG_FRAME_LEN];
        byte_t* tx = txbuf;
        size_t txlen = 0;
-       BigBuf_free();
+       // free eventually allocated BigBuf memory
+       BigBuf_free(); BigBuf_Clear_ext(false);
 
-// Clean up trace and prepare it for storing frames
+       // Clean up trace and prepare it for storing frames
        set_tracing(TRUE);
        clear_trace();
 
index dfd167f071bbba2ad5b4f662fdb284174214fbf3..be16447cf8b4096013dca1d809b234c75a6920c7 100644 (file)
@@ -546,7 +546,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();
@@ -2303,6 +2303,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 +2313,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 +3068,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 +3087,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;
index c68a50e567b2a9e8fd3f44e8dbba2a57a4241dd7..c0e357b8cb478a91aa64023e8a90838b7a3ff210 100644 (file)
@@ -260,7 +260,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
        // free eventually allocated BigBuf memory\r
-       BigBuf_free();\r
+       BigBuf_free(); BigBuf_Clear_ext(false);\r
        clear_trace();\r
        set_tracing(true);\r
        \r
@@ -778,8 +778,8 @@ void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *dat
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 \r
        // free eventually allocated BigBuf memory\r
-       BigBuf_free();\r
-\r
+       BigBuf_free(); BigBuf_Clear_ext(false);\r
+       \r
        if (calibrate) clear_trace();\r
        set_tracing(true);\r
 \r
index 1956e88a8a9f7124ea4ba029d364645e42762775..0a057d6541250b1fd38d9209255afc9715d7313e 100644 (file)
@@ -541,7 +541,6 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo)
                \r
 }\r
 \r
-\r
 // work with emulator memory\r
 void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
        emlSetMem_xt(data, blockNum, blocksCount, 16);\r
index c00fa0116ce5d3a4664c2e4c7bd57620ad815de3..4e74b88dd2eeaa20470c8e3b60c7150bdb188f5c 100644 (file)
@@ -331,8 +331,8 @@ void StartCountUS()
        // fast clock
        AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable
        AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK | // MCK(48MHz)/32 -- tick=1.5mks
-                                                                                                               AT91C_TC_WAVE | AT91C_TC_WAVESEL_UP_AUTO | AT91C_TC_ACPA_CLEAR |
-                                                                                                               AT91C_TC_ACPC_SET | AT91C_TC_ASWTRG_SET;
+                                                               AT91C_TC_WAVE | AT91C_TC_WAVESEL_UP_AUTO | AT91C_TC_ACPA_CLEAR |
+                                                               AT91C_TC_ACPC_SET | AT91C_TC_ASWTRG_SET;
        AT91C_BASE_TC0->TC_RA = 1;
        AT91C_BASE_TC0->TC_RC = 0xBFFF + 1; // 0xC000
        
index 583bafcaaade1b87573f0083dffc0a7dba1c6f12..04d8ad7aeab68a6647b59e89b7a56bff35e5255c 100644 (file)
@@ -197,14 +197,15 @@ void UsbCommandReceived(UsbCommand *UC)
                        return;
                } break;
 
-               case CMD_DEBUG_PRINT_INTEGERS:
+               case CMD_DEBUG_PRINT_INTEGERS: {
                        PrintAndLog("#db# %08x, %08x, %08x", UC->arg[0], UC->arg[1], UC->arg[2]);
                        break;
-
+               }
                case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K:
+               case CMD_DOWNLOADED_EML_BIGBUF: {
                        memcpy( sample_buf + (UC->arg[0]), UC->d.asBytes, UC->arg[1]);
                        break;
-
+               }
                default: {
                        storeCommand(UC);
                        break;
index 1725944eb9b10cc9eab469cb91e30eebf951b3a0..4903476924354bcf4fbb97691bf3737dd8004a3d 100644 (file)
@@ -23,3 +23,10 @@ void GetFromBigBuf(uint8_t *dest, int bytes, int start_index) {
        clearCommandBuffer();
        SendCommand(&c);
 }
+void GetEMLFromBigBuf(uint8_t *dest, int bytes, int start_index) {
+       sample_buf = dest;
+       UsbCommand c = {CMD_DOWNLOAD_EML_BIGBUF, {start_index, bytes, 0}};
+       clearCommandBuffer();
+       SendCommand(&c);
+}
+
index 7d85e1f158083ec89087c61a7a8d33a9962b4700..201aba04697362b3a6446be78d19b642323e5fc8 100644 (file)
@@ -19,5 +19,5 @@ extern uint8_t* sample_buf;
 #define arraylen(x) (sizeof(x)/sizeof((x)[0]))
 
 void GetFromBigBuf(uint8_t *dest, int bytes, int start_index);
-
+void GetEMLFromBigBuf(uint8_t *dest, int bytes, int start_index);
 #endif
index ad694ad9e215337dd653b466862c035649908942..983842a503c41ff77cc8f60024dd18460ef22b5c 100644 (file)
@@ -52,6 +52,9 @@ typedef struct {
 #define CMD_VERSION                                                       0x0107
 #define CMD_STATUS                                                                                                               0x0108
 #define CMD_PING                                                                                                                 0x0109
+
+#define CMD_DOWNLOAD_EML_BIGBUF                                                                                          0x0110
+#define CMD_DOWNLOADED_EML_BIGBUF                                                                                0x0111
  
 // For low-frequency tags
 #define CMD_READ_TI_TYPE                                                  0x0202
index e9675e79caa540d060c6ee36e19b845d87c81817..c9488e312e4bef4bc303950e070b99d8cf49f5c3 100644 (file)
@@ -22,6 +22,9 @@ local _commands = {
        CMD_VERSION =                                                        0x0107,
        CMD_STATUS =                                                         0x0108,
        CMD_PING =                                                           0x0109,
+       CMD_DOWNLOAD_EML_BIGBUF =                                                                                        0x0110,
+       CMD_DOWNLOADED_EML_BIGBUF =                                                                                      0x0111,
+
        --// For low-frequency tags
        CMD_READ_TI_TYPE =                                                   0x0202,
        CMD_WRITE_TI_TYPE =                                                  0x0203,
index cd23055c815b9a9d9ec4eec32ec5f6e881fc4f25..8d6dd9524124922d768e9767adc77ec1c1f66dc6 100644 (file)
@@ -63,6 +63,9 @@ typedef struct{
 #define CMD_STATUS                                                                                                               0x0108
 #define CMD_PING                                                                                                                 0x0109
 
+#define CMD_DOWNLOAD_EML_BIGBUF                                                                                          0x0110
+#define CMD_DOWNLOADED_EML_BIGBUF                                                                                0x0111
+
 // For low-frequency tags
 #define CMD_READ_TI_TYPE                                                  0x0202
 #define CMD_WRITE_TI_TYPE                                                 0x0203
Impressum, Datenschutz