mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 04:50:12 -07:00
ADD: finished of the "LF GUARD SIM" command. needs testing.
This commit is contained in:
parent
0d2c590974
commit
07291f87d8
2 changed files with 102 additions and 106 deletions
170
client/cmdlf.c
170
client/cmdlf.c
|
@ -743,94 +743,94 @@ int CmdLFfskSim(const char *Cmd)
|
||||||
// - allow pull data from DemodBuffer
|
// - allow pull data from DemodBuffer
|
||||||
int CmdLFaskSim(const char *Cmd)
|
int CmdLFaskSim(const char *Cmd)
|
||||||
{
|
{
|
||||||
//autodetect clock from Graphbuffer if using demod buffer
|
//autodetect clock from Graphbuffer if using demod buffer
|
||||||
// needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
|
// needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
|
||||||
uint8_t encoding = 1, separator = 0;
|
uint8_t encoding = 1, separator = 0, clk=0, invert=0;
|
||||||
uint8_t clk=0, invert=0;
|
bool errors = FALSE;
|
||||||
bool errors = FALSE;
|
char hexData[32] = {0x00};
|
||||||
char hexData[32] = {0x00};
|
uint8_t data[255]= {0x00}; // store entered hex data
|
||||||
uint8_t data[255]= {0x00}; // store entered hex data
|
int dataLen = 0;
|
||||||
int dataLen = 0;
|
uint8_t cmdp = 0;
|
||||||
uint8_t cmdp = 0;
|
|
||||||
while(param_getchar(Cmd, cmdp) != 0x00)
|
while(param_getchar(Cmd, cmdp) != 0x00) {
|
||||||
{
|
switch(param_getchar(Cmd, cmdp)) {
|
||||||
switch(param_getchar(Cmd, cmdp))
|
case 'h': return usage_lf_simask();
|
||||||
{
|
case 'i':
|
||||||
case 'h':
|
invert = 1;
|
||||||
return usage_lf_simask();
|
cmdp++;
|
||||||
case 'i':
|
break;
|
||||||
invert = 1;
|
case 'c':
|
||||||
cmdp++;
|
errors |= param_getdec(Cmd,cmdp+1,&clk);
|
||||||
break;
|
cmdp+=2;
|
||||||
case 'c':
|
break;
|
||||||
errors |= param_getdec(Cmd,cmdp+1,&clk);
|
case 'b':
|
||||||
cmdp+=2;
|
encoding=2; //biphase
|
||||||
break;
|
cmdp++;
|
||||||
case 'b':
|
break;
|
||||||
encoding=2; //biphase
|
case 'm':
|
||||||
cmdp++;
|
encoding=1;
|
||||||
break;
|
cmdp++;
|
||||||
case 'm':
|
break;
|
||||||
encoding=1;
|
case 'r':
|
||||||
cmdp++;
|
encoding=0;
|
||||||
break;
|
cmdp++;
|
||||||
case 'r':
|
break;
|
||||||
encoding=0;
|
case 's':
|
||||||
cmdp++;
|
separator=1;
|
||||||
break;
|
cmdp++;
|
||||||
case 's':
|
break;
|
||||||
separator=1;
|
case 'd':
|
||||||
cmdp++;
|
dataLen = param_getstr(Cmd, cmdp+1, hexData);
|
||||||
break;
|
if (dataLen==0)
|
||||||
case 'd':
|
errors = TRUE;
|
||||||
dataLen = param_getstr(Cmd, cmdp+1, hexData);
|
else
|
||||||
if (dataLen==0) {
|
dataLen = hextobinarray((char *)data, hexData);
|
||||||
errors=TRUE;
|
|
||||||
} else {
|
if (dataLen==0) errors = TRUE;
|
||||||
dataLen = hextobinarray((char *)data, hexData);
|
if (errors) PrintAndLog ("Error getting hex data, datalen: %d", dataLen);
|
||||||
}
|
cmdp+=2;
|
||||||
if (dataLen==0) errors=TRUE;
|
break;
|
||||||
if (errors) PrintAndLog ("Error getting hex data, datalen: %d",dataLen);
|
default:
|
||||||
cmdp+=2;
|
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
break;
|
errors = TRUE;
|
||||||
default:
|
break;
|
||||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
}
|
||||||
errors = TRUE;
|
if(errors) break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
if(errors) break;
|
if(cmdp == 0 && DemodBufferLen == 0)
|
||||||
}
|
errors = TRUE;// No args
|
||||||
if(cmdp == 0 && DemodBufferLen == 0)
|
|
||||||
{
|
|
||||||
errors = TRUE;// No args
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
//Validations
|
||||||
if(errors)
|
if(errors) return usage_lf_simask();
|
||||||
{
|
|
||||||
return usage_lf_simask();
|
if (dataLen == 0){ //using DemodBuffer
|
||||||
}
|
if (clk == 0)
|
||||||
if (dataLen == 0){ //using DemodBuffer
|
clk = GetAskClock("0", false, false);
|
||||||
if (clk == 0) clk = GetAskClock("0", false, false);
|
} else {
|
||||||
} else {
|
setDemodBuf(data, dataLen, 0);
|
||||||
setDemodBuf(data, dataLen, 0);
|
}
|
||||||
}
|
if (clk == 0) clk = 64;
|
||||||
if (clk == 0) clk = 64;
|
if (encoding == 0) clk = clk/2; //askraw needs to double the clock speed
|
||||||
if (encoding == 0) clk = clk/2; //askraw needs to double the clock speed
|
|
||||||
uint16_t arg1, arg2;
|
size_t size = DemodBufferLen;
|
||||||
size_t size=DemodBufferLen;
|
|
||||||
arg1 = clk << 8 | encoding;
|
if (size > USB_CMD_DATA_SIZE) {
|
||||||
arg2 = invert << 8 | separator;
|
PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size, USB_CMD_DATA_SIZE);
|
||||||
if (size > USB_CMD_DATA_SIZE) {
|
size = USB_CMD_DATA_SIZE;
|
||||||
PrintAndLog("DemodBuffer too long for current implementation - length: %d - max: %d", size, USB_CMD_DATA_SIZE);
|
}
|
||||||
size = USB_CMD_DATA_SIZE;
|
|
||||||
}
|
PrintAndLog("preparing to sim ask data: %d bits", size);
|
||||||
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
|
||||||
PrintAndLog("preparing to sim ask data: %d bits", size);
|
uint16_t arg1, arg2;
|
||||||
memcpy(c.d.asBytes, DemodBuffer, size);
|
arg1 = clk << 8 | encoding;
|
||||||
|
arg2 = invert << 8 | separator;
|
||||||
|
|
||||||
|
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
||||||
|
memcpy(c.d.asBytes, DemodBuffer, size);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// by marshmellow - sim psk data given carrier, clock, invert
|
// by marshmellow - sim psk data given carrier, clock, invert
|
||||||
|
|
|
@ -91,12 +91,6 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
|
||||||
|
|
||||||
if (g_debugMode) printf(" WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes)));
|
if (g_debugMode) printf(" WIE | %s\n", sprint_hex(rawbytes, sizeof(rawbytes)));
|
||||||
|
|
||||||
// NIBBLE_SWAP (works on all data)
|
|
||||||
// for (i = 0; i < 12; ++i)
|
|
||||||
// rawbytes[i] = SWAP_NIBBLE( rawbytes[i] );
|
|
||||||
|
|
||||||
// printf("SWAP | %s\n", sprint_hex(rawbytes, sizeof(rawbytes)));
|
|
||||||
|
|
||||||
// XOR (only works on wiegand stuff)
|
// XOR (only works on wiegand stuff)
|
||||||
for (i = 1; i < 12; ++i)
|
for (i = 1; i < 12; ++i)
|
||||||
rawbytes[i] ^= xorKey ;
|
rawbytes[i] ^= xorKey ;
|
||||||
|
@ -111,7 +105,7 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
|
||||||
if (g_debugMode) printf(" Raw | %s\n", sprint_bin(pre, 64) );
|
if (g_debugMode) printf(" Raw | %s\n", sprint_bin(pre, 64) );
|
||||||
|
|
||||||
// add spacer bit 0 every 4 bits, starting with index 0,
|
// add spacer bit 0 every 4 bits, starting with index 0,
|
||||||
// 12 bytes, 24 nibbles. 24+1 extra bites. 3bytes. Ie 9bytes | 1byte xorkey, 8bytes rawdata (64bits, should be enough for a 40bit wiegand)
|
// 12 bytes, 24 nibbles. 24+1 extra bites. 3bytes. ie 9bytes | 1byte xorkey, 8bytes rawdata (64bits, should be enough for a 40bit wiegand)
|
||||||
addParity(pre, guardBits+6, 64, 5, 3);
|
addParity(pre, guardBits+6, 64, 5, 3);
|
||||||
|
|
||||||
// preamble
|
// preamble
|
||||||
|
@ -121,10 +115,6 @@ int GetGuardBits(uint32_t fc, uint32_t cn, uint8_t *guardBits) {
|
||||||
guardBits[3] = 1;
|
guardBits[3] = 1;
|
||||||
guardBits[4] = 1;
|
guardBits[4] = 1;
|
||||||
guardBits[5] = 0;
|
guardBits[5] = 0;
|
||||||
/* 6 B
|
|
||||||
PRE | 0110 1101 0101 1110 0001 1101 1101 0111 1101011011010110110101101101011
|
|
||||||
FIN | 111110 0 0110 0 1101 0 0101 0 1110 0 0001 0 1101 0 1101 0 0111 0 110100110011010011001101001100110100110000000000
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (g_debugMode) printf(" FIN | %s\n", sprint_bin(guardBits, 96) );
|
if (g_debugMode) printf(" FIN | %s\n", sprint_bin(guardBits, 96) );
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -194,16 +184,11 @@ int CmdGuardSim(const char *Cmd) {
|
||||||
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim();
|
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_sim();
|
||||||
|
|
||||||
uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
|
uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
|
||||||
|
uint8_t clock = 64, encoding = 2, separator = 0, invert = 0;
|
||||||
|
|
||||||
uint8_t bs[96];
|
uint8_t bs[96];
|
||||||
size_t size = sizeof(bs);
|
memset(bs, 0x00, sizeof(bs));
|
||||||
memset(bs, 0x00, size);
|
|
||||||
|
|
||||||
// Pyramid uses: ASK Biphase, clk: 32, invert: 0
|
|
||||||
uint64_t arg1, arg2;
|
|
||||||
arg1 = (10 << 8) + 8;
|
|
||||||
arg2 = 32 | 0;
|
|
||||||
|
|
||||||
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_sim();
|
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_guard_sim();
|
||||||
|
|
||||||
facilitycode = (fc & 0x000000FF);
|
facilitycode = (fc & 0x000000FF);
|
||||||
|
@ -215,9 +200,20 @@ int CmdGuardSim(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLog("Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
|
PrintAndLog("Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
|
||||||
|
|
||||||
|
// Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase)
|
||||||
|
uint64_t arg1, arg2;
|
||||||
|
arg1 = (clock << 8) | encoding;
|
||||||
|
arg2 = (invert << 8) | separator;
|
||||||
|
|
||||||
|
uint8_t rawbytes[12];
|
||||||
|
size_t size = sizeof(rawbytes);
|
||||||
|
for (uint8_t i=0; i < size; ++i){
|
||||||
|
rawbytes[i] = bytebits_to_byte( bs + (i*8), 8);
|
||||||
|
}
|
||||||
|
|
||||||
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
||||||
memcpy(c.d.asBytes, bs, size);
|
memcpy(c.d.asBytes, rawbytes, size );
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -227,7 +223,7 @@ static command_t CommandTable[] = {
|
||||||
{"help", CmdHelp, 1, "This help"},
|
{"help", CmdHelp, 1, "This help"},
|
||||||
{"read", CmdGuardRead, 0, "Attempt to read and extract tag data"},
|
{"read", CmdGuardRead, 0, "Attempt to read and extract tag data"},
|
||||||
{"clone", CmdGuardClone, 0, "<Facility-Code> <Card Number> clone Guardall tag"},
|
{"clone", CmdGuardClone, 0, "<Facility-Code> <Card Number> clone Guardall tag"},
|
||||||
// {"sim", CmdGuardSim, 0, "<Facility-Code> <Card Number> simulate Guardall tag"},
|
{"sim", CmdGuardSim, 0, "<Facility-Code> <Card Number> simulate Guardall tag"},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue