]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Merge branch 'master' of https://github.com/Proxmark/proxmark3
authoriceman1001 <iceman@iuse.se>
Mon, 16 Feb 2015 17:59:44 +0000 (18:59 +0100)
committericeman1001 <iceman@iuse.se>
Mon, 16 Feb 2015 17:59:44 +0000 (18:59 +0100)
Conflicts:
armsrc/iclass.c

1  2 
armsrc/appmain.c
armsrc/iclass.c
armsrc/lfops.c
include/usb_cmd.h

diff --combined armsrc/appmain.c
index f19840b8e13edfd9b6df80ceaa06cff2023b803d,3da34777e441cea54f7aa1f6bf187b61909a6f55..f1edc3aa2dec2ab2420e81c38776d098e958d070
  // executes.
  //-----------------------------------------------------------------------------
  
 -#include "usb_cdc.h"
 -#include "cmd.h"
 +#include "../common/usb_cdc.h"
 +#include "../common/cmd.h"
  
 -#include "proxmark3.h"
 +#include "../include/proxmark3.h"
  #include "apps.h"
  #include "util.h"
  #include "printf.h"
  #include "string.h"
 -
  #include <stdarg.h>
  
  #include "legicrf.h"
 -#include <hitag2.h>
 +#include "../include/hitag2.h"
  #include "lfsampling.h"
  #include "BigBuf.h"
  #ifdef WITH_LCD
