CHG: "hf legic dump" now automatically detects tagtype and dumps accordingly.

CHG:  still #define codestyle  should it be with or without semicolons?
This commit is contained in:
iceman1001 2016-10-05 22:58:06 +02:00
commit 9015ae0f5d
3 changed files with 64 additions and 40 deletions

View file

@ -1,5 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// (c) 2009 Henryk Plötz <henryk@ploetzli.ch> // (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
// 2016 Iceman
// //
// This code is licensed to you under the terms of the GNU GPL, version 2 or, // 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 // at your option, any later version. See the LICENSE.txt file for the text of
@ -85,7 +86,7 @@ static void setup_timer(void) {
#define FUZZ_EQUAL(value, target, fuzz) ((value) > ((target)-(fuzz)) && (value) < ((target)+(fuzz))) #define FUZZ_EQUAL(value, target, fuzz) ((value) > ((target)-(fuzz)) && (value) < ((target)+(fuzz)))
#ifndef SHORT_COIL #ifndef SHORT_COIL
# define SHORT_COIL LOW(GPIO_SSC_DOUT); # define SHORT_COIL LOW(GPIO_SSC_DOUT);
#endif #endif
#ifndef OPEN_COIL #ifndef OPEN_COIL
# define OPEN_COIL HIGH(GPIO_SSC_DOUT); # define OPEN_COIL HIGH(GPIO_SSC_DOUT);
@ -102,7 +103,7 @@ static void setup_timer(void) {
WaitTicks( (RWD_TIME_PAUSE) ); \ WaitTicks( (RWD_TIME_PAUSE) ); \
OPEN_COIL; \ OPEN_COIL; \
WaitTicks((x)); \ WaitTicks((x)); \
} while (0) } while (0);
#endif #endif
// ToDo: define a meaningful maximum size for auth_table. The bigger this is, the lower will be the available memory for traces. // ToDo: define a meaningful maximum size for auth_table. The bigger this is, the lower will be the available memory for traces.
@ -210,9 +211,9 @@ void frame_sendAsReader(uint32_t data, uint8_t bits){
for (; mask < BITMASK(bits); mask <<= 1) { for (; mask < BITMASK(bits); mask <<= 1) {
if (send & mask) if (send & mask)
COIL_PULSE(RWD_TIME_1); COIL_PULSE(RWD_TIME_1)
else else
COIL_PULSE(RWD_TIME_0); COIL_PULSE(RWD_TIME_0)
} }
// Final pause to mark the end of the frame // Final pause to mark the end of the frame

View file

@ -142,7 +142,7 @@ int CmdLegicInfo(const char *Cmd) {
int dcf = 0; int dcf = 0;
int bIsSegmented = 0; int bIsSegmented = 0;
CmdLegicRdmem("0 21 55"); CmdLegicRdmem("0 22 55");
// copy data from device // copy data from device
GetEMLFromBigBuf(data, sizeof(data), 0); GetEMLFromBigBuf(data, sizeof(data), 0);
@ -864,41 +864,59 @@ int CmdLegicCalcCrc8(const char *Cmd){
if (data) free(data); if (data) free(data);
return 0; return 0;
} }
int HFLegicReader(const char *Cmd, bool verbose) {
char cmdp = param_getchar(Cmd, 0); int legic_print_type(uint32_t tagtype, uint8_t spaces){
if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_info(); char spc[11] = " ";
spc[10]=0x00;
char *spacer = spc + (10-spaces);
if ( tagtype == 22 )
PrintAndLog("%sTYPE : MIM%d card (outdated)", spacer, tagtype);
else if ( tagtype == 256 )
PrintAndLog("%sTYPE : MIM%d card (234 bytes)", spacer, tagtype);
else if ( tagtype == 1024 )
PrintAndLog("%sTYPE : MIM%d card (1002 bytes)", spacer, tagtype);
else
PrintAndLog("%sTYPE : Unknown %06x", spacer, tagtype);
return 0;
}
int legic_get_type(legic_card_select_t *card){
if ( card == NULL ) return 1;
UsbCommand c = {CMD_LEGIC_INFO, {0,0,0}}; UsbCommand c = {CMD_LEGIC_INFO, {0,0,0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
UsbCommand resp; UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 500)) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 500))
if ( verbose ) PrintAndLog("command execution time out"); return 2;
return 1;
}
uint8_t isOK = resp.arg[0] & 0xFF; uint8_t isOK = resp.arg[0] & 0xFF;
if ( !isOK ) { if ( !isOK )
if ( verbose ) PrintAndLog("legic card select failed"); return 3;
return 1;
} memcpy(card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t));
return 0;
}
int HFLegicReader(const char *Cmd, bool verbose) {
char cmdp = param_getchar(Cmd, 0);
if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_reader();
legic_card_select_t card; legic_card_select_t card;
memcpy(&card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t)); switch(legic_get_type(&card)){
case 1:
PrintAndLog(" UID : %s", sprint_hex(card.uid, sizeof(card.uid))); if ( verbose ) PrintAndLog("command execution time out");
switch(card.cardsize) {
case 22:
case 256:
case 1024:
PrintAndLog(" TYPE : MIM%d card (%d bytes)", card.cardsize, card.cardsize); break;
default: {
PrintAndLog("Unknown card format: %d", card.cardsize);
return 1; return 1;
} case 2:
case 3:
if ( verbose ) PrintAndLog("legic card select failed");
return 2;
default: break;
} }
PrintAndLog(" UID : %s", sprint_hex(card.uid, sizeof(card.uid)));
legic_print_type(card.cardsize, 0);
return 0; return 0;
} }
int CmdLegicReader(const char *Cmd){ int CmdLegicReader(const char *Cmd){
@ -912,9 +930,8 @@ int CmdLegicDump(const char *Cmd){
char *fnameptr = filename; char *fnameptr = filename;
size_t fileNlen = 0; size_t fileNlen = 0;
bool errors = false; bool errors = false;
uint16_t dumplen = 0x100; uint16_t dumplen;
uint8_t cmdp = 0;
char cmdp = param_getchar(Cmd, 0);
while(param_getchar(Cmd, cmdp) != 0x00) while(param_getchar(Cmd, cmdp) != 0x00)
{ {
@ -942,9 +959,16 @@ int CmdLegicDump(const char *Cmd){
if(errors) return usage_legic_dump(); if(errors) return usage_legic_dump();
// tagtype // tagtype
//uint32_t tagtype = GetHF14AMfU_Type(); legic_card_select_t card;
//if (tagtype == -1) return -1; if (legic_get_type(&card)) {
PrintAndLog("Failed to identify tagtype");
return -1;
}
dumplen = card.cardsize;
legic_print_type(dumplen, 0);
PrintAndLog("Reading tag memory...");
UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}}; UsbCommand c = {CMD_READER_LEGIC_RF, {0x00, dumplen, 0x55}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);

View file

@ -24,8 +24,8 @@
#include "legic.h" // legic_card_select_t struct #include "legic.h" // legic_card_select_t struct
int CmdHFLegic(const char *Cmd); int CmdHFLegic(const char *Cmd);
int CmdLegicInfo(const char *Cmd);
int CmdLegicInfo(const char *Cmd);
int CmdLegicRdmem(const char *Cmd); int CmdLegicRdmem(const char *Cmd);
int CmdLegicLoad(const char *Cmd); int CmdLegicLoad(const char *Cmd);
int CmdLegicSave(const char *Cmd); int CmdLegicSave(const char *Cmd);
@ -33,14 +33,13 @@ int CmdLegicRfSim(const char *Cmd);
int CmdLegicRfWrite(const char *Cmd); int CmdLegicRfWrite(const char *Cmd);
int CmdLegicRfRawWrite(const char *Cmd); int CmdLegicRfRawWrite(const char *Cmd);
int CmdLegicRfFill(const char *Cmd); int CmdLegicRfFill(const char *Cmd);
int CmdLegicCalcCrc8(const char *Cmd); int CmdLegicCalcCrc8(const char *Cmd);
int CmdLegicReader(const char *Cmd);
int HFLegicReader(const char *Cmd, bool verbose);
int CmdLegicDump(const char *Cmd); int CmdLegicDump(const char *Cmd);
int CmdLegicReader(const char *Cmd);
int HFLegicReader(const char *Cmd, bool verbose);
int legic_print_type(uint32_t tagtype, uint8_t spaces);
int legic_get_type(legic_card_select_t *card);
int usage_legic_calccrc8(void); int usage_legic_calccrc8(void);
int usage_legic_load(void); int usage_legic_load(void);