mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-19 21:03:23 -07:00
Merge pull request #149 from marshmellow42/T55xx_tests
Add lf viking, lf demod/clock detection improvements
This commit is contained in:
commit
2c7928874b
22 changed files with 1251 additions and 692 deletions
|
@ -98,6 +98,7 @@ CMDSRCS = nonce2key/crapto1.c\
|
|||
cmdmain.c \
|
||||
cmdlft55xx.c \
|
||||
cmdlfpcf7931.c\
|
||||
cmdlfviking.c\
|
||||
pm3_binlib.c\
|
||||
scripting.c\
|
||||
cmdscript.c\
|
||||
|
|
102
client/cmddata.c
102
client/cmddata.c
|
@ -58,11 +58,12 @@ int CmdSetDebugMode(const char *Cmd)
|
|||
}
|
||||
|
||||
int usage_data_printdemodbuf(){
|
||||
PrintAndLog("Usage: data printdemodbuffer x o <offset>");
|
||||
PrintAndLog("Usage: data printdemodbuffer x o <offset> l <length>");
|
||||
PrintAndLog("Options: ");
|
||||
PrintAndLog(" h This help");
|
||||
PrintAndLog(" x output in hex (omit for binary output)");
|
||||
PrintAndLog(" o <offset> enter offset in # of bits");
|
||||
PrintAndLog(" l <length> enter length to print in # of bits or hex characters respectively");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -87,7 +88,8 @@ int CmdPrintDemodBuff(const char *Cmd)
|
|||
char hex[512]={0x00};
|
||||
bool hexMode = false;
|
||||
bool errors = false;
|
||||
uint8_t offset = 0;
|
||||
uint32_t offset = 0; //could be size_t but no param_get16...
|
||||
uint32_t length = 512;
|
||||
char cmdp = 0;
|
||||
while(param_getchar(Cmd, cmdp) != 0x00)
|
||||
{
|
||||
|
@ -103,10 +105,16 @@ int CmdPrintDemodBuff(const char *Cmd)
|
|||
break;
|
||||
case 'o':
|
||||
case 'O':
|
||||
offset = param_get8(Cmd, cmdp+1);
|
||||
offset = param_get32ex(Cmd, cmdp+1, 0, 10);
|
||||
if (!offset) errors = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
length = param_get32ex(Cmd, cmdp+1, 512, 10);
|
||||
if (!length) errors = true;
|
||||
cmdp += 2;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
|
@ -116,18 +124,17 @@ int CmdPrintDemodBuff(const char *Cmd)
|
|||
}
|
||||
//Validations
|
||||
if(errors) return usage_data_printdemodbuf();
|
||||
|
||||
int numBits = (DemodBufferLen-offset) & 0x7FC; //make sure we don't exceed our string
|
||||
length = (length > (DemodBufferLen-offset)) ? DemodBufferLen-offset : length;
|
||||
int numBits = (length) & 0x00FFC; //make sure we don't exceed our string
|
||||
|
||||
if (hexMode){
|
||||
char *buf = (char *) (DemodBuffer + offset);
|
||||
numBits = (numBits > sizeof(hex)) ? sizeof(hex) : numBits;
|
||||
numBits = binarraytohex(hex, buf, numBits);
|
||||
if (numBits==0) return 0;
|
||||
PrintAndLog("DemodBuffer: %s",hex);
|
||||
} else {
|
||||
//setDemodBuf(DemodBuffer, DemodBufferLen-offset, offset);
|
||||
char *bin = sprint_bin_break(DemodBuffer+offset,numBits,16);
|
||||
PrintAndLog("DemodBuffer:\n%s",bin);
|
||||
PrintAndLog("DemodBuffer:\n%s", sprint_bin_break(DemodBuffer+offset,numBits,16));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -315,7 +322,7 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType)
|
|||
char amp = param_getchar(Cmd, 0);
|
||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
||||
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &);
|
||||
if (!maxLen) maxLen = 512*64;
|
||||
if (!maxLen) maxLen = BIGBUF_SIZE;
|
||||
if (invert != 0 && invert != 1) {
|
||||
PrintAndLog("Invalid argument: %s", Cmd);
|
||||
return 0;
|
||||
|
@ -646,7 +653,7 @@ int CmdVikingDemod(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
size_t size = DemodBufferLen;
|
||||
//call lfdemod.c demod for gProxII
|
||||
//call lfdemod.c demod for Viking
|
||||
int ans = VikingDemod_AM(DemodBuffer, &size);
|
||||
if (ans < 0) {
|
||||
if (g_debugMode) PrintAndLog("Error Viking_Demod %d", ans);
|
||||
|
@ -656,7 +663,7 @@ int CmdVikingDemod(const char *Cmd)
|
|||
uint32_t raw1 = bytebits_to_byte(DemodBuffer+ans, 32);
|
||||
uint32_t raw2 = bytebits_to_byte(DemodBuffer+ans+32, 32);
|
||||
uint32_t cardid = bytebits_to_byte(DemodBuffer+ans+24, 32);
|
||||
uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8);
|
||||
uint8_t checksum = bytebits_to_byte(DemodBuffer+ans+32+24, 8);
|
||||
PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, checksum);
|
||||
PrintAndLog("Raw: %08X%08X", raw1,raw2);
|
||||
setDemodBuf(DemodBuffer+ans, 64, 0);
|
||||
|
@ -936,14 +943,14 @@ char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
|
|||
int FSKrawDemod(const char *Cmd, bool verbose)
|
||||
{
|
||||
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||
//set defaults
|
||||
int rfLen = 0;
|
||||
int invert = 0;
|
||||
int fchigh = 0;
|
||||
int fclow = 0;
|
||||
uint8_t rfLen, invert, fchigh, fclow;
|
||||
|
||||
//set defaults
|
||||
//set options from parameters entered with the command
|
||||
sscanf(Cmd, "%i %i %i %i", &rfLen, &invert, &fchigh, &fclow);
|
||||
rfLen = param_get8ex(Cmd, 0, 0, 10);
|
||||
invert = param_get8ex(Cmd, 1, 0, 10);
|
||||
fchigh = param_get8ex(Cmd, 2, 0, 10);
|
||||
fclow = param_get8ex(Cmd, 3, 0, 10);
|
||||
|
||||
if (strlen(Cmd)>0 && strlen(Cmd)<=2) {
|
||||
if (rfLen==1){
|
||||
|
@ -957,34 +964,34 @@ int FSKrawDemod(const char *Cmd, bool verbose)
|
|||
if (BitLen==0) return 0;
|
||||
//get field clock lengths
|
||||
uint16_t fcs=0;
|
||||
if (fchigh==0 || fclow == 0){
|
||||
if (!fchigh || !fclow) {
|
||||
fcs = countFC(BitStream, BitLen, 1);
|
||||
if (fcs==0){
|
||||
fchigh=10;
|
||||
fclow=8;
|
||||
}else{
|
||||
fchigh = (fcs >> 8) & 0xFF;
|
||||
fclow = fcs & 0xFF;
|
||||
if (!fcs) {
|
||||
fchigh = 10;
|
||||
fclow = 8;
|
||||
} else {
|
||||
fchigh = (fcs >> 8) & 0x00FF;
|
||||
fclow = fcs & 0x00FF;
|
||||
}
|
||||
}
|
||||
//get bit clock length
|
||||
if (rfLen==0){
|
||||
if (!rfLen){
|
||||
rfLen = detectFSKClk(BitStream, BitLen, fchigh, fclow);
|
||||
if (rfLen == 0) rfLen = 50;
|
||||
if (!rfLen) rfLen = 50;
|
||||
}
|
||||
int size = fskdemod(BitStream,BitLen,(uint8_t)rfLen,(uint8_t)invert,(uint8_t)fchigh,(uint8_t)fclow);
|
||||
if (size>0){
|
||||
int size = fskdemod(BitStream, BitLen, rfLen, invert, fchigh, fclow);
|
||||
if (size > 0){
|
||||
setDemodBuf(BitStream,size,0);
|
||||
|
||||
// Now output the bitstream to the scrollback by line of 16 bits
|
||||
if (verbose || g_debugMode) {
|
||||
PrintAndLog("\nUsing Clock:%d, invert:%d, fchigh:%d, fclow:%d", rfLen, invert, fchigh, fclow);
|
||||
PrintAndLog("\nUsing Clock:%u, invert:%u, fchigh:%u, fclow:%u", rfLen, invert, fchigh, fclow);
|
||||
PrintAndLog("%s decoded bitstream:",GetFSKType(fchigh,fclow,invert));
|
||||
printDemodBuff();
|
||||
}
|
||||
|
||||
return 1;
|
||||
} else{
|
||||
} else {
|
||||
if (g_debugMode) PrintAndLog("no FSK data found");
|
||||
}
|
||||
return 0;
|
||||
|
@ -1481,6 +1488,17 @@ int CmdFSKdemodPyramid(const char *Cmd)
|
|||
// NATIONAL CODE, ICAR database
|
||||
// COUNTRY CODE (ISO3166) or http://cms.abvma.ca/uploads/ManufacturersISOsandCountryCodes.pdf
|
||||
// FLAG (animal/non-animal)
|
||||
/*
|
||||
38 IDbits
|
||||
10 country code
|
||||
1 extra app bit
|
||||
14 reserved bits
|
||||
1 animal bit
|
||||
16 ccitt CRC chksum over 64bit ID CODE.
|
||||
24 appli bits.
|
||||
|
||||
-- sample: 985121004515220 [ 37FF65B88EF94 ]
|
||||
*/
|
||||
int CmdFDXBdemodBI(const char *Cmd){
|
||||
|
||||
int invert = 1;
|
||||
|
@ -1507,6 +1525,10 @@ int CmdFDXBdemodBI(const char *Cmd){
|
|||
if (g_debugMode) PrintAndLog("Error FDXBDemod , no startmarker found :: %d",preambleIndex);
|
||||
return 0;
|
||||
}
|
||||
if (size != 128) {
|
||||
if (g_debugMode) PrintAndLog("Error incorrect data length found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
setDemodBuf(BitStream, 128, preambleIndex);
|
||||
|
||||
|
@ -1576,6 +1598,9 @@ int PSKDemod(const char *Cmd, bool verbose)
|
|||
//invalid carrier
|
||||
return 0;
|
||||
}
|
||||
if (g_debugMode){
|
||||
PrintAndLog("Carrier: rf/%d",carrier);
|
||||
}
|
||||
int errCnt=0;
|
||||
errCnt = pskRawDemod(BitStream, &BitLen, &clk, &invert);
|
||||
if (errCnt > maxErr){
|
||||
|
@ -1617,7 +1642,7 @@ int CmdIndalaDecode(const char *Cmd)
|
|||
uint8_t invert=0;
|
||||
size_t size = DemodBufferLen;
|
||||
size_t startIdx = indala26decode(DemodBuffer, &size, &invert);
|
||||
if (startIdx < 1) {
|
||||
if (startIdx < 1 || size > 224) {
|
||||
if (g_debugMode==1)
|
||||
PrintAndLog("Error2: %d",ans);
|
||||
return -1;
|
||||
|
@ -1633,7 +1658,7 @@ int CmdIndalaDecode(const char *Cmd)
|
|||
uid1=bytebits_to_byte(DemodBuffer,32);
|
||||
uid2=bytebits_to_byte(DemodBuffer+32,32);
|
||||
if (DemodBufferLen==64) {
|
||||
PrintAndLog("Indala UID=%s (%x%08x)", sprint_bin(DemodBuffer,DemodBufferLen), uid1, uid2);
|
||||
PrintAndLog("Indala UID=%s (%x%08x)", sprint_bin_break(DemodBuffer,DemodBufferLen,16), uid1, uid2);
|
||||
} else {
|
||||
uid3=bytebits_to_byte(DemodBuffer+64,32);
|
||||
uid4=bytebits_to_byte(DemodBuffer+96,32);
|
||||
|
@ -1641,7 +1666,7 @@ int CmdIndalaDecode(const char *Cmd)
|
|||
uid6=bytebits_to_byte(DemodBuffer+160,32);
|
||||
uid7=bytebits_to_byte(DemodBuffer+192,32);
|
||||
PrintAndLog("Indala UID=%s (%x%08x%08x%08x%08x%08x%08x)",
|
||||
sprint_bin(DemodBuffer,DemodBufferLen), uid1, uid2, uid3, uid4, uid5, uid6, uid7);
|
||||
sprint_bin_break(DemodBuffer,DemodBufferLen,16), uid1, uid2, uid3, uid4, uid5, uid6, uid7);
|
||||
}
|
||||
if (g_debugMode){
|
||||
PrintAndLog("DEBUG: printing demodbuffer:");
|
||||
|
@ -1711,7 +1736,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
|
|||
size_t BitLen = getFromGraphBuf(BitStream);
|
||||
if (BitLen==0) return 0;
|
||||
int errCnt=0;
|
||||
errCnt = nrzRawDemod(BitStream, &BitLen, &clk, &invert, maxErr);
|
||||
errCnt = nrzRawDemod(BitStream, &BitLen, &clk, &invert);
|
||||
if (errCnt > maxErr){
|
||||
if (g_debugMode) PrintAndLog("Too many errors found, clk: %d, invert: %d, numbits: %d, errCnt: %d",clk,invert,BitLen,errCnt);
|
||||
return 0;
|
||||
|
@ -1957,10 +1982,7 @@ int getSamples(const char *Cmd, bool silent)
|
|||
|
||||
int n = strtol(Cmd, NULL, 0);
|
||||
|
||||
if (n == 0)
|
||||
n = sizeof(got);
|
||||
|
||||
if (n > sizeof(got))
|
||||
if (n == 0 || n > sizeof(got))
|
||||
n = sizeof(got);
|
||||
|
||||
PrintAndLog("Reading %d bytes from device memory\n", n);
|
||||
|
@ -2370,14 +2392,14 @@ static command_t CommandTable[] =
|
|||
{"manrawdecode", Cmdmandecoderaw, 1, "[invert] [maxErr] -- Manchester decode binary stream in DemodBuffer"},
|
||||
{"norm", CmdNorm, 1, "Normalize max/min to +/-128"},
|
||||
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
||||
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> -- print the data in the DemodBuffer - 'x' for hex output"},
|
||||
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> [l] <length> -- print the data in the DemodBuffer - 'x' for hex output"},
|
||||
{"pskindalademod", CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Demodulate an indala tag (PSK1) from GraphBuffer (args optional)"},
|
||||
{"psknexwatchdemod",CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) (PSK1) from GraphBuffer"},
|
||||
{"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"},
|
||||
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window (GraphBuffer)"},
|
||||
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
|
||||
{"scale", CmdScale, 1, "<int> -- Set cursor display scale"},
|
||||
{"setdebugmode", CmdSetDebugMode, 1, "<0|1> -- Turn on or off Debugging Mode for demods"},
|
||||
{"setdebugmode", CmdSetDebugMode, 1, "<0|1|2> -- Turn on or off Debugging Level for lf demods"},
|
||||
{"shiftgraphzero", CmdGraphShiftZero, 1, "<shift> -- Shift 0 for Graphed wave + or - shift value"},
|
||||
{"dirthreshold", CmdDirectionalThreshold, 1, "<thres up> <thres down> -- Max rising higher up-thres/ Min falling lower down-thres, keep rest as prev."},
|
||||
{"tune", CmdTuneSamples, 0, "Get hw tune samples for graph window"},
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "cmdlft55xx.h"
|
||||
#include "cmdlfpcf7931.h"
|
||||
#include "cmdlfio.h"
|
||||
#include "cmdlfviking.h"
|
||||
#include "lfdemod.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
@ -124,7 +125,7 @@ int CmdFlexdemod(const char *Cmd)
|
|||
}
|
||||
}
|
||||
|
||||
#define LONG_WAIT 100
|
||||
#define LONG_WAIT 100
|
||||
int start;
|
||||
for (start = 0; start < GraphTraceLen - LONG_WAIT; start++) {
|
||||
int first = GraphBuffer[start];
|
||||
|
@ -206,10 +207,13 @@ int CmdIndalaDemod(const char *Cmd)
|
|||
uint8_t rawbits[4096];
|
||||
int rawbit = 0;
|
||||
int worst = 0, worstPos = 0;
|
||||
// PrintAndLog("Expecting a bit less than %d raw bits", GraphTraceLen / 32);
|
||||
// PrintAndLog("Expecting a bit less than %d raw bits", GraphTraceLen / 32);
|
||||
|
||||
// loop through raw signal - since we know it is psk1 rf/32 fc/2 skip every other value (+=2)
|
||||
for (i = 0; i < GraphTraceLen-1; i += 2) {
|
||||
count += 1;
|
||||
if ((GraphBuffer[i] > GraphBuffer[i + 1]) && (state != 1)) {
|
||||
// appears redundant - marshmellow
|
||||
if (state == 0) {
|
||||
for (j = 0; j < count - 8; j += 16) {
|
||||
rawbits[rawbit++] = 0;
|
||||
|
@ -222,6 +226,7 @@ int CmdIndalaDemod(const char *Cmd)
|
|||
state = 1;
|
||||
count = 0;
|
||||
} else if ((GraphBuffer[i] < GraphBuffer[i + 1]) && (state != 0)) {
|
||||
//appears redundant
|
||||
if (state == 1) {
|
||||
for (j = 0; j < count - 8; j += 16) {
|
||||
rawbits[rawbit++] = 1;
|
||||
|
@ -419,6 +424,7 @@ int CmdIndalaClone(const char *Cmd)
|
|||
c.arg[1] = uid2;
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -541,6 +547,7 @@ int CmdLFSetConfig(const char *Cmd)
|
|||
//Averaging is a flag on high-bit of arg[1]
|
||||
UsbCommand c = {CMD_SET_LF_SAMPLING_CONFIG};
|
||||
memcpy(c.d.asBytes,&config,sizeof(sample_config));
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -557,6 +564,7 @@ int CmdLFRead(const char *Cmd)
|
|||
if (param_getchar(Cmd, cmdp) == 's') arg1 = true; //suppress print
|
||||
//And ship it to device
|
||||
UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {arg1,0,0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
//WaitForResponse(CMD_ACK,NULL);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
|
||||
|
@ -576,6 +584,7 @@ int CmdLFSnoop(const char *Cmd)
|
|||
}
|
||||
|
||||
UsbCommand c = {CMD_LF_SNOOP_RAW_ADC_SAMPLES};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
return 0;
|
||||
|
@ -622,6 +631,7 @@ int CmdLFSim(const char *Cmd)
|
|||
printf("\n");
|
||||
PrintAndLog("Starting to simulate");
|
||||
UsbCommand c = {CMD_SIMULATE_TAG_125K, {GraphTraceLen, gap, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -771,6 +781,7 @@ int CmdLFfskSim(const char *Cmd)
|
|||
UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
|
||||
|
||||
memcpy(c.d.asBytes, DemodBuffer, size);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -864,6 +875,7 @@ int CmdLFaskSim(const char *Cmd)
|
|||
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
||||
PrintAndLog("preparing to sim ask data: %d bits", size);
|
||||
memcpy(c.d.asBytes, DemodBuffer, size);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -971,6 +983,7 @@ int CmdLFpskSim(const char *Cmd)
|
|||
UsbCommand c = {CMD_PSK_SIM_TAG, {arg1, arg2, size}};
|
||||
PrintAndLog("DEBUG: Sending DemodBuffer Length: %d", size);
|
||||
memcpy(c.d.asBytes, DemodBuffer, size);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
return 0;
|
||||
|
@ -1124,13 +1137,6 @@ int CmdLFfind(const char *Cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
//add psk and indala
|
||||
ans=CmdIndalaDecode("");
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nValid Indala ID Found!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ans=CmdAskEM410xDemod("");
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nValid EM410x ID Found!");
|
||||
|
@ -1161,6 +1167,12 @@ int CmdLFfind(const char *Cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
ans=CmdIndalaDecode("");
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nValid Indala ID Found!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ans=CmdPSKNexWatch("");
|
||||
if (ans>0) {
|
||||
PrintAndLog("\nValid NexWatch ID Found!");
|
||||
|
@ -1202,14 +1214,15 @@ int CmdLFfind(const char *Cmd)
|
|||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"awid", CmdLFAWID, 1, "{ AWID RFIDs... }"},
|
||||
{"em4x", CmdLFEM4X, 1, "{ EM4X RFIDs... }"},
|
||||
{"hid", CmdLFHID, 1, "{ HID RFIDs... }"},
|
||||
{"awid", CmdLFAWID, 1, "{ AWID RFIDs... }"},
|
||||
{"em4x", CmdLFEM4X, 1, "{ EM4X RFIDs... }"},
|
||||
{"hid", CmdLFHID, 1, "{ HID RFIDs... }"},
|
||||
{"hitag", CmdLFHitag, 1, "{ Hitag tags and transponders... }"},
|
||||
{"io", CmdLFIO, 1, "{ ioProx tags... }"},
|
||||
{"io", CmdLFIO, 1, "{ ioProx tags... }"},
|
||||
{"pcf7931", CmdLFPCF7931, 1, "{ PCF7931 RFIDs... }"},
|
||||
{"t55xx", CmdLFT55XX, 1, "{ T55xx RFIDs... }"},
|
||||
{"ti", CmdLFTI, 1, "{ TI RFIDs... }"},
|
||||
{"t55xx", CmdLFT55XX, 1, "{ T55xx RFIDs... }"},
|
||||
{"ti", CmdLFTI, 1, "{ TI RFIDs... }"},
|
||||
{"viking", CmdLFViking, 1, "{ Viking tags... }"},
|
||||
{"cmdread", CmdLFCommandRead, 0, "<d period> <z period> <o period> <c command> ['H'] -- Modulate LF reader field to send command before read (all periods in microseconds) (option 'H' for 134)"},
|
||||
{"config", CmdLFSetConfig, 0, "Set config for LF sampling, bit/sample, decimation, frequency"},
|
||||
{"flexdemod", CmdFlexdemod, 1, "Demodulate samples for FlexPass"},
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
#include "cmdparser.h" // CmdsParse, CmdsHelp
|
||||
#include "cmdlfawid.h" // AWID function declarations
|
||||
#include "lfdemod.h" // parityTest
|
||||
#include "util.h" // weigandparity
|
||||
#include "protocols.h" // for T55xx config register definitions
|
||||
#include "cmdmain.h"
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
int usage_lf_awid_fskdemod(void) {
|
||||
PrintAndLog("Enables AWID26 compatible reader mode printing details of scanned AWID26 tags.");
|
||||
|
@ -26,11 +28,11 @@ int usage_lf_awid_fskdemod(void) {
|
|||
PrintAndLog("If the ['1'] option is provided, reader mode is exited after reading a single AWID26 card.");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: lf awid fskdemod ['1']");
|
||||
PrintAndLog(" Options : ");
|
||||
PrintAndLog("Options : ");
|
||||
PrintAndLog(" 1 : (optional) stop after reading a single card");
|
||||
PrintAndLog("");
|
||||
PrintAndLog(" sample : lf awid fskdemod");
|
||||
PrintAndLog(" : lf awid fskdemod 1");
|
||||
PrintAndLog("Samples : lf awid fskdemod");
|
||||
PrintAndLog(" : lf awid fskdemod 1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -40,11 +42,11 @@ int usage_lf_awid_sim(void) {
|
|||
PrintAndLog("Per AWID26 format, the facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: lf awid sim <Facility-Code> <Card-Number>");
|
||||
PrintAndLog(" Options : ");
|
||||
PrintAndLog("Options : ");
|
||||
PrintAndLog(" <Facility-Code> : 8-bit value representing the AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value representing the AWID card number");
|
||||
PrintAndLog("");
|
||||
PrintAndLog(" sample : lf awid sim 224 1337");
|
||||
PrintAndLog("Sample : lf awid sim 224 1337");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -54,133 +56,91 @@ int usage_lf_awid_clone(void) {
|
|||
PrintAndLog("Per AWID26 format, the facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: lf awid clone <Facility-Code> <Card-Number>");
|
||||
PrintAndLog(" Options : ");
|
||||
PrintAndLog("Options : ");
|
||||
PrintAndLog(" <Facility-Code> : 8-bit value representing the AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value representing the AWID card number");
|
||||
PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip");
|
||||
PrintAndLog("");
|
||||
PrintAndLog(" sample : lf awid clone 224 1337");
|
||||
PrintAndLog("Sample : lf awid clone 224 1337");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdAWIDDemodFSK(const char *Cmd)
|
||||
{
|
||||
int CmdAWIDDemodFSK(const char *Cmd) {
|
||||
int findone=0;
|
||||
if(Cmd[0]=='1') findone=1;
|
||||
if (Cmd[0]=='h' || Cmd[0] == 'H') return usage_lf_awid_fskdemod();
|
||||
UsbCommand c={CMD_AWID_DEMOD_FSK};
|
||||
c.arg[0]=findone;
|
||||
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_awid_fskdemod();
|
||||
if (Cmd[0] == '1') findone = 1;
|
||||
|
||||
UsbCommand c = {CMD_AWID_DEMOD_FSK, {findone, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getAWIDBits(unsigned int fc, unsigned int cn, uint8_t *AWIDBits)
|
||||
{
|
||||
int i;
|
||||
uint32_t fcode=(fc & 0x000000FF), cnum=(cn & 0x0000FFFF), uBits=0;
|
||||
if (fcode != fc)
|
||||
PrintAndLog("NOTE: Facility code truncated for AWID26 format (8-bit facility code)");
|
||||
if (cnum!=cn)
|
||||
PrintAndLog("NOTE: Card number was truncated for AWID26 format (16-bit card number)");
|
||||
//refactored by marshmellow
|
||||
int getAWIDBits(uint32_t fc, uint32_t cn, uint8_t *AWIDBits) {
|
||||
uint8_t pre[66];
|
||||
memset(pre, 0, sizeof(pre));
|
||||
AWIDBits[7]=1;
|
||||
num_to_bytebits(26, 8, pre);
|
||||
|
||||
AWIDBits[0] = 0x01; // 6-bit Preamble with 2 parity bits
|
||||
AWIDBits[1] = 0x1D; // First byte from card format (26-bit) plus parity bits
|
||||
AWIDBits[2] = 0x80; // Set the next two bits as 0b10 to finish card format
|
||||
uBits = (fcode<<4) + (cnum>>12);
|
||||
if (!parityTest(uBits,12,0))
|
||||
AWIDBits[2] |= (1<<5); // If not already even parity, set bit to make even
|
||||
uBits = AWIDBits[2]>>5;
|
||||
if (!parityTest(uBits, 3, 1))
|
||||
AWIDBits[2] |= (1<<4);
|
||||
uBits = fcode>>5; // first 3 bits of facility-code
|
||||
AWIDBits[2] += (uBits<<1);
|
||||
if (!parityTest(uBits, 3, 1))
|
||||
AWIDBits[2]++; // Set parity bit to make odd parity
|
||||
uBits = (fcode & 0x1C)>>2;
|
||||
AWIDBits[3] = 0;
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[3] |= (1<<4);
|
||||
AWIDBits[3] += (uBits<<5);
|
||||
uBits = ((fcode & 0x3)<<1) + ((cnum & 0x8000)>>15); // Grab/shift 2 LSBs from facility code and add shifted MSB from cardnum
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[3]++; // Set LSB for parity
|
||||
AWIDBits[3]+= (uBits<<1);
|
||||
uBits = (cnum & 0x7000)>>12;
|
||||
AWIDBits[4] = uBits<<5;
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[4] |= (1<<4);
|
||||
uBits = (cnum & 0x0E00)>>9;
|
||||
AWIDBits[4] += (uBits<<1);
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[4]++; // Set LSB for parity
|
||||
uBits = (cnum & 0x1C0)>>6; // Next bits from card number
|
||||
AWIDBits[5]=(uBits<<5);
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[5] |= (1<<4); // Set odd parity bit as needed
|
||||
uBits = (cnum & 0x38)>>3;
|
||||
AWIDBits[5]+= (uBits<<1);
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[5]++; // Set odd parity bit as needed
|
||||
uBits = (cnum & 0x7); // Last three bits from card number!
|
||||
AWIDBits[6] = (uBits<<5);
|
||||
if (!parityTest(uBits,3,1))
|
||||
AWIDBits[6] |= (1<<4);
|
||||
uBits = (cnum & 0x0FFF);
|
||||
if (!parityTest(uBits,12,1))
|
||||
AWIDBits[6] |= (1<<3);
|
||||
else
|
||||
AWIDBits[6]++;
|
||||
for (i = 7; i<12; i++)
|
||||
AWIDBits[i]=0x11;
|
||||
uint8_t wiegand[24];
|
||||
num_to_bytebits(fc, 8, wiegand);
|
||||
num_to_bytebits(cn, 16, wiegand+8);
|
||||
|
||||
wiegand_add_parity(pre+8, wiegand, 24);
|
||||
|
||||
size_t bitLen = addParity(pre, AWIDBits+8, 66, 4, 1);
|
||||
if (bitLen != 88) return 0;
|
||||
//for (uint8_t i = 0; i<3; i++){
|
||||
// PrintAndLog("DEBUG: %08X", bytebits_to_byte(AWIDBits+(32*i),32));
|
||||
//}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CmdAWIDSim(const char *Cmd)
|
||||
{
|
||||
uint32_t fcode = 0, cnum = 0, fc=0, cn=0, i=0;
|
||||
uint8_t *BS, BitStream[12];
|
||||
int CmdAWIDSim(const char *Cmd) {
|
||||
uint32_t fcode = 0, cnum = 0, fc=0, cn=0;
|
||||
uint8_t BitStream[96];
|
||||
uint8_t *bs = BitStream;
|
||||
size_t size = sizeof(BitStream);
|
||||
memset(bs, 0, size);
|
||||
|
||||
uint64_t arg1 = (10<<8) + 8; // fcHigh = 10, fcLow = 8
|
||||
uint64_t arg2 = 50; // clk RF/50 invert=0
|
||||
BS = BitStream;
|
||||
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) {
|
||||
return usage_lf_awid_sim();
|
||||
}
|
||||
|
||||
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_awid_sim();
|
||||
|
||||
fcode = (fc & 0x000000FF);
|
||||
cnum = (cn & 0x0000FFFF);
|
||||
|
||||
if (fc != fcode) PrintAndLog("Facility-Code (%u) truncated to 8-bits: %u",fc,fcode);
|
||||
if (cn != cnum) PrintAndLog("Card number (%u) truncated to 16-bits: %u",cn,cnum);
|
||||
|
||||
fcode=(fc & 0x000000FF);
|
||||
cnum=(cn & 0x0000FFFF);
|
||||
if (fc!=fcode)
|
||||
PrintAndLog("Facility-Code (%u) truncated to 8-bits: %u",fc,fcode);
|
||||
if (cn!=cnum)
|
||||
PrintAndLog("Card number (%u) truncated to 16-bits: %u",cn,cnum);
|
||||
PrintAndLog("Emulating AWID26 -- FC: %u; CN: %u\n",fcode,cnum);
|
||||
PrintAndLog("Press pm3-button to abort simulation or run another command");
|
||||
|
||||
if (!getAWIDBits(fc, cn, bs)) {
|
||||
PrintAndLog("Error with tag bitstream generation.");
|
||||
return 1;
|
||||
}
|
||||
// AWID uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0
|
||||
if (getAWIDBits(fc, cn, BS)) {
|
||||
PrintAndLog("Running 'lf simfsk c 50 H 10 L 8 d %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
|
||||
BS[0],BS[1],BS[2],BS[3],BS[4],BS[5],BS[6],
|
||||
BS[7],BS[8],BS[9],BS[10],BS[11]);
|
||||
} else
|
||||
PrintAndLog("Error with tag bitstream generation.");
|
||||
UsbCommand c;
|
||||
c.cmd = CMD_FSK_SIM_TAG;
|
||||
c.arg[0] = arg1; // fcHigh<<8 + fcLow
|
||||
c.arg[1] = arg2; // Inversion and clk setting
|
||||
c.arg[2] = 96; // Bitstream length: 96-bits == 12 bytes
|
||||
for (i=0; i < 96; i++)
|
||||
c.d.asBytes[i] = (BS[i/8] & (1<<(7-(i%8))))?1:0;
|
||||
UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
|
||||
memcpy(c.d.asBytes, bs, size);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdAWIDClone(const char *Cmd)
|
||||
{
|
||||
uint32_t fc=0,cn=0,blocks[4] = {0x00107060, 0, 0, 0x11111111}, i=0;
|
||||
uint8_t BitStream[12];
|
||||
uint8_t *BS=BitStream;
|
||||
UsbCommand c, resp;
|
||||
int CmdAWIDClone(const char *Cmd) {
|
||||
uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0};
|
||||
uint32_t fc=0,cn=0;
|
||||
uint8_t BitStream[96];
|
||||
uint8_t *bs=BitStream;
|
||||
memset(bs,0,sizeof(BitStream));
|
||||
|
||||
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) {
|
||||
return usage_lf_awid_clone();
|
||||
}
|
||||
if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_awid_clone();
|
||||
|
||||
if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
|
||||
blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT;
|
||||
|
||||
if ((fc & 0xFF) != fc) {
|
||||
fc &= 0xFF;
|
||||
|
@ -190,48 +150,58 @@ int CmdAWIDClone(const char *Cmd)
|
|||
cn &= 0xFFFF;
|
||||
PrintAndLog("Card Number Truncated to 16-bits (AWID26): %u", cn);
|
||||
}
|
||||
if (getAWIDBits(fc,cn,BS)) {
|
||||
PrintAndLog("Preparing to clone AWID26 to T55x7 with FC: %u, CN: %u (Raw: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x)",
|
||||
fc,cn, BS[0],BS[1],BS[2],BS[3],BS[4],BS[5],BS[6],BS[7],BS[8],BS[9],BS[10],BS[11]);
|
||||
blocks[1] = (BS[0]<<24) + (BS[1]<<16) + (BS[2]<<8) + (BS[3]);
|
||||
blocks[2] = (BS[4]<<24) + (BS[5]<<16) + (BS[6]<<8) + (BS[7]);
|
||||
PrintAndLog("Block 0: 0x%08x", blocks[0]);
|
||||
PrintAndLog("Block 1: 0x%08x", blocks[1]);
|
||||
PrintAndLog("Block 2: 0x%08x", blocks[2]);
|
||||
PrintAndLog("Block 3: 0x%08x", blocks[3]);
|
||||
for (i=0; i<4; i++) {
|
||||
c.cmd = CMD_T55XX_WRITE_BLOCK;
|
||||
c.arg[0] = blocks[i];
|
||||
c.arg[1] = i;
|
||||
c.arg[2] = 0;
|
||||
SendCommand(&c);
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
|
||||
PrintAndLog("Error occurred, device did not respond during write operation.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( !getAWIDBits(fc, cn, bs)) {
|
||||
PrintAndLog("Error with tag bitstream generation.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
blocks[1] = bytebits_to_byte(bs,32);
|
||||
blocks[2] = bytebits_to_byte(bs+32,32);
|
||||
blocks[3] = bytebits_to_byte(bs+64,32);
|
||||
|
||||
PrintAndLog("Preparing to clone AWID26 to T55x7 with FC: %u, CN: %u",
|
||||
fc, cn);
|
||||
PrintAndLog("Blk | Data ");
|
||||
PrintAndLog("----+------------");
|
||||
PrintAndLog(" 00 | 0x%08x", blocks[0]);
|
||||
PrintAndLog(" 01 | 0x%08x", blocks[1]);
|
||||
PrintAndLog(" 02 | 0x%08x", blocks[2]);
|
||||
PrintAndLog(" 03 | 0x%08x", blocks[3]);
|
||||
|
||||
UsbCommand resp;
|
||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
|
||||
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
c.cmd = CMD_T55XX_WRITE_BLOCK;
|
||||
c.arg[0] = blocks[i];
|
||||
c.arg[1] = i;
|
||||
c.arg[2] = 0;
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
|
||||
PrintAndLog("Error occurred, device did not respond during write operation.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"fskdemod", CmdAWIDDemodFSK, 0, "['1'] Realtime AWID FSK demodulator (option '1' for one tag only)"},
|
||||
{"sim", CmdAWIDSim, 0, "<Facility-Code> <Card Number> -- AWID tag simulator"},
|
||||
{"clone", CmdAWIDClone, 0, "<Facility-Code> <Card Number> -- Clone AWID to T55x7 (tag must be in range of antenna)"},
|
||||
{"clone", CmdAWIDClone, 0, "<Facility-Code> <Card Number> <Q5> -- Clone AWID to T55x7 (tag must be in range of antenna)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdLFAWID(const char *Cmd)
|
||||
{
|
||||
int CmdLFAWID(const char *Cmd) {
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -67,9 +67,9 @@ int CmdIOClone(const char *Cmd)
|
|||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
//{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
|
||||
//{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
|
||||
{"fskdemod", CmdIODemodFSK, 0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
|
||||
{"clone", CmdIOClone, 0, "Clone ioProx Tag"},
|
||||
{"clone", CmdIOClone, 0, "Clone ioProx Tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -26,12 +26,14 @@
|
|||
#include "../common/iso14443crc.h"
|
||||
#include "cmdhf14a.h"
|
||||
|
||||
#define CONFIGURATION_BLOCK 0x00
|
||||
#define TRACE_BLOCK 0x01
|
||||
#define T55x7_CONFIGURATION_BLOCK 0x00
|
||||
#define T55x7_PAGE0 0x00
|
||||
#define T55x7_PAGE1 0x01
|
||||
#define T55x7_PWD 0x00000010
|
||||
#define REGULAR_READ_MODE_BLOCK 0xFF
|
||||
|
||||
// Default configuration
|
||||
t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00};
|
||||
t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };
|
||||
|
||||
t55xx_conf_block_t Get_t55xx_Config(){
|
||||
return config;
|
||||
|
@ -41,13 +43,14 @@ void Set_t55xx_Config(t55xx_conf_block_t conf){
|
|||
}
|
||||
|
||||
int usage_t55xx_config(){
|
||||
PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
|
||||
PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h This help");
|
||||
PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");
|
||||
PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");
|
||||
PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
|
||||
PrintAndLog(" i [1] Invert data signal, defaults to normal");
|
||||
PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
|
||||
PrintAndLog(" i [1] Invert data signal, defaults to normal");
|
||||
PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
|
||||
PrintAndLog(" Q5 Set as Q5(T5555) chip instead of T55x7");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Examples:");
|
||||
PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
|
||||
|
@ -123,13 +126,15 @@ int usage_t55xx_dump(){
|
|||
return 0;
|
||||
}
|
||||
int usage_t55xx_detect(){
|
||||
PrintAndLog("Usage: lf t55xx detect [1]");
|
||||
PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
|
||||
PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
|
||||
PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Examples:");
|
||||
PrintAndLog(" lf t55xx detect");
|
||||
PrintAndLog(" lf t55xx detect 1");
|
||||
PrintAndLog(" lf t55xx detect p 11223344");
|
||||
PrintAndLog("");
|
||||
return 0;
|
||||
}
|
||||
|
@ -144,9 +149,32 @@ int usage_t55xx_wakup(){
|
|||
PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
|
||||
return 0;
|
||||
}
|
||||
int usage_t55xx_bruteforce(){
|
||||
PrintAndLog("This command uses A) bruteforce to scan a number range");
|
||||
PrintAndLog(" B) a dictionary attack");
|
||||
PrintAndLog("Usage: lf t55xx bruteforce <start password> <end password> [i <*.dic>]");
|
||||
PrintAndLog(" password must be 4 bytes (8 hex symbols)");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h - this help");
|
||||
PrintAndLog(" <start_pwd> - 4 byte hex value to start pwd search at");
|
||||
PrintAndLog(" <end_pwd> - 4 byte hex value to end pwd search at");
|
||||
PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Examples:");
|
||||
PrintAndLog(" lf t55xx bruteforce aaaaaaaa bbbbbbbb");
|
||||
PrintAndLog(" lf t55xx bruteforce i default_pwd.dic");
|
||||
PrintAndLog("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
void printT5xxHeader(uint8_t page){
|
||||
PrintAndLog("Reading Page %d:", page);
|
||||
PrintAndLog("blk | hex data | binary");
|
||||
PrintAndLog("----+----------+---------------------------------");
|
||||
}
|
||||
|
||||
int CmdT55xxSetConfig(const char *Cmd) {
|
||||
|
||||
uint8_t offset = 0;
|
||||
|
@ -155,6 +183,7 @@ int CmdT55xxSetConfig(const char *Cmd) {
|
|||
uint8_t bitRate = 0;
|
||||
uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};
|
||||
uint8_t cmdp = 0;
|
||||
config.Q5 = FALSE;
|
||||
bool errors = FALSE;
|
||||
while(param_getchar(Cmd, cmdp) != 0x00 && !errors)
|
||||
{
|
||||
|
@ -227,6 +256,11 @@ int CmdT55xxSetConfig(const char *Cmd) {
|
|||
config.offset = offset;
|
||||
cmdp+=2;
|
||||
break;
|
||||
case 'Q':
|
||||
case 'q':
|
||||
config.Q5 = TRUE;
|
||||
cmdp++;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = TRUE;
|
||||
|
@ -249,7 +283,7 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32
|
|||
if ( usepwd ) {
|
||||
// try reading the config block and verify that PWD bit is set before doing this!
|
||||
if ( !override ) {
|
||||
if ( !AquireData(0, CONFIGURATION_BLOCK, false, 0 ) ) return 0;
|
||||
if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;
|
||||
if ( !tryDetectModulation() ) {
|
||||
PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
|
||||
return 0;
|
||||
|
@ -317,8 +351,8 @@ int CmdT55xxReadBlock(const char *Cmd) {
|
|||
PrintAndLog("Block must be between 0 and 7");
|
||||
return 0;
|
||||
}
|
||||
PrintAndLog("Reading Page %d:", page1);
|
||||
PrintAndLog("blk | hex data | binary");
|
||||
|
||||
printT5xxHeader(page1);
|
||||
return T55xxReadBlock(block, page1, usepwd, override, password);
|
||||
}
|
||||
|
||||
|
@ -346,18 +380,28 @@ bool DecodeT55xxBlock(){
|
|||
ans = FSKrawDemod(cmdStr, FALSE);
|
||||
break;
|
||||
case DEMOD_ASK:
|
||||
snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
ans = ASKDemod(cmdStr, FALSE, FALSE, 1);
|
||||
break;
|
||||
case DEMOD_PSK1:
|
||||
snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
|
||||
save_restoreGB(1);
|
||||
CmdLtrim("160");
|
||||
snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );
|
||||
ans = PSKDemod(cmdStr, FALSE);
|
||||
//undo trim samples
|
||||
save_restoreGB(0);
|
||||
break;
|
||||
case DEMOD_PSK2: //inverted won't affect this
|
||||
case DEMOD_PSK3: //not fully implemented
|
||||
snprintf(cmdStr, sizeof(buf),"%d 0 1", bitRate[config.bitrate] );
|
||||
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
|
||||
save_restoreGB(1);
|
||||
CmdLtrim("160");
|
||||
snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );
|
||||
ans = PSKDemod(cmdStr, FALSE);
|
||||
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||
//undo trim samples
|
||||
save_restoreGB(0);
|
||||
break;
|
||||
case DEMOD_NRZ:
|
||||
snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
|
@ -365,7 +409,7 @@ bool DecodeT55xxBlock(){
|
|||
break;
|
||||
case DEMOD_BI:
|
||||
case DEMOD_BIa:
|
||||
snprintf(cmdStr, sizeof(buf),"0 %d %d 0", bitRate[config.bitrate], config.inverted );
|
||||
snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );
|
||||
ans = ASKbiphaseDemod(cmdStr, FALSE);
|
||||
break;
|
||||
default:
|
||||
|
@ -375,15 +419,41 @@ bool DecodeT55xxBlock(){
|
|||
}
|
||||
|
||||
int CmdT55xxDetect(const char *Cmd){
|
||||
bool errors = FALSE;
|
||||
bool useGB = FALSE;
|
||||
bool usepwd = FALSE;
|
||||
uint32_t password = 0;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')
|
||||
return usage_t55xx_detect();
|
||||
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||
switch(param_getchar(Cmd, cmdp)) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
return usage_t55xx_detect();
|
||||
case 'p':
|
||||
case 'P':
|
||||
password = param_get32ex(Cmd, cmdp+1, 0, 16);
|
||||
usepwd = TRUE;
|
||||
cmdp += 2;
|
||||
break;
|
||||
case '1':
|
||||
// use Graphbuffer data
|
||||
useGB = TRUE;
|
||||
cmdp++;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (errors) return usage_t55xx_detect();
|
||||
|
||||
if (strlen(Cmd)==0)
|
||||
if ( !AquireData(0, CONFIGURATION_BLOCK, false, 0) )
|
||||
if ( !useGB) {
|
||||
if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if ( !tryDetectModulation() )
|
||||
PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
|
||||
|
||||
|
@ -396,21 +466,21 @@ bool tryDetectModulation(){
|
|||
t55xx_conf_block_t tests[15];
|
||||
int bitRate=0;
|
||||
uint8_t fc1 = 0, fc2 = 0, clk=0;
|
||||
save_restoreGB(1);
|
||||
|
||||
if (GetFskClock("", FALSE, FALSE)){
|
||||
fskClocks(&fc1, &fc2, &clk, FALSE);
|
||||
if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)){
|
||||
if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
|
||||
tests[hits].modulation = DEMOD_FSK;
|
||||
if (fc1==8 && fc2 == 5)
|
||||
tests[hits].modulation = DEMOD_FSK1a;
|
||||
else if (fc1==10 && fc2 == 8)
|
||||
else if (fc1==10 && fc2 == 8)
|
||||
tests[hits].modulation = DEMOD_FSK2;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
|
||||
++hits;
|
||||
}
|
||||
if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)) {
|
||||
if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_FSK;
|
||||
if (fc1 == 8 && fc2 == 5)
|
||||
tests[hits].modulation = DEMOD_FSK1;
|
||||
|
@ -425,28 +495,28 @@ bool tryDetectModulation(){
|
|||
} else {
|
||||
clk = GetAskClock("", FALSE, FALSE);
|
||||
if (clk>0) {
|
||||
if ( ASKDemod("0 0 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {
|
||||
if ( ASKDemod("0 0 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_ASK;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
|
||||
++hits;
|
||||
}
|
||||
if ( ASKDemod("0 1 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {
|
||||
if ( ASKDemod("0 1 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_ASK;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = TRUE;
|
||||
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
|
||||
++hits;
|
||||
}
|
||||
if ( ASKbiphaseDemod("0 0 0 0", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate) ) {
|
||||
if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {
|
||||
tests[hits].modulation = DEMOD_BI;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
|
||||
++hits;
|
||||
}
|
||||
if ( ASKbiphaseDemod("0 0 1 0", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate) ) {
|
||||
if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {
|
||||
tests[hits].modulation = DEMOD_BIa;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = TRUE;
|
||||
|
@ -455,10 +525,10 @@ bool tryDetectModulation(){
|
|||
}
|
||||
}
|
||||
//undo trim from ask
|
||||
save_restoreGB(0);
|
||||
//save_restoreGB(0);
|
||||
clk = GetNrzClock("", FALSE, FALSE);
|
||||
if (clk>0) {
|
||||
if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {
|
||||
if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_NRZ;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
|
@ -466,7 +536,7 @@ bool tryDetectModulation(){
|
|||
++hits;
|
||||
}
|
||||
|
||||
if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {
|
||||
if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_NRZ;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = TRUE;
|
||||
|
@ -475,18 +545,20 @@ bool tryDetectModulation(){
|
|||
}
|
||||
}
|
||||
|
||||
//undo trim from nrz
|
||||
save_restoreGB(0);
|
||||
// allow undo
|
||||
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
|
||||
save_restoreGB(1);
|
||||
CmdLtrim("160");
|
||||
clk = GetPskClock("", FALSE, FALSE);
|
||||
if (clk>0) {
|
||||
if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {
|
||||
if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_PSK1;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
|
||||
++hits;
|
||||
}
|
||||
if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {
|
||||
if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {
|
||||
tests[hits].modulation = DEMOD_PSK1;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = TRUE;
|
||||
|
@ -494,9 +566,9 @@ bool tryDetectModulation(){
|
|||
++hits;
|
||||
}
|
||||
// PSK2 - needs a call to psk1TOpsk2.
|
||||
if ( PSKDemod("0 0 1", FALSE)) {
|
||||
if ( PSKDemod("0 0 6", FALSE)) {
|
||||
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||
if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate)){
|
||||
if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
|
||||
tests[hits].modulation = DEMOD_PSK2;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
|
@ -505,9 +577,9 @@ bool tryDetectModulation(){
|
|||
}
|
||||
} // inverse waves does not affect this demod
|
||||
// PSK3 - needs a call to psk1TOpsk2.
|
||||
if ( PSKDemod("0 0 1", FALSE)) {
|
||||
if ( PSKDemod("0 0 6", FALSE)) {
|
||||
psk1TOpsk2(DemodBuffer, DemodBufferLen);
|
||||
if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate)){
|
||||
if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){
|
||||
tests[hits].modulation = DEMOD_PSK3;
|
||||
tests[hits].bitrate = bitRate;
|
||||
tests[hits].inverted = FALSE;
|
||||
|
@ -516,7 +588,9 @@ bool tryDetectModulation(){
|
|||
}
|
||||
} // inverse waves does not affect this demod
|
||||
}
|
||||
}
|
||||
//undo trim samples
|
||||
save_restoreGB(0);
|
||||
}
|
||||
if ( hits == 1) {
|
||||
config.modulation = tests[0].modulation;
|
||||
config.bitrate = tests[0].bitrate;
|
||||
|
@ -569,37 +643,28 @@ bool testModulation(uint8_t mode, uint8_t modread){
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
bool testBitRate(uint8_t readRate, uint8_t mod){
|
||||
uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};
|
||||
uint8_t detRate = 0;
|
||||
switch( mod ){
|
||||
bool testQ5Modulation(uint8_t mode, uint8_t modread){
|
||||
switch( mode ){
|
||||
case DEMOD_FSK:
|
||||
case DEMOD_FSK1:
|
||||
case DEMOD_FSK1a:
|
||||
case DEMOD_FSK2:
|
||||
case DEMOD_FSK2a:
|
||||
detRate = GetFskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate)
|
||||
return TRUE;
|
||||
if (modread >= 4 && modread <= 5) return TRUE;
|
||||
break;
|
||||
case DEMOD_ASK:
|
||||
case DEMOD_BI:
|
||||
case DEMOD_BIa:
|
||||
detRate = GetAskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate)
|
||||
return TRUE;
|
||||
if (modread == 0) return TRUE;
|
||||
break;
|
||||
case DEMOD_PSK1:
|
||||
if (modread == 1) return TRUE;
|
||||
break;
|
||||
case DEMOD_PSK2:
|
||||
if (modread == 2) return TRUE;
|
||||
break;
|
||||
case DEMOD_PSK3:
|
||||
detRate = GetPskClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate)
|
||||
return TRUE;
|
||||
if (modread == 3) return TRUE;
|
||||
break;
|
||||
case DEMOD_NRZ:
|
||||
detRate = GetNrzClock("",FALSE, FALSE);
|
||||
if (expected[readRate] == detRate)
|
||||
return TRUE;
|
||||
if (modread == 7) return TRUE;
|
||||
break;
|
||||
case DEMOD_BI:
|
||||
if (modread == 6) return TRUE;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
|
@ -607,13 +672,60 @@ bool testBitRate(uint8_t readRate, uint8_t mod){
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate){
|
||||
bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){
|
||||
|
||||
if ( DemodBufferLen < 64 ) return FALSE;
|
||||
uint8_t si = 0;
|
||||
for (uint8_t idx = 0; idx < 64; idx++){
|
||||
for (uint8_t idx = 28; idx < 64; idx++){
|
||||
si = idx;
|
||||
if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;
|
||||
if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;
|
||||
|
||||
uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
|
||||
uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8;
|
||||
// 2nibble must be zeroed.
|
||||
if (safer != 0x6) continue;
|
||||
if ( resv > 0x00) continue;
|
||||
//uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
//uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
si += 1+1;
|
||||
int bitRate = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5; //bit rate
|
||||
if (bitRate > 128 || bitRate < 8) continue;
|
||||
|
||||
//uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
//uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
//uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr
|
||||
//uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
si += 1+1+2+1;
|
||||
uint8_t modread = PackBits(si, 3, DemodBuffer); si += 3;
|
||||
uint8_t maxBlk = PackBits(si, 3, DemodBuffer); si += 3;
|
||||
//uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
if (maxBlk == 0) continue;
|
||||
//test modulation
|
||||
if (!testQ5Modulation(mode, modread)) continue;
|
||||
if (bitRate != clk) continue;
|
||||
*fndBitRate = bitRate;
|
||||
*offset = idx;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool testBitRate(uint8_t readRate, uint8_t clk){
|
||||
uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};
|
||||
if (expected[readRate] == clk)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){
|
||||
|
||||
if ( DemodBufferLen < 64 ) return FALSE;
|
||||
uint8_t si = 0;
|
||||
for (uint8_t idx = 28; idx < 64; idx++){
|
||||
si = idx;
|
||||
if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;
|
||||
|
||||
uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
|
||||
uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
|
||||
|
@ -622,7 +734,7 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate){
|
|||
if ( resv > 0x00) continue;
|
||||
|
||||
uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate
|
||||
int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate
|
||||
int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate
|
||||
if (bitRate > 7) continue;
|
||||
uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode
|
||||
uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1;
|
||||
|
@ -638,9 +750,14 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate){
|
|||
}
|
||||
//test modulation
|
||||
if (!testModulation(mode, modread)) continue;
|
||||
if (!testBitRate(bitRate, mode)) continue;
|
||||
if (!testBitRate(bitRate, clk)) continue;
|
||||
*fndBitRate = bitRate;
|
||||
*offset = idx;
|
||||
*Q5 = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
if (testQ5(mode, offset, fndBitRate, clk)) {
|
||||
*Q5 = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -664,6 +781,7 @@ void printT55xxBlock(const char *blockNum){
|
|||
bits[i - config.offset]=DemodBuffer[i];
|
||||
|
||||
blockData = PackBits(0, 32, bits);
|
||||
|
||||
PrintAndLog(" %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));
|
||||
}
|
||||
|
||||
|
@ -687,6 +805,7 @@ int special(const char *Cmd) {
|
|||
}
|
||||
|
||||
int printConfiguration( t55xx_conf_block_t b){
|
||||
PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");
|
||||
PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );
|
||||
PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );
|
||||
PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );
|
||||
|
@ -728,8 +847,8 @@ int CmdT55xxWakeUp(const char *Cmd) {
|
|||
|
||||
int CmdT55xxWriteBlock(const char *Cmd) {
|
||||
uint8_t block = 0xFF; //default to invalid block
|
||||
uint32_t data = 0xFFFFFFFF; //default to blank Block
|
||||
uint32_t password = 0xFFFFFFFF; //default to blank Block 7
|
||||
uint32_t data = 0; //default to blank Block
|
||||
uint32_t password = 0; //default to blank Block 7
|
||||
bool usepwd = false;
|
||||
bool page1 = false;
|
||||
bool gotdata = false;
|
||||
|
@ -778,13 +897,15 @@ int CmdT55xxWriteBlock(const char *Cmd) {
|
|||
UsbCommand resp;
|
||||
c.d.asBytes[0] = (page1) ? 0x2 : 0;
|
||||
|
||||
PrintAndLog("Writing to page: %d block: %d data : 0x%08X", page1, block, data);
|
||||
char pwdStr[16] = {0};
|
||||
snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);
|
||||
|
||||
PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "" );
|
||||
|
||||
//Password mode
|
||||
if (usepwd) {
|
||||
c.arg[2] = password;
|
||||
c.d.asBytes[0] |= 0x1;
|
||||
PrintAndLog("pwd : 0x%08X", password);
|
||||
}
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
@ -803,7 +924,7 @@ int CmdT55xxReadTrace(const char *Cmd) {
|
|||
return usage_t55xx_trace();
|
||||
|
||||
if (strlen(Cmd)==0)
|
||||
if ( !AquireData( TRACE_BLOCK, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )
|
||||
if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )
|
||||
return 0;
|
||||
|
||||
if (!DecodeT55xxBlock()) return 0;
|
||||
|
@ -835,11 +956,11 @@ int CmdT55xxReadTrace(const char *Cmd) {
|
|||
else
|
||||
year += 2010;
|
||||
|
||||
if (config.Q5) PrintAndLog("*** Warning *** Info read off a Q5 will not work as expected");
|
||||
if ( acl != 0xE0 ) {
|
||||
PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("");
|
||||
PrintAndLog("-- T55xx Trace Information ----------------------------------");
|
||||
PrintAndLog("-------------------------------------------------------------");
|
||||
|
@ -892,7 +1013,7 @@ int CmdT55xxInfo(const char *Cmd){
|
|||
return usage_t55xx_info();
|
||||
|
||||
if (strlen(Cmd)==0)
|
||||
if ( !AquireData( 0, CONFIGURATION_BLOCK, pwdmode, password ) )
|
||||
if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )
|
||||
return 1;
|
||||
|
||||
if (!DecodeT55xxBlock()) return 1;
|
||||
|
@ -916,7 +1037,7 @@ int CmdT55xxInfo(const char *Cmd){
|
|||
uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;
|
||||
|
||||
if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
|
||||
PrintAndLog("-------------------------------------------------------------");
|
||||
|
@ -956,32 +1077,21 @@ int CmdT55xxDump(const char *Cmd){
|
|||
override = true;
|
||||
}
|
||||
|
||||
PrintAndLog("Reading Page 0:");
|
||||
PrintAndLog("blk | hex data | binary");
|
||||
for ( uint8_t i = 0; i <8; ++i){
|
||||
printT5xxHeader(0);
|
||||
for ( uint8_t i = 0; i <8; ++i)
|
||||
T55xxReadBlock(i, 0, usepwd, override, password);
|
||||
/*memset(s,0,sizeof(s));
|
||||
if ( hasPwd ) {
|
||||
if ( override ) {
|
||||
sprintf(s,"b %d p %02x%02x%02x%02x o", i, pwd[0],pwd[1],pwd[2],pwd[3]);
|
||||
} else {
|
||||
sprintf(s,"b %d p %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);
|
||||
}
|
||||
} else {
|
||||
sprintf(s,"b %d", i);
|
||||
}
|
||||
CmdT55xxReadBlock(s);*/
|
||||
}
|
||||
PrintAndLog("Reading Page 1:");
|
||||
PrintAndLog("blk | hex data | binary");
|
||||
for ( uint8_t i = 0; i<4; i++){
|
||||
|
||||
printT5xxHeader(1);
|
||||
for ( uint8_t i = 0; i<4; i++)
|
||||
T55xxReadBlock(i, 1, usepwd, override, password);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
|
||||
// arg0 bitmodes:
|
||||
// bit0 = pwdmode
|
||||
// bit1 = page to read from
|
||||
uint8_t arg0 = (page<<1) | pwdmode;
|
||||
UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};
|
||||
|
||||
|
@ -1189,30 +1299,192 @@ int CmdResetRead(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
|
||||
{"detect", CmdT55xxDetect, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
|
||||
{"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
|
||||
{"resetread",CmdResetRead, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},
|
||||
{"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
|
||||
{"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
|
||||
{"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
|
||||
{"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
|
||||
{"special", special, 0, "Show block changes with 64 different offsets"},
|
||||
{"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},
|
||||
int CmdT55xxWipe(const char *Cmd) {
|
||||
char writeData[20] = {0};
|
||||
char *ptrData = writeData;
|
||||
|
||||
PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");
|
||||
|
||||
//try with the default password to reset block 0 (with a pwd should work even if pwd bit not set)
|
||||
snprintf(ptrData,sizeof(writeData),"b 0 d 00088040 p 0");
|
||||
|
||||
if (!CmdT55xxWriteBlock(ptrData))
|
||||
PrintAndLog("Error writing blk 0");
|
||||
|
||||
for (uint8_t blk = 1; blk<8; blk++) {
|
||||
snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);
|
||||
if (!CmdT55xxWriteBlock(ptrData))
|
||||
PrintAndLog("Error writing blk %d", blk);
|
||||
|
||||
memset(writeData, 0x00, sizeof(writeData));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdT55xxBruteForce(const char *Cmd) {
|
||||
|
||||
// load a default pwd file.
|
||||
char buf[9];
|
||||
char filename[FILE_PATH_SIZE]={0};
|
||||
int keycnt = 0;
|
||||
uint8_t stKeyBlock = 20;
|
||||
uint8_t *keyBlock = NULL, *p;
|
||||
keyBlock = calloc(stKeyBlock, 6);
|
||||
if (keyBlock == NULL) return 1;
|
||||
|
||||
uint32_t start_password = 0x00000000; //start password
|
||||
uint32_t end_password = 0xFFFFFFFF; //end password
|
||||
bool found = false;
|
||||
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();
|
||||
|
||||
if (cmdp == 'i' || cmdp == 'I') {
|
||||
|
||||
int len = strlen(Cmd+2);
|
||||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||
memcpy(filename, Cmd+2, len);
|
||||
|
||||
FILE * f = fopen( filename , "r");
|
||||
|
||||
if ( !f ) {
|
||||
PrintAndLog("File: %s: not found or locked.", filename);
|
||||
free(keyBlock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while( fgets(buf, sizeof(buf), f) ){
|
||||
if (strlen(buf) < 8 || buf[7] == '\n') continue;
|
||||
|
||||
while (fgetc(f) != '\n' && !feof(f)) ; //goto next line
|
||||
|
||||
//The line start with # is comment, skip
|
||||
if( buf[0]=='#' ) continue;
|
||||
|
||||
if (!isxdigit(buf[0])){
|
||||
PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
buf[8] = 0;
|
||||
|
||||
if ( stKeyBlock - keycnt < 2) {
|
||||
p = realloc(keyBlock, 6*(stKeyBlock+=10));
|
||||
if (!p) {
|
||||
PrintAndLog("Cannot allocate memory for defaultKeys");
|
||||
free(keyBlock);
|
||||
return 2;
|
||||
}
|
||||
keyBlock = p;
|
||||
}
|
||||
memset(keyBlock + 4 * keycnt, 0, 4);
|
||||
num_to_bytes(strtoll(buf, NULL, 16), 4, keyBlock + 4*keycnt);
|
||||
PrintAndLog("chk custom pwd[%2d] %08X", keycnt, bytes_to_num(keyBlock + 4*keycnt, 4));
|
||||
keycnt++;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (keycnt == 0) {
|
||||
PrintAndLog("No keys found in file");
|
||||
return 1;
|
||||
}
|
||||
PrintAndLog("Loaded %d keys", keycnt);
|
||||
|
||||
// loop
|
||||
uint64_t testpwd = 0x00;
|
||||
for (uint16_t c = 0; c < keycnt; ++c ) {
|
||||
|
||||
if (ukbhit()) {
|
||||
getchar();
|
||||
printf("\naborted via keyboard!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
testpwd = bytes_to_num(keyBlock + 4*c, 4);
|
||||
|
||||
PrintAndLog("Testing %08X", testpwd);
|
||||
|
||||
if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {
|
||||
PrintAndLog("Aquireing data from device failed. Quitting");
|
||||
return 0;
|
||||
}
|
||||
|
||||
found = tryDetectModulation();
|
||||
|
||||
if ( found ) {
|
||||
PrintAndLog("Found valid password: [%08X]", testpwd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PrintAndLog("Password NOT found.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try to read Block 7, first :)
|
||||
|
||||
// incremental pwd range search
|
||||
start_password = param_get32ex(Cmd, 0, 0, 16);
|
||||
end_password = param_get32ex(Cmd, 1, 0, 16);
|
||||
|
||||
if ( start_password >= end_password ) return usage_t55xx_bruteforce();
|
||||
|
||||
PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);
|
||||
|
||||
uint32_t i = start_password;
|
||||
|
||||
while ((!found) && (i <= end_password)){
|
||||
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
if (ukbhit()) {
|
||||
getchar();
|
||||
printf("\naborted via keyboard!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {
|
||||
PrintAndLog("Aquireing data from device failed. Quitting");
|
||||
return 0;
|
||||
}
|
||||
found = tryDetectModulation();
|
||||
|
||||
if (found) break;
|
||||
i++;
|
||||
}
|
||||
|
||||
PrintAndLog("");
|
||||
|
||||
if (found)
|
||||
PrintAndLog("Found valid password: [%08x]", i);
|
||||
else
|
||||
PrintAndLog("Password NOT found. Last tried: [%08x]", --i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"bruteforce",CmdT55xxBruteForce,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},
|
||||
{"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
|
||||
{"detect", CmdT55xxDetect, 1, "[1] Try detecting the tag modulation from reading the configuration block."},
|
||||
{"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
|
||||
{"resetread", CmdResetRead, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},
|
||||
{"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
|
||||
{"trace", CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},
|
||||
{"info", CmdT55xxInfo, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
|
||||
{"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
|
||||
{"special", special, 0, "Show block changes with 64 different offsets"},
|
||||
{"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},
|
||||
{"wipe", CmdT55xxWipe, 0, "Wipe a T55xx tag and set defaults (will destroy any data on tag)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdLFT55XX(const char *Cmd)
|
||||
{
|
||||
int CmdLFT55XX(const char *Cmd) {
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,12 +38,14 @@ typedef struct {
|
|||
RF_100 = 0x06,
|
||||
RF_128 = 0x07,
|
||||
} bitrate;
|
||||
bool Q5;
|
||||
} t55xx_conf_block_t;
|
||||
t55xx_conf_block_t Get_t55xx_Config();
|
||||
void Set_t55xx_Config(t55xx_conf_block_t conf);
|
||||
|
||||
|
||||
int CmdLFT55XX(const char *Cmd);
|
||||
int CmdT55xxBruteForce(const char *Cmd);
|
||||
int CmdT55xxSetConfig(const char *Cmd);
|
||||
int CmdT55xxReadBlock(const char *Cmd);
|
||||
int CmdT55xxWriteBlock(const char *Cmd);
|
||||
|
@ -51,6 +53,7 @@ int CmdT55xxReadTrace(const char *Cmd);
|
|||
int CmdT55xxInfo(const char *Cmd);
|
||||
int CmdT55xxDetect(const char *Cmd);
|
||||
int CmdResetRead(const char *Cmd);
|
||||
int CmdT55xxWipe(const char *Cmd);
|
||||
|
||||
char * GetBitRateStr(uint32_t id);
|
||||
char * GetSaferStr(uint32_t id);
|
||||
|
@ -63,7 +66,7 @@ int printConfiguration( t55xx_conf_block_t b);
|
|||
|
||||
bool DecodeT55xxBlock();
|
||||
bool tryDetectModulation();
|
||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate);
|
||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5);
|
||||
int special(const char *Cmd);
|
||||
int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password );
|
||||
|
||||
|
|
127
client/cmdlfviking.c
Normal file
127
client/cmdlfviking.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Low frequency Viking tag commands
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "util.h"
|
||||
#include "graph.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmddata.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmdlf.h"
|
||||
#include "cmdlfviking.h"
|
||||
#include "lfdemod.h"
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
int usage_lf_viking_clone(void) {
|
||||
PrintAndLog("clone a Viking AM tag to a T55x7 tag.");
|
||||
PrintAndLog("Usage: lf viking clone <Card ID - 8 hex digits> <Q5>");
|
||||
PrintAndLog("Options :");
|
||||
PrintAndLog(" <Card Number> : 8 digit hex viking card number");
|
||||
PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample : lf viking clone 1A337 Q5");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usage_lf_viking_sim(void) {
|
||||
PrintAndLog("Enables simulation of viking card with specified card number.");
|
||||
PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
|
||||
PrintAndLog("Per viking format, the card number is 8 digit hex number. Larger values are truncated.");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: lf viking sim <Card-Number>");
|
||||
PrintAndLog("Options :");
|
||||
PrintAndLog(" <Card Number> : 8 digit hex viking card number");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample : lf viking sim 1A337");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t getVikingBits(uint32_t id) {
|
||||
//calc checksum
|
||||
uint8_t checksum = (id>>24) ^ ((id>>16) & 0xFF) ^ ((id>>8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
|
||||
return ((uint64_t)0xF2 << 56) | (id << 8) | checksum;
|
||||
}
|
||||
//by marshmellow
|
||||
//see ASKDemod for what args are accepted
|
||||
int CmdVikingRead(const char *Cmd) {
|
||||
// read lf silently
|
||||
CmdLFRead("s");
|
||||
// get samples silently
|
||||
getSamples("30000",false);
|
||||
// demod and output viking ID
|
||||
return CmdVikingDemod(Cmd);
|
||||
}
|
||||
|
||||
int CmdVikingClone(const char *Cmd) {
|
||||
uint32_t id = 0;
|
||||
uint64_t rawID = 0;
|
||||
bool Q5 = false;
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if (strlen(Cmd) < 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_clone();
|
||||
|
||||
id = param_get32ex(Cmd, 0, 0, 16);
|
||||
if (id == 0) return usage_lf_viking_clone();
|
||||
if (param_getchar(Cmd, 1)=='Q' || param_getchar(Cmd, 1)=='q')
|
||||
Q5 = true;
|
||||
|
||||
rawID = getVikingBits(id);
|
||||
|
||||
UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFF, Q5}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
//check for ACK
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdVikingSim(const char *Cmd) {
|
||||
uint32_t id = 0;
|
||||
uint64_t rawID = 0;
|
||||
uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
|
||||
if (strlen(Cmd) < 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_viking_sim();
|
||||
id = param_get32ex(Cmd, 0, 0, 16);
|
||||
if (id == 0) return usage_lf_viking_sim();
|
||||
|
||||
rawID = getVikingBits(id);
|
||||
|
||||
uint16_t arg1, arg2;
|
||||
size_t size = 64;
|
||||
arg1 = clk << 8 | encoding;
|
||||
arg2 = invert << 8 | separator;
|
||||
|
||||
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
||||
PrintAndLog("preparing to sim ask data: %d bits", size);
|
||||
num_to_bytebits(rawID, 64, c.d.asBytes);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"read", CmdVikingRead, 0, "Attempt to read and Extract tag data"},
|
||||
{"clone", CmdVikingClone, 0, "<8 digit ID number> clone viking tag"},
|
||||
{"sim", CmdVikingSim, 0, "<8 digit ID number> simulate viking tag"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdLFViking(const char *Cmd) {
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
16
client/cmdlfviking.h
Normal file
16
client/cmdlfviking.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Low frequency T55xx commands
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef CMDLFVIKING_H__
|
||||
#define CMDLFVIKING_H__
|
||||
int CmdLFViking(const char *Cmd);
|
||||
int CmdVikingRead(const char *Cmd);
|
||||
int CmdVikingClone(const char *Cmd);
|
||||
int CmdVikingSim(const char *Cmd);
|
||||
#endif
|
||||
|
75
client/default_pwd.dic
Normal file
75
client/default_pwd.dic
Normal file
|
@ -0,0 +1,75 @@
|
|||
# known cloners
|
||||
# ref. http://www.proxmark.org/forum/viewtopic.php?id=2022
|
||||
51243648,
|
||||
000D8787,
|
||||
# Default pwd, simple:
|
||||
00000000,
|
||||
11111111,
|
||||
22222222,
|
||||
33333333,
|
||||
44444444,
|
||||
55555555,
|
||||
66666666,
|
||||
77777777,
|
||||
88888888,
|
||||
99999999,
|
||||
AAAAAAAA,
|
||||
BBBBBBBB,
|
||||
CCCCCCCC,
|
||||
DDDDDDDD,
|
||||
EEEEEEEE,
|
||||
FFFFFFFF,
|
||||
a0a1a2a3,
|
||||
b0b1b2b3,
|
||||
aabbccdd,
|
||||
bbccddee,
|
||||
ccddeeff,
|
||||
00000001,
|
||||
00000002,
|
||||
0000000a,
|
||||
0000000b,
|
||||
01020304,
|
||||
02030405,
|
||||
03040506,
|
||||
04050607,
|
||||
05060708,
|
||||
06070809,
|
||||
0708090A,
|
||||
08090A0B,
|
||||
090A0B0C,
|
||||
0A0B0C0D,
|
||||
0B0C0D0E,
|
||||
0C0D0E0F,
|
||||
01234567,
|
||||
12345678,
|
||||
10000000,
|
||||
20000000,
|
||||
30000000,
|
||||
40000000,
|
||||
50000000,
|
||||
60000000,
|
||||
70000000,
|
||||
80000000,
|
||||
90000000,
|
||||
A0000000,
|
||||
B0000000,
|
||||
C0000000,
|
||||
D0000000,
|
||||
E0000000,
|
||||
F0000000,
|
||||
10101010,
|
||||
01010101,
|
||||
11223344,
|
||||
22334455,
|
||||
33445566,
|
||||
44556677,
|
||||
55667788,
|
||||
66778899,
|
||||
778899AA,
|
||||
8899AABB,
|
||||
99AABBCC,
|
||||
AABBCCDD,
|
||||
BBCCDDEE,
|
||||
CCDDEEFF,
|
||||
0CB7E7FC, //rfidler?
|
||||
FABADA11, //china?
|
|
@ -85,6 +85,7 @@ typedef struct {
|
|||
#define CMD_ASK_SIM_TAG 0x021F
|
||||
#define CMD_PSK_SIM_TAG 0x0220
|
||||
#define CMD_AWID_DEMOD_FSK 0x0221
|
||||
#define CMD_VIKING_CLONE_TAG 0x0223
|
||||
#define CMD_T55XX_WAKEUP 0x0224
|
||||
|
||||
/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */
|
||||
|
|
|
@ -56,6 +56,7 @@ local _commands = {
|
|||
CMD_ASK_SIM_TAG = 0x021F,
|
||||
CMD_PSK_SIM_TAG = 0x0220,
|
||||
CMD_AWID_DEMOD_FSK = 0x0221,
|
||||
CMD_VIKING_CLONE_TAG = 0x0223,
|
||||
CMD_T55XX_WAKEUP = 0x0224,
|
||||
--/* CMD_SET_ADC_MUX: ext1 is 0 for lopkd, 1 for loraw, 2 for hipkd, 3 for hiraw */
|
||||
|
||||
|
|
|
@ -9,11 +9,13 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "util.h"
|
||||
#define MAX_BIN_BREAK_LENGTH (3072+384+1)
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
int ukbhit(void)
|
||||
{
|
||||
int cnt = 0;
|
||||
|
@ -123,16 +125,30 @@ char *sprint_hex(const uint8_t *data, const size_t len) {
|
|||
}
|
||||
|
||||
char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) {
|
||||
|
||||
int maxLen = ( len > 1020) ? 1020 : len;
|
||||
static char buf[1024];
|
||||
memset(buf, 0x00, 1024);
|
||||
// make sure we don't go beyond our char array memory
|
||||
int max_len;
|
||||
if (breaks==0)
|
||||
max_len = ( len > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len;
|
||||
else
|
||||
max_len = ( len+(len/breaks) > MAX_BIN_BREAK_LENGTH ) ? MAX_BIN_BREAK_LENGTH : len+(len/breaks);
|
||||
|
||||
static char buf[MAX_BIN_BREAK_LENGTH]; // 3072 + end of line characters if broken at 8 bits
|
||||
//clear memory
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
char *tmp = buf;
|
||||
|
||||
for (size_t i=0; i < maxLen; ++i){
|
||||
sprintf(tmp++, "%u", data[i]);
|
||||
if (breaks > 0 && !((i+1) % breaks))
|
||||
size_t in_index = 0;
|
||||
// loop through the out_index to make sure we don't go too far
|
||||
for (size_t out_index=0; out_index < max_len; out_index++) {
|
||||
// set character
|
||||
sprintf(tmp++, "%u", data[in_index]);
|
||||
// check if a line break is needed
|
||||
if ( (breaks > 0) && !((in_index+1) % breaks) && (out_index+1 != max_len) ) {
|
||||
// increment and print line break
|
||||
out_index++;
|
||||
sprintf(tmp++, "%s","\n");
|
||||
}
|
||||
in_index++;
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
@ -160,6 +176,13 @@ uint64_t bytes_to_num(uint8_t* src, size_t len)
|
|||
return num;
|
||||
}
|
||||
|
||||
void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest) {
|
||||
while (len--) {
|
||||
dest[len] = n & 1;
|
||||
n >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// aa,bb,cc,dd,ee,ff,gg,hh, ii,jj,kk,ll,mm,nn,oo,pp
|
||||
// to
|
||||
// hh,gg,ff,ee,dd,cc,bb,aa, pp,oo,nn,mm,ll,kk,jj,ii
|
||||
|
@ -446,7 +469,7 @@ void binarraytobinstring(char *target, char *source, int length)
|
|||
}
|
||||
|
||||
// return parity bit required to match type
|
||||
uint8_t GetParity( char *bits, uint8_t type, int length)
|
||||
uint8_t GetParity( uint8_t *bits, uint8_t type, int length)
|
||||
{
|
||||
int x;
|
||||
|
||||
|
@ -458,7 +481,7 @@ uint8_t GetParity( char *bits, uint8_t type, int length)
|
|||
}
|
||||
|
||||
// add HID parity to binary array: EVEN prefix for 1st half of ID, ODD suffix for 2nd half
|
||||
void wiegand_add_parity(char *target, char *source, char length)
|
||||
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length)
|
||||
{
|
||||
*(target++)= GetParity(source, EVEN, length / 2);
|
||||
memcpy(target, source, length);
|
||||
|
|
|
@ -43,6 +43,7 @@ char * sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t bre
|
|||
|
||||
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
|
||||
uint64_t bytes_to_num(uint8_t* src, size_t len);
|
||||
void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest);
|
||||
char * printBits(size_t const size, void const * const ptr);
|
||||
uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);
|
||||
|
||||
|
@ -62,8 +63,8 @@ int param_getstr(const char *line, int paramnum, char * str);
|
|||
int hextobinstring( char *target, char *source);
|
||||
int binarraytohex( char *target, char *source, int length);
|
||||
void binarraytobinstring(char *target, char *source, int length);
|
||||
uint8_t GetParity( char *string, uint8_t type, int length);
|
||||
void wiegand_add_parity(char *target, char *source, char length);
|
||||
uint8_t GetParity( uint8_t *string, uint8_t type, int length);
|
||||
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
|
||||
|
||||
void xor(unsigned char *dst, unsigned char *src, size_t len);
|
||||
int32_t le24toh(uint8_t data[3]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue