CHG: "hf legic write" got a make over in how its called. Now called with 'offset' and 'data'

'hf legic write o 10 d 11223344'  -  this will write 4 bytes (0x11,0x22,0x33,0x44) to tag from offset 10 (0x0A)
This commit is contained in:
iceman1001 2016-10-07 11:58:14 +02:00
commit f0fa663814
2 changed files with 107 additions and 59 deletions

View file

@ -417,11 +417,13 @@ int legic_write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) {
crc_update(&legic_crc, index, addr_sz);
crc_update(&legic_crc, byte, 8);
uint32_t crc = crc_finish(&legic_crc);
/*
uint32_t crc2 = legic4Crc(LEGIC_WRITE, index, byte, addr_sz+1);
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
@ -443,7 +445,7 @@ int legic_write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) {
int next_bit_at = 0;
// ACK 3.6ms = 3600us * 1.5 = 5400ticks.
WaitTicks(5360);
WaitTicks(5400);
for( t = 0; t < 80; ++t) {
edges = 0;
@ -512,16 +514,18 @@ OUT:
void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
#define LOWERLIMIT 4
int r = 0;
uint8_t isOK = 1;
legic_card_select_t card;
// UID not is writeable.
if ( offset <= 4 ) {
// uid NOT is writeable.
if ( offset <= LOWERLIMIT ) {
isOK = 0;
goto OUT;
}
legic_card_select_t card;
LegicCommonInit();
if ( legic_select_card_iv(&card, iv) ) {
@ -529,39 +533,25 @@ void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
goto OUT;
}
if (len + offset >= card.cardsize)
len = card.cardsize - offset;
switch_off_tag_rwd();
if ( len + offset + LOWERLIMIT >= card.cardsize) {
isOK = 0;
goto OUT;
}
setup_phase_reader(iv);
LED_B_ON();
int r = 0;
// how about we write backwards instead. no need for this extra DCF check.
// index = len - cardsize
// stops uid 01234,
/*
len = 20
offset = 5
index = 20+5 = 25
if ( index > cardsize ) return -1;
loop
write( data[index], index , card.addrsize);
--index;
end loop
*/
uint16_t index = len;
while(index > 4) {
while( len > 0 ) {
r = legic_write_byte( index, data[ index ], card.addrsize);
if ( r ) {
Dbprintf("operation aborted @ 0x%03.3x", index);
int r = legic_write_byte( len + offset + LOWERLIMIT, data[len], card.addrsize);
if ( r == -1 ) {
Dbprintf("operation aborted @ 0x%03.3x", len);
isOK = 0;
goto OUT;
}
--index;
--len;
WDT_HIT();
}