X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/b10a759fefc33673745dd65a6b4ba11af7cf8025..a7474bb30acb4881fe57db4c8ce0778823efa501:/client/cmdhf14b.c diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index d1eb9917..39232a0a 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -11,7 +11,6 @@ #include #include #include -//#include #include #include "iso14443crc.h" #include "proxmark3.h" @@ -35,7 +34,7 @@ int CmdHF14BList(const char *Cmd) int CmdHF14BSim(const char *Cmd) { - UsbCommand c={CMD_SIMULATE_TAG_ISO_14443B}; + UsbCommand c = {CMD_SIMULATE_TAG_ISO_14443B}; clearCommandBuffer(); SendCommand(&c); return 0; @@ -43,7 +42,7 @@ int CmdHF14BSim(const char *Cmd) int CmdHF14BSnoop(const char *Cmd) { - UsbCommand c = {CMD_SNOOP_ISO_14443B}; + UsbCommand c = {CMD_SNOOP_ISO_14443B}; clearCommandBuffer(); SendCommand(&c); return 0; @@ -73,11 +72,16 @@ int CmdSrix4kRead(const char *Cmd) return 0; } + int rawClose(void){ + UsbCommand resp; UsbCommand c = {CMD_ISO_14443B_COMMAND, {0, 0, 0}}; clearCommandBuffer(); SendCommand(&c); + if (!WaitForResponseTimeout(CMD_ACK,&resp,1000)) { return 0; + } + return 0; } int HF14BCmdRaw(bool reply, bool *crc, bool power, uint8_t *data, uint8_t *datalen, bool verbose){ @@ -225,7 +229,7 @@ int CmdHF14BCmdRaw (const char *Cmd) { // REQB if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false)==0) return rawClose(); - PrintAndLog("REQB : %s", sprint_hex(cmd2, 9)); + PrintAndLog("REQB : %s", sprint_hex(cmd2, cmdLen)); if ( SRx && (cmdLen != 3 || !crc2) ) return rawClose(); else if (cmd2[0] != 0x50 || cmdLen != 14 || !crc2) return rawClose(); @@ -251,7 +255,7 @@ int CmdHF14BCmdRaw (const char *Cmd) { // attrib if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false)==0) return rawClose(); - PrintAndLog("ATTRIB : %s", sprint_hex(cmd2, 3)); + PrintAndLog("ATTRIB : %s", sprint_hex(cmd2, cmdLen)); if (cmdLen != 3 || !crc2) return rawClose(); if (SRx && cmd2[0] != chipID) return rawClose(); @@ -310,7 +314,7 @@ char *get_ST_Chip_Model(uint8_t data){ case 0x6: sprintf(retStr, "SRI512"); break; case 0x7: sprintf(retStr, "SRI4K"); break; case 0xC: sprintf(retStr, "SRT512"); break; - default: sprintf(retStr, "Unknown"); break; + default : sprintf(retStr, "Unknown"); break; } return retStr; } @@ -454,8 +458,6 @@ int HF14BStdInfo(uint8_t *data, uint8_t *datalen){ //add more info here print_atqb_resp(data); - - return 1; } @@ -678,6 +680,84 @@ int CmdSriWrite( const char *Cmd){ return 0; } +int srix4kChecksum(uint32_t value) { +/* +// vv = value +// pp = position +// vv vv vv pp +4 bytes : 00 1A 20 01 +*/ + +#define NibbleHigh(b) ( (b & 0xF0) >> 4 ) +#define NibbleLow(b) ( b & 0x0F ) +#define Crumb(b,p) (((b & (0x3 << p) ) >> p ) & 0xF) + + // only the lower crumbs. + uint8_t block = (value & 0xFF); + uint8_t i = 0; + uint8_t valuebytes[] = {0,0,0}; + + // if ( strlen(Cmd) > 0){ + // value = param_get32ex(Cmd, 0, 0, 16); + + // block = value & 0xFF; + + // value &= 0xFFFFFF00; + // value >>=8; + // } + + num_to_bytes(value, 3, valuebytes); + + // Scrambled part + // Crumb swapping of value. + uint8_t temp[] = {0,0}; + temp[0] = (Crumb(value, 22) << 4 | Crumb(value, 14 ) << 2 | Crumb(value, 6)) << 4; + temp[0] |= Crumb(value, 20) << 4 | Crumb(value, 12 ) << 2 | Crumb(value, 4); + temp[1] = (Crumb(value, 18) << 4 | Crumb(value, 10 ) << 2 | Crumb(value, 2)) << 4; + temp[1] |= Crumb(value, 16) << 4 | Crumb(value, 8 ) << 2 | Crumb(value, 0); + + // chksum part + uint32_t chksum = 0xFF - block; + + // chksum is reduced by each nibbles of value. + for (i = 0; i < 3; ++i){ + chksum -= NibbleHigh(valuebytes[i]); + chksum -= NibbleLow(valuebytes[i]); + } + + // base4 conversion + // and left shift twice + i = 3; + uint8_t base4[] = {0,0,0,0}; + while( chksum !=0 ){ + base4[i--] = (chksum % 4 << 2); + chksum /= 4; + } + + // merge scambled and chksum parts + uint32_t encvalue = + ( NibbleLow ( base4[0]) << 28 ) | + ( NibbleHigh( temp[0]) << 24 ) | + + ( NibbleLow ( base4[1]) << 20 ) | + ( NibbleLow ( temp[0]) << 16 ) | + + ( NibbleLow ( base4[2]) << 12 ) | + ( NibbleHigh( temp[1]) << 8 ) | + + ( NibbleLow ( base4[3]) << 4 ) | + NibbleLow ( temp[1] ); + + PrintAndLog("ICE | %08X", encvalue); + return 0; +} +int srix4kMagicbytes(){ + return 0; +} +int srix4kValid(){ + return 0; +} + static command_t CommandTable[] = { {"help", CmdHelp, 1, "This help"}, @@ -690,6 +770,7 @@ static command_t CommandTable[] = {"srix4kread", CmdSrix4kRead, 0, "Read contents of a SRIX4K tag"}, {"sriwrite", CmdSriWrite, 0, "Write data to a SRI512 | SRIX4K tag"}, {"raw", CmdHF14BCmdRaw, 0, "Send raw hex data to tag"}, + //{"calcSrix4", srix4kchksum, 1, "a srix4k checksum test"}, {NULL, NULL, 0, NULL} };