Semi-Automated SendCommand -> SendCommandOLD

This commit is contained in:
Philippe Teuwen 2019-04-19 17:03:39 +02:00
commit c4766b2649
41 changed files with 543 additions and 957 deletions

View file

@ -524,10 +524,10 @@ static int CmdLegicRfSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_legic_sim();
PacketCommandOLD c = {CMD_SIMULATE_TAG_LEGIC_RF, {1}, {{0}}};
sscanf(Cmd, " %" SCNi64, &c.arg[0]);
uint64_t id = 1;
sscanf(Cmd, " %" SCNi64, &id);
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_SIMULATE_TAG_LEGIC_RF, id, 0, 0, NULL, 0);
return 0;
}
@ -642,11 +642,9 @@ static int CmdLegicRfWrite(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Writing to tag");
PacketCommandOLD c = {CMD_WRITER_LEGIC_RF, {offset, len, IV}, {{0}}};
memcpy(c.d.asBytes, data, len);
PacketResponseNG resp;
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_WRITER_LEGIC_RF, offset, len, IV, data, len);
uint8_t timeout = 0;
@ -756,9 +754,8 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
legic_chk_iv(&iv);
PacketCommandOLD c = {CMD_READER_LEGIC_RF, {offset, len, iv}, {{0}}};
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_READER_LEGIC_RF, offset, len, iv, NULL, 0);
PacketResponseNG resp;
uint8_t timeout = 0;
@ -810,9 +807,8 @@ int legic_get_type(legic_card_select_t *card) {
if (card == NULL) return 1;
PacketCommandOLD c = {CMD_LEGIC_INFO, {0, 0, 0}, {{0}}};
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_LEGIC_INFO, 0, 0, 0, NULL, 0);
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500))
return 2;
@ -837,15 +833,11 @@ void legic_chk_iv(uint32_t *iv) {
}
void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
PacketCommandOLD c = {CMD_LEGIC_ESET, {0, 0, 0}, {{0}}};
for (size_t i = offset; i < numofbytes; i += USB_CMD_DATA_SIZE) {
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
c.arg[0] = i; // offset
c.arg[1] = len; // number of bytes
memcpy(c.d.asBytes, src + i, len);
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_LEGIC_ESET, i, len, 0, src + i, len);
}
}
@ -900,9 +892,8 @@ static int CmdLegicDump(const char *Cmd) {
legic_print_type(dumplen, 0);
PrintAndLogEx(SUCCESS, "Reading tag memory %d b...", dumplen);
PacketCommandOLD c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}, {{0}}};
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_READER_LEGIC_RF, 0x00, dumplen, 0x55, NULL, 0);
PacketResponseNG resp;
uint8_t timeout = 0;
@ -1049,16 +1040,12 @@ static int CmdLegicRestore(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Restoring to card");
// transfer to device
PacketCommandOLD c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
PacketResponseNG resp;
for (size_t i = 7; i < numofbytes; i += USB_CMD_DATA_SIZE) {
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
c.arg[0] = i; // offset
c.arg[1] = len; // number of bytes
memcpy(c.d.asBytes, data + i, len);
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_WRITER_LEGIC_RF, i, len, 0x55, data + i, len);
uint8_t timeout = 0;
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
@ -1242,18 +1229,14 @@ static int CmdLegicWipe(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Erasing");
// transfer to device
PacketCommandOLD c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}, {{0}}};
PacketResponseNG resp;
for (size_t i = 7; i < card.cardsize; i += USB_CMD_DATA_SIZE) {
printf(".");
fflush(stdout);
size_t len = MIN((card.cardsize - i), USB_CMD_DATA_SIZE);
c.arg[0] = i; // offset
c.arg[1] = len; // number of bytes
memcpy(c.d.asBytes, data + i, len);
clearCommandBuffer();
SendCommand(&c);
SendCommandOLD(CMD_WRITER_LEGIC_RF, i, len, 0x55, data + i, len);
uint8_t timeout = 0;
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {