]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
ADD: started to add a legic detection to "HF SEARCH"
authoriceman1001 <iceman@iuse.se>
Mon, 26 Sep 2016 18:01:23 +0000 (20:01 +0200)
committericeman1001 <iceman@iuse.se>
Mon, 26 Sep 2016 18:01:23 +0000 (20:01 +0200)
armsrc/appmain.c
armsrc/legicrf.c
armsrc/legicrf.h
client/cmdhf.c
client/cmdhflegic.c
client/cmdhflegic.h
client/hid-flasher/usb_cmd.h
client/lualibs/commands.lua
include/usb_cmd.h

index 222e4b21913408cef0738c78803ff68d095d741a..549feff0bb25e82ee230d0163b65d9bba29bb97b 100644 (file)
@@ -1064,6 +1064,10 @@ void UsbPacketReceived(uint8_t *packet, int len)
                case CMD_READER_LEGIC_RF:
                        LegicRfReader(c->arg[0], c->arg[1], c->arg[2]);
                        break;
                case CMD_READER_LEGIC_RF:
                        LegicRfReader(c->arg[0], c->arg[1], c->arg[2]);
                        break;
+                       
+               case CMD_LEGIC_INFO:
+                       LegicRfInfo();
+                       break;
 #endif
 
 #ifdef WITH_ISO14443b
 #endif
 
 #ifdef WITH_ISO14443b
index 5b0cccf0cdd8a6d4abfa2524867de46bb88cc8e8..7a156f69fc8bc9803524beea1c7c8428e48649a7 100644 (file)
@@ -246,8 +246,8 @@ void frame_sendAsReader(uint32_t data, uint8_t bits){
                bits,
                BYTEx(data, 0), 
                BYTEx(data, 1),
                bits,
                BYTEx(data, 0), 
                BYTEx(data, 1),
-               0x00
-               0x00,
+               BYTEx(send, 0)
+               BYTEx(send, 1),
                prngstart,
                legic_prng_count()
        };
                prngstart,
                legic_prng_count()
        };
@@ -304,12 +304,14 @@ static void frame_receiveAsReader(struct legic_frame * const f, uint8_t bits) {
        // 500 = 0x1C  0001 1100
        uint32_t starttime = GET_TICKS;
        //uint16_t mywait =  TAG_FRAME_WAIT - (starttime - sendFrameStop);
        // 500 = 0x1C  0001 1100
        uint32_t starttime = GET_TICKS;
        //uint16_t mywait =  TAG_FRAME_WAIT - (starttime - sendFrameStop);
-       uint16_t mywait =  495 - (starttime - sendFrameStop);
-       if ( bits == 6)
-               WaitTicks( 495 - 9 );
-       else {
-               //Dbprintf("WAIT %d", mywait );
-               WaitTicks( mywait );
+       //uint16_t mywait =  495 - (starttime - sendFrameStop);
+       if ( bits == 6) {
+               //Dbprintf("6 WAIT %d", 495 - 9 - 9 );
+               WaitTicks( 495 - 9 - 9 );
+       } else {
+               //Dbprintf("x WAIT %d", mywait );
+               //WaitTicks( mywait );
+               WaitTicks( 450 );
        }
 
        next_bit_at =  GET_TICKS + TAG_BIT_PERIOD;
        }
 
        next_bit_at =  GET_TICKS + TAG_BIT_PERIOD;
@@ -419,9 +421,9 @@ static void LegicCommonInit(void) {
 // Switch off carrier, make sure tag is reset
 static void switch_off_tag_rwd(void) {
        LOW(GPIO_SSC_DOUT);
 // Switch off carrier, make sure tag is reset
 static void switch_off_tag_rwd(void) {
        LOW(GPIO_SSC_DOUT);
-       WaitUS(200);
+       WaitUS(20);
        WDT_HIT();
        WDT_HIT();
-       Dbprintf("Exit Switch_off_tag_rwd");
+       set_tracing(FALSE);
 }
 
 // calculate crc4 for a legic READ command 
 }
 
 // calculate crc4 for a legic READ command 
@@ -438,6 +440,9 @@ static uint32_t legic4Crc(uint8_t legicCmd, uint16_t byte_index, uint8_t value,
 
 int legic_read_byte(int byte_index, int cmd_sz) {
 
 
 int legic_read_byte(int byte_index, int cmd_sz) {
 
+       uint8_t byte = 0, crc = 0, calcCrc = 0;
+       uint32_t cmd = (byte_index << 1) | LEGIC_READ;
+       
        // (us)| ticks
        // -------------
        // 330 | 495
        // (us)| ticks
        // -------------
        // 330 | 495
@@ -446,10 +451,7 @@ int legic_read_byte(int byte_index, int cmd_sz) {
        // 244 | 366
        WaitTicks(387); 
        legic_prng_forward(4); // 460 / 100 = 4.6  iterations
        // 244 | 366
        WaitTicks(387); 
        legic_prng_forward(4); // 460 / 100 = 4.6  iterations
-
-       uint8_t byte = 0, crc = 0, calcCrc = 0;
-       uint32_t cmd = (byte_index << 1) | LEGIC_READ;
-
+       
        frame_sendAsReader(cmd, cmd_sz);
        frame_receiveAsReader(&current_frame, 12);
 
        frame_sendAsReader(cmd, cmd_sz);
        frame_receiveAsReader(&current_frame, 12);
 
@@ -776,6 +778,49 @@ void LegicRfRawWriter(int address, int byte, int iv) {
     if ( MF_DBGLEVEL >= 1) DbpString("write successful");
 }
 
     if ( MF_DBGLEVEL >= 1) DbpString("write successful");
 }
 
+void LegicRfInfo(void){
+
+       LegicCommonInit();
+       uint32_t tag_type = setup_phase_reader(0x55);
+       uint8_t cmd_sz = 0;
+       uint16_t card_sz = 0;
+       
+       switch(tag_type) {
+               case 0x0d:
+            cmd_sz = 6;
+                       card_sz = 22;
+                       break;
+               case 0x1d:
+                       cmd_sz = 9;
+                       card_sz = 256;
+                       break;
+               case 0x3d:
+            cmd_sz = 11;
+                       card_sz = 1024;
+                       break;
+               default: 
+                       cmd_send(CMD_ACK,0,0,0,0,0);
+                       goto OUT;
+       }
+
+       // read UID bytes.
+       uint8_t uid[] = {0,0,0,0};
+       for ( uint8_t i = 0; i < sizeof(uid); ++i) {
+               int r = legic_read_byte(i, cmd_sz);
+               if ( r == -1 ) {
+                       cmd_send(CMD_ACK,0,0,0,0,0);
+                       goto OUT;
+               }
+               uid[i] = r & 0xFF;
+       }
+
+       cmd_send(CMD_ACK,1,card_sz,0,uid,sizeof(uid));
+out:   
+       switch_off_tag_rwd();
+       LEDsoff();
+
+}
+
 /* Handle (whether to respond) a frame in tag mode
  * Only called when simulating a tag.
  */
 /* Handle (whether to respond) a frame in tag mode
  * Only called when simulating a tag.
  */
@@ -1656,56 +1701,6 @@ static void CodeAndTransmitLegicAsReader(const uint8_t *cmd, uint8_t cmdlen, int
        }
 }
 
        }
 }
 
-int ice_legic_select_card()
-{
-       //int cmd_size=0, card_size=0;
-       uint8_t wakeup[] = { 0x7F };
-       uint8_t getid[] = {0x19};
-
-       //legic_prng_init(SESSION_IV);
-
-       // first, wake up the tag, 7bits
-       CodeAndTransmitLegicAsReader(wakeup, sizeof(wakeup), 7);
-
-       GetSamplesForLegicDemod(1000, TRUE);
-
-       //frame_receiveAsReader(&current_frame, 6, 1);
-
-       legic_prng_forward(1); /* we wait anyways */
-       
-       //while(timer->TC_CV < 387) ; /* ~ 258us */
-       //frame_sendAsReader(0x19, 6);
-       CodeAndTransmitLegicAsReader(getid, sizeof(getid), 8);
-       GetSamplesForLegicDemod(1000, TRUE);
-
-       //if (Demod.len < 14) return 2; 
-       Dbprintf("CARD TYPE: %02x  LEN: %d", Demod.output[0], Demod.len);
-
-       switch(Demod.output[0]) {
-               case 0x1d:
-                       DbpString("MIM 256 card found");
-            // cmd_size = 9;
-                       // card_size = 256;
-                       break;
-               case 0x3d:
-                       DbpString("MIM 1024 card found");
-            // cmd_size = 11;
-                       // card_size = 1024;
-                       break;
-               default:
-                       return -1;
-       }
-       
-       // if(bytes == -1)
-               // bytes = card_size;
-
-       // if(bytes + offset >= card_size)
-               // bytes = card_size - offset;  
-       
-       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-       set_tracing(FALSE);
-       return 1;
-}
 
 // Set up LEGIC communication
 void ice_legic_setup() {
 
 // Set up LEGIC communication
 void ice_legic_setup() {
index 2008f5b9771bf3b3165d6d5ccea9ffb79053d68c..992878421a8b469a959d9d5bf18b9d4a98b27fa5 100644 (file)
 #include "crc.h"               // legic crc-4
 #include "ticks.h"             // timers
 
 #include "crc.h"               // legic crc-4
 #include "ticks.h"             // timers
 
-#define LEGIC_READ 0x01
-#define LEGIC_WRITE 0x00
-
 extern void LegicRfSimulate(int phase, int frame, int reqresp);
 extern int  LegicRfReader(int offset, int bytes, int iv);
 extern void LegicRfWriter(int offset, int bytes, int iv);
 extern void LegicRfRawWriter(int address, int data, int iv);
 extern void LegicRfSimulate(int phase, int frame, int reqresp);
 extern int  LegicRfReader(int offset, int bytes, int iv);
 extern void LegicRfWriter(int offset, int bytes, int iv);
 extern void LegicRfRawWriter(int address, int data, int iv);
+extern void LegicRfInfo(void);
 
 uint32_t get_key_stream(int skip, int count);
 void frame_send_tag(uint16_t response, uint8_t bits, uint8_t crypt);
 
 uint32_t get_key_stream(int skip, int count);
 void frame_send_tag(uint16_t response, uint8_t bits, uint8_t crypt);
index 6701bee1eafbe43f0b18ace0f361a43e0c44f253..b240878277a841205a6e0f1e7e7e13e5d427b55e 100644 (file)
@@ -894,6 +894,12 @@ int CmdHFSearch(const char *Cmd){
                PrintAndLog("\nValid Topaz Tag Found - Quiting Search\n");
                return 1;
        }
                PrintAndLog("\nValid Topaz Tag Found - Quiting Search\n");
                return 1;
        }
+       ans = HFLegicInfo("", false);
+       if ( ans == 0) {
+               PrintAndLog("\nValid LEGIC Tag Found - Quiting Search\n");
+               return 1;
+       }
+       
        PrintAndLog("\nno known/supported 13.56 MHz tags found\n");
        return 0;
 }
        PrintAndLog("\nno known/supported 13.56 MHz tags found\n");
        return 0;
 }
index 51082aa09cec99a0788bf788b3c7f14d4d2d18e7..2200a15b9b69af8fabe12a469801d0f3584d23c0 100644 (file)
@@ -90,7 +90,16 @@ int usage_legic_fill(void){
        PrintAndLog("Missing help text.");
        return 0;
 }
        PrintAndLog("Missing help text.");
        return 0;
 }