@@@ -179,7 -180,7 +179,7 @@@ void MeasureAntennaTuning(void
        int i, adcval = 0, peak = 0, peakv = 0, peakf = 0; //ptr = 0 
        int vLf125 = 0, vLf134 = 0, vHf = 0;    // in mV
  
 -      LED_B_ON();
 +  LED_B_ON();
  
  /*
   * Sweeps the useful LF range of the proxmark from
  
        for (i=18; i >= 0; i--) LF_Results[i] = 0;
        
 -      LED_A_ON();
 +  LED_A_ON();
        // Let the FPGA drive the high-frequency antenna around 13.56 MHz.
        FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
  
        cmd_send(CMD_MEASURED_ANTENNA_TUNING, vLf125 | (vLf134<<16), vHf, peakf | (peakv<<16), LF_Results, 256);
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
 -      LED_A_OFF();
 -      LED_B_OFF();
 -      return;
 +  LED_A_OFF();
 +  LED_B_OFF();
 +  return;
  }
  
  void MeasureAntennaTuningHf(void)
@@@ -369,7 -370,7 +369,7 @@@ void SamyRun(
        for (;;)
        {
                usb_poll();
 -    WDT_HIT();
 +              WDT_HIT();
  
                // Was our button held down or pressed?
                int button_pressed = BUTTON_HELD(1000);
@@@ -639,7 -640,7 +639,7 @@@ void UsbPacketReceived(uint8_t *packet
  {
        UsbCommand *c = (UsbCommand *)packet;
  
 -//  Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
 +  //Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
    
        switch(c->cmd) {
  #ifdef WITH_LF
                        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();
 +                      SimulateTagLowFrequency(c->arg[0], c->arg[1], 0);
 +                      //SimulateTagLowFrequencyA(c->arg[0], c->arg[1]);
                        break;
                case CMD_LF_SIMULATE_BIDIR:
                        SimulateTagLowFrequencyBidir(c->arg[0], c->arg[1]);
                        EPA_PACE_Collect_Nonce(c);
                        break;
                        
 +              // case CMD_EPA_:
 +              //      EpaFoo(c);
 +              // break;
 +                      
                case CMD_READER_MIFARE:
              ReaderMifare(c->arg[0]);
                        break;
                        break;
                case CMD_MIFAREU_READCARD:
                        MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
 -                      break;
 +                        break;
                case CMD_MIFAREUC_READCARD:
                        MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
                        break;
                        ReaderIClass(c->arg[0]);
                        break;
                case CMD_READER_ICLASS_REPLAY:
 -                  ReaderIClass_Replay(c->arg[0], c->d.asBytes);
 +                      ReaderIClass_Replay(c->arg[0], c->d.asBytes);
                        break;
+       case CMD_ICLASS_EML_MEMSET:
+                       emlSet(c->d.asBytes,c->arg[0], c->arg[1]);
+                       break;
  #endif
  
                case CMD_SIMULATE_TAG_HF_LISTEN:
@@@ -1030,7 -1031,7 +1033,7 @@@ void  __attribute__((noreturn)) AppMain
        LED_A_OFF();
  
        // Init USB device
 -  usb_enable();
 +      usb_enable();
  
        // The FPGA gets its clock from us from PCK0 output, so set that up.
        AT91C_BASE_PIOA->PIO_BSR = GPIO_PCK0;
        size_t rx_len;
    
        for(;;) {
 -    if (usb_poll()) {
 -      rx_len = usb_read(rx,sizeof(UsbCommand));
 -      if (rx_len) {
 -        UsbPacketReceived(rx,rx_len);
 -      }
 -    }
 +              if (usb_poll()) {
 +                      rx_len = usb_read(rx,sizeof(UsbCommand));
 +                      if (rx_len) {
 +                              UsbPacketReceived(rx,rx_len);
 +                      }
 +              }
                WDT_HIT();
  
  #ifdef WITH_LF
diff --combined armsrc/iclass.c
index 67130804910a13428772e31189182d3874d1c7af,2a0ba0d2f8d7559017991132ff5e808090bd656d..816cb904108adb8eab227155d63bb78b1abf4f41
@@@ -36,7 -36,7 +36,7 @@@
  //
  //-----------------------------------------------------------------------------
  
 -#include "proxmark3.h"
 +#include "../include/proxmark3.h"
  #include "apps.h"
  #include "util.h"
  #include "string.h"
  // Needed for CRC in emulation mode;
  // same construction as in ISO 14443;
  // different initial value (CRC_ICLASS)
 -#include "iso14443crc.h"
 -#include "iso15693tools.h"
 +#include "../common/iso14443crc.h"
 +#include "../common/iso15693tools.h"
 +//#include "iso15693tools.h"
 +
  
  static int timeout = 4096;
  
@@@ -353,7 -351,7 +353,7 @@@ static struct 
                SUB_SECOND_HALF,
                SUB_BOTH
        }               sub;
 -    uint8_t *output;
 +    uint8_t   *output;
  } Demod;
  
  static RAMFUNC int ManchesterDecoding(int v)
@@@ -658,7 -656,7 +658,7 @@@ void RAMFUNC SnoopIClass(void
        clear_trace();
      iso14a_set_trigger(FALSE);
  
 -      int lastRxCounter;
 +    int lastRxCounter;
      uint8_t *upTo;
      int smpl;
      int maxBehindBy = 0;
                if(ManchesterDecoding(smpl & 0x0F)) {
                        time_stop = (GetCountSspClk()-time_0) << 4;
  
 -                      rsamples = samples - Demod.samples;
 +                  rsamples = samples - Demod.samples;
                    LED_B_ON();
  
                        if(tracing)     {
@@@ -944,7 -942,7 +944,7 @@@ static void CodeIClassTagAnswer(const u
                uint8_t b = cmd[i];
                ToSend[++ToSendMax] = encode4Bits(b & 0xF); //Least significant half
                ToSend[++ToSendMax] = encode4Bits((b >>4) & 0xF);//Most significant half
 -      }
 +                      }
  
        // Send EOF
        ToSend[++ToSendMax] = 0xB8;
@@@ -1311,17 -1309,17 +1311,17 @@@ static void TransmitIClassCommand(cons
     {
       if(*wait < 10) *wait = 10;
       
 -     for(c = 0; c < *wait;) {
 -       if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
 -         AT91C_BASE_SSC->SSC_THR = 0x00;              // For exact timing!
 -         c++;
 -       }
 -       if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
 -         volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
 -         (void)r;
 -       }
 -       WDT_HIT();
 -     }
 +  for(c = 0; c < *wait;) {
 +    if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
 +      AT91C_BASE_SSC->SSC_THR = 0x00;         // For exact timing!
 +      c++;
 +    }
 +    if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
 +      volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
 +      (void)r;
 +    }
 +    WDT_HIT();
 +  }
  
     }
  
@@@ -1404,18 -1402,18 +1404,18 @@@ void CodeIClassCommand(const uint8_t * 
  
  void ReaderTransmitIClass(uint8_t* frame, int len)
  {
 -      int wait = 0;
 -      int samples = 0;
 +  int wait = 0;
 +  int samples = 0;
  
 -      // This is tied to other size changes
 -      CodeIClassCommand(frame,len);
 +  // This is tied to other size changes
 +  CodeIClassCommand(frame,len);
  
 -      // Select the card
 -      TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
 -      if(trigger)
 -              LED_A_ON();
 +  // Select the card
 +  TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
 +  if(trigger)
 +      LED_A_ON();
  
 -      // Store reader command in buffer
 +  // Store reader command in buffer
        if (tracing) {
                uint8_t par[MAX_PARITY_SIZE];
                GetParity(frame, len, par);
@@@ -1451,7 -1449,7 +1451,7 @@@ static int GetIClassAnswer(uint8_t *rec
        for(;;) {
                WDT_HIT();
  
 -              if(BUTTON_PRESS()) return FALSE;
 +          if(BUTTON_PRESS()) return FALSE;
  
                if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
                        AT91C_BASE_SSC->SSC_THR = 0x00;  // To make use of exact timing of next command from reader!!
@@@ -1605,20 -1603,20 +1605,20 @@@ void ReaderIClass(uint8_t arg0) 
                if(read_status == 1) datasize = 8;
                if(read_status == 2) datasize = 16;
  
 -              LED_B_ON();
 -              //Send back to client, but don't bother if we already sent this
 -              if(memcmp(last_csn, card_data, 8) != 0)
 +                    LED_B_ON();
 +                    //Send back to client, but don't bother if we already sent this
 +                    if(memcmp(last_csn, card_data, 8) != 0)
                {
  
                        if(!get_cc || (get_cc && read_status == 2))
                        {
 -                              cmd_send(CMD_ACK,read_status,0,0,card_data,datasize);
 +                        cmd_send(CMD_ACK,read_status,0,0,card_data,datasize);
                                if(abort_after_read) {
                                        LED_A_OFF();
                                        return;
                                }
 -                              //Save that we already sent this....
 -                              memcpy(last_csn, card_data, 8);
 +                    //Save that we already sent this....
 +                        memcpy(last_csn, card_data, 8);
                        }
                        //If 'get_cc' was specified and we didn't get a CC, we'll just keep trying...
                }
@@@ -1673,20 -1671,20 +1673,20 @@@ void ReaderIClass_Replay(uint8_t arg0, 
                uint8_t read_status = handshakeIclassTag(card_data);
                if(read_status < 2) continue;
  
 -              //for now replay captured auth (as cc not updated)
 -              memcpy(check+5,MAC,4);
 +                              //for now replay captured auth (as cc not updated)
 +                              memcpy(check+5,MAC,4);
  
                if(sendCmdGetResponseWithRetries(check, sizeof(check),resp, 4, 5))
                {
 -                      Dbprintf("Error: Authentication Fail!");
 +                                Dbprintf("Error: Authentication Fail!");
                        continue;
 -              }
 +                              }
  
                //first get configuration block (block 1)
                crc = block_crc_LUT[1];
 -              read[1]=1;
 -              read[2] = crc >> 8;
 -              read[3] = crc & 0xff;
 +                              read[1]=1;
 +                              read[2] = crc >> 8;
 +                              read[3] = crc & 0xff;
  
                if(sendCmdGetResponseWithRetries(read, sizeof(read),resp, 10, 10))
                {
                        continue;
                }
  
 -              mem=resp[5];
 -              memory.k16= (mem & 0x80);
 -              memory.book= (mem & 0x20);
 -              memory.k2= (mem & 0x8);
 -              memory.lockauth= (mem & 0x2);
 -              memory.keyaccess= (mem & 0x1);
 +                                       mem=resp[5];
 +                                       memory.k16= (mem & 0x80);
 +                                       memory.book= (mem & 0x20);
 +                                       memory.k2= (mem & 0x8);
 +                                       memory.lockauth= (mem & 0x2);
 +                                       memory.keyaccess= (mem & 0x1);
  
                cardsize = memory.k16 ? 255 : 32;
                WDT_HIT();
                //Set card_data to all zeroes, we'll fill it with data
                memset(card_data,0x0,USB_CMD_DATA_SIZE);
                uint8_t failedRead =0;
-               uint8_t stored_data_length =0;
+               uint32_t stored_data_length =0;
 -              //then loop around remaining blocks
 +                              //then loop around remaining blocks
                for(int block=0; block < cardsize; block++){
  
                        read[1]= block;
                        crc = block_crc_LUT[block];
 -                      read[2] = crc >> 8;
 -                      read[3] = crc & 0xff;
 +                                  read[2] = crc >> 8;
 +                                  read[3] = crc & 0xff;
  
                        if(!sendCmdGetResponseWithRetries(read, sizeof(read), resp, 10, 10))
                        {
 -                              Dbprintf("     %02x: %02x %02x %02x %02x %02x %02x %02x %02x",
 +                                       Dbprintf("     %02x: %02x %02x %02x %02x %02x %02x %02x %02x",
                                                 block, resp[0], resp[1], resp[2],
 -                                              resp[3], resp[4], resp[5],
 -                                              resp[6], resp[7]);
 +                                        resp[3], resp[4], resp[5],
 +                                        resp[6], resp[7]);
  
                                //Fill up the buffer
                                memcpy(card_data+stored_data_length,resp,8);
                                stored_data_length += 8;
                                if(stored_data_length +8 > USB_CMD_DATA_SIZE)
                                {//Time to send this off and start afresh
                                        cmd_send(CMD_ACK,
                                Dbprintf("Failed to dump block %d", block);
                        }
                }
                //Send off any remaining data
                if(stored_data_length > 0)
                {
@@@ -1784,7 -1782,7 +1784,7 @@@ void IClass_iso14443A_write(uint8_t arg
        uint8_t* resp = (((uint8_t *)BigBuf) + 3560);
  
        // Reset trace buffer
 -    memset(trace, 0x44, RECV_CMD_OFFSET);
 +      memset(trace, 0x44, RECV_CMD_OFFSET);
        traceLen = 0;
  
        // Setup SSC
diff --combined armsrc/lfops.c
index fabede413db7e891cd01f37562c70cb39ec34b02,e34eab35f5bc813f8201b699967db819ed9da556..16e46c8b49abd751ada81f296b6921a590c60eef
@@@ -37,15 -37,15 +37,15 @@@ void ModThenAcquireRawAdcSamples125k(in
        sample_config sc = { 0,0,1, divisor_used, 0};
        setSamplingConfig(&sc);
  
 -      /* Make sure the tag is reset */
 -      FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 -      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
 -      SpinDelay(2500);
 +    /* Make sure the tag is reset */
 +    FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 +    FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
 +    SpinDelay(2500);
  
        LFSetupFPGAForADC(sc.divisor, 1);
  
 -      // And a little more time for the tag to fully power up
 -      SpinDelay(2000);
 +    // And a little more time for the tag to fully power up
 +    SpinDelay(2000);
  
      // now modulate the reader field
      while(*command != '\0' && *command != ' ') {
@@@ -72,6 -72,8 +72,6 @@@
        DoAcquisition_config(false);
  }
  
 -
 -
  /* blank r/w tag data stream
  ...0000000000000000 01111111
  1010101010101010101010101010101010101010101010101010101010101010
@@@ -379,7 -381,7 +379,7 @@@ void WriteTItag(uint32_t idhi, uint32_
      DbpString("Now use tiread to check");
  }
  
 -void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
 +void SimulateTagLowFrequency(uint16_t period, uint32_t gap, uint8_t ledcontrol)
  {
      int i;
      uint8_t *tab = BigBuf_get_addr();
@@@ -560,7 -562,7 +560,7 @@@ void CmdHIDdemodFSK(int findone, int *h
          if (ledcontrol) LED_A_ON();
  
                DoAcquisition_default(-1,true);
 -              // FSK demodulator
 +        // FSK demodulator
          size = sizeOfBigBuff;  //variable size will change after demod so re initialize it before use
                idx = HIDdemodFSK(dest, &size, &hi2, &hi, &lo);
          
@@@ -649,7 -651,7 +649,7 @@@ void CmdEM410xdemod(int findone, int *h
          if (ledcontrol) LED_A_ON();
  
                DoAcquisition_default(-1,true);
 -              size  = BigBuf_max_traceLen();
 +        size  = BigBuf_max_traceLen();
          //Dbprintf("DEBUG: Buffer got");
                //askdemod and manchester decode
                errCnt = askmandemod(dest, &size, &clk, &invert, maxErr);
@@@ -702,7 -704,7 +702,7 @@@ void CmdIOdemodFSK(int findone, int *hi
          WDT_HIT();
          if (ledcontrol) LED_A_ON();
                DoAcquisition_default(-1,true);
 -              //fskdemod and get start index
 +        //fskdemod and get start index
          WDT_HIT();
          idx = IOdemodFSK(dest, BigBuf_max_traceLen());
          if (idx>0){
   * To compensate antenna falling times shorten the write times
   * and enlarge the gap ones.
   */
 -#define START_GAP 250
 -#define WRITE_GAP 160
 -#define WRITE_0   144 // 192
 -#define WRITE_1   400 // 432 for T55x7; 448 for E5550
 +#define START_GAP 30*8 // 10 - 50fc 250
 +#define WRITE_GAP 20*8 //  8 - 30fc
 +#define WRITE_0   24*8 // 16 - 31fc 24fc 192
 +#define WRITE_1   54*8 // 48 - 63fc 54fc 432 for T55x7; 448 for E5550
 +
 +//  VALUES TAKEN FROM EM4x function: SendForward
 +//  START_GAP = 440;       (55*8) cycles at 125Khz (8us = 1cycle)
 +//  WRITE_GAP = 128;       (16*8)
 +//  WRITE_1   = 256 32*8;  (32*8) 
 +
 +//  These timings work for 4469/4269/4305 (with the 55*8 above)
 +//  WRITE_0 = 23*8 , 9*8  SpinDelayUs(23*8); 
 +
 +#define T55xx_SAMPLES_SIZE            12000 // 32 x 32 x 10  (32 bit times numofblock (7), times clock skip..)
  
  // Write one bit to card
  void T55xxWriteBit(int bit)
      FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
      FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
      FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 -    if (bit == 0)
 +      if (!bit)
          SpinDelayUs(WRITE_0);
      else
          SpinDelayUs(WRITE_1);
  // Write one card block in page 0, no lock
  void T55xxWriteBlock(uint32_t Data, uint32_t Block, uint32_t Pwd, uint8_t PwdMode)
  {
 -    //unsigned int i;  //enio adjustment 12/10/14
 -    uint32_t i;
 +      uint32_t i = 0;
  
 -    FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 -    FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 -    FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 -
 -    // Give it a bit of time for the resonant antenna to settle.
 -    // And for the tag to fully power up
 -    SpinDelay(150);
 +      // Set up FPGA, 125kHz
 +      // Wait for config.. (192+8190xPOW)x8 == 67ms
 +      LFSetupFPGAForADC(0, true);
  
      // Now start writting
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
  // Read one card block in page 0
  void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode)
  {
 +    uint32_t i = 0;
      uint8_t *dest = BigBuf_get_addr();
 -    //int m=0, i=0; //enio adjustment 12/10/14
 -    uint32_t m=0, i=0;
 -    FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 -    m = BigBuf_max_traceLen();
 -    // Clear destination buffer before sending the command
 -    memset(dest, 128, m);
 -    // Connect the A/D to the peak-detected low-frequency path.
 -    SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
 -    // Now set up the SSC to get the ADC samples that are now streaming at us.
 -    FpgaSetupSsc();
 -
 -    LED_D_ON();
 -    FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 -    FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 -
 -    // Give it a bit of time for the resonant antenna to settle.
 -    // And for the tag to fully power up
 -    SpinDelay(150);
 -
 -    // Now start writting
 +    uint16_t bufferlength = BigBuf_max_traceLen();
 +      if ( bufferlength > T55xx_SAMPLES_SIZE )
 +              bufferlength = T55xx_SAMPLES_SIZE;
 +
 +      memset(dest, 0x80, bufferlength);
 +      
 +      // Set up FPGA, 125kHz
 +      // Wait for config.. (192+8190xPOW)x8 == 67ms
 +      LFSetupFPGAForADC(0, true);
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
      SpinDelayUs(START_GAP);
  
          T55xxWriteBit(Block & i);
  
      // Turn field on to read the response
 -    FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 -    FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 +      TurnReadLFOn();
  
      // Now do the acquisition
      i = 0;
      for(;;) {
          if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
              AT91C_BASE_SSC->SSC_THR = 0x43;
 +                      LED_D_ON();
          }
          if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
              dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
 -            // we don't care about actual value, only if it's more or less than a
 -            // threshold essentially we capture zero crossings for later analysis
 -            //                        if(dest[i] < 127) dest[i] = 0; else dest[i] = 1;
 -            i++;
 -            if (i >= m) break;
 +                      ++i;
 +                      LED_D_OFF();
 +                      if (i >= bufferlength) break;
          }
      }
  
 +      cmd_send(CMD_ACK,0,0,0,0,0);
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
      LED_D_OFF();
 -    DbpString("DONE!");
  }
  
  // Read card traceability data (page 1)
  void T55xxReadTrace(void){
 -    uint8_t *dest = BigBuf_get_addr();
 -    int m=0, i=0;
  
 -    FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
 -    m = BigBuf_max_traceLen();
 -    // Clear destination buffer before sending the command
 -    memset(dest, 128, m);
 -    // Connect the A/D to the peak-detected low-frequency path.
 -    SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
 -    // Now set up the SSC to get the ADC samples that are now streaming at us.
 -    FpgaSetupSsc();
 -
 -    LED_D_ON();
 -    FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 -    FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 -
 -    // Give it a bit of time for the resonant antenna to settle.
 -    // And for the tag to fully power up
 -    SpinDelay(150);
 +      uint32_t i = 0;
 +    uint8_t *dest = BigBuf_get_addr();
 +    uint16_t bufferlength = BigBuf_max_traceLen();
 +      if ( bufferlength > T55xx_SAMPLES_SIZE )
 +              bufferlength = T55xx_SAMPLES_SIZE;
  
 -    // Now start writting
 +      memset(dest, 0x80, bufferlength);  
 +  
 +      LFSetupFPGAForADC(0, true);
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
      SpinDelayUs(START_GAP);
  
      T55xxWriteBit(1); //Page 1
  
      // Turn field on to read the response
 -    FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 -    FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 +      TurnReadLFOn();
  
      // Now do the acquisition
 -    i = 0;
      for(;;) {
          if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
              AT91C_BASE_SSC->SSC_THR = 0x43;
 +                      LED_D_ON();
          }
          if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
              dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
 -            i++;
 -            if (i >= m) break;
 -        }
 -    }
 -
 +                      ++i;
 +                      LED_D_OFF();
 +              
 +                      if (i >= bufferlength) break;
 +              }
 +      }
 +  
 +      cmd_send(CMD_ACK,0,0,0,0,0);
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
      LED_D_OFF();
 -    DbpString("DONE!");
 +}
 +
 +void TurnReadLFOn(){
 +      //FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
 +      FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
 +      // Give it a bit of time for the resonant antenna to settle.
 +      //SpinDelay(30);
 +      SpinDelayUs(9*150);
  }
  
  /*-------------- Cloning routines -----------*/
