]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlfnedap.c
FIX: lf hitag : Mea culpa, simulation should not have reader_field on. thanks to...
[proxmark3-svn] / client / cmdlfnedap.c
index 2aaae5dbb2115fbfea7f0eb50c8bcbe61c18896b..7a3268bb2043886c12f19defb27c1eb4dfa282b3 100644 (file)
@@ -14,12 +14,13 @@ static int CmdHelp(const char *Cmd);
 int usage_lf_nedap_clone(void){
        PrintAndLog("clone a NEDAP tag to a T55x7 tag.");
        PrintAndLog("");
-       PrintAndLog("Usage: lf nedap clone <Card-Number>");
-       PrintAndLog("Options :");
-       PrintAndLog("  <Card Number>   : 24-bit value card number");
-//     PrintAndLog("  Q5              : optional - clone to Q5 (T5555) instead of T55x7 chip");
+       PrintAndLog("Usage: lf nedap clone [h] <Card-Number>");
+       PrintAndLog("Options:");
+       PrintAndLog("      h             : This help");
+       PrintAndLog("      <Card Number> : 24-bit value card number");
+//     PrintAndLog("      Q5            : optional - clone to Q5 (T5555) instead of T55x7 chip");
        PrintAndLog("");
-       PrintAndLog("Sample  : lf nedap clone 112233");
+       PrintAndLog("Sample: lf nedap clone 112233");
        return 0;
 }
 
@@ -27,11 +28,12 @@ int usage_lf_nedap_sim(void) {
        PrintAndLog("Enables simulation of NEDAP card with specified card number.");
        PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
        PrintAndLog("");
-       PrintAndLog("Usage:  lf nedap sim <Card-Number>");
-       PrintAndLog("Options :");
-       PrintAndLog("  <Card Number>   : 24-bit value card number");
+       PrintAndLog("Usage:  lf nedap sim [h] <Card-Number>");
+       PrintAndLog("Options:");
+       PrintAndLog("      h               : This help");
+       PrintAndLog("      <Card Number>   : 24-bit value card number");
        PrintAndLog("");
-       PrintAndLog("Sample  : lf nedap sim 112233");
+       PrintAndLog("Sample: lf nedap sim 112233");
        return 0;
 }
 
@@ -82,16 +84,11 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
 
 int CmdLFNedapDemod(const char *Cmd) {
        //raw ask demod 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;
-
-       //get binary from ask wave
        if (!ASKbiphaseDemod("0 64 0 0", FALSE)) {
-               if (g_debugMode) PrintAndLog("Error NEDAP: ASKbiphaseDemod failed");
+               if (g_debugMode) PrintAndLog("DEBUG: Error - Nedap ASKbiphaseDemod failed");
                return 0;
        }
-       size = DemodBufferLen;
+       size_t size = DemodBufferLen;
        int idx = NedapDemod(DemodBuffer, &size);
        if (idx < 0){
                if (g_debugMode){
@@ -102,11 +99,11 @@ int CmdLFNedapDemod(const char *Cmd) {
                        // else if (idx == -2)
                                // PrintAndLog("DEBUG: Error - problem during ASK/Biphase demod");
                        if (idx == -3)
-                               PrintAndLog("DEBUG: Error - Size not correct: %d", size);
+                               PrintAndLog("DEBUG: Error - Nedap Size not correct: %d", size);
                        else if (idx == -4)
-                               PrintAndLog("DEBUG: Error - NEDAP preamble not found");
+                               PrintAndLog("DEBUG: Error - Nedap preamble not found");
                        else
-                               PrintAndLog("DEBUG: Error - idx: %d",idx);
+                               PrintAndLog("DEBUG: Error - Nedap idx: %d",idx);
                }
                return 0;
        }
@@ -139,17 +136,18 @@ int CmdLFNedapDemod(const char *Cmd) {
        raw[2] = bytebits_to_byte(DemodBuffer+idx+32,32);
        raw[3] = bytebits_to_byte(DemodBuffer+idx,32);
        setDemodBuf(DemodBuffer,128,idx);
-
+       setGrid_Clock(64);
+       
        uint8_t firstParity = GetParity( DemodBuffer, EVEN, 63);
        if ( firstParity != DemodBuffer[63]  ) {
-               PrintAndLog("1st 64bit parity check failed:  %d|%d ", DemodBuffer[63], firstParity);
-               //return 0;
+               PrintAndLog("DEBUG: Error - Nedap 1st 64bit parity check failed:  %d|%d ", DemodBuffer[63], firstParity);
+               return 0;
        }
 
        uint8_t secondParity = GetParity( DemodBuffer+64, EVEN, 63);
        if ( secondParity != DemodBuffer[127]  ) {
-               PrintAndLog("2st 64bit parity check failed:  %d|%d ", DemodBuffer[127], secondParity);
-               //return 0;
+               PrintAndLog("DEBUG: Error - Nedap 2st 64bit parity check failed:  %d|%d ", DemodBuffer[127], secondParity);
+               return 0;
        }
 
        // ok valid card found!
@@ -205,7 +203,7 @@ lf t55xx wr b 4 d 4c0003ff
 
 int CmdLFNedapRead(const char *Cmd) {
        CmdLFRead("s");
-       getSamples("30000",false);
+       getSamples("12000", TRUE);
        return CmdLFNedapDemod("");
 }
 /*
@@ -229,13 +227,14 @@ int CmdLFNedapClone(const char *Cmd) {
                return 1;
        }       
 
-       ((ASK/biphase   data rawdemod ab 0 64 1 0
-       //NEDAP - compat mode, ASK/Biphase, data rate 64, 4 data blocks
-       blocks[0] = T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 4<<T55x7_MAXBLOCK_SHIFT;
+       ((ASK/DIphase   data rawdemod ab 0 64 1 0
+       //NEDAP - compat mode, ASK/DIphase, data rate 64, 4 data blocks
+       // DI-pahse (CDP) T55x7_MODULATION_DIPHASE
+       blocks[0] = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 7 << T55x7_MAXBLOCK_SHIFT;
 
        if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
                //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
-               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | 64<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
+               blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | ((64-2)>>1) << T5555_BITRATE_SHIFT | 7 <<T5555_MAXBLOCK_SHIFT;
 
        blocks[1] = bytebits_to_byte(bs,32);
        blocks[2] = bytebits_to_byte(bs+32,32);
@@ -256,7 +255,7 @@ int CmdLFNedapClone(const char *Cmd) {
                c.arg[1] = i;
                clearCommandBuffer();
                SendCommand(&c);
-               if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
+               if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)){
                        PrintAndLog("Error occurred, device did not respond during write operation.");
                        return -1;
                }
@@ -276,13 +275,13 @@ int CmdLFNedapSim(const char *Cmd) {
        size_t size = sizeof(bs);
        memset(bs, 0x00, size);
        
-       // NEDAP,  Bihase = 2, clock 64, inverted, 
+       // NEDAP,  Biphase = 2, clock 64, inverted,  (DIPhase == inverted BIphase
        uint8_t encoding = 2, separator = 0, clk=64, invert=1;
        uint16_t arg1, arg2;
        arg1 = clk << 8 | encoding;
        arg2 = invert << 8 | separator;
 
-       if (sscanf(Cmd, "%u", &cn ) != 2) return usage_lf_nedap_sim();
+       if (sscanf(Cmd, "%u", &cn ) != 1) return usage_lf_nedap_sim();
        cardnumber = (cn & 0x00FFFFFF);
        
        if ( !GetNedapBits(cardnumber, bs)) {
@@ -299,10 +298,8 @@ int CmdLFNedapSim(const char *Cmd) {
        return 0;
 }
 
-
-
 int CmdLFNedapChk(const char *Cmd){
-    
+    //301600714021BE
        uint8_t data[256] = { 0x30, 0x16, 0x00, 0x71, 0x40, 0x21, 0xBE};
        int len = 0;
        param_gethex_ex(Cmd, 0, data, &len);
@@ -317,7 +314,7 @@ int CmdLFNedapChk(const char *Cmd){
     uint8_t cl = 0x1D, ch = 0x1D, carry = 0;
     uint8_t al, bl, temp;
     
-       for (int i = 0; i < len; ++i){
+       for (int i =len; i >= 0; --i){
                al = data[i];
         for (int j = 8; j > 0; --j) {
                        
@@ -344,7 +341,7 @@ int CmdLFNedapChk(const char *Cmd){
         }
     }
        
-       PrintAndLog("Nedap checksum: [ 0x21, 0xBE ] %x", ((ch << 8) | cl) );
+       PrintAndLog("Nedap checksum: 0x%X", ((ch << 8) | cl) );
        return 0;
 }
 
Impressum, Datenschutz