From: iceman1001 Date: Tue, 4 Oct 2016 16:05:55 +0000 (+0200) Subject: CHG: "hf legic write" started to change this command to the updated code X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/7bc3c99e7ea67d2d67c4c7a44abcea92fa523231 CHG: "hf legic write" started to change this command to the updated code --- diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index 4aa45b6d..42e7649c 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -72,7 +72,7 @@ static void setup_timer(void) { #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 #define RWD_TIME_PAUSE 30 // 20us == 20 * 1.5 == 30ticks */ -#define TAG_BIT_PERIOD 144 // 100us == 100 * 1.5 == 150ticks +#define TAG_BIT_PERIOD 142 // 100us == 100 * 1.5 == 150ticks #define TAG_FRAME_WAIT 495 // 330us from READER frame end to TAG frame start. 330 * 1.5 == 495 #define RWD_TIME_FUZZ 20 // rather generous 13us, since the peak detector + hysteresis fuzz quite a bit @@ -433,11 +433,11 @@ int legic_write_byte(uint8_t byte, uint16_t addr, uint8_t addr_sz) { crc_update(&legic_crc, addr, addr_sz); crc_update(&legic_crc, byte, 8); uint32_t crc = crc_finish(&legic_crc); - uint32_t crc2 = legic4Crc(LEGIC_WRITE, addr, byte, addr_sz+1); - if ( crc != crc2 ) + if ( crc != crc2 ) { Dbprintf("crc is missmatch"); - + return 1; + } // send write command uint32_t cmd = ((crc <<(addr_sz+1+8)) //CRC |(byte <<(addr_sz+1)) //Data @@ -448,11 +448,10 @@ int legic_write_byte(uint8_t byte, uint16_t addr, uint8_t addr_sz) { legic_prng_forward(2); /* we wait anyways */ - WaitUS(TAG_FRAME_WAIT); + WaitTicks(330); frame_sendAsReader(cmd, cmd_sz); - - + AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_DIN; AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DIN; diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 4a252bb1..ea75e15f 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -604,7 +604,6 @@ int CmdLegicRfWrite(const char *Cmd) { uint32_t offset = 0, len = 0, IV = 0; - UsbCommand c = {CMD_WRITER_LEGIC_RF, {0,0,0}}; int res = sscanf(Cmd, "%x %x %x", &offset, &len, &IV); if(res < 2) { PrintAndLog("Please specify the offset and length as two hex strings and, optionally, the IV also as an hex string"); @@ -612,8 +611,10 @@ int CmdLegicRfWrite(const char *Cmd) { } // OUT-OF-BOUNDS check - if(len + offset > MAX_LENGTH) len = MAX_LENGTH - offset; - + if ( len + offset > MAX_LENGTH ) { + len = MAX_LENGTH - offset; + PrintAndLog("Out-of-bound, shorten len to %d", len); + } if ( (IV & 0x7F) != IV ){ IV &= 0x7F; PrintAndLog("Truncating IV to 7bits"); @@ -623,14 +624,21 @@ int CmdLegicRfWrite(const char *Cmd) { PrintAndLog("LSB of IV must be SET"); } - PrintAndLog("Current IV: 0x%02x", IV); - - c.arg[0] = offset; - c.arg[1] = len; - c.arg[2] = IV; - + UsbCommand c = {CMD_WRITER_LEGIC_RF, {offset, len, IV}}; clearCommandBuffer(); SendCommand(&c); + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + uint8_t isOK = resp.arg[0] & 0xFF; + if ( isOK ) { + } else { + PrintAndLog("failed writig tag"); + } + } else { + PrintAndLog("command execution time out"); + return 1; + } + return 0; }