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
bits,
BYTEx(data, 0),
BYTEx(data, 1),
- 0x00,
- 0x00,
+ BYTEx(send, 0),
+ BYTEx(send, 1),
prngstart,
legic_prng_count()
};
// 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;
// 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();
- Dbprintf("Exit Switch_off_tag_rwd");
+ set_tracing(FALSE);
}
// calculate crc4 for a legic READ command
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
// 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(¤t_frame, 12);
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.
*/
}
}
-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(¤t_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() {
#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 LegicRfInfo(void);
uint32_t get_key_stream(int skip, int count);
void frame_send_tag(uint16_t response, uint8_t bits, uint8_t crypt);
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("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
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)"},
{"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}
};
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_info(void);
#endif
#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_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
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_LEGIC_INFO = 0x03BC,
+
CMD_ICLASS_READCHECK = 0x038F,
CMD_ICLASS_CLONE = 0x0390,
CMD_ICLASS_DUMP = 0x0391,
#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_LEGIC_INFO 0x03BC
+
#define CMD_ICLASS_READCHECK 0x038F
#define CMD_ICLASS_CLONE 0x0390
#define CMD_ICLASS_DUMP 0x0391