]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Add @iceman1001 s presco and pyramid functions +
authormarshmellow42 <marshmellowrf@gmail.com>
Sun, 6 Mar 2016 04:45:28 +0000 (23:45 -0500)
committermarshmellow42 <marshmellowrf@gmail.com>
Sun, 6 Mar 2016 04:45:28 +0000 (23:45 -0500)
plus comment some includes.
fix indala error checking bugs
cmddata.h previously relied on several headers being included prior to
cmddata.h, now self contained.

client/Makefile
client/cmddata.c
client/cmddata.h
client/cmdlf.c
client/cmdlfpresco.c [new file with mode: 0644]
client/cmdlfpresco.h [new file with mode: 0644]
client/cmdlfpyramid.c [new file with mode: 0644]
client/cmdlfpyramid.h [new file with mode: 0644]
client/util.h
common/lfdemod.c
common/lfdemod.h

index 0972f441912280439ca04265472a76ab0d31af6c..7f9c4c84a8e7d1a129388a70303e983a6b584da0 100644 (file)
@@ -99,6 +99,8 @@ CMDSRCS =     nonce2key/crapto1.c\
                        cmdlft55xx.c \
                        cmdlfpcf7931.c\
                        cmdlfviking.c\
+                       cmdlfpresco.c\
+                       cmdlfpyramid.c\
                        pm3_binlib.c\
                        scripting.c\
                        cmdscript.c\
index 801649ee938f705c4bf09c84b4815cb01343fb8e..9854ccfa89807744db2cb7fa74895bd0361ff38f 100644 (file)
@@ -8,23 +8,22 @@
 // Data and Graph commands
 //-----------------------------------------------------------------------------
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include "proxmark3.h"
-#include "data.h"
-#include "ui.h"
-#include "graph.h"
-#include "cmdparser.h"
+#include <stdio.h>    // also included in util.h
+#include <string.h>   // also included in util.h
+#include <limits.h>   // for CmdNorm INT_MIN && INT_MAX
+#include "data.h"     // also included in util.h
+#include "cmddata.h"
 #include "util.h"
 #include "cmdmain.h"
-#include "cmddata.h"
-#include "lfdemod.h"
-#include "usb_cmd.h"
-#include "crc.h"
-#include "crc16.h"
-#include "loclass/cipherutils.h"
+#include "proxmark3.h"
+#include "ui.h"       // for show graph controls
+#include "graph.h"    // for graph data
+#include "cmdparser.h"// already included in cmdmain.h
+#include "usb_cmd.h"  // already included in cmdmain.h and proxmark3.h
+#include "lfdemod.h"  // for demod code
+#include "crc.h"      // for pyramid checksum maxim
+#include "crc16.h"    // for FDXB demod checksum
+#include "loclass/cipherutils.h" // for decimating samples in getsamples
 
 uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
 uint8_t g_debugMode=0;
@@ -1265,7 +1264,7 @@ int CmdFSKdemodAWID(const char *Cmd)
        //get binary from fsk wave
        int idx = AWIDdemodFSK(BitStream, &size);
        if (idx<=0){
-               if (g_debugMode==1){
+               if (g_debugMode){
                        if (idx == -1)
                                PrintAndLog("DEBUG: Error - not enough samples");
                        else if (idx == -2)
@@ -1303,7 +1302,7 @@ int CmdFSKdemodAWID(const char *Cmd)
 
        size = removeParity(BitStream, idx+8, 4, 1, 88);
        if (size != 66){
-               if (g_debugMode==1) PrintAndLog("DEBUG: Error - at parity check-tag size does not match AWID format");
+               if (g_debugMode) PrintAndLog("DEBUG: Error - at parity check-tag size does not match AWID format");
                return 0;
        }
        // ok valid card found!
@@ -1363,7 +1362,7 @@ int CmdFSKdemodPyramid(const char *Cmd)
        //get binary from fsk wave
        int idx = PyramiddemodFSK(BitStream, &size);
        if (idx < 0){
-               if (g_debugMode==1){
+               if (g_debugMode){
                        if (idx == -5)
                                PrintAndLog("DEBUG: Error - not enough samples");
                        else if (idx == -1)
@@ -1419,7 +1418,7 @@ int CmdFSKdemodPyramid(const char *Cmd)
 
        size = removeParity(BitStream, idx+8, 8, 1, 120);
        if (size != 105){
-               if (g_debugMode==1
+               if (g_debugMode) 
                        PrintAndLog("DEBUG: Error at parity check - tag size does not match Pyramid format, SIZE: %d, IDX: %d, hi3: %x",size, idx, rawHi3);
                return 0;
        }
@@ -1642,21 +1641,21 @@ int CmdIndalaDecode(const char *Cmd)
        }
 
        if (!ans){
-               if (g_debugMode==1
+               if (g_debugMode) 
                        PrintAndLog("Error1: %d",ans);
                return 0;
        }
        uint8_t invert=0;
        size_t size = DemodBufferLen;
-       size_t startIdx = indala26decode(DemodBuffer, &size, &invert);
-       if (startIdx < 1 || size > 224) {
-               if (g_debugMode==1)
+       int startIdx = indala26decode(DemodBuffer, &size, &invert);
+       if (startIdx < 0 || size > 224) {
+               if (g_debugMode)
                        PrintAndLog("Error2: %d",ans);
                return -1;
        }
-       setDemodBuf(DemodBuffer, size, startIdx);
+       setDemodBuf(DemodBuffer, size, (size_t)startIdx);
        if (invert)
-               if (g_debugMode==1)
+               if (g_debugMode)
                        PrintAndLog("Had to invert bits");
 
        PrintAndLog("BitLen: %d",DemodBufferLen);
index 20bdbd2b193d5e4de45b94310a1f3b54cdddc6a1..9b9f2da92d2945879a74e483b5a4790bd8e212f0 100644 (file)
 #ifndef CMDDATA_H__
 #define CMDDATA_H__
 
+#include <stdlib.h>  //size_t
+#include <stdint.h>  //uint_32+
+#include <stdbool.h> //bool
+
+#include "cmdparser.h" // for command_t
+
 command_t * CmdDataCommands();
 
 int CmdData(const char *Cmd);
index 9d23d97cc99d7bccc480e3a32f1ad6d97aa82014..22bceda41874d07d960c22083e15934193fcdb59 100644 (file)
 #include <string.h>
 #include <limits.h>
 #include "proxmark3.h"
-#include "data.h"
-#include "graph.h"
-#include "ui.h"
-#include "cmdparser.h"
-#include "cmdmain.h"
-#include "cmddata.h"
-#include "util.h"
 #include "cmdlf.h"
-#include "cmdlfhid.h"
-#include "cmdlfawid.h"
-#include "cmdlfti.h"
-#include "cmdlfem4x.h"
-#include "cmdlfhitag.h"
-#include "cmdlft55xx.h"
-#include "cmdlfpcf7931.h"
-#include "cmdlfio.h"
-#include "cmdlfviking.h"
-#include "lfdemod.h"
+#include "util.h"        // for parsing cli command utils
+#include "ui.h"          // for show graph controls
+#include "graph.h"       // for graph data
+#include "cmdparser.h"   // for getting cli commands included in cmdmain.h
+#include "cmdmain.h"     // for sending cmds to device
+#include "data.h"        // for GetFromBigBuf
+#include "cmddata.h"     // for `lf search`
+#include "cmdlfawid.h"   // for awid menu
+#include "cmdlfem4x.h"   // for em4x menu
+#include "cmdlfhid.h"    // for hid menu
+#include "cmdlfhitag.h"  // for hitag menu
+#include "cmdlfio.h"     // for ioprox menu
+#include "cmdlft55xx.h"  // for t55xx menu
+#include "cmdlfti.h"     // for ti menu
+#include "cmdlfpresco.h" // for presco menu
+#include "cmdlfpcf7931.h"// for pcf7931 menu
+#include "cmdlfpyramid.h"// for pyramid menu
+#include "cmdlfviking.h" // for viking menu
 
 static int CmdHelp(const char *Cmd);
 
@@ -1220,7 +1221,9 @@ static command_t CommandTable[] =
        {"hid",         CmdLFHID,           1, "{ HID RFIDs...     }"},
        {"hitag",       CmdLFHitag,         1, "{ Hitag tags and transponders... }"},
        {"io",          CmdLFIO,            1, "{ ioProx tags...   }"},
+       {"presco",      CmdLFPresco,        1, "{ Presco RFIDs... }"},
        {"pcf7931",     CmdLFPCF7931,       1, "{ PCF7931 RFIDs... }"},
+       {"pyramid",     CmdLFPyramid,       1, "{ Farpointe/Pyramid RFIDs... }"},
        {"t55xx",       CmdLFT55XX,         1, "{ T55xx RFIDs...   }"},
        {"ti",          CmdLFTI,            1, "{ TI RFIDs...      }"},
        {"viking",      CmdLFViking,        1, "{ Viking tags...   }"},
diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c
new file mode 100644 (file)
index 0000000..20b42bc
--- /dev/null
@@ -0,0 +1,223 @@
+//-----------------------------------------------------------------------------
+//
+// 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 Presco tag commands
+//-----------------------------------------------------------------------------
+#include <string.h>
+#include <inttypes.h>
+#include "cmdlfpresco.h"
+static int CmdHelp(const char *Cmd);
+
+int usage_lf_presco_clone(void){
+       PrintAndLog("clone a Presco tag to a T55x7 tag.");
+       PrintAndLog("Usage: lf presco clone <Card ID - 9 digits> <Q5>");
+       PrintAndLog("Options :");
+       PrintAndLog("  <Card Number>  : 9 digit presco card number");
+       //PrintAndLog("  <Q5>           : specify write to Q5 (t5555 instead of t55x7)");
+       PrintAndLog("");
+       PrintAndLog("Sample  : lf presco clone 123456789");
+       return 0;
+}
+
+int usage_lf_presco_sim(void) {
+       PrintAndLog("Enables simulation of presco card with specified card number.");
+       PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
+       PrintAndLog("Per presco format, the card number is 9 digit number and can contain *# chars. Larger values are truncated.");
+       PrintAndLog("");
+       PrintAndLog("Usage:  lf presco sim <Card-Number>");
+       PrintAndLog("Options :");
+       PrintAndLog("  <Card Number>   : 9 digit presco card number");
+       PrintAndLog("");
+       PrintAndLog("Sample  : lf presco sim 123456789");
+       return 0;
+}
+
+// calc checksum
+int GetWiegandFromPresco(const char *id, uint32_t *sitecode, uint32_t *usercode) {
+       
+       uint8_t val = 0;
+       for (int index =0; index < strlen(id); ++index) {
+               
+               // Get value from number string.
+               if ( id[index] == '*' ) val = 10;
+               if ( id[index] == '#')  val = 11;               
+               if ( id[index] >= 0x30 && id[index] <= 0x39 )
+                       val = id[index] - 0x30;
+               
+               *sitecode += val;
+               
+               // last digit is only added, not multipled.
+               if ( index < strlen(id)-1 ) 
+                       *sitecode *= 12;
+       }
+       *usercode = *sitecode % 65536;
+       *sitecode /= 16777216;
+       return 0;
+}
+
+int GetPrescoBits(uint32_t sitecode, uint32_t usercode, uint8_t        *prescoBits) {
+       uint8_t pre[66];
+       memset(pre, 0, sizeof(pre));
+       prescoBits[7]=1;
+       num_to_bytebits(26, 8, pre);
+
+       uint8_t wiegand[24];
+       num_to_bytebits(sitecode, 8, wiegand);
+       num_to_bytebits(usercode, 16, wiegand+8);
+
+       wiegand_add_parity(pre+8, wiegand, 24);
+       size_t bitLen = addParity(pre, prescoBits+8, 66, 4, 1);
+
+       if (bitLen != 88) return 0;
+       return 1;
+}
+//see ASKDemod for what args are accepted
+int CmdPrescoDemod(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 = PrescoDemod(DemodBuffer, &size);
+       if (ans < 0) {
+               if (g_debugMode) PrintAndLog("Error Presco_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);
+       PrintAndLog("Presco Tag Found: Card ID %08X", cardid);
+       PrintAndLog("Raw: %08X%08X", raw1,raw2);
+       setDemodBuf(DemodBuffer+ans, 64, 0);
+       
+       // uint32_t sitecode = 0, usercode = 0;
+       // GetWiegandFromPresco(id, &sitecode, &usercode);
+       // PrintAndLog8("SiteCode %d  |  UserCode %d", sitecode, usercode);
+       
+       return 1;
+}
+
+//see ASKDemod for what args are accepted
+int CmdPrescoRead(const char *Cmd) {
+       //      Presco Number: 123456789 --> Sitecode 30 | usercode 8665
+
+       // read lf silently
+       CmdLFRead("s");
+       // get samples silently
+       getSamples("30000",false);
+       // demod and output Presco ID   
+       return CmdPrescoDemod(Cmd);
+}
+
+int CmdPrescoClone(const char *Cmd) {
+
+       char cmdp = param_getchar(Cmd, 0);
+       if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_presco_clone();
+
+       uint32_t sitecode=0, usercode=0;
+       uint8_t bits[96];
+       uint8_t *bs = bits;
+       memset(bs,0,sizeof(bits));
+       uint32_t blocks[5] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 4<<T55x7_MAXBLOCK_SHIFT | T55x7_ST_TERMINATOR, 0, 0, 0, 5};
+       
+       if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+               blocks[0] = T5555_MODULATION_MANCHESTER | 32<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT | T5555_ST_TERMINATOR;
+
+       // get wiegand from printed number.
+       GetWiegandFromPresco(Cmd, &sitecode, &usercode);
+       
+       if ((sitecode & 0xFF) != sitecode) {
+               sitecode &= 0xFF;
+               PrintAndLog("Facility-Code Truncated to 8-bits (Presco): %u", sitecode);
+       }
+
+       if ((usercode & 0xFFFF) != usercode) {
+               usercode &= 0xFFFF;
+               PrintAndLog("Card Number Truncated to 16-bits (Presco): %u", usercode);
+       }
+       
+       if ( !GetPrescoBits(sitecode, usercode, 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);
+       blocks[4] = bytebits_to_byte(bs+96,32);
+
+       PrintAndLog("Preparing to clone Presco to T55x7 with SiteCode: %u, UserCode: %u", sitecode, usercode);
+       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]); 
+       PrintAndLog(" 04 | 0x%08x", blocks[4]); 
+       
+       // UsbCommand resp;
+       // UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
+
+       // for (uint8_t i=0; i<5; i++) {
+               // c.arg[0] = blocks[i];
+               // c.arg[1] = i;
+               // clearCommandBuffer();
+               // SendCommand(&c);
+               // if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
+                       // PrintAndLog("Error occurred, device did not respond during write operation.");
+                       // return -1;
+               // }
+       // }
+    return 0;
+}
+
+int CmdPrescoSim(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_presco_sim();
+
+       // id = param_get32ex(Cmd, 0, 0, 16);
+       // if (id == 0) return usage_lf_presco_sim();
+
+       //rawID = getVikingBits(id);
+
+       // uint16_t arg1, arg2;
+       // size_t size = 64;
+       // arg1 = clk << 8 | encoding;
+       // arg2 = invert << 8 | separator;
+
+       // PrintAndLog("Simulating - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
+       
+       // UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
+       // num_to_bytebits(rawID, size, c.d.asBytes);
+       // clearCommandBuffer();
+       // SendCommand(&c);
+       return 0;
+}
+
+static command_t CommandTable[] = {
+    {"help",   CmdHelp,                1, "This help"},
+       {"read",        CmdPrescoRead,  0, "Attempt to read and Extract tag data"},
+       {"clone",       CmdPrescoClone, 0, "<8 digit ID number> clone presco tag"},
+//     {"sim",         CmdPrescoSim,   0, "<8 digit ID number> simulate presco tag"},
+    {NULL, NULL, 0, NULL}
+};
+
+int CmdLFPresco(const char *Cmd) {
+       clearCommandBuffer();
+    CmdsParse(CommandTable, Cmd);
+    return 0;
+}
+
+int CmdHelp(const char *Cmd) {
+    CmdsHelp(CommandTable);
+    return 0;
+}
diff --git a/client/cmdlfpresco.h b/client/cmdlfpresco.h
new file mode 100644 (file)
index 0000000..f9cfbd9
--- /dev/null
@@ -0,0 +1,30 @@
+//-----------------------------------------------------------------------------
+//
+// 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 CMDLFPRESCO_H__
+#define CMDLFPRESCO_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 "protocols.h"  // for T55xx config register definitions
+#include "lfdemod.h"    // parityTest
+int CmdLFPresco(const char *Cmd);
+int CmdPrescoClone(const char *Cmd);
+//int CmdPrescoSim(const char *Cmd);
+
+int usage_lf_presco_clone(void);
+int usage_lf_presco_sim(void);
+
+int GetWiegandFromPresco(const char *id, uint32_t *sitecode, uint32_t *usercode);
+#endif
+
diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c
new file mode 100644 (file)
index 0000000..990dccb
--- /dev/null
@@ -0,0 +1,185 @@
+//-----------------------------------------------------------------------------
+//
+// 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 Farpoint / Pyramid tag commands
+//-----------------------------------------------------------------------------
+#include <string.h>
+#include <inttypes.h>
+#include "cmdlfpyramid.h"
+static int CmdHelp(const char *Cmd);
+
+int usage_lf_pyramid_clone(void){
+       PrintAndLog("clone a Farpointe/Pyramid tag to a T55x7 tag.");
+       PrintAndLog("The facility-code is 8-bit and the card number is 16-bit.  Larger values are truncated. ");
+       PrintAndLog("Currently work only on 26bit");
+       PrintAndLog("");
+       PrintAndLog("Usage: lf pyramid clone <Facility-Code> <Card-Number>");
+       PrintAndLog("Options :");
+       PrintAndLog("  <Facility-Code> :  8-bit value facility code");
+       PrintAndLog("  <Card Number>   : 16-bit value card number");
+       PrintAndLog("");
+       PrintAndLog("Sample  : lf pyramid clone 123 11223");
+       return 0;
+}
+
+int usage_lf_pyramid_sim(void) {
+       PrintAndLog("Enables simulation of Farpointe/Pyramid card with specified card number.");
+       PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
+       PrintAndLog("The facility-code is 8-bit and the card number is 16-bit.  Larger values are truncated.");
+       PrintAndLog("Currently work only on 26bit");
+       PrintAndLog("");
+       PrintAndLog("Usage:  lf pyramid sim <Card-Number>");
+       PrintAndLog("Options :");
+       PrintAndLog("  <Facility-Code> :  8-bit value facility code");
+       PrintAndLog("  <Card Number>   : 16-bit value card number");
+       PrintAndLog("");
+       PrintAndLog("Sample  : lf pyramid sim 123 11223");
+       return 0;
+}
+
+// Works for 26bits.
+int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
+
+       uint8_t pre[128];
+       memset(pre, 0x00, sizeof(pre));
+
+       // format start bit
+       pre[79] = 1;
+       
+       // Get 26 wiegand from FacilityCode, CardNumber 
+       uint8_t wiegand[24];
+       memset(wiegand, 0x00, sizeof(wiegand));
+       num_to_bytebits(fc, 8, wiegand);
+       num_to_bytebits(cn, 16, wiegand+8);
+
+       // add wiegand parity bits (dest, source, len)
+       wiegand_add_parity(pre+80, wiegand, 24);
+       
+       // add paritybits       (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
+       addParity(pre+8, pyramidBits+8, 102, 8, 1);
+
+       // add checksum         
+       uint8_t csBuff[13];
+       for (uint8_t i = 0; i < 13; i++)
+               csBuff[i] = bytebits_to_byte(pyramidBits + 16 + (i*8), 8);
+
+       uint32_t crc = CRC8Maxim(csBuff, 13);
+       num_to_bytebits(crc, 8, pyramidBits+120);
+       return 1;
+}
+
+int CmdPyramidRead(const char *Cmd) {
+       CmdLFRead("s");
+       getSamples("30000",false);
+       return CmdFSKdemodPyramid("");
+}
+
+int CmdPyramidClone(const char *Cmd) {
+
+       char cmdp = param_getchar(Cmd, 0);
+       if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_clone();
+
+       uint32_t facilitycode=0, cardnumber=0, fc = 0, cn = 0;
+       uint32_t blocks[5];
+       uint8_t i;
+       uint8_t bs[128];
+       memset(bs, 0x00, sizeof(bs));
+
+       if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_pyramid_clone();
+
+       facilitycode = (fc & 0x000000FF);
+       cardnumber = (cn & 0x0000FFFF);
+       
+       if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
+               PrintAndLog("Error with tag bitstream generation.");
+               return 1;
+       }       
+
+//     if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
+//             blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+
+       //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
+       blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<<T55x7_MAXBLOCK_SHIFT;
+       blocks[1] = bytebits_to_byte(bs,32);
+       blocks[2] = bytebits_to_byte(bs+32,32);
+       blocks[3] = bytebits_to_byte(bs+64,32);
+       blocks[4] = bytebits_to_byte(bs+96,32);
+
+       PrintAndLog("Preparing to clone Farpointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
+       PrintAndLog("Blk | Data ");
+       PrintAndLog("----+------------");
+       for ( i = 0; i<5; ++i )
+               PrintAndLog(" %02d | %08" PRIx32, i, blocks[i]);
+
+       UsbCommand resp;
+       UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
+
+       for ( i = 0; i<5; ++i ) {
+               c.arg[0] = blocks[i];
+               c.arg[1] = i;
+               clearCommandBuffer();
+               SendCommand(&c);
+               if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
+                       PrintAndLog("Error occurred, device did not respond during write operation.");
+                       return -1;
+               }
+       }
+    return 0;
+}
+
+int CmdPyramidSim(const char *Cmd) {
+
+       char cmdp = param_getchar(Cmd, 0);
+       if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_sim();
+
+       uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0;
+       
+       uint8_t bs[128];
+       size_t size = sizeof(bs);
+       memset(bs, 0x00, size);
+       
+       // Pyramid uses:  fcHigh: 10, fcLow: 8, clk: 50, invert: 0
+       uint64_t arg1, arg2;
+       arg1 = (10 << 8) + 8;
+       arg2 = 50 | 0;
+
+       if (sscanf(Cmd, "%u %u", &fc, &cn ) != 2) return usage_lf_pyramid_sim();
+
+       facilitycode = (fc & 0x000000FF);
+       cardnumber = (cn & 0x0000FFFF);
+       
+       if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
+               PrintAndLog("Error with tag bitstream generation.");
+               return 1;
+       }       
+
+       PrintAndLog("Simulating Farpointe/Pyramid - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber );
+       
+       UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
+       memcpy(c.d.asBytes, bs, size);
+       clearCommandBuffer();
+       SendCommand(&c);
+       return 0;
+}
+
+static command_t CommandTable[] = {
+    {"help",   CmdHelp,                1, "This help"},
+       {"read",        CmdPyramidRead,  0, "Attempt to read and extract tag data"},
+       {"clone",       CmdPyramidClone, 0, "<Facility-Code> <Card Number>  clone pyramid tag"},
+       {"sim",         CmdPyramidSim,   0, "<Facility-Code> <Card Number>  simulate pyramid tag"},
+    {NULL, NULL, 0, NULL}
+};
+
+int CmdLFPyramid(const char *Cmd) {
+       clearCommandBuffer();
+    CmdsParse(CommandTable, Cmd);
+    return 0;
+}
+
+int CmdHelp(const char *Cmd) {
+    CmdsHelp(CommandTable);
+    return 0;
+}
diff --git a/client/cmdlfpyramid.h b/client/cmdlfpyramid.h
new file mode 100644 (file)
index 0000000..d00b7d0
--- /dev/null
@@ -0,0 +1,30 @@
+//-----------------------------------------------------------------------------
+//
+// 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 CMDLFPYRAMID_H__
+#define CMDLFPYRAMID_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 "protocols.h"  // for T55xx config register definitions
+#include "lfdemod.h"    // parityTest
+#include "crc.h"
+
+int CmdLFPyramid(const char *Cmd);
+int CmdPyramidClone(const char *Cmd);
+int CmdPyramidSim(const char *Cmd);
+
+int usage_lf_pyramid_clone(void);
+int usage_lf_pyramid_sim(void);
+#endif
+
index 5674adcfdd07e26666b04560b242a1b03b8acf14..dc5dcfa0f0e222c2ce89ac8b280ac2126b4944a4 100644 (file)
@@ -9,13 +9,12 @@
 //-----------------------------------------------------------------------------
 
 #include <stdio.h>
-#include <stdint.h>
-#include <stdio.h>
+#include <stdint.h>  included in data.h
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <time.h>
-#include "data.h"
+#include "data.h"  //for FILE_PATH_SIZE
 
 #ifndef ROTR
 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
index 665bad89e8d6b5d0b8fd140a687f1329911eb3d4..d6c024fab9bfa872d9a210fa9dfb9334453e6aca 100644 (file)
@@ -684,6 +684,19 @@ int VikingDemod_AM(uint8_t *dest, size_t *size) {
        return (int) startIdx;
 }
 
+// find presco preamble 0x10D in already demoded data
+int PrescoDemod(uint8_t *dest, size_t *size) {
+       //make sure buffer has data
+       if (*size < 64*2) return -2;
+
+       size_t startIdx = 0;
+       uint8_t preamble[] = {1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0};
+       uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx);
+       if (errChk == 0) return -4; //preamble not found
+       //return start position
+       return (int) startIdx;
+}
+
 // Ask/Biphase Demod then try to locate an ISO 11784/85 ID
 // BitStream must contain previously askrawdemod and biphasedemoded data
 int FDXBdemodBI(uint8_t *dest, size_t *size)
index d4a1fda06e47aaf28f62310cc7e95f8c6cd12dce..56c758ae7b2879fc48b3fa1f85646929c1941e39 100644 (file)
@@ -13,8 +13,8 @@
 
 #ifndef LFDEMOD_H__
 #define LFDEMOD_H__
-#include <stdint.h>
-#include "common.h"  //for bool
+#include <stdint.h>  // for uint_32+
+#include <stdbool.h> // for bool
 
 //generic
 size_t   addParity(uint8_t *BitSource, uint8_t *dest, uint8_t sourceLen, uint8_t pLen, uint8_t pType);
@@ -54,5 +54,5 @@ int indala26decode(uint8_t *bitStream, size_t *size, uint8_t *invert);
 int ParadoxdemodFSK(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo);
 int PyramiddemodFSK(uint8_t *dest, size_t *size);
 int VikingDemod_AM(uint8_t *dest, size_t *size);
-
+int PrescoDemod(uint8_t *dest, size_t *size);
 #endif
Impressum, Datenschutz