mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-03 19:43:09 +08:00
tosend into bigbuff
This commit is contained in:
parent
b48d6ca14d
commit
a6c240fe3b
7 changed files with 195 additions and 157 deletions
|
@ -227,3 +227,47 @@ uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length) {
|
|||
Dbprintf("Error, trying to set memory outside of bounds! %d > %d", (offset + length), CARD_MEMORY_SIZE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// The ToSend buffer.
|
||||
// A buffer where we can queue things up to be sent through the FPGA, for
|
||||
// any purpose (fake tag, as reader, whatever). We go MSB first, since that
|
||||
// is the order in which they go out on the wire.
|
||||
//=============================================================================
|
||||
static tosend_t toSend = {
|
||||
.max = -1,
|
||||
.bit = 8,
|
||||
.buf = NULL
|
||||
};
|
||||
|
||||
// get the address of the ToSend buffer. Allocate part of Bigbuf for it, if not yet done
|
||||
tosend_t *get_tosend(void) {
|
||||
|
||||
if (toSend.buf == NULL)
|
||||
toSend.buf = BigBuf_malloc(TOSEND_BUFFER_SIZE);
|
||||
|
||||
return &toSend;
|
||||
}
|
||||
|
||||
void tosend_reset(void) {
|
||||
toSend.max = -1;
|
||||
toSend.bit = 8;
|
||||
}
|
||||
|
||||
void tosend_stuffbit(int b) {
|
||||
if (toSend.bit >= 8) {
|
||||
toSend.max++;
|
||||
toSend.buf[toSend.max] = 0;
|
||||
toSend.bit = 0;
|
||||
}
|
||||
|
||||
if (b)
|
||||
toSend.buf[ toSend.max] |= (1 << (7 - toSend.bit));
|
||||
|
||||
toSend.bit++;
|
||||
|
||||
if (toSend.max >= TOSEND_BUFFER_SIZE) {
|
||||
toSend.bit = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#define CARD_MEMORY_SIZE 4096
|
||||
#define DMA_BUFFER_SIZE 128
|
||||
|
||||
// 8 data bits and 1 parity bit per payload byte, 1 correction bit, 1 SOC bit, 2 EOC bits
|
||||
#define TOSEND_BUFFER_SIZE (9 * MAX_FRAME_SIZE + 1 + 1 + 2)
|
||||
|
||||
uint8_t *BigBuf_get_addr(void);
|
||||
uint32_t BigBuf_get_size(void);
|
||||
uint8_t *BigBuf_get_EM_addr(void);
|
||||
|
@ -42,4 +45,15 @@ bool get_tracing(void);
|
|||
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
|
||||
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length);
|
||||
|
||||
|
||||
typedef struct {
|
||||
int max;
|
||||
int bit;
|
||||
uint8_t *buf;
|
||||
} tosend_t;
|
||||
|
||||
tosend_t *get_tosend(void);
|
||||
void tosend_reset(void);
|
||||
void tosend_stuffbit(int b);
|
||||
|
||||
#endif /* __BIGBUF_H */
|
||||
|
|
|
@ -62,17 +62,6 @@
|
|||
#include "spiffs.h"
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
// A buffer where we can queue things up to be sent through the FPGA, for
|
||||
// any purpose (fake tag, as reader, whatever). We go MSB first, since that
|
||||
// is the order in which they go out on the wire.
|
||||
//=============================================================================
|
||||
|
||||
#define TOSEND_BUFFER_SIZE (9*MAX_FRAME_SIZE + 1 + 1 + 2) // 8 data bits and 1 parity bit per payload byte, 1 correction bit, 1 SOC bit, 2 EOC bits
|
||||
uint8_t ToSend[TOSEND_BUFFER_SIZE] = {0};
|
||||
int ToSendMax = -1;
|
||||
static int ToSendBit;
|
||||
|
||||
extern uint32_t _stack_start, _stack_end;
|
||||
struct common_area common_area __attribute__((section(".commonarea")));
|
||||
static int button_status = BUTTON_NO_CLICK;
|
||||
|
@ -84,29 +73,6 @@ inline void send_wtx(uint16_t wtx) {
|
|||
}
|
||||
}
|
||||
|
||||
void ToSendReset(void) {
|
||||
ToSendMax = -1;
|
||||
ToSendBit = 8;
|
||||
}
|
||||
|
||||
void ToSendStuffBit(int b) {
|
||||
if (ToSendBit >= 8) {
|
||||
ToSendMax++;
|
||||
ToSend[ToSendMax] = 0;
|
||||
ToSendBit = 0;
|
||||
}
|
||||
|
||||
if (b)
|
||||
ToSend[ToSendMax] |= (1 << (7 - ToSendBit));
|
||||
|
||||
ToSendBit++;
|
||||
|
||||
if (ToSendMax >= sizeof(ToSend)) {
|
||||
ToSendBit = 0;
|
||||
DbpString("ToSendStuffBit overflowed!");
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read an ADC channel and block till it completes, then return the result
|
||||
// in ADC units (0 to 1023). Also a routine to sum up a number of samples and
|
||||
|
@ -326,6 +292,28 @@ static void TimingIntervalAcquisition(void) {
|
|||
StartTickCount();
|
||||
}
|
||||
|
||||
static void print_debug_level(void) {
|
||||
char dbglvlstr[20] = {0};
|
||||
switch(DBGLEVEL) {
|
||||
case DBG_NONE:
|
||||
sprintf(dbglvlstr, "NONE");
|
||||
break;
|
||||
case DBG_ERROR:
|
||||
sprintf(dbglvlstr, "ERROR");
|
||||
break;
|
||||
case DBG_INFO:
|
||||
sprintf(dbglvlstr, "INFO");
|
||||
break;
|
||||
case DBG_DEBUG:
|
||||
sprintf(dbglvlstr, "DEBUG");
|
||||
break;
|
||||
case DBG_EXTENDED:
|
||||
sprintf(dbglvlstr, "EXTENDED");
|
||||
break;
|
||||
}
|
||||
Dbprintf(" DBGLEVEL................%d ( " _YELLOW_("%s")" )", DBGLEVEL, dbglvlstr);
|
||||
}
|
||||
|
||||
// measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
|
||||
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the PacketCommandNG structure included.
|
||||
static void printConnSpeed(void) {
|
||||
|
@ -372,29 +360,10 @@ static void SendStatus(void) {
|
|||
DbpString(_CYAN_("Various"));
|
||||
|
||||
print_stack_usage();
|
||||
|
||||
char dbglvlstr[20] = {0};
|
||||
switch(DBGLEVEL) {
|
||||
case DBG_NONE:
|
||||
sprintf(dbglvlstr, "NONE");
|
||||
break;
|
||||
case DBG_ERROR:
|
||||
sprintf(dbglvlstr, "ERROR");
|
||||
break;
|
||||
case DBG_INFO:
|
||||
sprintf(dbglvlstr, "INFO");
|
||||
break;
|
||||
case DBG_DEBUG:
|
||||
sprintf(dbglvlstr, "DEBUG");
|
||||
break;
|
||||
case DBG_EXTENDED:
|
||||
sprintf(dbglvlstr, "EXTENDED");
|
||||
break;
|
||||
}
|
||||
Dbprintf(" DBGLEVEL................%d ( " _YELLOW_("%s")" )", DBGLEVEL, dbglvlstr);
|
||||
print_debug_level();
|
||||
|
||||
Dbprintf(" ToSendMax...............%d", ToSendMax);
|
||||
Dbprintf(" ToSendBit...............%d", ToSendBit);
|
||||
tosend_t *ts = get_tosend();
|
||||
Dbprintf(" ToSendMax...............%d", ts->max );
|
||||
Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE);
|
||||
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
|
||||
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks
|
||||
|
@ -752,7 +721,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
// emulator
|
||||
case CMD_SET_DBGMODE: {
|
||||
DBGLEVEL = packet->data.asBytes[0];
|
||||
Dbprintf("Debug level: %d", DBGLEVEL);
|
||||
print_debug_level();
|
||||
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -114,8 +114,9 @@ int HfSniff(uint32_t samplesToSkip, uint32_t triggersToSkip, uint16_t *len) {
|
|||
}
|
||||
|
||||
void HfPlotDownload(void) {
|
||||
uint8_t *buf = ToSend;
|
||||
uint8_t *this_buf = buf;
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
uint8_t *this_buf = ts->buf;
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
|
@ -124,7 +125,7 @@ void HfPlotDownload(void) {
|
|||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
|
||||
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address
|
||||
AT91C_BASE_PDC_SSC->PDC_RCR = PM3_CMD_DATA_SIZE; // transfer this many samples
|
||||
buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register
|
||||
ts->buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register
|
||||
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM
|
||||
|
@ -132,7 +133,7 @@ void HfPlotDownload(void) {
|
|||
LED_B_ON();
|
||||
for (size_t i = 0; i < FPGA_TRACE_SIZE; i += PM3_CMD_DATA_SIZE) {
|
||||
// prepare next DMA transfer:
|
||||
uint8_t *next_buf = buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE));
|
||||
uint8_t *next_buf = ts->buf + ((i + PM3_CMD_DATA_SIZE) % (2 * PM3_CMD_DATA_SIZE));
|
||||
|
||||
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf;
|
||||
AT91C_BASE_PDC_SSC->PDC_RNCR = PM3_CMD_DATA_SIZE;
|
||||
|
|
|
@ -90,9 +90,10 @@ static void rotateCSN(uint8_t *original_csn, uint8_t *rotated_csn) {
|
|||
|
||||
// Encode SOF only
|
||||
static void CodeIClassTagSOF(void) {
|
||||
ToSendReset();
|
||||
ToSend[++ToSendMax] = 0x1D;
|
||||
ToSendMax++;
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
ts->buf[++ts->max] = 0x1D;
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
|
||||
|
@ -393,42 +394,43 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||
|
||||
// Prepare card messages
|
||||
ToSendMax = 0;
|
||||
tosend_t *ts = get_tosend();
|
||||
ts->max = 0;
|
||||
|
||||
// First card answer: SOF
|
||||
CodeIClassTagSOF();
|
||||
memcpy(resp_sof, ToSend, ToSendMax);
|
||||
resp_sof_len = ToSendMax;
|
||||
memcpy(resp_sof, ts->buf, ts->max);
|
||||
resp_sof_len = ts->max;
|
||||
|
||||
// Anticollision CSN
|
||||
CodeIso15693AsTag(anticoll_data, sizeof(anticoll_data));
|
||||
memcpy(resp_anticoll, ToSend, ToSendMax);
|
||||
resp_anticoll_len = ToSendMax;
|
||||
memcpy(resp_anticoll, ts->buf, ts->max);
|
||||
resp_anticoll_len = ts->max;
|
||||
|
||||
// CSN (block 0)
|
||||
CodeIso15693AsTag(csn_data, sizeof(csn_data));
|
||||
memcpy(resp_csn, ToSend, ToSendMax);
|
||||
resp_csn_len = ToSendMax;
|
||||
memcpy(resp_csn, ts->buf, ts->max);
|
||||
resp_csn_len = ts->max;
|
||||
|
||||
// Configuration (block 1)
|
||||
CodeIso15693AsTag(conf_block, sizeof(conf_block));
|
||||
memcpy(resp_conf, ToSend, ToSendMax);
|
||||
resp_conf_len = ToSendMax;
|
||||
memcpy(resp_conf, ts->buf, ts->max);
|
||||
resp_conf_len = ts->max;
|
||||
|
||||
// e-Purse (block 2)
|
||||
CodeIso15693AsTag(card_challenge_data, sizeof(card_challenge_data));
|
||||
memcpy(resp_cc, ToSend, ToSendMax);
|
||||
resp_cc_len = ToSendMax;
|
||||
memcpy(resp_cc, ts->buf, ts->max);
|
||||
resp_cc_len = ts->max;
|
||||
|
||||
// Kd, Kc (blocks 3 and 4)
|
||||
CodeIso15693AsTag(ff_data, sizeof(ff_data));
|
||||
memcpy(resp_ff, ToSend, ToSendMax);
|
||||
resp_ff_len = ToSendMax;
|
||||
memcpy(resp_ff, ts->buf, ts->max);
|
||||
resp_ff_len = ts->max;
|
||||
|
||||
// Application Issuer Area (block 5)
|
||||
CodeIso15693AsTag(aia_data, sizeof(aia_data));
|
||||
memcpy(resp_aia, ToSend, ToSendMax);
|
||||
resp_aia_len = ToSendMax;
|
||||
memcpy(resp_aia, ts->buf, ts->max);
|
||||
resp_aia_len = ts->max;
|
||||
|
||||
//This is used for responding to READ-block commands or other data which is dynamically generated
|
||||
//First the 'trace'-data, not encoded for FPGA
|
||||
|
@ -542,8 +544,8 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data = data_generic_trace;
|
||||
trace_data_size = 10;
|
||||
CodeIso15693AsTag(trace_data, trace_data_size);
|
||||
memcpy(modulated_response, ToSend, ToSendMax);
|
||||
modulated_response_size = ToSendMax;
|
||||
memcpy(modulated_response, ts->buf, ts->max);
|
||||
modulated_response_size = ts->max;
|
||||
goto send;
|
||||
}
|
||||
break;
|
||||
|
@ -586,9 +588,9 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data = data_generic_trace;
|
||||
trace_data_size = 4;
|
||||
CodeIso15693AsTag(trace_data, trace_data_size);
|
||||
memcpy(data_response, ToSend, ToSendMax);
|
||||
memcpy(data_response, ts->buf, ts->max);
|
||||
modulated_response = data_response;
|
||||
modulated_response_size = ToSendMax;
|
||||
modulated_response_size = ts->max;
|
||||
} else {
|
||||
// Not fullsim, we don't respond
|
||||
// We do not know what to answer, so lets keep quiet
|
||||
|
@ -636,8 +638,8 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data = data_generic_trace;
|
||||
trace_data_size = 34;
|
||||
CodeIso15693AsTag(trace_data, trace_data_size);
|
||||
memcpy(modulated_response, ToSend, ToSendMax);
|
||||
modulated_response_size = ToSendMax;
|
||||
memcpy(modulated_response, ts->buf, ts->max);
|
||||
modulated_response_size = ts->max;
|
||||
goto send;
|
||||
}
|
||||
|
||||
|
@ -650,8 +652,8 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
if (block == 2) { // update e-purse
|
||||
memcpy(card_challenge_data, receivedCmd + 2, 8);
|
||||
CodeIso15693AsTag(card_challenge_data, sizeof(card_challenge_data));
|
||||
memcpy(resp_cc, ToSend, ToSendMax);
|
||||
resp_cc_len = ToSendMax;
|
||||
memcpy(resp_cc, ts->buf, ts->max);
|
||||
resp_cc_len = ts->max;
|
||||
cipher_state_KD[current_page] = opt_doTagMAC_1(card_challenge_data, diversified_kd);
|
||||
cipher_state_KC[current_page] = opt_doTagMAC_1(card_challenge_data, diversified_kc);
|
||||
|
||||
|
@ -684,9 +686,9 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data = data_generic_trace;
|
||||
trace_data_size = 10;
|
||||
CodeIso15693AsTag(trace_data, trace_data_size);
|
||||
memcpy(data_response, ToSend, ToSendMax);
|
||||
memcpy(data_response, ts->buf, ts->max);
|
||||
modulated_response = data_response;
|
||||
modulated_response_size = ToSendMax;
|
||||
modulated_response_size = ts->max;
|
||||
}
|
||||
goto send;
|
||||
|
||||
|
@ -714,9 +716,9 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
|
|||
trace_data_size = 10;
|
||||
|
||||
CodeIso15693AsTag(trace_data, trace_data_size);
|
||||
memcpy(data_response, ToSend, ToSendMax);
|
||||
memcpy(data_response, ts->buf, ts->max);
|
||||
modulated_response = data_response;
|
||||
modulated_response_size = ToSendMax;
|
||||
modulated_response_size = ts->max;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,8 +754,9 @@ send:
|
|||
// THE READER CODE
|
||||
static void iclass_send_as_reader(uint8_t *frame, int len, uint32_t *start_time) {
|
||||
CodeIso15693AsReader(frame, len);
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, start_time);
|
||||
uint32_t end_time = *start_time + (32 * ((8 * ToSendMax) - 4)); // substract the 4 padding bits after EOF
|
||||
tosend_t *ts = get_tosend();
|
||||
TransmitTo15693Tag(ts->buf, ts->max, start_time);
|
||||
uint32_t end_time = *start_time + (32 * ((8 * ts->max) - 4)); // substract the 4 padding bits after EOF
|
||||
LogTrace(frame, len, (*start_time * 4), (end_time * 4), NULL, true);
|
||||
}
|
||||
|
||||
|
@ -770,7 +773,7 @@ static bool iclass_send_cmd_with_retries(uint8_t* cmd, size_t cmdsize, uint8_t*
|
|||
if (expected_size == GetIso15693AnswerFromTag(resp, max_resp_size, timeout, eof_time)) {
|
||||
return true;
|
||||
}
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
// start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -796,24 +799,19 @@ static bool select_iclass_tag(uint8_t *card_data, bool use_credit_key, uint32_t
|
|||
|
||||
if (use_credit_key)
|
||||
read_check_cc[0] = 0x10 | ICLASS_CMD_READCHECK;
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
int len;
|
||||
uint32_t start_time;
|
||||
uint8_t tries = 10;
|
||||
do {
|
||||
// wakeup
|
||||
start_time = GetCountSspClk();
|
||||
iclass_send_as_reader(act_all, 1, &start_time);
|
||||
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time);
|
||||
if (len >= 0) {
|
||||
break;
|
||||
} else if (len == -2) {
|
||||
return false;
|
||||
}
|
||||
} while (tries-- > 0);
|
||||
// wakeup
|
||||
uint32_t start_time = GetCountSspClk();
|
||||
iclass_send_as_reader(act_all, 1, &start_time);
|
||||
int len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time);
|
||||
if (len < 0)
|
||||
return false;
|
||||
|
||||
/*
|
||||
bool ok = iclass_send_cmd_with_retries(act_all, 1, resp, sizeof(resp), 1, 5, start_time, ICLASS_READER_TIMEOUT_ACTALL, eof_time);
|
||||
if (ok == false)
|
||||
return false;
|
||||
*/
|
||||
// send Identify
|
||||
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
iclass_send_as_reader(identify, 1, &start_time);
|
||||
|
@ -881,8 +879,6 @@ void ReaderIClass(uint8_t flags) {
|
|||
Iso15693InitReader();
|
||||
}
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
if ((flags & FLAG_ICLASS_READER_CLEARTRACE) == FLAG_ICLASS_READER_CLEARTRACE) {
|
||||
clear_trace();
|
||||
}
|
||||
|
|
|
@ -118,10 +118,11 @@ static void BuildInventoryResponse(uint8_t *uid);
|
|||
// n ... length of data
|
||||
void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
||||
|
||||
ToSendReset();
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// SOF for 1of4
|
||||
ToSend[++ToSendMax] = 0x84; //10000100
|
||||
ts->buf[++ts->max] = 0x84; //10000100
|
||||
|
||||
// data
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
@ -129,31 +130,32 @@ void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
|||
uint8_t these = (cmd[i] >> j) & 0x03;
|
||||
switch(these) {
|
||||
case 0:
|
||||
ToSend[++ToSendMax] = 0x40; //01000000
|
||||
ts->buf[++ts->max] = 0x40; //01000000
|
||||
break;
|
||||
case 1:
|
||||
ToSend[++ToSendMax] = 0x10; //00010000
|
||||
ts->buf[++ts->max] = 0x10; //00010000
|
||||
break;
|
||||
case 2:
|
||||
ToSend[++ToSendMax] = 0x04; //00000100
|
||||
ts->buf[++ts->max] = 0x04; //00000100
|
||||
break;
|
||||
case 3:
|
||||
ToSend[++ToSendMax] = 0x01; //00000001
|
||||
ts->buf[++ts->max] = 0x01; //00000001
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
ToSend[++ToSendMax] = 0x20; //0010 + 0000 padding
|
||||
ToSendMax++;
|
||||
ts->buf[++ts->max] = 0x20; //0010 + 0000 padding
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
// Encode EOF only
|
||||
static void CodeIso15693AsReaderEOF(void) {
|
||||
ToSendReset();
|
||||
ToSend[++ToSendMax] = 0x20;
|
||||
ToSendMax++;
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
ts->buf[++ts->max] = 0x20;
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
|
||||
|
@ -162,27 +164,28 @@ static void CodeIso15693AsReaderEOF(void) {
|
|||
// is designed for more robust communication over longer distances
|
||||
static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
|
||||
|
||||
ToSendReset();
|
||||
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// SOF for 1of256
|
||||
ToSend[++ToSendMax] = 0x81; //10000001
|
||||
ts->buf[++ts->max] = 0x81; //10000001
|
||||
|
||||
// data
|
||||
for(int i = 0; i < n; i++) {
|
||||
for (int j = 0; j <= 255; j++) {
|
||||
if (cmd[i] == j) {
|
||||
ToSendStuffBit(0);
|
||||
ToSendStuffBit(1);
|
||||
tosend_stuffbit(0);
|
||||
tosend_stuffbit(1);
|
||||
} else {
|
||||
ToSendStuffBit(0);
|
||||
ToSendStuffBit(0);
|
||||
tosend_stuffbit(0);
|
||||
tosend_stuffbit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
ToSend[++ToSendMax] = 0x20; //0010 + 0000 padding
|
||||
ToSendMax++;
|
||||
ts->buf[++ts->max] = 0x20; //0010 + 0000 padding
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
static const uint8_t encode_4bits[16] = {
|
||||
|
@ -219,22 +222,22 @@ void CodeIso15693AsTag(uint8_t *cmd, size_t len) {
|
|||
* A logic 0 is 10
|
||||
*
|
||||
* */
|
||||
|
||||
ToSendReset();
|
||||
tosend_reset();
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// SOF
|
||||
ToSend[++ToSendMax] = 0x1D; // 00011101
|
||||
ts->buf[++ts->max] = 0x1D; // 00011101
|
||||
|
||||
// data
|
||||
for (int i = 0; i < len; i++) {
|
||||
ToSend[++ToSendMax] = encode_4bits[cmd[i] & 0xF];
|
||||
ToSend[++ToSendMax] = encode_4bits[cmd[i] >> 4];
|
||||
ts->buf[++ts->max] = encode_4bits[cmd[i] & 0xF];
|
||||
ts->buf[++ts->max] = encode_4bits[cmd[i] >> 4];
|
||||
}
|
||||
|
||||
// EOF
|
||||
ToSend[++ToSendMax] = 0xB8; // 10111000
|
||||
ts->buf[++ts->max] = 0xB8; // 10111000
|
||||
|
||||
ToSendMax++;
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
// Transmit the command (to the tag) that was placed in cmd[].
|
||||
|
@ -617,9 +620,7 @@ static void DecodeTagReset(DecodeTag_t *DecodeTag) {
|
|||
*/
|
||||
int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
int samples = 0;
|
||||
int ret = 0;
|
||||
|
||||
int samples = 0, ret = 0;
|
||||
uint16_t dmaBuf[ISO15693_DMA_BUFFER_SIZE];
|
||||
|
||||
// the Decoder data structure
|
||||
|
@ -641,7 +642,8 @@ int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeo
|
|||
for(;;) {
|
||||
uint16_t behindBy = ((uint16_t*)AT91C_BASE_PDC_SSC->PDC_RPR - upTo) & (ISO15693_DMA_BUFFER_SIZE-1);
|
||||
|
||||
if (behindBy == 0) continue;
|
||||
if (behindBy == 0)
|
||||
continue;
|
||||
|
||||
samples++;
|
||||
if (samples == 1) {
|
||||
|
@ -702,7 +704,7 @@ int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeo
|
|||
Dbprintf("timing: sof_time = %d, eof_time = %d", (sof_time * 4), (*eof_time * 4));
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret == -1) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1115,8 +1117,10 @@ void AcquireRawAdcSamplesIso15693(void) {
|
|||
SpinDelay(100);
|
||||
|
||||
// Now send the command
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
uint32_t start_time = 0;
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
TransmitTo15693Tag(ts->buf, ts->max, &start_time);
|
||||
|
||||
// wait for last transfer to complete
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXEMPTY)) ;
|
||||
|
@ -1321,11 +1325,11 @@ void Iso15693InitReader(void) {
|
|||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
// give tags some time to energize
|
||||
SpinDelay(200);
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
StartCountSspClk();
|
||||
}
|
||||
|
||||
|
@ -1396,8 +1400,9 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t
|
|||
CodeIso15693AsReader256(send, sendlen);
|
||||
}
|
||||
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
uint32_t end_time = start_time + 32 * (8 * ToSendMax -4); // substract the 4 padding bits after EOF
|
||||
tosend_t *ts = get_tosend();
|
||||
TransmitTo15693Tag(ts->buf, ts->max, &start_time);
|
||||
uint32_t end_time = start_time + 32 * (8 * ts->max - 4); // substract the 4 padding bits after EOF
|
||||
LogTrace(send, sendlen, (start_time * 4), (end_time * 4), NULL, true);
|
||||
|
||||
int res = 0;
|
||||
|
@ -1410,8 +1415,9 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t
|
|||
int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
CodeIso15693AsReaderEOF();
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
uint32_t end_time = start_time + 32 * (8 * ToSendMax - 4); // substract the 4 padding bits after EOF
|
||||
tosend_t *ts = get_tosend();
|
||||
TransmitTo15693Tag(ts->buf, ts->max, &start_time);
|
||||
uint32_t end_time = start_time + 32 * (8 * ts->max - 4); // substract the 4 padding bits after EOF
|
||||
LogTrace(NULL, 0, (start_time * 4), (end_time * 4), NULL, true);
|
||||
|
||||
int res = 0;
|
||||
|
@ -1591,6 +1597,8 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
// not so obvious, but in the call to BuildInventoryResponse, the command is copied to the global ToSend buffer used below.
|
||||
BuildInventoryResponse(uid);
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
while (!BUTTON_PRESS()) {
|
||||
WDT_HIT();
|
||||
|
||||
|
@ -1602,7 +1610,7 @@ void SimTagIso15693(uint8_t *uid) {
|
|||
if ((cmd_len >= 5) && (cmd[0] & ISO15_REQ_INVENTORY) && (cmd[1] == ISO15_CMD_INVENTORY)) { // TODO: check more flags
|
||||
bool slow = !(cmd[0] & ISO15_REQ_DATARATE_HIGH);
|
||||
start_time = eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM;
|
||||
TransmitTo15693Reader(ToSend, ToSendMax, &start_time, 0, slow);
|
||||
TransmitTo15693Reader(ts->buf, ts->max, &start_time, 0, slow);
|
||||
}
|
||||
|
||||
if (DBGLEVEL >= DBG_EXTENDED) {
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
void ReadThinFilm(void) {
|
||||
|
||||
clear_trace();
|
||||
|
||||
set_tracing(true);
|
||||
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
|
@ -60,15 +59,19 @@ static uint16_t ReadReaderField(void) {
|
|||
}
|
||||
|
||||
static void CodeThinfilmAsTag(const uint8_t *cmd, uint16_t len) {
|
||||
ToSendReset();
|
||||
|
||||
tosend_reset();
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
for (uint16_t i = 0; i < len; i++) {
|
||||
uint8_t b = cmd[i];
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
ToSend[++ToSendMax] = (b & 0x80) ? SEC_D : SEC_E;
|
||||
ts->buf[++ts->max] = (b & 0x80) ? SEC_D : SEC_E;
|
||||
b <<= 1;
|
||||
}
|
||||
}
|
||||
ToSendMax++;
|
||||
ts->max++;
|
||||
}
|
||||
|
||||
static int EmSendCmdThinfilmRaw(uint8_t *resp, uint16_t respLen) {
|
||||
|
@ -132,6 +135,8 @@ void SimulateThinFilm(uint8_t *data, size_t len) {
|
|||
|
||||
uint16_t hf_baseline = ReadReaderField();
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
|
||||
// Start the timer
|
||||
StartCountSspClk();
|
||||
|
||||
|
@ -147,7 +152,8 @@ void SimulateThinFilm(uint8_t *data, size_t len) {
|
|||
if (hf_av < hf_baseline)
|
||||
hf_baseline = hf_av;
|
||||
if (hf_av > hf_baseline + 10) {
|
||||
EmSendCmdThinfilmRaw(ToSend, ToSendMax);
|
||||
|
||||
EmSendCmdThinfilmRaw(ts->buf, ts->max);
|
||||
if (!reader_detected) {
|
||||
LED_B_ON();
|
||||
//Dbprintf("Reader detected, start beaming data");
|
||||
|
|
Loading…
Reference in a new issue