FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
int selected = 0;
- int playing = 0, iGotoRecord = 0, iGotoClone = 0;
- int cardRead[OPTS] = {0};
+ bool playing = false, GotoRecord = false, GotoClone = false;
+ bool cardRead[OPTS] = {false};
uint8_t readUID[10] = {0};
uint32_t uid_1st[OPTS]={0};
uint32_t uid_2nd[OPTS]={0};
WDT_HIT();
SpinDelay(300);
- if (iGotoRecord == 1 || cardRead[selected] == 0)
+ if (GotoRecord || !cardRead[selected])
{
- iGotoRecord = 0;
+ GotoRecord = false;
LEDsoff();
LED(selected + 1, 0);
LED(LED_RED2, 0);
else if (cardRead[(selected+1)%OPTS]) {
Dbprintf("Button press detected but no card in bank[%d] so playing from bank[%d]", selected, (selected+1)%OPTS);
selected = (selected+1)%OPTS;
- break; // playing = 1;
+ break;
}
else {
Dbprintf("Button press detected but no stored tag to play. (Ignoring button)");
LED(selected + 1, 0);
// Next state is replay:
- playing = 1;
+ playing = true;
- cardRead[selected] = 1;
+ cardRead[selected] = true;
}
/* MF Classic UID clone */
- else if (iGotoClone==1)
+ else if (GotoClone)
{
- iGotoClone=0;
+ GotoClone=false;
LEDsoff();
LED(selected + 1, 0);
LED(LED_ORANGE, 250);
MifareCGetBlock(0x3F, 1, 0, oldBlock0);
if (oldBlock0[0] == 0 && oldBlock0[0] == oldBlock0[1] && oldBlock0[1] == oldBlock0[2] && oldBlock0[2] == oldBlock0[3]) {
Dbprintf("No changeable tag detected. Returning to replay mode for bank[%d]", selected);
- playing = 1;
+ playing = true;
}
else {
Dbprintf("UID from target tag: %02X%02X%02X%02X", oldBlock0[0],oldBlock0[1],oldBlock0[2],oldBlock0[3]);
if (memcmp(testBlock0,newBlock0,16)==0)
{
DbpString("Cloned successfull!");
- cardRead[selected] = 0; // Only if the card was cloned successfully should we clear it
- playing = 0;
- iGotoRecord = 1;
+ cardRead[selected] = false; // Only if the card was cloned successfully should we clear it
+ playing = false;
+ GotoRecord = true;
selected = (selected+1) % OPTS;
}
else {
Dbprintf("Clone failed. Back to replay mode on bank[%d]", selected);
- playing = 1;
+ playing = true;
}
}
LEDsoff();
}
// Change where to record (or begin playing)
- else if (playing==1) // button_pressed == BUTTON_SINGLE_CLICK && cardRead[selected])
+ else if (playing) // button_pressed == BUTTON_SINGLE_CLICK && cardRead[selected])
{
LEDsoff();
LED(selected + 1, 0);
// Begin transmitting
- if (playing)
- {
- LED(LED_GREEN, 0);
- DbpString("Playing");
- for ( ; ; ) {
- WDT_HIT();
- int button_action = BUTTON_HELD(1000);
- if (button_action == 0) { // No button action, proceed with sim
- uint8_t data[512] = {0}; // in case there is a read command received we shouldn't break
- Dbprintf("Simulating ISO14443a tag with uid[0]: %08x, uid[1]: %08x [Bank: %u]", uid_1st[selected],uid_2nd[selected],selected);
- if (hi14a_card[selected].sak == 8 && hi14a_card[selected].atqa[0] == 4 && hi14a_card[selected].atqa[1] == 0) {
- DbpString("Mifare Classic");
- SimulateIso14443aTag(1,uid_1st[selected], uid_2nd[selected], data); // Mifare Classic
- }
- else if (hi14a_card[selected].sak == 0 && hi14a_card[selected].atqa[0] == 0x44 && hi14a_card[selected].atqa[1] == 0) {
- DbpString("Mifare Ultralight");
- SimulateIso14443aTag(2,uid_1st[selected],uid_2nd[selected],data); // Mifare Ultralight
- }
- else if (hi14a_card[selected].sak == 20 && hi14a_card[selected].atqa[0] == 0x44 && hi14a_card[selected].atqa[1] == 3) {
- DbpString("Mifare DESFire");
- SimulateIso14443aTag(3,uid_1st[selected],uid_2nd[selected],data); // Mifare DESFire
- }
- else {
- Dbprintf("Unrecognized tag type -- defaulting to Mifare Classic emulation");
- SimulateIso14443aTag(1,uid_1st[selected], uid_2nd[selected], data);
- }
+ LED(LED_GREEN, 0);
+ DbpString("Playing");
+ for ( ; ; ) {
+ WDT_HIT();
+ int button_action = BUTTON_HELD(1000);
+ if (button_action == 0) { // No button action, proceed with sim
+ uint8_t data[512] = {0}; // in case there is a read command received we shouldn't break
+ Dbprintf("Simulating ISO14443a tag with uid[0]: %08x, uid[1]: %08x [Bank: %u]", uid_1st[selected],uid_2nd[selected],selected);
+ if (hi14a_card[selected].sak == 8 && hi14a_card[selected].atqa[0] == 4 && hi14a_card[selected].atqa[1] == 0) {
+ DbpString("Mifare Classic");
+ SimulateIso14443aTag(1,uid_1st[selected], uid_2nd[selected], data); // Mifare Classic
}
- else if (button_action == BUTTON_SINGLE_CLICK) {
- selected = (selected + 1) % OPTS;
- Dbprintf("Done playing. Switching to record mode on bank %d",selected);
- iGotoRecord = 1;
- break;
+ else if (hi14a_card[selected].sak == 0 && hi14a_card[selected].atqa[0] == 0x44 && hi14a_card[selected].atqa[1] == 0) {
+ DbpString("Mifare Ultralight");
+ SimulateIso14443aTag(2,uid_1st[selected],uid_2nd[selected],data); // Mifare Ultralight
}
- else if (button_action == BUTTON_HOLD) {
- Dbprintf("Playtime over. Begin cloning...");
- iGotoClone = 1;
- break;
+ else if (hi14a_card[selected].sak == 20 && hi14a_card[selected].atqa[0] == 0x44 && hi14a_card[selected].atqa[1] == 3) {
+ DbpString("Mifare DESFire");
+ SimulateIso14443aTag(3,uid_1st[selected],uid_2nd[selected],data); // Mifare DESFire
+ }
+ else {
+ Dbprintf("Unrecognized tag type -- defaulting to Mifare Classic emulation");
+ SimulateIso14443aTag(1,uid_1st[selected], uid_2nd[selected], data);
}
- WDT_HIT();
}
-
- /* We pressed a button so ignore it here with a delay */
- SpinDelay(300);
- LEDsoff();
- LED(selected + 1, 0);
+ else if (button_action == BUTTON_SINGLE_CLICK) {
+ selected = (selected + 1) % OPTS;
+ Dbprintf("Done playing. Switching to record mode on bank %d",selected);
+ GotoRecord = true;
+ break;
+ }
+ else if (button_action == BUTTON_HOLD) {
+ Dbprintf("Playtime over. Begin cloning...");
+ GotoClone = true;
+ break;
+ }
+ WDT_HIT();
}
- else
- while(BUTTON_PRESS())
- WDT_HIT();
+
+ /* We pressed a button so ignore it here with a delay */
+ SpinDelay(300);
+ LEDsoff();
+ LED(selected + 1, 0);
}
}
}
int lastbit;
bool bSkip;
int tag_sof;
- byte_t rx[HITAG_FRAME_LEN];
+ byte_t rx[HITAG_FRAME_LEN] = {0};
size_t rxlen=0;
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
auth_table_len = 0;
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
auth_table_len = 0;
bSuccessful = false;
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
//DbpString("Starting Hitag reader family");
bSuccessful = false;
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
//DbpString("Starting Hitag reader family");
;
LOW(GPIO_SSC_DOUT);
while (AT91C_BASE_TC0->TC_CV < T0 * 32)
- ;;
+ ;
}
LED_A_OFF();
break;
int i, j;
byte_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
-//bool bQuitTraceFull = false;
bQuiet = false;
byte_t txbuf[HITAG_FRAME_LEN];
byte_t* tx = txbuf;
BigBuf_free();
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
DbpString("Starting HitagS simulation");
bSuccessful = false;
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
bQuiet = false;
tag.tstate = NO_OP;
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
bQuiet = false;
bSuccessful = false;
// Clean up trace and prepare it for storing frames
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
bQuiet = false;
if(!Uart.bitBuffer) {
Uart.bitBuffer = bit ^ 0xFF0;
- return FALSE;
+ return false;
}
else {
Uart.bitBuffer <<= 4;
Uart.output[Uart.byteCnt] = Uart.bitBuffer & 0xFF;
Uart.byteCnt++;
Uart.swapper = 0;
- if(Uart.byteCnt > 15) { return TRUE; }
+ if(Uart.byteCnt > 15) { return true; }
}
else {
Uart.swapper = 1;
Uart.highCnt = 0;
if(Uart.byteCnt == 0) {
// Its not straightforward to show single EOFs
- // So just leave it and do not return TRUE
+ // So just leave it and do not return true
Uart.output[0] = 0xf0;
Uart.byteCnt++;
}
else {
- return TRUE;
+ return true;
}
}
else if(Uart.state != STATE_START_OF_COMMUNICATION) {
Uart.byteCnt++;
Uart.output[Uart.byteCnt] = 0xAA;
Uart.byteCnt++;
- return TRUE;
+ return true;
}*/
}
}
}
- return FALSE;
+ return false;
}
//=============================================================================
if(Demod.buff < 3) {
Demod.buff++;
- return FALSE;
+ return false;
}
if(Demod.state==DEMOD_UNSYNCD) {
Demod.len++;
Demod.state = DEMOD_UNSYNCD;
// error = 0x0f;
- return TRUE;
+ return true;
}
else {
Demod.state = DEMOD_ERROR_WAIT;
}
Demod.state = DEMOD_UNSYNCD;
- return TRUE;
+ return true;
}
else {
Demod.output[Demod.len] = 0xad;
Demod.len++;
Demod.output[Demod.len] = 0xBB;
Demod.len++;
- return TRUE;
+ return true;
}
}
} // end (state != UNSYNCED)
- return FALSE;
+ return false;
}
//=============================================================================
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
// response from the tag.
- //int triggered = FALSE; // FALSE to wait first for card
+ //int triggered = false; // false to wait first for card
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// The DMA buffer, used to stream samples from the FPGA
uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE);
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
- iso14a_set_trigger(FALSE);
+ iso14a_set_trigger(false);
int lastRxCounter;
uint8_t *upTo;
time_stop = (GetCountSspClk()-time_0) << 4;
LED_C_ON();
- //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,TRUE)) break;
- //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, TRUE)) break;
+ //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,true)) break;
+ //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, true)) break;
if(tracing) {
uint8_t parity[MAX_PARITY_SIZE];
GetParity(Uart.output, Uart.byteCnt, parity);
- LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
+ LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, true);
}
if(tracing) {
uint8_t parity[MAX_PARITY_SIZE];
GetParity(Demod.output, Demod.len, parity);
- LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
+ LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, false);
}
// And ready to receive another response.
//-----------------------------------------------------------------------------
// Wait for commands from reader
// Stop when button is pressed
-// Or return TRUE when command is captured
+// Or return true when command is captured
//-----------------------------------------------------------------------------
static int GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen)
{
for(;;) {
WDT_HIT();
- if(BUTTON_PRESS()) return FALSE;
+ if(BUTTON_PRESS()) return false;
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x00;
if(OutOfNDecoding(b & 0x0f)) {
*len = Uart.byteCnt;
- return TRUE;
+ return true;
}
}
}
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// Enable and clear the trace
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
//Use the emulator memory for SIM
uint8_t *emulator = BigBuf_get_EM_addr();
if (tracing) {
uint8_t parity[MAX_PARITY_SIZE];
GetParity(receivedCmd, len, parity);
- LogTrace(receivedCmd,len, (r2t_time-time_0)<< 4, (r2t_time-time_0) << 4, parity, TRUE);
+ LogTrace(receivedCmd,len, (r2t_time-time_0)<< 4, (r2t_time-time_0) << 4, parity, true);
if (trace_data != NULL) {
GetParity(trace_data, trace_data_size, parity);
- LogTrace(trace_data, trace_data_size, (t2r_time-time_0) << 4, (t2r_time-time_0) << 4, parity, FALSE);
+ LogTrace(trace_data, trace_data_size, (t2r_time-time_0) << 4, (t2r_time-time_0) << 4, parity, false);
}
if(!tracing) {
DbpString("Trace full");
uint8_t sendbyte;
- bool firstpart = TRUE;
+ bool firstpart = true;
c = 0;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
if (tracing) {
uint8_t par[MAX_PARITY_SIZE];
GetParity(frame, len, par);
- LogTrace(frame, len, rsamples, rsamples, par, TRUE);
+ LogTrace(frame, len, rsamples, rsamples, par, true);
}
}
//-----------------------------------------------------------------------------
// Wait a certain time for tag response
-// If a response is captured return TRUE
-// If it takes too long return FALSE
+// If a response is captured return true
+// If it takes too long return false
//-----------------------------------------------------------------------------
static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) //uint8_t *buffer
{
uint8_t b;
if (elapsed) *elapsed = 0;
- bool skip = FALSE;
+ bool skip = false;
c = 0;
for(;;) {
WDT_HIT();
- if(BUTTON_PRESS()) return FALSE;
+ if(BUTTON_PRESS()) return false;
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x00; // To make use of exact timing of next command from reader!!
if (elapsed) (*elapsed)++;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- if(c < timeout) { c++; } else { return FALSE; }
+ if(c < timeout) { c++; } else { return false; }
b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
skip = !skip;
if(skip) continue;
if(ManchesterDecoding(b & 0x0f)) {
*samples = c << 3;
- return TRUE;
+ return true;
}
}
}
int ReaderReceiveIClass(uint8_t* receivedAnswer)
{
int samples = 0;
- if (!GetIClassAnswer(receivedAnswer,160,&samples,0)) return FALSE;
+ if (!GetIClassAnswer(receivedAnswer,160,&samples,0)) return false;
rsamples += samples;
if (tracing) {
uint8_t parity[MAX_PARITY_SIZE];
GetParity(receivedAnswer, Demod.len, parity);
- LogTrace(receivedAnswer,Demod.len,rsamples,rsamples,parity,FALSE);
+ LogTrace(receivedAnswer,Demod.len,rsamples,rsamples,parity,false);
}
- if(samples == 0) return FALSE;
+ if(samples == 0) return false;
return Demod.len;
}
{
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// Reset trace buffer
- set_tracing(TRUE);
+ set_tracing(true);
clear_trace();
// Setup SSC
uint8_t resp[ICLASS_BUFFER_SIZE];
setupIclassReader();
- set_tracing(TRUE);
+ set_tracing(true);
while(!BUTTON_PRESS()) {
LED_A_OFF(); // Finished receiving
Uart.state = STATE_UNSYNCD;
if (Uart.byteCnt != 0) {
- return TRUE;
+ return true;
}
} else {
// this is an error
break;
}
- return FALSE;
+ return false;
}
// Receive a command (from the reader to us, where we are the simulated tag),
// and store it in the given buffer, up to the given maximum length. Keeps
// spinning, waiting for a well-framed command, until either we get one
-// (returns TRUE) or someone presses the pushbutton on the board (FALSE).
+// (returns true) or someone presses the pushbutton on the board (false).
//
// Assume that we're called with the SSC (to the FPGA) and ADC path set
// correctly.
for(;;) {
WDT_HIT();
- if(BUTTON_PRESS()) return FALSE;
+ if(BUTTON_PRESS()) return false;
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
for(uint8_t mask = 0x80; mask != 0x00; mask >>= 1) {
if(Handle14443bUartBit(b & mask)) {
*len = Uart.byteCnt;
- return TRUE;
+ return true;
}
}
}
}
- return FALSE;
+ return false;
}
//-----------------------------------------------------------------------------
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
clear_trace();
- set_tracing(TRUE);
+ set_tracing(true);
const uint8_t *resp;
uint8_t *respCode;
if (tracing) {
uint8_t parity[MAX_PARITY_SIZE];
- LogTrace(receivedCmd, len, 0, 0, parity, TRUE);
+ LogTrace(receivedCmd, len, 0, 0, parity, true);
}
// Good, look at the command now.
// trace the response:
if (tracing) {
uint8_t parity[MAX_PARITY_SIZE];
- LogTrace(resp, respLen, 0, 0, parity, FALSE);
+ LogTrace(resp, respLen, 0, 0, parity, false);
}
}
LED_C_OFF();
if(s == 0x000) {
// This is EOF (start, stop and all data bits == '0'
- return TRUE;
+ return true;
}
}
}
break;
}
- return FALSE;
+ return false;
}
/*
* Demodulate the samples we received from the tag, also log to tracebuffer
- * quiet: set to 'TRUE' to disable debug output
+ * quiet: set to 'true' to disable debug output
*/
static void GetSamplesFor14443bDemod(int n, bool quiet)
{
int max = 0;
- bool gotFrame = FALSE;
+ bool gotFrame = false;
int lastRxCounter, ci, cq, samples = 0;
// Allocate memory from BigBuf for some buffers
samples += 2;
if(Handle14443bSamplesDemod(ci, cq)) {
- gotFrame = TRUE;
+ gotFrame = true;
break;
}
}
//Tracing
if (tracing && Demod.len > 0) {
uint8_t parity[MAX_PARITY_SIZE];
- LogTrace(Demod.output, Demod.len, 0, 0, parity, FALSE);
+ LogTrace(Demod.output, Demod.len, 0, 0, parity, false);
}
}
TransmitFor14443b();
if (tracing) {
uint8_t parity[MAX_PARITY_SIZE];
- LogTrace(cmd,len, 0, 0, parity, TRUE);
+ LogTrace(cmd,len, 0, 0, parity, true);
}
}
// send
CodeAndTransmit14443bAsReader(message_frame, message_length + 4);
// get response
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT*100, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT*100, true);
if(Demod.len < 3)
{
return 0;
// first, wake up the tag
CodeAndTransmit14443bAsReader(wupb, sizeof(wupb));
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
// ATQB too short?
if (Demod.len < 14)
{
attrib[7] = Demod.output[10] & 0x0F;
ComputeCrc14443(CRC_14443_B, attrib, 9, attrib + 9, attrib + 10);
CodeAndTransmit14443bAsReader(attrib, sizeof(attrib));
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
// Answer to ATTRIB too short?
if(Demod.len < 3)
{
SpinDelay(200);
clear_trace();
- set_tracing(TRUE);
+ set_tracing(true);
// First command: wake up the tag using the INITIATE command
uint8_t cmd1[] = {0x06, 0x00, 0x97, 0x5b};
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
if (Demod.len == 0) {
DbpString("No response from tag");
cmd1[1] = Demod.output[0];
ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
if (Demod.len != 3) {
Dbprintf("Expected 3 bytes from tag, got %d", Demod.len);
return;
cmd1[0] = 0x0B;
ComputeCrc14443(CRC_14443_B, cmd1, 1 , &cmd1[1], &cmd1[2]);
CodeAndTransmit14443bAsReader(cmd1, 3); // Only first three bytes for this one
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
if (Demod.len != 10) {
Dbprintf("Expected 10 bytes from tag, got %d", Demod.len);
return;
cmd1[1] = i;
ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);
CodeAndTransmit14443bAsReader(cmd1, sizeof(cmd1));
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
if (Demod.len != 6) { // Check if we got an answer from the tag
DbpString("Expected 6 bytes from tag, got less...");
return;
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
// response from the tag.
- int triggered = TRUE; // TODO: set and evaluate trigger condition
+ int triggered = true; // TODO: set and evaluate trigger condition
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
BigBuf_free();
clear_trace();
- set_tracing(TRUE);
+ set_tracing(true);
// The DMA buffer, used to stream samples from the FPGA
int8_t *dmaBuf = (int8_t*) BigBuf_malloc(ISO14443B_DMA_BUFFER_SIZE);
FpgaSetupSscDma((uint8_t*) dmaBuf, ISO14443B_DMA_BUFFER_SIZE);
uint8_t parity[MAX_PARITY_SIZE];
- bool TagIsActive = FALSE;
- bool ReaderIsActive = FALSE;
+ bool TagIsActive = false;
+ bool ReaderIsActive = false;
// And now we loop, receiving samples.
for(;;) {
if (!TagIsActive) { // no need to try decoding reader data if the tag is sending
if(Handle14443bUartBit(ci & 0x01)) {
if(triggered && tracing) {
- LogTrace(Uart.output, Uart.byteCnt, samples, samples, parity, TRUE);
+ LogTrace(Uart.output, Uart.byteCnt, samples, samples, parity, true);
}
/* And ready to receive another command. */
UartReset();
}
if(Handle14443bUartBit(cq & 0x01)) {
if(triggered && tracing) {
- LogTrace(Uart.output, Uart.byteCnt, samples, samples, parity, TRUE);
+ LogTrace(Uart.output, Uart.byteCnt, samples, samples, parity, true);
}
/* And ready to receive another command. */
UartReset();
if(tracing)
{
uint8_t parity[MAX_PARITY_SIZE];
- LogTrace(Demod.output, Demod.len, samples, samples, parity, FALSE);
+ LogTrace(Demod.output, Demod.len, samples, samples, parity, false);
}
- triggered = TRUE;
+ triggered = true;
// And ready to receive another response.
DemodReset();
FpgaSetupSsc();
if (datalen){
- set_tracing(TRUE);
+ set_tracing(true);
CodeAndTransmit14443bAsReader(data, datalen);
if(recv) {
- GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, TRUE);
+ GetSamplesFor14443bDemod(RECEIVE_SAMPLES_TIMEOUT, true);
uint16_t iLen = MIN(Demod.len, USB_CMD_DATA_SIZE);
cmd_send(CMD_ACK, iLen, 0, 0, Demod.output, iLen);
}
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
//spindelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
c = 0;
- getNext = FALSE;
+ getNext = false;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x43;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
//spindelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
c = 0;
- getNext = FALSE;
+ getNext = false;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x43;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
c = 0;
- getNext = FALSE;
+ getNext = false;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x43;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
c = 0;
- getNext = FALSE;
+ getNext = false;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
AT91C_BASE_SSC->SSC_THR = 0x43;
uint8_t wavesPerClock = clock/fc;
uint8_t mod = clock % fc; //modifier
uint8_t modAdj = fc/mod; //how often to apply modifier
- bool modAdjOk = !(fc % mod); //if (fc % mod==0) modAdjOk=TRUE;
+ bool modAdjOk = !(fc % mod); //if (fc % mod==0) modAdjOk=true;
// loop through clock - step field clock
for (uint8_t idx=0; idx < wavesPerClock; idx++){
// put 1/2 FC length 1's and 1/2 0's per field clock wave (to create the wave)
for (i=0; i<size; i++){
if (BitStream[i] == curPhase){
- pskSimBit(carrier, &n, clk, &curPhase, FALSE);
+ pskSimBit(carrier, &n, clk, &curPhase, false);
} else {
- pskSimBit(carrier, &n, clk, &curPhase, TRUE);
+ pskSimBit(carrier, &n, clk, &curPhase, true);
}
}
Dbprintf("Simulating with Carrier: %d, clk: %d, invert: %d, n: %d",carrier, clk, invert, n);
if (blockN >= 128 && blockN <= 256) {\r
return ((blockN & 0x0F) == 0x0F);\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){\r
sniffSAK = 0;
sniffUIDType = SNF_UID_4;
- return FALSE;
+ return false;
}
bool MfSniffEnd(void){
cmd_send(CMD_ACK,0,0,0,0,0);
LED_B_OFF();
- return FALSE;
+ return false;
}
bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, uint16_t bitCnt, bool reader) {
sniffBuf[11] = sniffSAK;
sniffBuf[12] = 0xFF;
sniffBuf[13] = 0xFF;
- LogTrace(sniffBuf, 14, 0, 0, NULL, TRUE);
+ LogTrace(sniffBuf, 14, 0, 0, NULL, true);
sniffState = SNF_CARD_CMD;
} // intentionally no break;
case SNF_CARD_CMD:{
}
- return FALSE;
+ return false;
}
bool RAMFUNC MfSniffSend(uint16_t maxTimeoutMs) {
if (BigBuf_get_traceLen() && (GetTickCount() > timerData + maxTimeoutMs)) {
return intMfSniffSend();
}
- return FALSE;
+ return false;
}
// internal sending function. not a RAMFUNC.
clear_trace();
- return TRUE;
+ return true;
}
padc = '0';
goto reswitch;
}
+ // intentionally fall through to next case
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
for (n = 0;; ++fmt) {
char param2 = '\0';
char param3 = '\0';
char type[40] = {0};
- char filename[FILE_PATH_SIZE];
+ char filename[FILE_PATH_SIZE] = {0};
uint8_t protocol = 0;
// parse command line
// try to see if card responses to "chinese magic backdoor" commands.
- mfCIdentify();
+ (void)mfCIdentify();
if (isMifareClassic) {
switch(DetectClassicPrng()) {
case 0:
- PrintAndLog("Prng detection: HARDEND (hardnested)");
+ PrintAndLog("Prng detection: HARDENED (hardnested)");
break;
case 1:
PrintAndLog("Prng detection: WEAK");
};
int CmdHF14A(const char *Cmd) {
- // flush
- WaitForResponseTimeout(CMD_ACK,NULL,100);
-
- // parse
- CmdsParse(CommandTable, Cmd);
- return 0;
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);
+ CmdsParse(CommandTable, Cmd);
+ return 0;
}
int CmdHelp(const char *Cmd)
int CmdHFEPA(const char *Cmd)
{
- // flush
- WaitForResponseTimeout(CMD_ACK,NULL,100);
-
- // parse
- CmdsParse(CommandTable, Cmd);
- return 0;
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);
+ CmdsParse(CommandTable, Cmd);
+ return 0;
}
uint32_t ar1 = crypto1_word(pcs, 0, 0) ^ ad->ar_enc;
uint32_t at1 = crypto1_word(pcs, 0, 0) ^ ad->at_enc;
- if (!(ar == ar1 && at == at1 && NTParityChk(ad, nt1)))
+ if (!(ar == ar1 && at == at1 && NTParityChk(ad, nt1))) {
+ crypto1_destroy(pcs);
return false;
+ }
memcpy(buf, cmd, cmdsize);
mf_crypto1_decrypt(pcs, buf, cmdsize, 0);
blockNo = i * 4;\r
keyType = j;\r
num_to_bytes(e_sector[i].Key[j], 6, key);\r
- \r
keyFound = true;\r
break;\r
}\r
// Can't found a key....\r
if (!keyFound) {\r
PrintAndLog("Can't found any of the known keys.");\r
+ free(e_sector);\r
return 4;\r
}\r
PrintAndLog("--auto key. block no:%3d, key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));\r
\r
// initialize storage for found keys\r
e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
- if (e_sector == NULL) return 1;\r
+ if (e_sector == NULL) {\r
+ free(keyBlock);\r
+ return 1;\r
+ }\r
for (uint8_t keyAB = 0; keyAB < 2; keyAB++) {\r
for (uint16_t sectorNo = 0; sectorNo < SectorsCnt; sectorNo++) {\r
e_sector[sectorNo].Key[keyAB] = 0xffffffffffff;\r
\r
int CmdHFMF(const char *Cmd)\r
{\r
- // flush\r
- WaitForResponseTimeout(CMD_ACK,NULL,100);\r
-\r
- CmdsParse(CommandTable, Cmd);\r
- return 0;\r
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);\r
+ CmdsParse(CommandTable, Cmd);\r
+ return 0;\r
}\r
\r
int CmdHelp(const char *Cmd)\r
if (bytesread != filesize) {
printf("File read error with %s. Aborting...\n", state_file_name);
fclose(statesfile);
- inflateEnd(&compressed_stream);
exit(5);
}
fclose(statesfile);
};
int CmdHFMFUltra(const char *Cmd){
- WaitForResponseTimeout(CMD_ACK,NULL,100);
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);
CmdsParse(CommandTable, Cmd);
return 0;
}
PrintAndLog("HR0 : %02x (%sa Topaz tag (%scapable of carrying a NDEF message), %s memory map)", rid_response[0],
(rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
(rid_response[0] & 0xF0) == 0x10 ? "" : "not ",
- (rid_response[0] & 0x0F) == 0x10 ? "static" : "dynamic");
+ (rid_response[0] & 0x0F) == 0x01 ? "static" : "dynamic");
PrintAndLog("HR1 : %02x", rid_response[1]);
status = topaz_rall(uid_echo, rall_response);
int CmdHFTopaz(const char *Cmd) {
- // flush
- WaitForResponseTimeout(CMD_ACK,NULL,100);
-
- // parse
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);
CmdsParse(CommandTable, Cmd);
return 0;
}
if (strlen(filename) > 0) {
if ((pf = fopen(filename,"wb")) == NULL) {
PrintAndLog("Error: Could not open file [%s]",filename);
+ free(got);
return 1;
}
}
return 1;
}
tag_mem_supplied = true;
- if (fread(c.d.asBytes,48,1,pf) == 0) {
- PrintAndLog("Error: File reading error");
- fclose(pf);
+ if (fread(c.d.asBytes,1,48,pf) != 48) {
+ PrintAndLog("Error: File reading error");
+ fclose(pf);
return 1;
- }
+ }
fclose(pf);
} else {
tag_mem_supplied = false;
return 1;
}
tag_mem_supplied = true;
- if (fread(c.d.asBytes, 4*64, 1, pf) == 0) {
+ if (fread(c.d.asBytes, 1, 4*64, pf) != 4*64) {
PrintAndLog("Error: File reading error");
fclose(pf);
return 1;
return 1;
}
file_given = true;
- if (fread(c.d.asBytes,8*60,1,pf) == 0) {
- PrintAndLog("Error: File reading error");
- fclose(pf);
+ if (fread(c.d.asBytes,1,8*60,pf) != 8*60) {
+ PrintAndLog("Error: File reading error");
+ fclose(pf);
return 1;
}
fclose(pf);
}
int CmdIndalaClone(const char *Cmd) {
- UsbCommand c;
+ UsbCommand c = {0};
unsigned int uid1, uid2, uid3, uid4, uid5, uid6, uid7;
uid1 = uid2 = uid3 = uid4 = uid5 = uid6 = uid7 = 0;
int res = rsa_check_pubkey(&cp->ctx);
if(res != 0) {
fprintf(stderr, "PolarSSL public key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
-
+ free(cp);
return NULL;
}
int res = rsa_check_privkey(&cp->ctx);
if(res != 0) {
fprintf(stderr, "PolarSSL private key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
+ free(cp);
return NULL;
}
int res = rsa_gen_key(&cp->ctx, &myrand, NULL, nbits, exp);
if (res) {
fprintf(stderr, "PolarSSL private key generation error res=%x exp=%d nbits=%d.\n", res * -1, exp, nbits);
+ free(cp);
return NULL;
}
res = rsa_public(&cp->ctx, buf, result);
if(res) {
printf("RSA encrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
+ free(result);
return NULL;
}
res = rsa_private(&cp->ctx, buf, result); // CHECK???
if(res) {
printf("RSA decrypt failed. Error: %x data len: %zd key len: %zd\n", res * -1, len, keylen);
+ free(result);
return NULL;
}
// Turn PHDRs into flasher segments, checking for PHDR sanity and merging adjacent
// unaligned segments if needed
-static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, int num_phdrs)
+static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, uint16_t num_phdrs)
{
Elf32_Phdr *phdr = phdrs;
flash_seg_t *seg;
FILE *fd = NULL;
Elf32_Ehdr ehdr;
Elf32_Phdr *phdrs = NULL;
- int num_phdrs;
+ uint16_t num_phdrs;
int res;
fd = fopen(name, "rb");
// Get the state of the proxmark, backwards compatible
static int get_proxmark_state(uint32_t *state)
{
- UsbCommand c;
+ UsbCommand c = {0};
c.cmd = CMD_DEVICE_INFO;
SendCommand(&c);
UsbCommand resp;
for(uint16_t j = 0; j < num_infiles; j++) {
for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
- c = fgetc(infile[j]);
+ c = (uint8_t)fgetc(infile[j]);
if (!feof(infile[j])) {
fpga_config[i++] = c;
} else if (num_infiles > 1) {
struct Crypto1State *p1, *p2, *p3, *p4;\r
\r
// flush queue\r
- WaitForResponseTimeout(CMD_ACK, NULL, 100);\r
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);\r
\r
UsbCommand c = {CMD_MIFARE_NESTED, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, calibrate}};\r
memcpy(c.d.asBytes, key, 6);\r
uint32_t nr1 = crypto1_word(pcs, nr_enc, 1) ^ nr_enc;\r
uint32_t ar1 = crypto1_word(pcs, 0, 0) ^ ar_enc;\r
uint32_t at1 = crypto1_word(pcs, 0, 0) ^ at_enc;\r
+ crypto1_destroy(pcs);\r
printf("key> the same key test. nr1: %08x ar1: %08x at1: %08x \n", nr1, ar1, at1);\r
\r
if (NTParityCheck(nt1))\r
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool usb_present)
{
#ifdef Q_WS_X11
- bool useGUI = getenv("DISPLAY") != 0;
-#else
- bool useGUI = true;
-#endif
- if (!useGUI)
+ if (getenv("DISPLAY") == NULL)
return;
+#endif
main_loop_thread = new WorkerThread(script_cmds_file, script_cmd, usb_present);
gui = new ProxGuiQT(argc, argv, main_loop_thread);
ProxWidget *plotwidget;
int argc;
char **argv;
- void (*main_func)(void);
WorkerThread *proxmarkThread;
public:
unsigned char buf[USB_CMD_DATA_SIZE];
size_t len = 0;
const char *data = luaL_checklstring(L, 1, &len);
- if (USB_CMD_DATA_SIZE < len)
+ if (len > USB_CMD_DATA_SIZE-2)
len = USB_CMD_DATA_SIZE-2;
for (int i = 0; i < len; i += 2) {
#include <sys/timeb.h>
struct _timeb t;
_ftime(&t);
- return 1000 * t.time + t.millitm;
+ return 1000 * (uint64_t)t.time + t.millitm;
// NORMAL CODE (use _ftime_s)
//struct _timeb t;
#define SPI_FPGA_MODE 0
#define SPI_LCD_MODE 1
-#define TRUE 1
-#define FALSE 0
-
//#define PACKED __attribute__((__packed__))
#define LED_A_ON() HIGH(GPIO_LED_A)
// 32 bit recover key from 2 nonces
int main (int argc, char *argv[]) {
- nonces_t data;
+ nonces_t data = {0};
uint32_t ks2; // keystream used to encrypt reader response
uint64_t key; // recovered key