mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
194
armsrc/felica.c
194
armsrc/felica.c
|
@ -31,23 +31,25 @@ static uint32_t felica_lasttime_prox2air_start;
|
|||
|
||||
static void iso18092_setup(uint8_t fpga_minor_mode);
|
||||
static uint8_t felica_select_card(felica_card_select_t *card);
|
||||
static void TransmitFor18092_AsReader(uint8_t * frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed);
|
||||
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed);
|
||||
bool WaitForFelicaReply(uint16_t maxbytes);
|
||||
|
||||
void iso18092_set_timeout(uint32_t timeout) {
|
||||
felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) + 2;
|
||||
void iso18092_set_timeout(uint32_t timeout)
|
||||
{
|
||||
felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2;
|
||||
}
|
||||
|
||||
uint32_t iso18092_get_timeout(void) {
|
||||
return felica_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) - 2;
|
||||
uint32_t iso18092_get_timeout(void)
|
||||
{
|
||||
return felica_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) - 2;
|
||||
}
|
||||
|
||||
#ifndef FELICA_MAX_FRAME_SIZE
|
||||
#define FELICA_MAX_FRAME_SIZE 260
|
||||
#define FELICA_MAX_FRAME_SIZE 260
|
||||
#endif
|
||||
|
||||
//structure to hold outgoing NFC frame
|
||||
static uint8_t frameSpace[FELICA_MAX_FRAME_SIZE+4];
|
||||
static uint8_t frameSpace[FELICA_MAX_FRAME_SIZE + 4];
|
||||
|
||||
//structure to hold incoming NFC frame, used for ISO/IEC 18092-compatible frames
|
||||
static struct {
|
||||
|
@ -67,8 +69,8 @@ static struct {
|
|||
uint16_t len;
|
||||
uint8_t byte_offset;
|
||||
uint8_t *framebytes;
|
||||
//should be enough. maxlen is 255, 254 for data, 2 for sync, 2 for crc
|
||||
// 0,1 -> SYNC, 2 - len, 3-(len+1)->data, then crc
|
||||
//should be enough. maxlen is 255, 254 for data, 2 for sync, 2 for crc
|
||||
// 0,1 -> SYNC, 2 - len, 3-(len+1)->data, then crc
|
||||
} FelicaFrame;
|
||||
|
||||
//b2 4d is SYNC, 45645 in 16-bit notation, 10110010 01001101 binary. Frame will not start filling until this is shifted in
|
||||
|
@ -77,33 +79,37 @@ static struct {
|
|||
# define SYNC_16BIT 0xB24D
|
||||
#endif
|
||||
|
||||
static void FelicaFrameReset() {
|
||||
static void FelicaFrameReset()
|
||||
{
|
||||
FelicaFrame.state = STATE_UNSYNCD;
|
||||
FelicaFrame.posCnt = 0;
|
||||
FelicaFrame.crc_ok = false;
|
||||
FelicaFrame.byte_offset = 0;
|
||||
}
|
||||
static void FelicaFrameinit(uint8_t *data) {
|
||||
static void FelicaFrameinit(uint8_t *data)
|
||||
{
|
||||
FelicaFrame.framebytes = data;
|
||||
FelicaFrameReset();
|
||||
}
|
||||
|
||||
//shift byte into frame, reversing it at the same time
|
||||
static void shiftInByte(uint8_t bt) {
|
||||
static void shiftInByte(uint8_t bt)
|
||||
{
|
||||
uint8_t j;
|
||||
for(j=0; j < FelicaFrame.byte_offset; j++) {
|
||||
FelicaFrame.framebytes[FelicaFrame.posCnt] = ( FelicaFrame.framebytes[FelicaFrame.posCnt]<<1 ) + (bt & 1);
|
||||
for (j = 0; j < FelicaFrame.byte_offset; j++) {
|
||||
FelicaFrame.framebytes[FelicaFrame.posCnt] = (FelicaFrame.framebytes[FelicaFrame.posCnt] << 1) + (bt & 1);
|
||||
bt >>= 1;
|
||||
}
|
||||
FelicaFrame.posCnt++;
|
||||
FelicaFrame.rem_len--;
|
||||
for(j = FelicaFrame.byte_offset; j<8; j++) {
|
||||
FelicaFrame.framebytes[FelicaFrame.posCnt] = (FelicaFrame.framebytes[FelicaFrame.posCnt]<<1 ) + (bt & 1);
|
||||
for (j = FelicaFrame.byte_offset; j < 8; j++) {
|
||||
FelicaFrame.framebytes[FelicaFrame.posCnt] = (FelicaFrame.framebytes[FelicaFrame.posCnt] << 1) + (bt & 1);
|
||||
bt >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void Process18092Byte(uint8_t bt) {
|
||||
static void Process18092Byte(uint8_t bt)
|
||||
{
|
||||
switch (FelicaFrame.state) {
|
||||
case STATE_UNSYNCD: {
|
||||
//almost any nonzero byte can be start of SYNC. SYNC should be preceded by zeros, but that is not alsways the case
|
||||
|
@ -119,7 +125,7 @@ static void Process18092Byte(uint8_t bt) {
|
|||
FelicaFrame.shiftReg = bt;
|
||||
FelicaFrame.state = STATE_UNSYNCD;
|
||||
} else {
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
|
||||
if (FelicaFrame.shiftReg == SYNC_16BIT) {
|
||||
//SYNC done!
|
||||
|
@ -128,13 +134,13 @@ static void Process18092Byte(uint8_t bt) {
|
|||
FelicaFrame.framebytes[1] = 0x4d;
|
||||
FelicaFrame.byte_offset = i;
|
||||
//shift in remaining byte, slowly...
|
||||
for(uint8_t j=i; j<8; j++) {
|
||||
for (uint8_t j = i; j < 8; j++) {
|
||||
FelicaFrame.framebytes[2] = (FelicaFrame.framebytes[2] << 1) + (bt & 1);
|
||||
bt >>= 1;
|
||||
}
|
||||
|
||||
FelicaFrame.posCnt = 2;
|
||||
if (i==0)
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
FelicaFrame.shiftReg = (FelicaFrame.shiftReg << 1) + (bt & 1);
|
||||
|
@ -171,12 +177,12 @@ static void Process18092Byte(uint8_t bt) {
|
|||
case STATE_GET_CRC: {
|
||||
shiftInByte(bt);
|
||||
|
||||
if ( FelicaFrame.rem_len <= 0 ) {
|
||||
if (FelicaFrame.rem_len <= 0) {
|
||||
// skip sync 2bytes. IF ok, residue should be 0x0000
|
||||
FelicaFrame.crc_ok = check_crc(CRC_FELICA, FelicaFrame.framebytes+2, FelicaFrame.len-2);
|
||||
FelicaFrame.crc_ok = check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2);
|
||||
FelicaFrame.state = STATE_FULL;
|
||||
FelicaFrame.rem_len = 0;
|
||||
if (MF_DBGLEVEL > 3) Dbprintf("[+] got 2 crc bytes [%s]", (FelicaFrame.crc_ok) ? "OK" : "No" );
|
||||
if (MF_DBGLEVEL > 3) Dbprintf("[+] got 2 crc bytes [%s]", (FelicaFrame.crc_ok) ? "OK" : "No");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -190,7 +196,8 @@ static void Process18092Byte(uint8_t bt) {
|
|||
* Currently does NOT do any collision handling.
|
||||
* It expects 0-1 cards in the device's range.
|
||||
*/
|
||||
static uint8_t felica_select_card(felica_card_select_t *card) {
|
||||
static uint8_t felica_select_card(felica_card_select_t *card)
|
||||
{
|
||||
|
||||
// POLL command
|
||||
// 0xB2 0x4B = sync code
|
||||
|
@ -205,7 +212,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
|||
// b0 = fc/64 (212kbps)
|
||||
// 0x00 = timeslot
|
||||
// 0x09 0x21 = crc
|
||||
static uint8_t poll[10] = {0xb2,0x4d,0x06,FELICA_POLL_REQ,0xFF,0xFF,0x00,0x00,0x09,0x21};
|
||||
static uint8_t poll[10] = {0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xFF, 0xFF, 0x00, 0x00, 0x09, 0x21};
|
||||
|
||||
int len = 20;
|
||||
|
||||
|
@ -225,7 +232,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
|||
} while (--len);
|
||||
|
||||
// timed-out
|
||||
if ( len == 0 )
|
||||
if (len == 0)
|
||||
return 1;
|
||||
|
||||
// wrong answer
|
||||
|
@ -233,7 +240,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
|||
return 2;
|
||||
|
||||
// VALIDATE CRC residue is 0, hence if crc is a value it failed.
|
||||
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes+2, FelicaFrame.len-2))
|
||||
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2))
|
||||
return 3;
|
||||
|
||||
// copy UID
|
||||
|
@ -245,7 +252,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
|||
memcpy(card->code, card->IDm, 2);
|
||||
memcpy(card->uid, card->IDm + 2, 6);
|
||||
memcpy(card->iccode, card->PMm, 2);
|
||||
memcpy(card->mrt, card->PMm+2, 6);
|
||||
memcpy(card->mrt, card->PMm + 2, 6);
|
||||
|
||||
}
|
||||
// more status bytes?
|
||||
|
@ -264,7 +271,8 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
|
|||
// Felica standard has a different file system, AFAIK,
|
||||
// 8-byte IDm, number of blocks, blocks numbers
|
||||
// number of blocks limited to 4 for FelicaLite(S)
|
||||
static void BuildFliteRdblk(uint8_t* idm, int blocknum, uint16_t *blocks ) {
|
||||
static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks)
|
||||
{
|
||||
|
||||
if (blocknum > 4 || blocknum <= 0)
|
||||
Dbprintf("Invalid number of blocks, %d != 4", blocknum);
|
||||
|
@ -298,13 +306,13 @@ static void BuildFliteRdblk(uint8_t* idm, int blocknum, uint16_t *blocks ) {
|
|||
//number of blocks
|
||||
frameSpace[c++] = blocknum;
|
||||
|
||||
for (i=0; i < blocknum; i++) {
|
||||
for (i = 0; i < blocknum; i++) {
|
||||
|
||||
//3-byte block
|
||||
if (blocks[i] >= 256) {
|
||||
frameSpace[c++] = 0x00;
|
||||
frameSpace[c++] = (blocks[i] >> 8); //block number, little endian....
|
||||
frameSpace[c++] = (blocks[i] & 0xff);
|
||||
frameSpace[c++] = 0x00;
|
||||
frameSpace[c++] = (blocks[i] >> 8); //block number, little endian....
|
||||
frameSpace[c++] = (blocks[i] & 0xff);
|
||||
} else {
|
||||
frameSpace[c++] = 0x80;
|
||||
frameSpace[c++] = blocks[i];
|
||||
|
@ -312,15 +320,16 @@ static void BuildFliteRdblk(uint8_t* idm, int blocknum, uint16_t *blocks ) {
|
|||
}
|
||||
|
||||
//set length
|
||||
frameSpace[2] = c-2;
|
||||
AddCrc(frameSpace, c-2);
|
||||
frameSpace[2] = c - 2;
|
||||
AddCrc(frameSpace, c - 2);
|
||||
}
|
||||
|
||||
static void TransmitFor18092_AsReader(uint8_t * frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed) {
|
||||
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed)
|
||||
{
|
||||
|
||||
uint8_t flags = FPGA_MAJOR_MODE_ISO18092;
|
||||
|
||||
if ( power )
|
||||
if (power)
|
||||
flags |= FPGA_HF_ISO18092_FLAG_READER;
|
||||
if (highspeed)
|
||||
flags |= FPGA_HF_ISO18092_FLAG_424K;
|
||||
|
@ -356,31 +365,32 @@ static void TransmitFor18092_AsReader(uint8_t * frame, int len, uint32_t *timing
|
|||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
/**/
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) {};
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00; //minimum delay
|
||||
|
||||
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))) {};
|
||||
AT91C_BASE_SSC->SSC_THR = 0x00; //spin
|
||||
/**/
|
||||
/**/
|
||||
|
||||
// log
|
||||
LogTrace(
|
||||
frame,
|
||||
len,
|
||||
(felica_lasttime_prox2air_start<<4) + DELAY_ARM2AIR_AS_READER,
|
||||
((felica_lasttime_prox2air_start + felica_lasttime_prox2air_start)<<4) + DELAY_ARM2AIR_AS_READER,
|
||||
(felica_lasttime_prox2air_start << 4) + DELAY_ARM2AIR_AS_READER,
|
||||
((felica_lasttime_prox2air_start + felica_lasttime_prox2air_start) << 4) + DELAY_ARM2AIR_AS_READER,
|
||||
NULL,
|
||||
true
|
||||
);
|
||||
|
||||
felica_nexttransfertime = MAX(felica_nexttransfertime ,felica_lasttime_prox2air_start + FELICA_REQUEST_GUARD_TIME);
|
||||
felica_nexttransfertime = MAX(felica_nexttransfertime, felica_lasttime_prox2air_start + FELICA_REQUEST_GUARD_TIME);
|
||||
}
|
||||
|
||||
// Wait for tag reply
|
||||
// stop when button is pressed
|
||||
// or return TRUE when command is captured
|
||||
bool WaitForFelicaReply(uint16_t maxbytes) {
|
||||
bool WaitForFelicaReply(uint16_t maxbytes)
|
||||
{
|
||||
|
||||
uint32_t c = 0;
|
||||
|
||||
|
@ -393,7 +403,7 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
|||
uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
uint32_t timeout = iso18092_get_timeout();
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
|
@ -403,15 +413,15 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
|||
felica_nexttransfertime =
|
||||
MAX(
|
||||
felica_nexttransfertime,
|
||||
(GetCountSspClk() & 0xfffffff8) - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/16 + FELICA_FRAME_DELAY_TIME
|
||||
(GetCountSspClk() & 0xfffffff8) - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 16 + FELICA_FRAME_DELAY_TIME
|
||||
)
|
||||
;
|
||||
;
|
||||
|
||||
LogTrace(
|
||||
FelicaFrame.framebytes,
|
||||
FelicaFrame.len,
|
||||
((GetCountSspClk() & 0xfffffff8)<<4) - DELAY_AIR2ARM_AS_READER - timeout,
|
||||
((GetCountSspClk() & 0xfffffff8)<<4) - DELAY_AIR2ARM_AS_READER,
|
||||
((GetCountSspClk() & 0xfffffff8) << 4) - DELAY_AIR2ARM_AS_READER - timeout,
|
||||
((GetCountSspClk() & 0xfffffff8) << 4) - DELAY_AIR2ARM_AS_READER,
|
||||
NULL,
|
||||
false
|
||||
);
|
||||
|
@ -430,13 +440,15 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
|
|||
|
||||
// Set up FeliCa communication (similar to iso14443a_setup)
|
||||
// field is setup for "Sending as Reader"
|
||||
static void iso18092_setup(uint8_t fpga_minor_mode) {
|
||||
static void iso18092_setup(uint8_t fpga_minor_mode)
|
||||
{
|
||||
|
||||
LEDsoff();
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
// allocate command receive buffer
|
||||
BigBuf_free(); BigBuf_Clear_ext(false);
|
||||
BigBuf_free();
|
||||
BigBuf_Clear_ext(false);
|
||||
|
||||
// Initialize Demod and Uart structs
|
||||
//DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
|
||||
|
@ -473,7 +485,8 @@ static void iso18092_setup(uint8_t fpga_minor_mode) {
|
|||
// arg0 FeliCa flags
|
||||
// arg1 len of commandbytes
|
||||
// d.asBytes command bytes to send
|
||||
void felica_sendraw(UsbCommand *c) {
|
||||
void felica_sendraw(UsbCommand *c)
|
||||
{
|
||||
|
||||
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter");
|
||||
|
||||
|
@ -494,10 +507,10 @@ void felica_sendraw(UsbCommand *c) {
|
|||
|
||||
// notify client selecting status.
|
||||
// if failed selecting, turn off antenna and quite.
|
||||
if( !(param & FELICA_NO_SELECT) ) {
|
||||
if (!(param & FELICA_NO_SELECT)) {
|
||||
arg0 = felica_select_card(&card);
|
||||
cmd_send(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t));
|
||||
if ( arg0 > 0 )
|
||||
if (arg0 > 0)
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
|
@ -505,26 +518,26 @@ void felica_sendraw(UsbCommand *c) {
|
|||
if ((param & FELICA_RAW)) {
|
||||
|
||||
// 2 sync, 1 len, 2crc == 5
|
||||
uint8_t *buf = BigBuf_malloc(len+5);
|
||||
uint8_t *buf = BigBuf_malloc(len + 5);
|
||||
// add sync bits
|
||||
buf[0] = 0xb2;
|
||||
buf[1] = 0x4d;
|
||||
buf[2] = len;
|
||||
|
||||
// copy command
|
||||
memcpy(buf+2, cmd, len);
|
||||
memcpy(buf + 2, cmd, len);
|
||||
|
||||
if ((param & FELICA_APPEND_CRC)) {
|
||||
// Don't append crc on empty bytearray...
|
||||
if ( len > 0 ) {
|
||||
if (len > 0) {
|
||||
AddCrc(buf, len);
|
||||
len += 2;
|
||||
}
|
||||
}
|
||||
|
||||
TransmitFor18092_AsReader(buf, buf[2]+4, NULL, 1, 0);
|
||||
TransmitFor18092_AsReader(buf, buf[2] + 4, NULL, 1, 0);
|
||||
arg0 = !WaitForFelicaReply(1024);
|
||||
cmd_send(CMD_ACK, arg0, 0, 0, FelicaFrame.framebytes+2, FelicaFrame.len-2);
|
||||
cmd_send(CMD_ACK, arg0, 0, 0, FelicaFrame.framebytes + 2, FelicaFrame.len - 2);
|
||||
}
|
||||
|
||||
if ((param & FELICA_NO_DISCONNECT))
|
||||
|
@ -539,25 +552,26 @@ OUT:
|
|||
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Exit");
|
||||
}
|
||||
|
||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip)
|
||||
{
|
||||
|
||||
int remFrames = (samplesToSkip) ? samplesToSkip : 0;
|
||||
|
||||
Dbprintf("Snoop FelicaLiteS: Getting first %d frames, Skipping %d triggers.\n", samplesToSkip, triggersToSkip);
|
||||
|
||||
iso18092_setup( FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||
iso18092_setup(FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||
|
||||
//the frame bits are slow enough.
|
||||
int n = BigBuf_max_traceLen() / sizeof(uint8_t); // take all memory
|
||||
int numbts = 0;
|
||||
uint8_t *dest = (uint8_t *)BigBuf_get_addr();
|
||||
uint8_t *destend = dest + n-2;
|
||||
uint8_t *destend = dest + n - 2;
|
||||
|
||||
uint32_t endframe = GetCountSspClk();
|
||||
|
||||
while (dest <= destend) {
|
||||
WDT_HIT();
|
||||
if( BUTTON_PRESS()) break;
|
||||
if (BUTTON_PRESS()) break;
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||
|
@ -566,7 +580,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
|||
//to be sure we are in frame
|
||||
if (FelicaFrame.state == STATE_GET_LENGTH) {
|
||||
//length is after 48 (PRE)+16 (SYNC) - 64 ticks +maybe offset? not 100%
|
||||
uint16_t distance = GetCountSspClk() - endframe - 64 + (FelicaFrame.byte_offset > 0 ? (8-FelicaFrame.byte_offset) : 0);
|
||||
uint16_t distance = GetCountSspClk() - endframe - 64 + (FelicaFrame.byte_offset > 0 ? (8 - FelicaFrame.byte_offset) : 0);
|
||||
*dest = distance >> 8;
|
||||
dest++;
|
||||
*dest = (distance & 0xff);
|
||||
|
@ -577,16 +591,16 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
|||
endframe = GetCountSspClk();
|
||||
//*dest = FelicaFrame.crc_ok; //kind of wasteful
|
||||
dest++;
|
||||
for(int i=0; i < FelicaFrame.len; i++) {
|
||||
for (int i = 0; i < FelicaFrame.len; i++) {
|
||||
*dest = FelicaFrame.framebytes[i];
|
||||
dest++;
|
||||
if (dest >= destend ) break;
|
||||
if (dest >= destend) break;
|
||||
|
||||
}
|
||||
|
||||
remFrames--;
|
||||
if (remFrames <= 0) break;
|
||||
if (dest >= destend ) break;
|
||||
if (dest >= destend) break;
|
||||
|
||||
numbts += FelicaFrame.len;
|
||||
|
||||
|
@ -602,7 +616,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
|||
set_tracelen(numbts);
|
||||
|
||||
Dbprintf("Felica sniffing done, tracelen: %i, use hf list felica for annotations", BigBuf_get_traceLen());
|
||||
cmd_send(CMD_ACK,1, numbts,0,0,0);
|
||||
cmd_send(CMD_ACK, 1, numbts, 0, 0, 0);
|
||||
}
|
||||
|
||||
#define R_POLL0_LEN 0x16
|
||||
|
@ -610,7 +624,8 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
|||
#define R_READBLK_LEN 0x21
|
||||
//simulate NFC Tag3 card - for now only poll response works
|
||||
// second half (4 bytes) of NDEF2 goes into nfcid2_0, first into nfcid2_1
|
||||
void felica_sim_lite(uint64_t nfcid) {
|
||||
void felica_sim_lite(uint64_t nfcid)
|
||||
{
|
||||
|
||||
int i, curlen = 0;
|
||||
uint8_t *curresp = 0;
|
||||
|
@ -619,21 +634,21 @@ void felica_sim_lite(uint64_t nfcid) {
|
|||
num_to_bytes(nfcid, 8, ndef);
|
||||
|
||||
//prepare our 3 responses...
|
||||
uint8_t resp_poll0[R_POLL0_LEN] = { 0xb2,0x4d,0x12,FELICA_POLL_ACK,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf1,0x00,0x00,0x00,0x01,0x43,0x00,0xb3,0x7f};
|
||||
uint8_t resp_poll1[R_POLL1_LEN] = { 0xb2,0x4d,0x14,FELICA_POLL_ACK,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf1,0x00,0x00,0x00,0x01,0x43,0x00, 0x88,0xb4,0xb3,0x7f};
|
||||
uint8_t resp_readblk[R_READBLK_LEN] = { 0xb2,0x4d,0x1d,FELICA_RDBLK_ACK,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x04,0x01,0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x23,0xcb,0x6e};
|
||||
uint8_t resp_poll0[R_POLL0_LEN] = { 0xb2, 0x4d, 0x12, FELICA_POLL_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f};
|
||||
uint8_t resp_poll1[R_POLL1_LEN] = { 0xb2, 0x4d, 0x14, FELICA_POLL_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0x88, 0xb4, 0xb3, 0x7f};
|
||||
uint8_t resp_readblk[R_READBLK_LEN] = { 0xb2, 0x4d, 0x1d, FELICA_RDBLK_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x04, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x23, 0xcb, 0x6e};
|
||||
|
||||
//NFC tag 3/ ISo technically. Many overlapping standards
|
||||
DbpString("Felica Lite-S sim start");
|
||||
Dbprintf("NDEF2 UID: %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||
ndef[0], ndef[1], ndef[2], ndef[3], ndef[4], ndef[5], ndef[6], ndef[7]
|
||||
);
|
||||
ndef[0], ndef[1], ndef[2], ndef[3], ndef[4], ndef[5], ndef[6], ndef[7]
|
||||
);
|
||||
|
||||
//fill in blanks
|
||||
for( i=0; i<8; i++) {
|
||||
resp_poll0[i+4] = ndef[i];
|
||||
resp_poll1[i+4] = ndef[i];
|
||||
resp_readblk[i+4] = ndef[i];
|
||||
for (i = 0; i < 8; i++) {
|
||||
resp_poll0[i + 4] = ndef[i];
|
||||
resp_poll1[i + 4] = ndef[i];
|
||||
resp_readblk[i + 4] = ndef[i];
|
||||
}
|
||||
|
||||
//calculate and set CRC
|
||||
|
@ -641,12 +656,12 @@ void felica_sim_lite(uint64_t nfcid) {
|
|||
AddCrc(resp_poll1, resp_poll1[2]);
|
||||
AddCrc(resp_readblk, resp_readblk[2]);
|
||||
|
||||
iso18092_setup( FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||
iso18092_setup(FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||
|
||||
bool listenmode = true;
|
||||
//uint32_t frtm = GetCountSspClk();
|
||||
for(;;) {
|
||||
if( BUTTON_PRESS()) break;
|
||||
for (;;) {
|
||||
if (BUTTON_PRESS()) break;
|
||||
WDT_HIT();
|
||||
|
||||
if (listenmode) {
|
||||
|
@ -716,11 +731,12 @@ void felica_sim_lite(uint64_t nfcid) {
|
|||
DbpString("Felica Lite-S sim end");
|
||||
}
|
||||
|
||||
void felica_dump_lite_s() {
|
||||
void felica_dump_lite_s()
|
||||
{
|
||||
|
||||
uint8_t ndef[8];
|
||||
uint8_t poll[10] = { 0xb2,0x4d,0x06,FELICA_POLL_REQ,0xff,0xff,0x00,0x00,0x09,0x21};
|
||||
uint16_t liteblks[28] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x90,0x91,0x92,0xa0};
|
||||
uint8_t poll[10] = { 0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21};
|
||||
uint16_t liteblks[28] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x90, 0x91, 0x92, 0xa0};
|
||||
|
||||
// setup device.
|
||||
iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||
|
@ -743,15 +759,15 @@ void felica_dump_lite_s() {
|
|||
// copy 8bytes to ndef.
|
||||
memcpy(ndef, FelicaFrame.framebytes + 4, 8);
|
||||
// for (c=0; c < 8; c++)
|
||||
// ndef[c] = FelicaFrame.framebytes[c+4];
|
||||
// ndef[c] = FelicaFrame.framebytes[c+4];
|
||||
|
||||
for (blknum=0; blknum < sizeof(liteblks); ) {
|
||||
for (blknum = 0; blknum < sizeof(liteblks);) {
|
||||
|
||||
// block to read.
|
||||
BuildFliteRdblk(ndef, 1, &liteblks[blknum]);
|
||||
|
||||
//TransmitFor18092_AsReader(frameSpace, frameSpace[2]+4, GetCountSspClk()+512, 1, 0);
|
||||
TransmitFor18092_AsReader(frameSpace, frameSpace[2]+4, NULL, 1, 0);
|
||||
TransmitFor18092_AsReader(frameSpace, frameSpace[2] + 4, NULL, 1, 0);
|
||||
|
||||
// read block
|
||||
if (WaitForFelicaReply(1024) && FelicaFrame.framebytes[3] == FELICA_RDBLK_ACK) {
|
||||
|
@ -764,15 +780,15 @@ void felica_dump_lite_s() {
|
|||
|
||||
//memcpy(dest+cnt, FelicaFrame.framebytes + 15, 16);
|
||||
//cnt += 16;
|
||||
for(uint8_t j=0; j < 16; j++)
|
||||
dest[cnt++] = fb[15+j];
|
||||
for (uint8_t j = 0; j < 16; j++)
|
||||
dest[cnt++] = fb[15 + j];
|
||||
|
||||
blknum++;
|
||||
cntfails = 0;
|
||||
|
||||
// // print raw log.
|
||||
// Dbprintf("LEN %u | Dump bytes count %u ", FelicaFrame.len, cnt);
|
||||
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes+15, 0);
|
||||
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes + 15, 0);
|
||||
} else {
|
||||
cntfails++;
|
||||
if (cntfails > 12) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue