chg: 'hf 15 read' - nice output and with lock info

chg: 'hf 15 readmulti' - nicer output and with lock info

You can still break the client if you ask to read too many blocks at one time.
I suggest 'hf 15 dump' instead for that purpose
This commit is contained in:
iceman1001 2017-09-06 22:04:00 +02:00
commit 6d98779ff8
3 changed files with 48 additions and 29 deletions

View file

@ -313,4 +313,3 @@ $(DEPENDENCY_FILES): ;
.PRECIOUS: $(DEPENDENCY_FILES) .PRECIOUS: $(DEPENDENCY_FILES)
-include $(DEPENDENCY_FILES) -include $(DEPENDENCY_FILES)

View file

@ -28,9 +28,9 @@
#define Logic1 Iso15693Logic1 #define Logic1 Iso15693Logic1
#define FrameEOF Iso15693FrameEOF #define FrameEOF Iso15693FrameEOF
#define Crc(data,datalen) Iso15693Crc(data,datalen) #define Crc(data, len) Iso15693Crc((data), (len))
#define AddCrc(data,datalen) Iso15693AddCrc(data,datalen) #define AddCrc(data, len) Iso15693AddCrc((data), (len))
#define sprintUID(target,uid) Iso15693sprintUID(target,uid) #define sprintUID(target, uid) Iso15693sprintUID((target), (uid))
// structure and database for uid -> tagtype lookups // structure and database for uid -> tagtype lookups
typedef struct { typedef struct {
@ -712,7 +712,7 @@ int CmdHF15Dump(const char*Cmd) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
if ( ISO15_CRC_CHECK == Crc(recv, len) ) { if ( ISO15_CRC_CHECK == Crc(recv, len-2) ) {
if (!(recv[0] & ISO15_RES_ERROR)) { if (!(recv[0] & ISO15_RES_ERROR)) {
@ -736,7 +736,7 @@ int CmdHF15Dump(const char*Cmd) {
} }
printf("\n"); printf("\n");
PrintAndLog("Block# | Data |lck| Ascii"); PrintAndLog("block# | data |lck| ascii");
PrintAndLog("---------+--------------+---+----------"); PrintAndLog("---------+--------------+---+----------");
for (int i = 0; i < blocknum; i++) { for (int i = 0; i < blocknum; i++) {
PrintAndLog("%3d/0x%02X | %s | %d | %s", i, i, sprint_hex(mem[i].block, 4 ), mem[i].lock, sprint_ascii(mem[i].block, 4) ); PrintAndLog("%3d/0x%02X | %s | %d | %s", i, i, sprint_hex(mem[i].block, 4 ), mem[i].lock, sprint_ascii(mem[i].block, 4) );
@ -876,13 +876,13 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd) {
// strip // strip
while (**cmd==' ' || **cmd=='\t') (*cmd)++; while (**cmd==' ' || **cmd=='\t') (*cmd)++;
if (strstr(*cmd,"-o") == *cmd) { if (strstr(*cmd, "-o") == *cmd) {
req[reqlen] = ISO15_REQ_OPTION; req[reqlen] = ISO15_REQ_OPTION;
(*cmd) += 2; (*cmd) += 2;
} }
// strip // strip
while (**cmd==' ' || **cmd=='\t') (*cmd)++; while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
switch (**cmd) { switch (**cmd) {
case 0: case 0:
@ -951,7 +951,8 @@ int CmdHF15Readmulti(const char *Cmd) {
uint8_t *recv; uint8_t *recv;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
uint8_t *req = c.d.asBytes; uint8_t *req = c.d.asBytes;
int reqlen = 0, pagenum,pagecount; int reqlen = 0;
uint8_t pagenum, pagecount;
char cmdbuf[100]; char cmdbuf[100];
char *cmd = cmdbuf; char *cmd = cmdbuf;
strncpy(cmd, Cmd, 99); strncpy(cmd, Cmd, 99);
@ -959,20 +960,23 @@ int CmdHF15Readmulti(const char *Cmd) {
if ( !prepareHF15Cmd(&cmd, &c, ISO15_CMD_READMULTI) ) if ( !prepareHF15Cmd(&cmd, &c, ISO15_CMD_READMULTI) )
return 0; return 0;
// add OPTION flag, in order to get lock-info
req[0] |= ISO15_REQ_OPTION;
reqlen = c.arg[0]; reqlen = c.arg[0];
pagenum = strtol(cmd, NULL, 0); // decimal
pagenum = param_get8ex(cmd, 0, 0, 10);
pagecount = param_get8ex(cmd, 1, 0, 10);
// skip to next space printf("ice %d %d\n", pagenum, pagecount);
while (*cmd!=' ' && *cmd!='\t') cmd++;
// skip over the space
while (*cmd==' ' || *cmd=='\t') cmd++;
pagecount = strtol(cmd, NULL, 0);
if (pagecount > 0) pagecount--; // 0 means 1 page, 1 means 2 pages, ...
req[reqlen++] = (uint8_t)pagenum; // 0 means 1 page,
req[reqlen++] = (uint8_t)pagecount; // 1 means 2 pages, ...
if (pagecount > 0) pagecount--;
req[reqlen++] = pagenum;
req[reqlen++] = pagecount;
reqlen = AddCrc(req, reqlen); reqlen = AddCrc(req, reqlen);
c.arg[0] = reqlen; c.arg[0] = reqlen;
@ -992,7 +996,7 @@ int CmdHF15Readmulti(const char *Cmd) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
if (ISO15_CRC_CHECK == Crc(recv, status)) { if (ISO15_CRC_CHECK == Crc(recv, status-2)) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
return 2; return 2;
} }
@ -1002,9 +1006,18 @@ int CmdHF15Readmulti(const char *Cmd) {
return 3; return 3;
} }
int start = 1; // skip status byte
int stop = (pagecount+1) * 5;
int currblock = pagenum;
// print response // print response
PrintAndLog("%s", sprint_hex_ascii( recv+1, status-3)); PrintAndLog("");
PrintAndLog("block# | data |lck| ascii");
PrintAndLog("---------+--------------+---+----------");
for (int i = start; i < stop; i += 5) {
PrintAndLog("%3d/0x%02X | %s | %d | %s", currblock, currblock, sprint_hex(recv+i+1, 4 ), recv[i], sprint_ascii(recv+i+1, 4) );
currblock++;
}
return 0; return 0;
} }
@ -1026,7 +1039,7 @@ int CmdHF15Read(const char *Cmd) {
// arg2 (recv == 1 == expect a response) // arg2 (recv == 1 == expect a response)
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}};
uint8_t *req = c.d.asBytes; uint8_t *req = c.d.asBytes;
int reqlen = 0, pagenum; int reqlen = 0, blocknum;
char cmdbuf[100]; char cmdbuf[100];
char *cmd = cmdbuf; char *cmd = cmdbuf;
strncpy(cmd, Cmd, 99); strncpy(cmd, Cmd, 99);
@ -1034,11 +1047,14 @@ int CmdHF15Read(const char *Cmd) {
if ( !prepareHF15Cmd(&cmd, &c, ISO15_CMD_READ) ) if ( !prepareHF15Cmd(&cmd, &c, ISO15_CMD_READ) )
return 0; return 0;
// add OPTION flag, in order to get lock-info
req[0] |= ISO15_REQ_OPTION;
reqlen = c.arg[0]; reqlen = c.arg[0];
pagenum = strtol(cmd, NULL, 0); blocknum = strtol(cmd, NULL, 0);
req[reqlen++] = (uint8_t)pagenum; req[reqlen++] = (uint8_t)blocknum;
reqlen = AddCrc(req, reqlen); reqlen = AddCrc(req, reqlen);
@ -1060,7 +1076,7 @@ int CmdHF15Read(const char *Cmd) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
if (ISO15_CRC_CHECK == Crc(recv, status)) { if (ISO15_CRC_CHECK == Crc(recv, status-2)) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
return 2; return 2;
} }
@ -1071,7 +1087,11 @@ int CmdHF15Read(const char *Cmd) {
} }
// print response // print response
PrintAndLog("%s", sprint_hex_ascii(recv+1, status-3) ); PrintAndLog("");
PrintAndLog("block #%3d |lck| ascii", blocknum );
PrintAndLog("------------+---+------" );
PrintAndLog("%s| %d | %s", sprint_hex(recv+2, status-4), recv[1], sprint_ascii(recv+2, status-4) );
PrintAndLog("");
return 0; return 0;
} }
@ -1140,7 +1160,7 @@ int CmdHF15Write(const char *Cmd) {
recv = resp.d.asBytes; recv = resp.d.asBytes;
if (ISO15_CRC_CHECK == Crc(recv, status)) { if (ISO15_CRC_CHECK == Crc(recv, status-2)) {
PrintAndLog("CRC failed"); PrintAndLog("CRC failed");
return 2; return 2;
} }

View file

@ -37,7 +37,7 @@ uint16_t Iso15693Crc(uint8_t *v, int n)
// n length without crc // n length without crc
// returns the new length of the dataframe. // returns the new length of the dataframe.
int Iso15693AddCrc(uint8_t *req, int n) { int Iso15693AddCrc(uint8_t *req, int n) {
uint16_t crc=Iso15693Crc(req,n); uint16_t crc = Iso15693Crc(req, n);
req[n] = crc & 0xff; req[n] = crc & 0xff;
req[n+1] = crc >> 8; req[n+1] = crc >> 8;
return n+2; return n+2;