#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
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
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;
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");
}
// 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");
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;
}