chg: lf t55xx write - now uses NG frames.

This commit is contained in:
iceman1001
2019-05-13 13:23:53 +02:00
parent 09afadc965
commit d2a4ade2af
15 changed files with 159 additions and 73 deletions

View File

@@ -395,9 +395,16 @@ static int CmdAWIDClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -291,9 +291,15 @@ static int CmdFdxClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -180,9 +180,15 @@ static int CmdGuardClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -165,9 +165,15 @@ static int CmdJablotronClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -145,7 +145,6 @@ static int CmdKeriClone(const char *Cmd) {
blocks[2] = data & 0xFFFFFFFF;
print_blocks(blocks, 3);
PacketResponseNG resp;
// fast push mode
@@ -156,9 +155,15 @@ static int CmdKeriClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -212,9 +212,14 @@ static int CmdLFNedapClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -164,9 +164,14 @@ static int CmdNoralsyClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -130,9 +130,14 @@ static int CmdPrescoClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -242,9 +242,14 @@ static int CmdPyramidClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}

View File

@@ -1041,6 +1041,11 @@ static int CmdT55xxWriteBlock(const char *Cmd) {
case 'b':
errors |= param_getdec(Cmd, cmdp + 1, &block);
cmdp += 2;
if (block > 7) {
PrintAndLogEx(WARNING, "Block number must be between 0 and 7");
errors = true;
}
break;
case 'd':
data = param_get32ex(Cmd, cmdp + 1, 0, 16);
@@ -1068,31 +1073,37 @@ static int CmdT55xxWriteBlock(const char *Cmd) {
}
if (errors || !gotdata) return usage_t55xx_write();
if (block > 7) {
PrintAndLogEx(WARNING, "Block number must be between 0 and 7");
return 0;
}
PacketResponseNG resp;
uint8_t flags[1] = {0};
flags[0] = (page1) ? 0x2 : 0;
flags[0] |= (testMode) ? 0x4 : 0;
uint8_t flags;
flags = (usepwd) ? 0x1 : 0;
flags |= (page1) ? 0x2 : 0;
flags |= (testMode) ? 0x4 : 0;
char pwdStr[16] = {0};
snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);
PrintAndLogEx(INFO, "Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "");
uint64_t arg_pwd = 0;
//Password mode
if (usepwd) {
arg_pwd = password;
flags[0] |= 0x1;
}
clearCommandBuffer();
SendCommandOLD(CMD_T55XX_WRITE_BLOCK, data, block, arg_pwd, flags, sizeof(flags));
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
/*
OLD style
arg0 = data, (4 bytes)
arg1 = block (1 byte)
arg2 = password (4 bytes)
flags = data[0] (1 byte)
new style
uses struct in pm3_cmd.h
*/
t55xx_write_block_t ng;
ng.data = data;
ng.pwd = password;
ng.blockno = block;
ng.flags = flags;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, 1500)) {
PrintAndLogEx(WARNING, "Error occurred, device did not ACK write operation. (May be due to old firmware)");
return 0;
}

View File

@@ -176,9 +176,15 @@ static int CmdVisa2kClone(const char *Cmd) {
conn.block_after_ACK = false;
}
clearCommandBuffer();
uint8_t data[] = {0};
SendCommandMIX(CMD_T55XX_WRITE_BLOCK, blocks[i], i, 0, data, sizeof(data));
if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) {
t55xx_write_block_t ng;
ng.data = blocks[i];
ng.pwd = 0;
ng.blockno = i;
ng.flags = 0;
SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng));
if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) {
PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation.");
return -1;
}