mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 23:36:31 +08:00
Syntax suger, making the code easier to read (for me at least)
This commit is contained in:
parent
ab7bb49475
commit
614da335f6
|
@ -351,7 +351,6 @@ void SendStatus(void)
|
||||||
#if defined(WITH_ISO14443a_StandAlone) || defined(WITH_LF)
|
#if defined(WITH_ISO14443a_StandAlone) || defined(WITH_LF)
|
||||||
|
|
||||||
#define OPTS 2
|
#define OPTS 2
|
||||||
|
|
||||||
void StandAloneMode()
|
void StandAloneMode()
|
||||||
{
|
{
|
||||||
DbpString("Stand-alone mode! No PC necessary.");
|
DbpString("Stand-alone mode! No PC necessary.");
|
||||||
|
@ -365,13 +364,9 @@ void StandAloneMode()
|
||||||
LED(LED_GREEN, 200);
|
LED(LED_GREEN, 200);
|
||||||
LED(LED_ORANGE, 200);
|
LED(LED_ORANGE, 200);
|
||||||
LED(LED_RED, 200);
|
LED(LED_RED, 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WITH_ISO14443a_StandAlone
|
#ifdef WITH_ISO14443a_StandAlone
|
||||||
void StandAloneMode14a()
|
void StandAloneMode14a()
|
||||||
{
|
{
|
||||||
|
@ -640,8 +635,7 @@ void SamyRun()
|
||||||
// Turn on selected LED
|
// Turn on selected LED
|
||||||
LED(selected + 1, 0);
|
LED(selected + 1, 0);
|
||||||
|
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
usb_poll();
|
usb_poll();
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
|
||||||
|
@ -669,6 +663,32 @@ void SamyRun()
|
||||||
CmdHIDdemodFSK(1, &high[selected], &low[selected], 0);
|
CmdHIDdemodFSK(1, &high[selected], &low[selected], 0);
|
||||||
Dbprintf("Recorded %x %x %x", selected, high[selected], low[selected]);
|
Dbprintf("Recorded %x %x %x", selected, high[selected], low[selected]);
|
||||||
|
|
||||||
|
LEDsoff();
|
||||||
|
LED(selected + 1, 0);
|
||||||
|
// Finished recording
|
||||||
|
// If we were previously playing, set playing off
|
||||||
|
// so next button push begins playing what we recorded
|
||||||
|
playing = 0;
|
||||||
|
cardRead = 1;
|
||||||
|
}
|
||||||
|
else if (button_pressed > 0 && cardRead == 1) {
|
||||||
|
LEDsoff();
|
||||||
|
LED(selected + 1, 0);
|
||||||
|
LED(LED_ORANGE, 0);
|
||||||
|
|
||||||
|
// record
|
||||||
|
Dbprintf("Cloning %x %x %x", selected, high[selected], low[selected]);
|
||||||
|
|
||||||
|
// wait for button to be released
|
||||||
|
while(BUTTON_PRESS())
|
||||||
|
WDT_HIT();
|
||||||
|
|
||||||
|
/* need this delay to prevent catching some weird data */
|
||||||
|
SpinDelay(500);
|
||||||
|
|
||||||
|
CopyHIDtoT55x7(high[selected], low[selected], 0, 0);
|
||||||
|
Dbprintf("Cloned %x %x %x", selected, high[selected], low[selected]);
|
||||||
|
|
||||||
LEDsoff();
|
LEDsoff();
|
||||||
LED(selected + 1, 0);
|
LED(selected + 1, 0);
|
||||||
// Finished recording
|
// Finished recording
|
||||||
|
@ -676,45 +696,11 @@ void SamyRun()
|
||||||
// If we were previously playing, set playing off
|
// If we were previously playing, set playing off
|
||||||
// so next button push begins playing what we recorded
|
// so next button push begins playing what we recorded
|
||||||
playing = 0;
|
playing = 0;
|
||||||
|
cardRead = 0;
|
||||||
cardRead = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (button_pressed > 0 && cardRead == 1)
|
|
||||||
{
|
|
||||||
LEDsoff();
|
|
||||||
LED(selected + 1, 0);
|
|
||||||
LED(LED_ORANGE, 0);
|
|
||||||
|
|
||||||
// record
|
|
||||||
Dbprintf("Cloning %x %x %x", selected, high[selected], low[selected]);
|
|
||||||
|
|
||||||
// wait for button to be released
|
|
||||||
while(BUTTON_PRESS())
|
|
||||||
WDT_HIT();
|
|
||||||
|
|
||||||
/* need this delay to prevent catching some weird data */
|
|
||||||
SpinDelay(500);
|
|
||||||
|
|
||||||
CopyHIDtoT55x7(high[selected], low[selected], 0, 0);
|
|
||||||
Dbprintf("Cloned %x %x %x", selected, high[selected], low[selected]);
|
|
||||||
|
|
||||||
LEDsoff();
|
|
||||||
LED(selected + 1, 0);
|
|
||||||
// Finished recording
|
|
||||||
|
|
||||||
// If we were previously playing, set playing off
|
|
||||||
// so next button push begins playing what we recorded
|
|
||||||
playing = 0;
|
|
||||||
|
|
||||||
cardRead = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change where to record (or begin playing)
|
// Change where to record (or begin playing)
|
||||||
else if (button_pressed)
|
else if (button_pressed) {
|
||||||
{
|
|
||||||
// Next option if we were previously playing
|
// Next option if we were previously playing
|
||||||
if (playing)
|
if (playing)
|
||||||
selected = (selected + 1) % OPTS;
|
selected = (selected + 1) % OPTS;
|
||||||
|
|
|
@ -744,7 +744,7 @@ void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
|
||||||
(unsigned int) lo,
|
(unsigned int) lo,
|
||||||
(unsigned int) (lo>>1) & 0xFFFF
|
(unsigned int) (lo>>1) & 0xFFFF
|
||||||
);
|
);
|
||||||
}else { //standard HID tags 44/96 bits
|
} else { //standard HID tags 44/96 bits
|
||||||
uint8_t bitlen = 0;
|
uint8_t bitlen = 0;
|
||||||
uint32_t fc = 0;
|
uint32_t fc = 0;
|
||||||
uint32_t cardnum = 0;
|
uint32_t cardnum = 0;
|
||||||
|
@ -1260,7 +1260,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
|
||||||
|
|
||||||
if (longFMT){
|
if (longFMT){
|
||||||
// Ensure no more than 84 bits supplied
|
// Ensure no more than 84 bits supplied
|
||||||
if (hi2>0xFFFFF) {
|
if (hi2 > 0xFFFFF) {
|
||||||
DbpString("Tags can only have 84 bits.");
|
DbpString("Tags can only have 84 bits.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1276,7 +1276,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
|
||||||
data[6] = manchesterEncode2Bytes(lo & 0xFFFF);
|
data[6] = manchesterEncode2Bytes(lo & 0xFFFF);
|
||||||
} else {
|
} else {
|
||||||
// Ensure no more than 44 bits supplied
|
// Ensure no more than 44 bits supplied
|
||||||
if (hi>0xFFF) {
|
if (hi > 0xFFF) {
|
||||||
DbpString("Tags can only have 44 bits.");
|
DbpString("Tags can only have 44 bits.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,10 +386,9 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void SendCmdPCF7931(uint32_t * tab){
|
void SendCmdPCF7931(uint32_t * tab){
|
||||||
uint16_t u=0;
|
uint16_t u=0, tempo=0;
|
||||||
uint16_t tempo=0;
|
|
||||||
|
|
||||||
Dbprintf("SENDING DATA FRAME...");
|
Dbprintf("Sending data frame...");
|
||||||
|
|
||||||
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
||||||
|
|
||||||
|
@ -413,27 +412,19 @@ void SendCmdPCF7931(uint32_t * tab){
|
||||||
|
|
||||||
|
|
||||||
tempo = AT91C_BASE_TC0->TC_CV;
|
tempo = AT91C_BASE_TC0->TC_CV;
|
||||||
for(u=0;tab[u]!= 0;u+=3){
|
for( u = 0; tab[u] != 0; u += 3){
|
||||||
|
|
||||||
|
|
||||||
// modulate antenna
|
// modulate antenna
|
||||||
HIGH(GPIO_SSC_DOUT);
|
HIGH(GPIO_SSC_DOUT);
|
||||||
while(tempo != tab[u]){
|
while(tempo != tab[u]) tempo = AT91C_BASE_TC0->TC_CV;
|
||||||
tempo = AT91C_BASE_TC0->TC_CV;
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop modulating antenna
|
// stop modulating antenna
|
||||||
LOW(GPIO_SSC_DOUT);
|
LOW(GPIO_SSC_DOUT);
|
||||||
while(tempo != tab[u+1]){
|
while(tempo != tab[u+1]) tempo = AT91C_BASE_TC0->TC_CV;
|
||||||
tempo = AT91C_BASE_TC0->TC_CV;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// modulate antenna
|
// modulate antenna
|
||||||
HIGH(GPIO_SSC_DOUT);
|
HIGH(GPIO_SSC_DOUT);
|
||||||
while(tempo != tab[u+2]){
|
while(tempo != tab[u+2]) tempo = AT91C_BASE_TC0->TC_CV;
|
||||||
tempo = AT91C_BASE_TC0->TC_CV;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LED_A_OFF();
|
LED_A_OFF();
|
||||||
|
@ -455,7 +446,7 @@ void SendCmdPCF7931(uint32_t * tab){
|
||||||
bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p){
|
bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p){
|
||||||
|
|
||||||
uint32_t u;
|
uint32_t u;
|
||||||
for (u=0; u<8; u++)
|
for ( u=0; u<8; u++)
|
||||||
{
|
{
|
||||||
if (byte&(1<<u)) { //bit à 1
|
if (byte&(1<<u)) { //bit à 1
|
||||||
if( AddBitPCF7931(1, tab, l, p)==1) return 1;
|
if( AddBitPCF7931(1, tab, l, p)==1) return 1;
|
||||||
|
@ -463,7 +454,6 @@ bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p){
|
||||||
if (AddBitPCF7931(0, tab, l, p)==1) return 1;
|
if (AddBitPCF7931(0, tab, l, p)==1) return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,16 +475,18 @@ bool AddBitPCF7931(bool b, uint32_t * tab, int32_t l, int32_t p){
|
||||||
else
|
else
|
||||||
tab[u] = 34 * T0_PCF + tab[u-1] + p;
|
tab[u] = 34 * T0_PCF + tab[u-1] + p;
|
||||||
|
|
||||||
tab[u+1] = 6 * T0_PCF + tab[u] + l;
|
tab[u+1] = 6 * T0_PCF + tab[u] + l;
|
||||||
tab[u+2] = 88 * T0_PCF + tab[u+1] - l - p;
|
tab[u+2] = 88 * T0_PCF + tab[u+1] - l - p;
|
||||||
return 0;
|
return 0;
|
||||||
} else { //add a bit 0
|
} else { //add a bit 0
|
||||||
|
|
||||||
if(u==0) tab[u] = 98*T0_PCF+p;
|
if ( u == 0 )
|
||||||
else tab[u] = 98*T0_PCF+tab[u-1]+p;
|
tab[u] = 98 * T0_PCF + p;
|
||||||
|
else
|
||||||
|
tab[u] = 98 * T0_PCF + tab[u-1] + p;
|
||||||
|
|
||||||
tab[u+1] = 6*T0_PCF+tab[u]+l;
|
tab[u+1] = 6 * T0_PCF + tab[u] + l;
|
||||||
tab[u+2] = 24*T0_PCF+tab[u+1]-l-p;
|
tab[u+2] = 24 * T0_PCF + tab[u+1] - l - p;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,13 +502,11 @@ bool AddBitPCF7931(bool b, uint32_t * tab, int32_t l, int32_t p){
|
||||||
*/
|
*/
|
||||||
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t * tab){
|
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t * tab){
|
||||||
uint32_t u = 0;
|
uint32_t u = 0;
|
||||||
for(u=0;tab[u]!=0;u+=3){} //we put the cursor at the last value of the array
|
for(u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array
|
||||||
|
|
||||||
if(u==0) tab[u] = a;
|
tab[u] = (u == 0) ? a : a + tab[u-1];
|
||||||
else tab[u] = a + tab[u-1];
|
tab[u+1] = b + tab[u];
|
||||||
|
tab[u+2] = c + tab[u+1];
|
||||||
tab[u+1] = b+tab[u];
|
|
||||||
tab[u+2] = c+tab[u+1];
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue