mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
CHG: minor code clean up, removed commented old code.
ADD: usb_poll_validate_length to some deviceside loops. ADD: @marshmellow42 's fixes to LF
This commit is contained in:
parent
bca7107931
commit
edaf10af99
4 changed files with 66 additions and 61 deletions
|
@ -81,38 +81,39 @@ static void setup_timer(void)
|
||||||
/* Generate Keystream */
|
/* Generate Keystream */
|
||||||
static uint32_t get_key_stream(int skip, int count)
|
static uint32_t get_key_stream(int skip, int count)
|
||||||
{
|
{
|
||||||
uint32_t key=0; int i;
|
uint32_t key=0; int i;
|
||||||
|
|
||||||
/* Use int to enlarge timer tc to 32bit */
|
/* Use int to enlarge timer tc to 32bit */
|
||||||
legic_prng_bc += prng_timer->TC_CV;
|
legic_prng_bc += prng_timer->TC_CV;
|
||||||
prng_timer->TC_CCR = AT91C_TC_SWTRG;
|
prng_timer->TC_CCR = AT91C_TC_SWTRG;
|
||||||
|
|
||||||
/* If skip == -1, forward prng time based */
|
/* If skip == -1, forward prng time based */
|
||||||
if(skip == -1) {
|
if(skip == -1) {
|
||||||
i = (legic_prng_bc+SIM_SHIFT)/SIM_DIVISOR; /* Calculate Cycles based on timer */
|
i = (legic_prng_bc+SIM_SHIFT)/SIM_DIVISOR; /* Calculate Cycles based on timer */
|
||||||
i -= legic_prng_count(); /* substract cycles of finished frames */
|
i -= legic_prng_count(); /* substract cycles of finished frames */
|
||||||
i -= count; /* substract current frame length, rewidn to bedinning */
|
i -= count; /* substract current frame length, rewidn to bedinning */
|
||||||
legic_prng_forward(i);
|
legic_prng_forward(i);
|
||||||
} else {
|
} else {
|
||||||
legic_prng_forward(skip);
|
legic_prng_forward(skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write Time Data into LOG */
|
/* Write Time Data into LOG */
|
||||||
uint8_t *BigBuf = BigBuf_get_addr();
|
uint8_t *BigBuf = BigBuf_get_addr();
|
||||||
if(count == 6) { i = -1; } else { i = legic_read_count; }
|
i = (count == 6) ? -1 : legic_read_count;
|
||||||
BigBuf[OFFSET_LOG+128+i] = legic_prng_count();
|
|
||||||
BigBuf[OFFSET_LOG+256+i*4] = (legic_prng_bc >> 0) & 0xff;
|
|
||||||
BigBuf[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff;
|
|
||||||
BigBuf[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff;
|
|
||||||
BigBuf[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff;
|
|
||||||
BigBuf[OFFSET_LOG+384+i] = count;
|
|
||||||
|
|
||||||
/* Generate KeyStream */
|
BigBuf[OFFSET_LOG+128+i] = legic_prng_count();
|
||||||
for(i=0; i<count; i++) {
|
BigBuf[OFFSET_LOG+256+i*4] = (legic_prng_bc >> 0) & 0xff;
|
||||||
key |= legic_prng_get_bit() << i;
|
BigBuf[OFFSET_LOG+256+i*4+1] = (legic_prng_bc >> 8) & 0xff;
|
||||||
legic_prng_forward(1);
|
BigBuf[OFFSET_LOG+256+i*4+2] = (legic_prng_bc >>16) & 0xff;
|
||||||
}
|
BigBuf[OFFSET_LOG+256+i*4+3] = (legic_prng_bc >>24) & 0xff;
|
||||||
return key;
|
BigBuf[OFFSET_LOG+384+i] = count;
|
||||||
|
|
||||||
|
/* Generate KeyStream */
|
||||||
|
for(i=0; i<count; i++) {
|
||||||
|
key |= legic_prng_get_bit() << i;
|
||||||
|
legic_prng_forward(1);
|
||||||
|
}
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a frame in tag mode, the FPGA must have been set up by
|
/* Send a frame in tag mode, the FPGA must have been set up by
|
||||||
|
@ -145,11 +146,11 @@ static void frame_send_tag(uint16_t response, int bits, int crypt)
|
||||||
int nextbit = timer->TC_CV + TAG_TIME_BIT;
|
int nextbit = timer->TC_CV + TAG_TIME_BIT;
|
||||||
int bit = response & 1;
|
int bit = response & 1;
|
||||||
response = response >> 1;
|
response = response >> 1;
|
||||||
if(bit) {
|
if(bit)
|
||||||
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
||||||
} else {
|
else
|
||||||
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
||||||
}
|
|
||||||
while(timer->TC_CV < nextbit) ;
|
while(timer->TC_CV < nextbit) ;
|
||||||
}
|
}
|
||||||
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
||||||
|
@ -171,11 +172,11 @@ static void frame_send_rwd(uint32_t data, int bits)
|
||||||
int bit = data & 1;
|
int bit = data & 1;
|
||||||
data = data >> 1;
|
data = data >> 1;
|
||||||
|
|
||||||
if(bit ^ legic_prng_get_bit()) {
|
if(bit ^ legic_prng_get_bit())
|
||||||
bit_end = starttime + RWD_TIME_1;
|
bit_end = starttime + RWD_TIME_1;
|
||||||
} else {
|
else
|
||||||
bit_end = starttime + RWD_TIME_0;
|
bit_end = starttime + RWD_TIME_0;
|
||||||
}
|
|
||||||
|
|
||||||
/* RWD_TIME_PAUSE time off, then some time on, so that the complete bit time is
|
/* RWD_TIME_PAUSE time off, then some time on, so that the complete bit time is
|
||||||
* RWD_TIME_x, where x is the bit to be transmitted */
|
* RWD_TIME_x, where x is the bit to be transmitted */
|
||||||
|
@ -184,16 +185,15 @@ static void frame_send_rwd(uint32_t data, int bits)
|
||||||
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
||||||
legic_prng_forward(1); /* bit duration is longest. use this time to forward the lfsr */
|
legic_prng_forward(1); /* bit duration is longest. use this time to forward the lfsr */
|
||||||
|
|
||||||
while(timer->TC_CV < bit_end) ;
|
while(timer->TC_CV < bit_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
/* One final pause to mark the end of the frame */
|
||||||
/* One final pause to mark the end of the frame */
|
int pause_end = timer->TC_CV + RWD_TIME_PAUSE;
|
||||||
int pause_end = timer->TC_CV + RWD_TIME_PAUSE;
|
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
||||||
AT91C_BASE_PIOA->PIO_CODR = GPIO_SSC_DOUT;
|
while(timer->TC_CV < pause_end) ;
|
||||||
while(timer->TC_CV < pause_end) ;
|
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
||||||
AT91C_BASE_PIOA->PIO_SODR = GPIO_SSC_DOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset the timer, to measure time until the start of the tag frame */
|
/* Reset the timer, to measure time until the start of the tag frame */
|
||||||
timer->TC_CCR = AT91C_TC_SWTRG;
|
timer->TC_CCR = AT91C_TC_SWTRG;
|
||||||
|
@ -239,8 +239,7 @@ static void frame_receive_rwd(struct legic_frame * const f, int bits, int crypt)
|
||||||
* since we cannot compute it on the fly while reading */
|
* since we cannot compute it on the fly while reading */
|
||||||
legic_prng_forward(2);
|
legic_prng_forward(2);
|
||||||
|
|
||||||
if(crypt)
|
if(crypt) {
|
||||||
{
|
|
||||||
for(i=0; i<bits; i++) {
|
for(i=0; i<bits; i++) {
|
||||||
data |= legic_prng_get_bit() << i;
|
data |= legic_prng_get_bit() << i;
|
||||||
legic_prng_forward(1);
|
legic_prng_forward(1);
|
||||||
|
@ -277,9 +276,9 @@ static void frame_receive_rwd(struct legic_frame * const f, int bits, int crypt)
|
||||||
|
|
||||||
static void frame_append_bit(struct legic_frame * const f, int bit)
|
static void frame_append_bit(struct legic_frame * const f, int bit)
|
||||||
{
|
{
|
||||||
if(f->bits >= 31) {
|
if(f->bits >= 31)
|
||||||
return; /* Overflow, won't happen */
|
return; /* Overflow, won't happen */
|
||||||
}
|
|
||||||
f->data |= (bit<<f->bits);
|
f->data |= (bit<<f->bits);
|
||||||
f->bits++;
|
f->bits++;
|
||||||
}
|
}
|
||||||
|
@ -448,12 +447,11 @@ int LegicRfReader(int offset, int bytes) {
|
||||||
Dbprintf("Unknown card format: %x",tag_type);
|
Dbprintf("Unknown card format: %x",tag_type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(bytes == -1) {
|
if(bytes == -1)
|
||||||
bytes = card_sz;
|
bytes = card_sz;
|
||||||
}
|
|
||||||
if(bytes+offset >= card_sz) {
|
if(bytes+offset >= card_sz)
|
||||||
bytes = card_sz-offset;
|
bytes = card_sz-offset;
|
||||||
}
|
|
||||||
|
|
||||||
perform_setup_phase_rwd(SESSION_IV);
|
perform_setup_phase_rwd(SESSION_IV);
|
||||||
|
|
||||||
|
|
|
@ -1304,6 +1304,9 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
|
||||||
// load chip config block
|
// load chip config block
|
||||||
data[0] = T55x7_BITRATE_RF_50 | T55x7_MODULATION_FSK2a | last_block << T55x7_MAXBLOCK_SHIFT;
|
data[0] = T55x7_BITRATE_RF_50 | T55x7_MODULATION_FSK2a | last_block << T55x7_MAXBLOCK_SHIFT;
|
||||||
|
|
||||||
|
//TODO add selection of chip for Q5 or T55x7
|
||||||
|
// data[0] = (((50-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | last_block << T5555_MAXBLOCK_SHIFT;
|
||||||
|
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
// Program the data blocks for supplied ID
|
// Program the data blocks for supplied ID
|
||||||
// and the block 0 for HID format
|
// and the block 0 for HID format
|
||||||
|
@ -1316,6 +1319,8 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
|
||||||
|
|
||||||
void CopyIOtoT55x7(uint32_t hi, uint32_t lo) {
|
void CopyIOtoT55x7(uint32_t hi, uint32_t lo) {
|
||||||
uint32_t data[] = {T55x7_BITRATE_RF_64 | T55x7_MODULATION_FSK2a | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
|
uint32_t data[] = {T55x7_BITRATE_RF_64 | T55x7_MODULATION_FSK2a | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
|
||||||
|
//TODO add selection of chip for Q5 or T55x7
|
||||||
|
// data[0] = (((64-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT;
|
||||||
|
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
// Program the data blocks for supplied ID
|
// Program the data blocks for supplied ID
|
||||||
|
@ -1332,6 +1337,9 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) {
|
||||||
//Program the 2 data blocks for supplied 64bit UID
|
//Program the 2 data blocks for supplied 64bit UID
|
||||||
// and the Config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2)
|
// and the Config for Indala 64 format (RF/32;PSK1 with RF/2;Maxblock=2)
|
||||||
uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
|
uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
|
||||||
|
//TODO add selection of chip for Q5 or T55x7
|
||||||
|
// data[0] = (((32-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_PSK1 | 2 << T5555_MAXBLOCK_SHIFT;
|
||||||
|
|
||||||
WriteT55xx(data, 0, 3);
|
WriteT55xx(data, 0, 3);
|
||||||
//Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=2;Inverse data)
|
//Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=2;Inverse data)
|
||||||
// T5567WriteBlock(0x603E1042,0);
|
// T5567WriteBlock(0x603E1042,0);
|
||||||
|
@ -1344,6 +1352,8 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t
|
||||||
// and the block 0 for Indala224 format
|
// and the block 0 for Indala224 format
|
||||||
//Config for Indala (RF/32;PSK1 with RF/2;Maxblock=7)
|
//Config for Indala (RF/32;PSK1 with RF/2;Maxblock=7)
|
||||||
data[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (7 << T55x7_MAXBLOCK_SHIFT);
|
data[0] = T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK1 | (7 << T55x7_MAXBLOCK_SHIFT);
|
||||||
|
//TODO add selection of chip for Q5 or T55x7
|
||||||
|
// data[0] = (((32-2)/2)<<T5555_BITRATE_SHIFT) | T5555_MODULATION_PSK1 | 7 << T5555_MAXBLOCK_SHIFT;
|
||||||
WriteT55xx(data, 0, 8);
|
WriteT55xx(data, 0, 8);
|
||||||
//Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=7;Inverse data)
|
//Alternative config for Indala (Extended mode;RF/32;PSK1 with RF/2;Maxblock=7;Inverse data)
|
||||||
// T5567WriteBlock(0x603E10E2,0);
|
// T5567WriteBlock(0x603E10E2,0);
|
||||||
|
@ -1415,19 +1425,20 @@ void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
|
||||||
|
|
||||||
// Write EM410x ID
|
// Write EM410x ID
|
||||||
uint32_t data[] = {0, id>>32, id & 0xFFFFFFFF};
|
uint32_t data[] = {0, id>>32, id & 0xFFFFFFFF};
|
||||||
if (card) {
|
|
||||||
clock = (card & 0xFF00) >> 8;
|
clock = (card & 0xFF00) >> 8;
|
||||||
clock = (clock == 0) ? 64 : clock;
|
clock = (clock == 0) ? 64 : clock;
|
||||||
Dbprintf("Clock rate: %d", clock);
|
Dbprintf("Clock rate: %d", clock);
|
||||||
|
if (card & 0xFF) { //t55x7
|
||||||
clock = GetT55xxClockBit(clock);
|
clock = GetT55xxClockBit(clock);
|
||||||
if (clock == 0) {
|
if (clock == 0) {
|
||||||
Dbprintf("Invalid clock rate: %d", clock);
|
Dbprintf("Invalid clock rate: %d", clock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT);
|
data[0] = clock | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT);
|
||||||
} else {
|
} else { //t5555 (Q5)
|
||||||
data[0] = (0x1F << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT);
|
clock = (clock-2)>>1; //n = (RF-2)/2
|
||||||
|
data[0] = (clock << T5555_BITRATE_SHIFT) | T5555_MODULATION_MANCHESTER | (2 << T5555_MAXBLOCK_SHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteT55xx(data, 0, 3);
|
WriteT55xx(data, 0, 3);
|
||||||
|
|
|
@ -141,7 +141,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
|
||||||
uint32_t sample_total_numbers =0 ;
|
uint32_t sample_total_numbers =0 ;
|
||||||
uint32_t sample_total_saved =0 ;
|
uint32_t sample_total_saved =0 ;
|
||||||
|
|
||||||
while(!BUTTON_PRESS()) {
|
while(!BUTTON_PRESS() && !usb_poll_validate_length() ) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
AT91C_BASE_SSC->SSC_THR = 0x43;
|
||||||
|
@ -269,7 +269,7 @@ void doT55x7Acquisition(size_t sample_size) {
|
||||||
uint8_t curSample = 0;
|
uint8_t curSample = 0;
|
||||||
uint8_t firstSample = 0;
|
uint8_t firstSample = 0;
|
||||||
uint16_t skipCnt = 0;
|
uint16_t skipCnt = 0;
|
||||||
while(!BUTTON_PRESS() && skipCnt<1000) {
|
while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt<1000) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
|
||||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
AT91C_BASE_SSC->SSC_THR = 0x43;
|
||||||
|
|
|
@ -1220,10 +1220,6 @@ int CmdFSKdemodIO(const char *Cmd)
|
||||||
//print full AWID Prox ID and some bit format details if found
|
//print full AWID Prox ID and some bit format details if found
|
||||||
int CmdFSKdemodAWID(const char *Cmd)
|
int CmdFSKdemodAWID(const char *Cmd)
|
||||||
{
|
{
|
||||||
|
|
||||||
//int verbose=1;
|
|
||||||
//sscanf(Cmd, "%i", &verbose);
|
|
||||||
|
|
||||||
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
||||||
size_t size = getFromGraphBuf(BitStream);
|
size_t size = getFromGraphBuf(BitStream);
|
||||||
|
@ -1254,7 +1250,7 @@ int CmdFSKdemodAWID(const char *Cmd)
|
||||||
// | | | | | | |
|
// | | | | | | |
|
||||||
// 01234567 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 - to 96
|
// 01234567 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 456 7 890 1 234 5 678 9 012 3 - to 96
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// 00000001 000 1 110 1 101 1 011 1 101 1 010 0 000 1 000 1 010 0 001 0 110 1 100 0 000 1 000 1
|
// 00000001 000 1 110 1 101 1 011 1 1 d01 1 010 0 000 1 000 1 010 0 001 0 110 1 100 0 000 1 000 1
|
||||||
// premable bbb o bbb o bbw o fff o fff o ffc o ccc o ccc o ccc o ccc o ccc o wxx o xxx o xxx o - to 96
|
// premable bbb o bbb o bbw o fff o fff o ffc o ccc o ccc o ccc o ccc o ccc o wxx o xxx o xxx o - to 96
|
||||||
// |---26 bit---| |-----117----||-------------142-------------|
|
// |---26 bit---| |-----117----||-------------142-------------|
|
||||||
// b = format bit len, o = odd parity of last 3 bits
|
// b = format bit len, o = odd parity of last 3 bits
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue