add 'losimman' command - simulate arbitrary Manchester encoded LF tags

This commit is contained in:
adam@algroup.co.uk 2010-01-28 11:49:05 +00:00
parent cef938d883
commit 13a79da4e9
4 changed files with 52 additions and 14 deletions

View file

@ -26,7 +26,7 @@ int kvsprintf(char const *fmt, void *arg, int radix, va_list ap);
// is the order in which they go out on the wire. // is the order in which they go out on the wire.
//============================================================================= //=============================================================================
BYTE ToSend[256]; BYTE ToSend[512];
int ToSendMax; int ToSendMax;
static int ToSendBit; static int ToSendBit;
struct common_area common_area __attribute__((section(".commonarea"))); struct common_area common_area __attribute__((section(".commonarea")));
@ -34,7 +34,7 @@ struct common_area common_area __attribute__((section(".commonarea")));
void BufferClear(void) void BufferClear(void)
{ {
memset(BigBuf,0,sizeof(BigBuf)); memset(BigBuf,0,sizeof(BigBuf));
DbpString("Buffer cleared"); Dbprintf("Buffer cleared (%i bytes)",sizeof(BigBuf));
} }
void ToSendReset(void) void ToSendReset(void)
@ -718,13 +718,14 @@ void UsbPacketReceived(BYTE *packet, int len)
case CMD_DOWNLOADED_SIM_SAMPLES_125K: { case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
BYTE *b = (BYTE *)BigBuf; BYTE *b = (BYTE *)BigBuf;
memcpy(b+c->arg[0], c->d.asBytes, 48); memcpy(b+c->arg[0], c->d.asBytes, 48);
//Dbprintf("copied 48 bytes to %i",b+c->arg[0]);
break; break;
} }
#ifdef WITH_LF #ifdef WITH_LF
case CMD_SIMULATE_TAG_125K: case CMD_SIMULATE_TAG_125K:
LED_A_ON(); LED_A_ON();
SimulateTagLowFrequency(c->arg[0], 1); SimulateTagLowFrequency(c->arg[0], c->arg[1], 1);
LED_A_OFF(); LED_A_OFF();
break; break;
#endif #endif
@ -794,7 +795,7 @@ void UsbPacketReceived(BYTE *packet, int len)
} }
break; break;
default: default:
DbpString("unknown command"); Dbprintf("%s: 0x%04x","unknown command:",c->cmd);
break; break;
} }
} }

View file

@ -78,7 +78,7 @@ void ReadTItag(void);
void WriteTItag(DWORD idhi, DWORD idlo, WORD crc); void WriteTItag(DWORD idhi, DWORD idlo, WORD crc);
void AcquireTiType(void); void AcquireTiType(void);
void AcquireRawBitsTI(void); void AcquireRawBitsTI(void);
void SimulateTagLowFrequency(int period, int ledcontrol); void SimulateTagLowFrequency(int period, int gap, int ledcontrol);
void CmdHIDsimTAG(int hi, int lo, int ledcontrol); void CmdHIDsimTAG(int hi, int lo, int ledcontrol);
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol); void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol);
void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen); void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen);

View file

@ -423,7 +423,7 @@ void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
DbpString("Now use tiread to check"); DbpString("Now use tiread to check");
} }
void SimulateTagLowFrequency(int period, int ledcontrol) void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
{ {
int i; int i;
BYTE *tab = (BYTE *)BigBuf; BYTE *tab = (BYTE *)BigBuf;
@ -468,7 +468,13 @@ void SimulateTagLowFrequency(int period, int ledcontrol)
} }
i++; i++;
if(i == period) i = 0; if(i == period) {
i = 0;
if (gap) {
SHORT_COIL();
SpinDelayUs(gap);
}
}
} }
} }
@ -762,7 +768,7 @@ void CmdHIDsimTAG(int hi, int lo, int ledcontrol)
if (ledcontrol) if (ledcontrol)
LED_A_ON(); LED_A_ON();
SimulateTagLowFrequency(n, ledcontrol); SimulateTagLowFrequency(n, 0, ledcontrol);
if (ledcontrol) if (ledcontrol)
LED_A_OFF(); LED_A_OFF();

View file

@ -577,7 +577,6 @@ retest:
static void CmdEM410xsim(char *str) static void CmdEM410xsim(char *str)
{ {
int i, n, j, h, binary[4], parity[4]; int i, n, j, h, binary[4], parity[4];
char *s = "0";
/* clock is 64 in EM410x tags */ /* clock is 64 in EM410x tags */
int clock = 64; int clock = 64;
@ -628,12 +627,40 @@ static void CmdEM410xsim(char *str)
} }
/* modulate that biatch */ /* modulate that biatch */
Cmdmanchestermod(s); Cmdmanchestermod("");
/* booyah! */ /* booyah! */
RepaintGraphWindow(); RepaintGraphWindow();
CmdLosim(s); CmdLosim("");
}
/* simulate an LF Manchester encoded tag with specified bitstream, clock rate and inter-id gap */
static void CmdLosimManchester(char *str)
{
static int clock, gap;
static char data[1024], gapstring[8];
int i;
/* get settings/bits */
sscanf(str, "%i %s %i", &clock, &data[0], &gap);
/* clear our graph */
CmdClearGraph(0);
/* fill it with our bitstream */
for (i= 0; i < strlen(data) ; ++i)
CmdAppendGraph(0, clock, data[i]- '0');
/* modulate */
Cmdmanchestermod("");
/* show what we've done */
RepaintGraphWindow();
/* simulate */
sprintf(&gapstring[0], "%i", gap);
CmdLosim(gapstring);
} }
static void ChkBitstream(char *str) static void ChkBitstream(char *str)
@ -654,6 +681,9 @@ static void ChkBitstream(char *str)
static void CmdLosim(char *str) static void CmdLosim(char *str)
{ {
int i; int i;
static int gap;
sscanf(str,"%i",&gap);
/* convert to bitstream if necessary */ /* convert to bitstream if necessary */
ChkBitstream(str); ChkBitstream(str);
@ -667,7 +697,7 @@ static void CmdLosim(char *str)
SendCommand(&c); SendCommand(&c);
} }
UsbCommand c={CMD_SIMULATE_TAG_125K, {GraphTraceLen, 0, 0}}; UsbCommand c={CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
SendCommand(&c); SendCommand(&c);
} }
@ -2881,7 +2911,8 @@ static struct {
{"hi15sim", CmdHi15tag, 0, "Fake an ISO15693 tag"}, {"hi15sim", CmdHi15tag, 0, "Fake an ISO15693 tag"},
{"hidsimtag", CmdHIDsimTAG, 0, "<ID> -- HID tag simulator"}, {"hidsimtag", CmdHIDsimTAG, 0, "<ID> -- HID tag simulator"},
{"hisimlisten", CmdHisimlisten, 0, "Get HF samples as fake tag"}, {"hisimlisten", CmdHisimlisten, 0, "Get HF samples as fake tag"},
{"losim", CmdLosim, 0, "Simulate LF tag"}, {"losim", CmdLosim, 0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"},
{"losimman", CmdLosimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
{"losimbidir", CmdLosimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"}, {"losimbidir", CmdLosimBidir, 0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
/* card reading functions */ /* card reading functions */
@ -2923,7 +2954,7 @@ static struct {
void CommandReceived(char *cmd) void CommandReceived(char *cmd)
{ {
int i; int i;
char line[256]; char line[512];
PrintToScrollback("> %s", cmd); PrintToScrollback("> %s", cmd);