X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/3e750be37cd8e3231ae02260be6899391d206cb4..11dee3d5a681d906fa676005269f9bf43f2b810d:/armsrc/legicrf.c diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index 7a156f69..97c14b69 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -68,10 +68,6 @@ static void setup_timer(void) { */ // At TIMER_CLOCK3 (MCK/32) -//#define RWD_TIME_1 150 /* RWD_TIME_PAUSE off, 80us on = 100us */ -//#define RWD_TIME_0 90 /* RWD_TIME_PAUSE off, 40us on = 60us */ -//#define RWD_TIME_PAUSE 30 /* 20us */ - // testing calculating in (us) microseconds. #define RWD_TIME_1 120 // READER_TIME_PAUSE 20us off, 80us on = 100us 80 * 1.5 == 120ticks #define RWD_TIME_0 60 // READER_TIME_PAUSE 20us off, 40us on = 60us 40 * 1.5 == 60ticks @@ -290,7 +286,6 @@ static void frame_receiveAsReader(struct legic_frame * const f, uint8_t bits) { AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DIN; // calibrate the prng. - // legic_prng_forward(2); // precompute the cipher @@ -365,7 +360,7 @@ static uint32_t setup_phase_reader(uint8_t iv) { // Switch on carrier and let the tag charge for 1ms HIGH(GPIO_SSC_DOUT); - WaitUS(1000); + WaitUS(100); ResetTicks(); @@ -423,7 +418,6 @@ static void switch_off_tag_rwd(void) { LOW(GPIO_SSC_DOUT); WaitUS(20); WDT_HIT(); - set_tracing(FALSE); } // calculate crc4 for a legic READ command @@ -449,8 +443,8 @@ int legic_read_byte(int byte_index, int cmd_sz) { // 460 | 690 // 258 | 387 // 244 | 366 - WaitTicks(387); - legic_prng_forward(4); // 460 / 100 = 4.6 iterations + WaitTicks(495); + legic_prng_forward(3); // 460 / 100 = 4.6 iterations frame_sendAsReader(cmd, cmd_sz); frame_receiveAsReader(¤t_frame, 12); @@ -815,7 +809,7 @@ void LegicRfInfo(void){ } cmd_send(CMD_ACK,1,card_sz,0,uid,sizeof(uid)); -out: +OUT: switch_off_tag_rwd(); LEDsoff(); @@ -1127,6 +1121,7 @@ void LegicRfSimulate(int phase, int frame, int reqresp) // The software UART that receives commands from the reader, and its state // variables. //----------------------------------------------------------------------------- +/* static struct { enum { STATE_UNSYNCD, @@ -1141,7 +1136,7 @@ static struct { int posCnt; uint8_t *output; } Uart; - +*/ /* Receive & handle a bit coming from the reader. * * This function is called 4 times per bit (every 2 subcarrier cycles). @@ -1266,7 +1261,7 @@ static struct { // return FALSE; // } - +/* static void UartReset() { Uart.byteCntMax = 3; @@ -1276,7 +1271,7 @@ static void UartReset() { Uart.posCnt = 0; memset(Uart.output, 0x00, 3); } - +*/ // static void UartInit(uint8_t *data) { // Uart.output = data; // UartReset(); @@ -1288,7 +1283,7 @@ static void UartReset() { // tag's response, which we leave in the buffer to be demodulated on the // PC side. //============================================================================= - +/* static struct { enum { DEMOD_UNSYNCD, @@ -1307,7 +1302,7 @@ static struct { int sumI; int sumQ; } Demod; - +*/ /* * Handles reception of a bit from the tag * @@ -1322,32 +1317,8 @@ static struct { * false if we are still waiting for some more * */ - - #ifndef SUBCARRIER_DETECT_THRESHOLD - # define SUBCARRIER_DETECT_THRESHOLD 8 - #endif - // Subcarrier amplitude v = sqrt(ci^2 + cq^2), approximated here by max(abs(ci),abs(cq)) + 1/2*min(abs(ci),abs(cq))) -#ifndef CHECK_FOR_SUBCARRIER -# define CHECK_FOR_SUBCARRIER() { v = MAX(ai, aq) + MIN(halfci, halfcq); } -#endif - -// The soft decision on the bit uses an estimate of just the -// quadrant of the reference angle, not the exact angle. -// Subcarrier amplitude v = sqrt(ci^2 + cq^2), approximated here by max(abs(ci),abs(cq)) + 1/2*min(abs(ci),abs(cq))) -#define MAKE_SOFT_DECISION() { \ - if(Demod.sumI > 0) \ - v = ci; \ - else \ - v = -ci; \ - \ - if(Demod.sumQ > 0) \ - v += cq; \ - else \ - v -= cq; \ - \ - } - +/* static RAMFUNC int HandleLegicSamplesDemod(int ci, int cq) { int v = 0; @@ -1502,7 +1473,8 @@ static RAMFUNC int HandleLegicSamplesDemod(int ci, int cq) } return FALSE; } - +*/ +/* // Clear out the state of the "UART" that receives from the tag. static void DemodReset() { Demod.len = 0; @@ -1520,13 +1492,17 @@ static void DemodInit(uint8_t *data) { Demod.output = data; DemodReset(); } +*/ /* * Demodulate the samples we received from the tag, also log to tracebuffer * quiet: set to 'TRUE' to disable debug output */ + + /* #define LEGIC_DMA_BUFFER_SIZE 256 -static void GetSamplesForLegicDemod(int n, bool quiet) + + static void GetSamplesForLegicDemod(int n, bool quiet) { int max = 0; bool gotFrame = FALSE; @@ -1601,9 +1577,13 @@ static void GetSamplesForLegicDemod(int n, bool quiet) LogTrace(Demod.output, Demod.len, 0, 0, parity, FALSE); } } + +*/ + //----------------------------------------------------------------------------- // Transmit the command (to the tag) that was placed in ToSend[]. //----------------------------------------------------------------------------- +/* static void TransmitForLegic(void) { int c; @@ -1650,12 +1630,13 @@ static void TransmitForLegic(void) } LED_B_OFF(); } - +*/ //----------------------------------------------------------------------------- // Code a layer 2 command (string of octets, including CRC) into ToSend[], // so that it is ready to transmit to the tag using TransmitForLegic(). //----------------------------------------------------------------------------- +/* static void CodeLegicBitsAsReader(const uint8_t *cmd, uint8_t cmdlen, int bits) { int i, j; @@ -1687,11 +1668,12 @@ static void CodeLegicBitsAsReader(const uint8_t *cmd, uint8_t cmdlen, int bits) // Convert from last character reference to length ++ToSendMax; } - +*/ /** Convenience function to encode, transmit and trace Legic comms **/ -static void CodeAndTransmitLegicAsReader(const uint8_t *cmd, uint8_t cmdlen, int bits) +/* + static void CodeAndTransmitLegicAsReader(const uint8_t *cmd, uint8_t cmdlen, int bits) { CodeLegicBitsAsReader(cmd, cmdlen, bits); TransmitForLegic(); @@ -1701,8 +1683,9 @@ static void CodeAndTransmitLegicAsReader(const uint8_t *cmd, uint8_t cmdlen, int } } - +*/ // Set up LEGIC communication +/* void ice_legic_setup() { // standard things. @@ -1731,4 +1714,5 @@ void ice_legic_setup() { // initalize prng legic_prng_init(0); -} \ No newline at end of file +} +*/ \ No newline at end of file