From d7f1ab2175e52bfdb9124f67d9aff10d7f641078 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 20 May 2019 09:15:45 -0400 Subject: [PATCH] chg: lf cmdread - now uses NG --- armsrc/appmain.c | 12 ++++++++-- armsrc/lfops.c | 10 ++++----- armsrc/lfsampling.c | 2 +- client/cmdlf.c | 53 ++++++++++++++++++++++++++++++--------------- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b09cd4caa..484150293 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -755,9 +755,17 @@ static void PacketReceived(PacketCommandNG *packet) { reply_old(CMD_ACK, bits, 0, 0, 0, 0); break; } - case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K: - ModThenAcquireRawAdcSamples125k(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2], packet->data.asBytes); + case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K: { + struct p { + uint32_t delay; + uint16_t ones; + uint16_t zeros; + } PACKED; + struct p *payload; + payload = (struct p*)packet->data.asBytes; + ModThenAcquireRawAdcSamples125k(payload->delay, payload->zeros, payload->ones, packet->data.asBytes+8); break; + } case CMD_LF_SNIFF_RAW_ADC_SAMPLES: { uint32_t bits = SniffLF(); reply_old(CMD_ACK, bits, 0, 0, 0, 0); diff --git a/armsrc/lfops.c b/armsrc/lfops.c index a49f205c4..2793b90a6 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -242,7 +242,7 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint // Turn off antenna FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); // tell client we are done - reply_old(CMD_ACK, 0, 0, 0, 0, 0); + reply_ng(CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, PM3_SUCCESS, NULL, 0); } /* blank r/w tag data stream @@ -1409,7 +1409,7 @@ void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t fl // make sure tag is fully powered up... WaitMS(4); - + // Trigger T55x7 in mode. FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS(t_config.start_gap); @@ -1423,7 +1423,7 @@ void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t fl // std opcode 10 == page 0 // std opcode 11 == page 1 T55xxWriteBit(1); - T55xxWriteBit(page); + T55xxWriteBit(page); } if (pwd_mode) { @@ -1479,8 +1479,8 @@ void T55xxWriteBlockExt(uint32_t data, uint8_t blockno, uint32_t pwd, uint8_t fl // Write one card block in page 0, no lock // uses NG format void T55xxWriteBlock(uint8_t *data) { - t55xx_write_block_t *c = (t55xx_write_block_t *)data; - T55xxWriteBlockExt(c->data, c->blockno, c->pwd, c->flags); + t55xx_write_block_t *c = (t55xx_write_block_t *)data; + T55xxWriteBlockExt(c->data, c->blockno, c->pwd, c->flags); reply_ng(CMD_T55XX_WRITE_BLOCK, PM3_SUCCESS, NULL, 0); } diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index 191f01d5e..b8a76c016 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -199,7 +199,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag } if (!silent) { - Dbprintf("Done, saved %d out of %d seen samples at %d bits/sample", sample_total_saved, sample_total_numbers, bits_per_sample); + Dbprintf("Done, saved " _YELLOW_("%d")"out of " _YELLOW_("%d")"seen samples at " _YELLOW_("%d")"bits/sample", sample_total_saved, sample_total_numbers, bits_per_sample); Dbprintf("buffer samples: %02x %02x %02x %02x %02x %02x %02x %02x ...", dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]); } diff --git a/client/cmdlf.c b/client/cmdlf.c index 86e218066..62e45051e 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -145,32 +145,37 @@ static int usage_lf_find(void) { int CmdLFCommandRead(const char *Cmd) { bool errors = false; - - uint32_t arg0 = 0; - uint32_t arg1 = 0; - uint32_t arg2 = 0; - uint8_t data[PM3_CMD_DATA_SIZE]; uint16_t datalen = 0; + struct p { + uint32_t delay; + uint16_t ones; + uint16_t zeros; + uint8_t data[PM3_CMD_DATA_SIZE - 8]; + } PACKED; + + struct p payload; + + uint8_t cmdp = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': return usage_lf_cmdread(); - case 'c': - datalen = param_getstr(Cmd, cmdp + 1, (char *)&data, sizeof(data)); + case 'c': // cmd bytes 1010 + datalen = param_getstr(Cmd, cmdp + 1, (char *)&payload.data, sizeof(payload.data)); cmdp += 2; break; - case 'd': - arg0 = param_get32ex(Cmd, cmdp + 1, 0, 10); + case 'd': // delay + payload.delay = param_get32ex(Cmd, cmdp + 1, 0, 10); cmdp += 2; break; - case 'z': - arg1 = param_get32ex(Cmd, cmdp + 1, 0, 10) & 0xFFFF; + case 'z': // zero + payload.zeros = param_get32ex(Cmd, cmdp + 1, 0, 10) & 0xFFFF; cmdp += 2; break; - case 'o': - arg2 = param_get32ex(Cmd, cmdp + 1, 0, 10) & 0xFFFF; + case 'o': // ones + payload.ones = param_get32ex(Cmd, cmdp + 1, 0, 10) & 0xFFFF; cmdp += 2; break; default: @@ -183,12 +188,26 @@ int CmdLFCommandRead(const char *Cmd) { //Validations if (errors || cmdp == 0) return usage_lf_cmdread(); + PrintAndLogEx(SUCCESS, "Sending"); clearCommandBuffer(); - SendCommandOLD(CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, arg0, arg1, arg2, data, datalen); + SendCommandNG(CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, (uint8_t*)&payload, 8 + datalen ); - WaitForResponse(CMD_ACK, NULL); - getSamples(0, true); - return 0; + printf("\n"); + uint8_t i = 10; + while ( !WaitForResponseTimeout(CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, NULL, 2000 ) && i != 0) { + printf("."); + fflush(stdout); + i--; + } + printf("\n"); + + if ( i ) { + PrintAndLogEx(SUCCESS, "Downloading response signal data"); + getSamples(0, true); + return PM3_SUCCESS; + } + PrintAndLogEx(WARNING, "timeout while waiting for reply."); + return PM3_EOPABORTED; } int CmdFlexdemod(const char *Cmd) {