@@@ -1286,9 -1297,9 +1286,10 @@@ void CopyIndala224toT55x7(int uid1, in
  #define max(x,y) ( x<y ? y:x)
  
  int DemodPCF7931(uint8_t **outBlocks) {
--    uint8_t BitStream[256];
--    uint8_t Blocks[8][16];
--    uint8_t *GraphBuffer = BigBuf_get_addr();
++
++    uint8_t BitStream[256] = {0x00};
++      uint8_t Blocks[8][16] = [0x00};
++    uint8_t *dest = BigBuf_get_addr();
      int GraphTraceLen = BigBuf_max_traceLen();
      int i, j, lastval, bitidx, half_switch;
      int clock = 64;
      uint8_t dir;
  
        LFSetupFPGAForADC(95, true);
--      DoAcquisition_default(0, 0);
--
++      DoAcquisition_default(0, true);
  
      lmin = 64;
      lmax = 192;
      i = 2;
  
      /* Find first local max/min */
--    if(GraphBuffer[1] > GraphBuffer[0]) {
++    if(dest[1] > dest[0]) {
          while(i < GraphTraceLen) {
--            if( !(GraphBuffer[i] > GraphBuffer[i-1]) && GraphBuffer[i] > lmax)
++            if( !(dest[i] > dest[i-1]) && dest[i] > lmax)
                  break;
              i++;
          }
      }
      else {
          while(i < GraphTraceLen) {
--            if( !(GraphBuffer[i] < GraphBuffer[i-1]) && GraphBuffer[i] < lmin)
++            if( !(dest[i] < dest[i-1]) && v[i] < lmin)
                  break;
              i++;
          }
  
      for (bitidx = 0; i < GraphTraceLen; i++)
      {
--        if ( (GraphBuffer[i-1] > GraphBuffer[i] && dir == 1 && GraphBuffer[i] > lmax) || (GraphBuffer[i-1] < GraphBuffer[i] && dir == 0 && GraphBuffer[i] < lmin))
++        if ( (dest[i-1] > dest[i] && dir == 1 && dest[i] > lmax) || (dest[i-1] < dest[i] && dir == 0 && dest[i] < lmin))
          {
              lc = i - lastval;
              lastval = i;
              }
              if(i < GraphTraceLen)
              {
--                if (GraphBuffer[i-1] > GraphBuffer[i]) dir=0;
++                if (dest[i-1] > dest[i]) dir=0;
                  else dir = 1;
              }
          }
@@@ -1707,14 -1718,9 +1707,14 @@@ void EM4xLogin(uint32_t Password) 
  
  void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode) {
  
 +      uint8_t *dest =  BigBuf_get_addr();
 +      uint16_t bufferlength = BigBuf_max_traceLen();
 +      uint32_t i = 0;
 +
 +      // Clear destination buffer before sending the command  0x80 = average.
 +      memset(dest, 0x80, bufferlength);
 +      
      uint8_t fwd_bit_count;
 -    uint8_t *dest = BigBuf_get_addr();
 -    int m=0, i=0;
  
      //If password mode do login
      if (PwdMode == 1) EM4xLogin(Pwd);
      fwd_bit_count = Prepare_Cmd( FWD_CMD_READ );
      fwd_bit_count += Prepare_Addr( Address );
  
 -    m = BigBuf_max_traceLen();
 -    // Clear destination buffer before sending the command
 -    memset(dest, 128, m);
      // Connect the A/D to the peak-detected low-frequency path.
      SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
      // Now set up the SSC to get the ADC samples that are now streaming at us.
          }
          if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
              dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
 -            i++;
 -            if (i >= m) break;
 -        }
 -    }
 +                      ++i;
 +                      if (i >= bufferlength) break;
 +              }
 +      }
 +  
 +      cmd_send(CMD_ACK,0,0,0,0,0);
      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // field off
      LED_D_OFF();
  }
