]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
Merge branch 'master' into GenericTracing
[proxmark3-svn] / armsrc / appmain.c
index 13995f591735333a8b897d3ab478418205b3ec78..7c50a51ec89bc183c145aacdc4ace0227ad9b31d 100644 (file)
 #include "util.h"
 #include "printf.h"
 #include "string.h"
+
 #include <stdarg.h>
 
 #include "legicrf.h"
 #include <hitag2.h>
-
+#include "lfsampling.h"
 #ifdef WITH_LCD
  #include "LCD.h"
 #endif
@@ -41,12 +42,6 @@ int ToSendMax;
 static int ToSendBit;
 struct common_area common_area __attribute__((section(".commonarea")));
 
-void BufferClear(void)
-{
-       memset(BigBuf,0,sizeof(BigBuf));
-       Dbprintf("Buffer cleared (%i bytes)",sizeof(BigBuf));
-}
-
 void ToSendReset(void)
 {
        ToSendMax = -1;
@@ -245,7 +240,10 @@ void MeasureAntennaTuningHf(void)
 
 void SimulateTagHfListen(void)
 {
-       uint8_t *dest = (uint8_t *)BigBuf+FREE_BUFFER_OFFSET;
+       // ToDo: historically this used the free buffer, which was 2744 Bytes long. 
+       // There might be a better size to be defined:
+       #define HF_14B_SNOOP_BUFFER_SIZE 2744
+       uint8_t *dest = BigBuf_malloc(HF_14B_SNOOP_BUFFER_SIZE);
        uint8_t v = 0;
        int i;
        int p = 0;
@@ -280,7 +278,7 @@ void SimulateTagHfListen(void)
                                p = 0;
                                i++;
 
-                               if(i >= FREE_BUFFER_SIZE) {
+                               if(i >= HF_14B_SNOOP_BUFFER_SIZE) {
                                        break;
                                }
                        }
@@ -628,16 +626,17 @@ void UsbPacketReceived(uint8_t *packet, int len)
   
        switch(c->cmd) {
 #ifdef WITH_LF
+               case CMD_SET_LF_SAMPLING_CONFIG:
+                       setSamplingConfig((sample_config *) c->d.asBytes);
+                       break;
                case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
-                       AcquireRawAdcSamples125k(c->arg[0]);
-                       cmd_send(CMD_ACK,0,0,0,0,0);
+                       cmd_send(CMD_ACK,SampleLF(),0,0,0,0);
                        break;
                case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
                        ModThenAcquireRawAdcSamples125k(c->arg[0],c->arg[1],c->arg[2],c->d.asBytes);
                        break;
                case CMD_LF_SNOOP_RAW_ADC_SAMPLES:
-                       SnoopLFRawAdcSamples(c->arg[0], c->arg[1]);
-                       cmd_send(CMD_ACK,0,0,0,0,0);
+                       cmd_send(CMD_ACK,SnoopLF(),0,0,0,0);
                        break;
                case CMD_HID_DEMOD_FSK:
                        CmdHIDdemodFSK(c->arg[0], 0, 0, 1);
@@ -667,7 +666,9 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        WriteTItag(c->arg[0],c->arg[1],c->arg[2]);
                        break;
                case CMD_SIMULATE_TAG_125K:
+                       LED_A_ON();
                        SimulateTagLowFrequency(c->arg[0], c->arg[1], 1);
+                       LED_A_OFF();
                        break;
                case CMD_LF_SIMULATE_BIDIR:
                        SimulateTagLowFrequencyBidir(c->arg[0], c->arg[1]);
@@ -805,11 +806,11 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        MifareUC_Auth2(c->arg[0],c->d.asBytes);
                        break;
                case CMD_MIFAREU_READCARD:
-                       MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
-                        break;
+                       MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+                       break;
                case CMD_MIFAREUC_READCARD:
-                       MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
-                        break;
+                       MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+                       break;
                case CMD_MIFARE_READSC:
                        MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
                        break;
@@ -888,7 +889,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
                        break;
 
                case CMD_BUFF_CLEAR:
-                       BufferClear();
+                       BigBuf_Clear();
                        break;
 
                case CMD_MEASURE_ANTENNA_TUNING:
@@ -912,17 +913,18 @@ void UsbPacketReceived(uint8_t *packet, int len)
                case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
 
                        LED_B_ON();
+                       uint8_t *BigBuf = BigBuf_get_addr();
                        for(size_t i=0; i<c->arg[1]; i += USB_CMD_DATA_SIZE) {
                                size_t len = MIN((c->arg[1] - i),USB_CMD_DATA_SIZE);
-                               cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,i,len,0,((byte_t*)BigBuf)+c->arg[0]+i,len);
+                               cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,i,len,traceLen,BigBuf+c->arg[0]+i,len);
                        }
                        // Trigger a finish downloading signal with an ACK frame
-                       cmd_send(CMD_ACK,0,0,0,0,0);
+                       cmd_send(CMD_ACK,1,0,traceLen,getSamplingConfig(),sizeof(sample_config));
                        LED_B_OFF();
                        break;
 
                case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
-                       uint8_t *b = (uint8_t *)BigBuf;
+                       uint8_t *b = BigBuf_get_addr();
                        memcpy(b+c->arg[0], c->d.asBytes, USB_CMD_DATA_SIZE);
                        cmd_send(CMD_ACK,0,0,0,0,0);
                        break;
@@ -993,7 +995,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
 void  __attribute__((noreturn)) AppMain(void)
 {
        SpinDelay(100);
-
+       clear_trace();
        if(common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) {
                /* Initialize common area */
                memset(&common_area, 0, sizeof(common_area));
Impressum, Datenschutz