ADD: @marshmellow's fixes to awid, viking and T55x7
ADD: 'lf t55xx detect' now can be called with a password. ADD: trying to add the read counter and increase counter commands for ntag sim.
This commit is contained in:
@@ -635,6 +635,32 @@ int CmdG_Prox_II_Demod(const char *Cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//see ASKDemod for what args are accepted
|
||||
int CmdVikingDemod(const char *Cmd)
|
||||
{
|
||||
if (!ASKDemod(Cmd, false, false, 1)) {
|
||||
if (g_debugMode) PrintAndLog("ASKDemod failed");
|
||||
return 0;
|
||||
}
|
||||
size_t size = DemodBufferLen;
|
||||
//call lfdemod.c demod for Viking
|
||||
int ans = VikingDemod_AM(DemodBuffer, &size);
|
||||
if (ans < 0) {
|
||||
if (g_debugMode) PrintAndLog("Error Viking_Demod %d", ans);
|
||||
return 0;
|
||||
}
|
||||
//got a good demod
|
||||
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);
|
||||
PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, checksum);
|
||||
PrintAndLog("Raw: %08X%08X", raw1,raw2);
|
||||
setDemodBuf(DemodBuffer+ans, 64, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//by marshmellow - see ASKDemod
|
||||
int Cmdaskrawdemod(const char *Cmd)
|
||||
{
|
||||
@@ -1128,8 +1154,6 @@ int CmdFSKdemodParadox(const char *Cmd)
|
||||
//print ioprox ID and some format details
|
||||
int CmdFSKdemodIO(const char *Cmd)
|
||||
{
|
||||
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||
//set defaults
|
||||
int idx=0;
|
||||
//something in graphbuffer?
|
||||
if (GraphTraceLen < 65) {
|
||||
@@ -1218,7 +1242,6 @@ int CmdFSKdemodIO(const char *Cmd)
|
||||
//print full AWID Prox ID and some bit format details if found
|
||||
int CmdFSKdemodAWID(const char *Cmd)
|
||||
{
|
||||
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
|
||||
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
|
||||
size_t size = getFromGraphBuf(BitStream);
|
||||
if (size==0) return 0;
|
||||
@@ -2373,7 +2396,7 @@ static command_t CommandTable[] =
|
||||
{"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"},
|
||||
|
||||
@@ -192,7 +192,6 @@ int CmdLFCommandRead(const char *Cmd)
|
||||
if (errors) return usage_lf_cmdread();
|
||||
|
||||
// in case they specified 'H'
|
||||
// added to the end..
|
||||
strcpy((char *)&c.d.asBytes + strLength, dummy);
|
||||
|
||||
clearCommandBuffer();
|
||||
@@ -505,6 +504,7 @@ int CmdIndalaClone(const char *Cmd)
|
||||
c.arg[1] = uid2;
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
@@ -582,6 +582,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;
|
||||
}
|
||||
@@ -760,6 +761,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;
|
||||
}
|
||||
@@ -853,6 +855,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;
|
||||
}
|
||||
@@ -960,6 +963,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;
|
||||
|
||||
@@ -16,149 +16,93 @@
|
||||
#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);
|
||||
|
||||
int usage_lf_awid_fskdemod(void) {
|
||||
PrintAndLog("Enables AWID26 compatible reader mode printing details of scanned AWID26 tags.");
|
||||
PrintAndLog("By default, values are printed and logged until the button is pressed or another USB command is issued.");
|
||||
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(" 1 : (optional) stop after reading a single card");
|
||||
PrintAndLog("");
|
||||
PrintAndLog(" sample : lf awid fskdemod");
|
||||
PrintAndLog(" : lf awid fskdemod 1");
|
||||
return 0;
|
||||
PrintAndLog("Enables AWID26 compatible reader mode printing details of scanned AWID26 tags.");
|
||||
PrintAndLog("By default, values are printed and logged until the button is pressed or another USB command is issued.");
|
||||
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(" 1 : (optional) stop after reading a single card");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples : lf awid fskdemod");
|
||||
PrintAndLog(" : lf awid fskdemod 1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usage_lf_awid_sim(void) {
|
||||
PrintAndLog("Enables simulation of AWID26 card with specified facility-code and card number.");
|
||||
PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
|
||||
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(" <Facility-Code> : 8-bit value AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value AWID card number");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("sample : lf awid sim 224 1337");
|
||||
return 0;
|
||||
PrintAndLog("Enables simulation of AWID26 card with specified facility-code and card number.");
|
||||
PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
|
||||
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(" <Facility-Code> : 8-bit value AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value AWID card number");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample : lf awid sim 224 1337");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usage_lf_awid_clone(void) {
|
||||
PrintAndLog("Enables cloning of AWID26 card with specified facility-code and card number onto T55x7.");
|
||||
PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
|
||||
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(" <Facility-Code> : 8-bit value AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value AWID card number");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("sample : lf awid clone 224 1337");
|
||||
return 0;
|
||||
PrintAndLog("Enables cloning of AWID26 card with specified facility-code and card number onto T55x7.");
|
||||
PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
|
||||
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(" <Facility-Code> : 8-bit value AWID facility code");
|
||||
PrintAndLog(" <Card Number> : 16-bit value AWID card number");
|
||||
PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample : lf awid clone 224 1337");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdAWIDDemodFSK(const char *Cmd) {
|
||||
int findone = 0;
|
||||
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 findone = 0;
|
||||
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);
|
||||
uint32_t cnum = (cn & 0x0000FFFF);
|
||||
uint32_t 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);
|
||||
|
||||
uint8_t pre[] = {0x01, 0x1D, 0x80, 0x00,0x00,0x00,0x00, 0x11, 0x11, 0x11, 0x11, 0x11};
|
||||
memcpy(AWIDBits, pre , sizeof(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
|
||||
uint8_t wiegand[24];
|
||||
num_to_bytebits(fc, 8, wiegand);
|
||||
num_to_bytebits(cn, 16, wiegand+8);
|
||||
|
||||
// for (i = 7; i<12; i++)
|
||||
// AWIDBits[i]=0x11;
|
||||
|
||||
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]++;
|
||||
|
||||
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 bits[12];
|
||||
uint8_t *bs=bits;
|
||||
int CmdAWIDSim(const char *Cmd) {
|
||||
uint32_t fcode = 0, cnum = 0, fc=0, cn=0;
|
||||
uint8_t bits[96];
|
||||
uint8_t *bs = bits;
|
||||
size_t size = sizeof(bits);
|
||||
memset(bs, 0, size);
|
||||
|
||||
uint64_t arg1 = (10<<8) + 8; // fcHigh = 10, fcLow = 8
|
||||
uint64_t arg2 = 50; // clk RF/50 invert=0
|
||||
@@ -179,30 +123,28 @@ int CmdAWIDSim(const char *Cmd)
|
||||
return 1;
|
||||
}
|
||||
// AWID uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0
|
||||
PrintAndLog("Running 'lf simfsk c 50 H 10 L 8 d %s'", sprint_hex(bs, sizeof(bs)));
|
||||
|
||||
// arg1 --- fcHigh<<8 + fcLow
|
||||
// arg2 --- Inversion and clk setting
|
||||
// 96 --- Bitstream length: 96-bits == 12 bytes
|
||||
UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, 96}};
|
||||
|
||||
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 blocks[4] = {0x00107060, 0, 0, 0x11111111};
|
||||
uint32_t fc=0, cn=0, i=0;
|
||||
uint8_t bits[12];
|
||||
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 bits[96];
|
||||
uint8_t *bs=bits;
|
||||
memset(bs,0,sizeof(bits));
|
||||
|
||||
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;
|
||||
PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc);
|
||||
@@ -218,12 +160,12 @@ int CmdAWIDClone(const char *Cmd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintAndLog("Preparing to clone AWID26 to T55x7 with FC: %u, CN: %u ", fc, cn);
|
||||
PrintAndLog("Raw: %s", sprint_hex(bs, sizeof(bs)));
|
||||
blocks[1] = bytebits_to_byte(bs,32);
|
||||
blocks[2] = bytebits_to_byte(bs+32,32);
|
||||
blocks[3] = bytebits_to_byte(bs+64,32);
|
||||
|
||||
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("Preparing to clone AWID26 to T55x7 with FC: %u, CN: %u",
|
||||
fc, cn);
|
||||
PrintAndLog("Blk | Data ");
|
||||
PrintAndLog("----+------------");
|
||||
PrintAndLog(" 00 | 0x%08x", blocks[0]);
|
||||
@@ -234,7 +176,7 @@ int CmdAWIDClone(const char *Cmd)
|
||||
UsbCommand resp;
|
||||
UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
c.arg[0] = blocks[i];
|
||||
c.arg[1] = i;
|
||||
clearCommandBuffer();
|
||||
@@ -247,23 +189,20 @@ int CmdAWIDClone(const char *Cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
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"},
|
||||
{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;
|
||||
}
|
||||
|
||||
@@ -126,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 11223344");
|
||||
PrintAndLog("");
|
||||
return 0;
|
||||
}
|
||||
@@ -397,28 +399,41 @@ bool DecodeT55xxBlock(){
|
||||
|
||||
int CmdT55xxDetect(const char *Cmd){
|
||||
|
||||
//bool override = false;
|
||||
//bool pwdmode = false;
|
||||
bool errors = FALSE;
|
||||
bool useGB = FALSE;
|
||||
bool usepwd = FALSE;
|
||||
uint32_t password = 0;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
uint32_t password = 0; //default to blank Block 7
|
||||
bool usepwd = ( strlen(Cmd) > 0);
|
||||
if ( usepwd ){
|
||||
password = param_get32ex(Cmd, 0, 0, 16);
|
||||
// if (param_getchar(Cmd, 1) =='o' )
|
||||
// override = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_detect();
|
||||
if (errors) return usage_t55xx_detect();
|
||||
|
||||
if (strlen(Cmd)==0) {
|
||||
password = param_get32ex(Cmd, 0, 0, 16);
|
||||
//if (param_getchar(Cmd, 1) =='o' ) override = true;
|
||||
if ( !useGB) {
|
||||
if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )
|
||||
return 0;
|
||||
}
|
||||
|
||||
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\'");
|
||||
|
||||
@@ -1242,7 +1257,7 @@ void t55x7_create_config_block( int tagtype ){
|
||||
static char buf[60];
|
||||
char *retStr = buf;
|
||||
|
||||
switch (id){
|
||||
switch (tagtype){
|
||||
case 0: snprintf(retStr, sizeof(buf),"%08X - T55X7 Default", T55X7_DEFAULT_CONFIG_BLOCK); break;
|
||||
case 1: snprintf(retStr, sizeof(buf),"%08X - T55X7 Raw", T55X7_RAW_CONFIG_BLOCK); break;
|
||||
default:
|
||||
@@ -1292,16 +1307,15 @@ int CmdT55xxWipe(const char *Cmd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
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."},
|
||||
{"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, 0, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},
|
||||
{"info", CmdT55xxInfo, 0, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
|
||||
{"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"},
|
||||
@@ -1309,14 +1323,12 @@ static command_t CommandTable[] =
|
||||
{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;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// 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>
|
||||
@@ -15,76 +23,111 @@ 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 16 bytes of hex number>");
|
||||
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;
|
||||
}
|
||||
|
||||
//by marshmellow
|
||||
//see ASKDemod for what args are accepted
|
||||
int CmdVikingDemod(const char *Cmd)
|
||||
{
|
||||
//CmdLFRead("s");
|
||||
//getSamples("30000",false);
|
||||
|
||||
if (!ASKDemod(Cmd, false, false, 1)) {
|
||||
if (g_debugMode) PrintAndLog("ASKDemod failed");
|
||||
return 0;
|
||||
}
|
||||
size_t size = DemodBufferLen;
|
||||
|
||||
int ans = VikingDemod_AM(DemodBuffer, &size);
|
||||
if (ans < 0) {
|
||||
if (g_debugMode) PrintAndLog("Error Viking_Demod %d", ans);
|
||||
return 0;
|
||||
}
|
||||
//got a good demod
|
||||
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);
|
||||
PrintAndLog("Viking Tag Found: Card ID %08X, Checksum: %02X", cardid, checksum);
|
||||
PrintAndLog("Raw: %08X%08X", raw1,raw2);
|
||||
setDemodBuf(DemodBuffer+ans, 64, 0);
|
||||
return 1;
|
||||
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;
|
||||
}
|
||||
|
||||
int CmdVikingClone(const char *Cmd)
|
||||
{
|
||||
uint32_t b1,b2;
|
||||
// get the tag number 64 bits (8 bytes) in hex
|
||||
uint8_t id[8];
|
||||
|
||||
// calc checksum
|
||||
uint64_t getVikingBits(uint32_t id) {
|
||||
uint8_t checksum = (id>>24) ^ ((id>>16) & 0xFF) ^ ((id>>8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
|
||||
uint64_t ret = (uint64_t)0xF2 << 56;
|
||||
ret |= (id << 8);
|
||||
ret |= checksum;
|
||||
return ret;
|
||||
}
|
||||
//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();
|
||||
|
||||
if (param_gethex(Cmd, 0, id, 16) == 1)
|
||||
return usage_lf_viking_clone();
|
||||
id = param_get32ex(Cmd, 0, 0, 16);
|
||||
if (id == 0) return usage_lf_viking_clone();
|
||||
|
||||
b1 = bytes_to_num(id, sizeof(uint32_t));
|
||||
b2 = bytes_to_num(id + sizeof(uint32_t), sizeof(uint32_t));
|
||||
UsbCommand c = {CMD_VIKING_CLONE_TAG,{b1,b2}};
|
||||
cmdp = param_getchar(Cmd, 1);
|
||||
if ( cmdp == 'Q' || cmdp == 'q')
|
||||
Q5 = true;
|
||||
|
||||
rawID = getVikingBits(id);
|
||||
|
||||
UsbCommand c = {CMD_VIKING_CLONE_TAG,{rawID >> 32, rawID & 0xFFFF, Q5}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
//check for ACK?
|
||||
//check for ACK
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] =
|
||||
{
|
||||
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"},
|
||||
{"demod", CmdVikingDemod, 1, "Extract tag data"},
|
||||
{"clone", CmdVikingClone, 1, "<16 digits card data> clone viking tag"},
|
||||
{"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)
|
||||
{
|
||||
int CmdLFViking(const char *Cmd) {
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +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 CmdVikingDemod(const char *Cmd);
|
||||
int CmdVikingRead(const char *Cmd);
|
||||
int CmdVikingClone(const char *Cmd);
|
||||
int CmdVikingSim(const char *Cmd);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -159,6 +159,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
|
||||
@@ -445,7 +452,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;
|
||||
|
||||
@@ -457,7 +464,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]);
|
||||
|
||||
Reference in New Issue
Block a user