diff --combined include/usb_cmd.h
index 295f0ebf1da7f0fef4dcb8954a0f207deafa66bf,d9a950aefe8a9533f10355bb79cd5990bcf0077e..ec162b4e907c6935384da1b04151cd09b9344620
@@@ -125,13 -125,13 +125,14 @@@ typedef struct
  #define CMD_READER_LEGIC_RF                                               0x0388
  #define CMD_WRITER_LEGIC_RF                                               0x0389
  #define CMD_EPA_PACE_COLLECT_NONCE                                        0x038A
 +//#define CMD_EPA_                                                          0x038B
  
  #define CMD_SNOOP_ICLASS                                                  0x0392
  #define CMD_SIMULATE_TAG_ICLASS                                           0x0393
  #define CMD_READER_ICLASS                                                 0x0394
 -#define CMD_READER_ICLASS_REPLAY                                                                                0x0395
 +#define CMD_READER_ICLASS_REPLAY                                                                                0x0395
  #define CMD_ICLASS_ISO14443A_WRITE                                                                              0x0397
+ #define CMD_ICLASS_EML_MEMSET                                             0x0398
  
  // For measurements of the antenna tuning
  #define CMD_MEASURE_ANTENNA_TUNING                                        0x0400
  #define CMD_MIFARE_NESTED                                                 0x0612
  
  #define CMD_MIFARE_READBL                                                 0x0620
 -#define CMD_MIFAREU_READBL                                              0x0720
 +#define CMD_MIFAREU_READBL                                                                      0x0720
 +
  #define CMD_MIFARE_READSC                                                 0x0621
 -#define CMD_MIFAREU_READCARD                                            0x0721
 +#define CMD_MIFAREU_READCARD                                                                0x0721
 +
  #define CMD_MIFARE_WRITEBL                                                0x0622
  #define CMD_MIFAREU_WRITEBL                                                                     0x0722
  #define CMD_MIFAREU_WRITEBL_COMPAT                                                          0x0723
  
  
  //Iclass reader flags
 -#define FLAG_ICLASS_READER_ONLY_ONCE    0x01
 +#define FLAG_ICLASS_READER_ONLY_ONCE 0x01
  #define FLAG_ICLASS_READER_GET_CC       0x02
  
  
Impressum, Datenschutz