-
+int usage_legic_info(void){
+       PrintAndLog("Read info from a legic tag.");
+       PrintAndLog("Usage:  hf legic info [h]");
+       PrintAndLog("Options:");
+       PrintAndLog("  h             : this help");
+       PrintAndLog("");
+       PrintAndLog("Samples:");
+       PrintAndLog("      hf legic info");
+       return 0;
+}
 /*
  *  Output BigBuf and deobfuscate LEGIC RF tag data.
  *  This is based on information given in the talk held
 /*
  *  Output BigBuf and deobfuscate LEGIC RF tag data.
  *  This is based on information given in the talk held
@@ -810,6 +819,43 @@ int CmdLegicCalcCrc8(const char *Cmd){
        return 0;
 } 
  
        return 0;
 } 
  
+int HFLegicInfo(const char *Cmd, bool verbose) {
+
+       char cmdp = param_getchar(Cmd, 0);
+       if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_info();
+       
+       UsbCommand c = {CMD_LEGIC_INFO, {0,0,0}};
+       clearCommandBuffer();
+    SendCommand(&c);
+       UsbCommand resp;
+       if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
+               uint8_t isOK = resp.arg[0] & 0xFF;
+               uint16_t tagtype = resp.arg[1] & 0xFFF;
+                if ( isOK ) {
+                       PrintAndLog(" UID : %s", sprint_hex(resp.d.asBytes, 4));
+                       switch(tagtype) {
+                               case 22: PrintAndLog("MIM22 card (22bytes)"); break;
+                               case 256: PrintAndLog("MIM256 card (256bytes)"); break;
+                               case 1024: PrintAndLog("MIM1024 card (1024bytes)");     break;                          
+                               default: {
+                                       PrintAndLog("Unknown card format: %x", tagtype); 
+                                       return 1;
+                               }
+                       }               
+               } else {
+                       PrintAndLog("legic card select failed");
+                       return 1;
+               }
+       } else {
+               PrintAndLog("command execution time out");
+               return 1;
+       }
+       return 0;
+}
+int CmdLegicInfo(const char *Cmd){
+       return HFLegicInfo(Cmd, TRUE);
+}
+       
 static command_t CommandTable[] =  {
        {"help",        CmdHelp,        1, "This help"},
        {"decode",      CmdLegicDecode, 0, "Display deobfuscated and decoded LEGIC RF tag data (use after hf legic reader)"},
 static command_t CommandTable[] =  {
        {"help",        CmdHelp,        1, "This help"},
        {"decode",      CmdLegicDecode, 0, "Display deobfuscated and decoded LEGIC RF tag data (use after hf legic reader)"},
@@ -821,7 +867,7 @@ static command_t CommandTable[] =  {
        {"writeraw",CmdLegicRfRawWrite, 0, "<address> <value> <iv> -- Write direct to address"},
        {"fill",        CmdLegicRfFill, 0, "<offset> <length> <value> -- Fill/Write tag with constant value"},
        {"crc8",        CmdLegicCalcCrc8, 1, "Calculate Legic CRC8 over given hexbytes"},
        {"writeraw",CmdLegicRfRawWrite, 0, "<address> <value> <iv> -- Write direct to address"},
        {"fill",        CmdLegicRfFill, 0, "<offset> <length> <value> -- Fill/Write tag with constant value"},
        {"crc8",        CmdLegicCalcCrc8, 1, "Calculate Legic CRC8 over given hexbytes"},
-       {"info",        CmdLegicCalcCrc8, 1, "Information"},
+       {"info",        CmdLegicInfo, 1, "Information"},
        {NULL, NULL, 0, NULL}
 };
 
        {NULL, NULL, 0, NULL}
 };
 
index 60818f616e0284276182e3e203da5f3e8e54f1a5..b43c47fe67f7fac6254049dbdafb1a8980e4886a 100644 (file)
@@ -34,8 +34,11 @@ int CmdLegicRfRawWrite(const char *Cmd);
 int CmdLegicRfFill(const char *Cmd);
 
 int CmdLegicCalcCrc8(const char *Cmd);
 int CmdLegicRfFill(const char *Cmd);
 
 int CmdLegicCalcCrc8(const char *Cmd);
+int CmdLegicInfo(const char *Cmd);
+int HFLegicInfo(const char *Cmd, bool verbose);
 
 int usage_legic_calccrc8(void);
 int usage_legic_load(void);
 int usage_legic_read(void);
 
 int usage_legic_calccrc8(void);
 int usage_legic_load(void);
 int usage_legic_read(void);
+int usage_legic_info(void);
 #endif
 #endif
index f1f3eb94f6a4c1b24988e50e5bd40cd6017140f6..1c61ebcfb5efc8c875de7bc2dd983bafb4dba0cd 100644 (file)
@@ -129,12 +129,16 @@ typedef struct {
 #define CMD_SNOOP_ISO_14443a                                              0x0383
 #define CMD_SIMULATE_TAG_ISO_14443a                                       0x0384
 #define CMD_READER_ISO_14443a                                             0x0385
 #define CMD_SNOOP_ISO_14443a                                              0x0383
 #define CMD_SIMULATE_TAG_ISO_14443a                                       0x0384
 #define CMD_READER_ISO_14443a                                             0x0385
+
 #define CMD_SIMULATE_TAG_LEGIC_RF                                         0x0387
 #define CMD_READER_LEGIC_RF                                               0x0388
 #define CMD_WRITER_LEGIC_RF                                               0x0389
 #define CMD_SIMULATE_TAG_LEGIC_RF                                         0x0387
 #define CMD_READER_LEGIC_RF                                               0x0388
 #define CMD_WRITER_LEGIC_RF                                               0x0389
+
 #define CMD_EPA_PACE_COLLECT_NONCE                                        0x038A
 #define CMD_EPA_PACE_REPLAY                                               0x038B
 
 #define CMD_EPA_PACE_COLLECT_NONCE                                        0x038A
 #define CMD_EPA_PACE_REPLAY                                               0x038B
 
+#define CMD_LEGIC_INFO                                                                                                   0x03BC
+
 #define CMD_SNOOP_ICLASS                                                  0x0392
 #define CMD_SIMULATE_TAG_ICLASS                                           0x0393
 #define CMD_READER_ICLASS                                                 0x0394
 #define CMD_SNOOP_ICLASS                                                  0x0392
 #define CMD_SIMULATE_TAG_ICLASS                                           0x0393
 #define CMD_READER_ICLASS                                                 0x0394
index b953562e8779587b9e1d264952231f33ddaa322b..680e6da91e957861120ba7a028aa1703ee59e604 100644 (file)
@@ -99,9 +99,12 @@ local _commands = {
        CMD_SIMULATE_TAG_LEGIC_RF =                                          0x0387,
        CMD_READER_LEGIC_RF =                                                0x0388,
        CMD_WRITER_LEGIC_RF =                                                0x0389,
        CMD_SIMULATE_TAG_LEGIC_RF =                                          0x0387,
        CMD_READER_LEGIC_RF =                                                0x0388,
        CMD_WRITER_LEGIC_RF =                                                0x0389,
+       
        CMD_EPA_PACE_COLLECT_NONCE =                                         0x038A,
        CMD_EPA_PACE_REPLAY =                                                0x038B,
 
        CMD_EPA_PACE_COLLECT_NONCE =                                         0x038A,
        CMD_EPA_PACE_REPLAY =                                                0x038B,
 
+       CMD_LEGIC_INFO =                                                                                                         0x03BC,
+       
        CMD_ICLASS_READCHECK =                                               0x038F,
        CMD_ICLASS_CLONE =                                                   0x0390,
        CMD_ICLASS_DUMP =                                                    0x0391,
        CMD_ICLASS_READCHECK =                                               0x038F,
        CMD_ICLASS_CLONE =                                                   0x0390,
        CMD_ICLASS_DUMP =                                                    0x0391,
index e4ec049356ae60b8d0a23b92ddd67046137714c1..a0ce422365d65b1384bb6ed225ee2ce6bc632f21 100644 (file)
@@ -142,9 +142,12 @@ typedef struct{
 #define CMD_SIMULATE_TAG_LEGIC_RF                                         0x0387
 #define CMD_READER_LEGIC_RF                                               0x0388
 #define CMD_WRITER_LEGIC_RF                                               0x0389
 #define CMD_SIMULATE_TAG_LEGIC_RF                                         0x0387
 #define CMD_READER_LEGIC_RF                                               0x0388
 #define CMD_WRITER_LEGIC_RF                                               0x0389
+
 #define CMD_EPA_PACE_COLLECT_NONCE                                        0x038A
 #define CMD_EPA_PACE_REPLAY                                               0x038B
 
 #define CMD_EPA_PACE_COLLECT_NONCE                                        0x038A
 #define CMD_EPA_PACE_REPLAY                                               0x038B
 
+#define CMD_LEGIC_INFO                                                                                                   0x03BC
+
 #define CMD_ICLASS_READCHECK                                              0x038F
 #define CMD_ICLASS_CLONE                                                  0x0390
 #define CMD_ICLASS_DUMP                                                   0x0391
 #define CMD_ICLASS_READCHECK                                              0x038F
 #define CMD_ICLASS_CLONE                                                  0x0390
 #define CMD_ICLASS_DUMP                                                   0x0391
Impressum, Datenschutz