mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
CHG: iso15 from b8f35947f2
@lnv42
This commit is contained in:
parent
466bbe1733
commit
93ecfddb88
3 changed files with 51 additions and 53 deletions
|
@ -83,6 +83,7 @@
|
||||||
|
|
||||||
#define Crc(data,datalen) Iso15693Crc(data, datalen)
|
#define Crc(data,datalen) Iso15693Crc(data, datalen)
|
||||||
#define AddCrc(data,datalen) Iso15693AddCrc(data, datalen)
|
#define AddCrc(data,datalen) Iso15693AddCrc(data, datalen)
|
||||||
|
#define CheckCrc(data,datalen) Iso15693CheckCrc(data,datalen)
|
||||||
#define sprintUID(target,uid) Iso15693sprintUID(target, uid)
|
#define sprintUID(target,uid) Iso15693sprintUID(target, uid)
|
||||||
|
|
||||||
int DEBUG = 0;
|
int DEBUG = 0;
|
||||||
|
@ -693,9 +694,7 @@ static void BuildIdentifyRequest(uint8_t *out) {
|
||||||
// no mask
|
// no mask
|
||||||
cmd[2] = 0x00;
|
cmd[2] = 0x00;
|
||||||
// CRC
|
// CRC
|
||||||
uint16_t crc = Crc(cmd, 3);
|
AddCrc(cmd, 3);
|
||||||
cmd[3] = crc & 0xff;
|
|
||||||
cmd[4] = crc >> 8;
|
|
||||||
// coding as high speed (1 out of 4)
|
// coding as high speed (1 out of 4)
|
||||||
CodeIso15693AsReader(cmd, CMD_ID_RESP);
|
CodeIso15693AsReader(cmd, CMD_ID_RESP);
|
||||||
memcpy(out, cmd, CMD_ID_RESP);
|
memcpy(out, cmd, CMD_ID_RESP);
|
||||||
|
@ -724,10 +723,7 @@ static void BuildReadBlockRequest(uint8_t **out, uint8_t *uid, uint8_t blockNumb
|
||||||
// Block number to read
|
// Block number to read
|
||||||
cmd[10] = blockNumber;//0x00;
|
cmd[10] = blockNumber;//0x00;
|
||||||
// CRC
|
// CRC
|
||||||
uint16_t crc = Crc(cmd, 11); // the crc needs to be calculated over 12 bytes
|
AddCrc(cmd, 11);
|
||||||
cmd[11] = crc & 0xff;
|
|
||||||
cmd[12] = crc >> 8;
|
|
||||||
|
|
||||||
CodeIso15693AsReader(cmd, CMD_READ_RESP);
|
CodeIso15693AsReader(cmd, CMD_READ_RESP);
|
||||||
memcpy(out, cmd, CMD_ID_RESP);
|
memcpy(out, cmd, CMD_ID_RESP);
|
||||||
}
|
}
|
||||||
|
@ -753,10 +749,7 @@ static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) {
|
||||||
cmd[8] = uid[1]; //0x05;
|
cmd[8] = uid[1]; //0x05;
|
||||||
cmd[9] = uid[0]; //0xe0;
|
cmd[9] = uid[0]; //0xe0;
|
||||||
// CRC
|
// CRC
|
||||||
uint16_t crc = Crc(cmd, 10);
|
AddCrc(cmd, 10);
|
||||||
cmd[10] = crc & 0xff;
|
|
||||||
cmd[11] = crc >> 8;
|
|
||||||
|
|
||||||
CodeIso15693AsReader(cmd, CMD_INV_RESP);
|
CodeIso15693AsReader(cmd, CMD_INV_RESP);
|
||||||
memcpy(out, cmd, CMD_ID_RESP);
|
memcpy(out, cmd, CMD_ID_RESP);
|
||||||
}
|
}
|
||||||
|
@ -808,7 +801,6 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outda
|
||||||
#define DBD15STATLEN 48
|
#define DBD15STATLEN 48
|
||||||
void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||||
char status[DBD15STATLEN+1] = {0};
|
char status[DBD15STATLEN+1] = {0};
|
||||||
uint16_t crc;
|
|
||||||
|
|
||||||
if (len > 3) {
|
if (len > 3) {
|
||||||
if (d[0] & ( 1 << 3 ))
|
if (d[0] & ( 1 << 3 ))
|
||||||
|
@ -818,45 +810,44 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||||
strncat(status, "Error ", DBD15STATLEN);
|
strncat(status, "Error ", DBD15STATLEN);
|
||||||
switch (d[1]) {
|
switch (d[1]) {
|
||||||
case 0x01:
|
case 0x01:
|
||||||
strncat(status, "01:notSupp", DBD15STATLEN);
|
strncat(status, "01: not supported", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
strncat(status, "02:notRecog", DBD15STATLEN);
|
strncat(status, "02: not recognized", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
strncat(status, "03:optNotSupp", DBD15STATLEN);
|
strncat(status, "03: opt not supported", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x0f:
|
case 0x0f:
|
||||||
strncat(status, "0f:noInfo", DBD15STATLEN);
|
strncat(status, "0F: no info", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x10:
|
case 0x10:
|
||||||
strncat(status, "10:dontExist", DBD15STATLEN);
|
strncat(status, "10: dont exist", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x11:
|
case 0x11:
|
||||||
strncat(status, "11:lockAgain", DBD15STATLEN);
|
strncat(status, "11: lock again", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x12:
|
case 0x12:
|
||||||
strncat(status, "12:locked", DBD15STATLEN);
|
strncat(status, "12: locked", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x13:
|
case 0x13:
|
||||||
strncat(status, "13:progErr", DBD15STATLEN);
|
strncat(status, "13: program error", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
case 0x14:
|
case 0x14:
|
||||||
strncat(status, "14:lockErr", DBD15STATLEN);
|
strncat(status, "14: lock error", DBD15STATLEN);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strncat(status, "unknownErr", DBD15STATLEN);
|
strncat(status, "unknown error", DBD15STATLEN);
|
||||||
}
|
}
|
||||||
strncat(status ," " ,DBD15STATLEN);
|
strncat(status ," " ,DBD15STATLEN);
|
||||||
} else {
|
} else {
|
||||||
strncat(status ,"No err ", DBD15STATLEN);
|
strncat(status ,"No error ", DBD15STATLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
crc = Crc(d, len-2);
|
if (CheckCrc(d,len))
|
||||||
if ( (( crc & 0xff ) == d[len-2]) && (( crc >> 8 ) == d[len-1]) )
|
strncat(status, "[+] crc OK", DBD15STATLEN);
|
||||||
strncat(status, "Crc OK", DBD15STATLEN);
|
|
||||||
else
|
else
|
||||||
strncat(status, "Crc Fail!", DBD15STATLEN);
|
strncat(status, "[!] crc fail", DBD15STATLEN);
|
||||||
|
|
||||||
if ( DEBUG ) Dbprintf("%s", status);
|
if ( DEBUG ) Dbprintf("%s", status);
|
||||||
}
|
}
|
||||||
|
@ -868,7 +859,7 @@ void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
||||||
|
|
||||||
void SetDebugIso15693(uint32_t debug) {
|
void SetDebugIso15693(uint32_t debug) {
|
||||||
DEBUG = debug;
|
DEBUG = debug;
|
||||||
Dbprintf("Iso15693 Debug is now %s", DEBUG ? "on" : "off");
|
Dbprintf("[!] Iso15693 debug is %s", DEBUG ? "on" : "off");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,17 @@ int Iso15693AddCrc(uint8_t *req, int n) {
|
||||||
return n+2;
|
return n+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check the CRC as described in ISO 15693-Part 3-Annex C
|
||||||
|
// v buffer with data
|
||||||
|
// n length (including crc)
|
||||||
|
// returns true if the crc is valid, else return false
|
||||||
|
bool Iso15693CheckCrc(uint8_t *v, int n) {
|
||||||
|
uint16_t crc = Iso15693Crc(v, n-2);
|
||||||
|
if ( (( crc & 0xff ) == v[n-2]) && (( crc >> 8 ) == v[n-1]) )
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int sprintf(char *str, const char *format, ...);
|
int sprintf(char *str, const char *format, ...);
|
||||||
|
|
||||||
// returns a string representation of the UID
|
// returns a string representation of the UID
|
||||||
|
@ -62,31 +73,26 @@ char* Iso15693sprintUID(char *target, uint8_t *uid) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t iclass_crc16(char *data_p, unsigned short length)
|
uint16_t iclass_crc16(char *data_p, unsigned short length) {
|
||||||
{
|
unsigned char i;
|
||||||
unsigned char i;
|
unsigned int data;
|
||||||
unsigned int data;
|
uint16_t crc = 0xffff;
|
||||||
uint16_t crc = 0xffff;
|
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return (~crc);
|
return (~crc);
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
for (i=0, data = (unsigned int)0xff & *data_p++; i < 8; i++, data >>= 1) {
|
||||||
for (i=0, data=(unsigned int)0xff & *data_p++;
|
if ((crc & 0x0001) ^ (data & 0x0001))
|
||||||
i < 8;
|
crc = (crc >> 1) ^ POLY;
|
||||||
i++, data >>= 1)
|
else
|
||||||
{
|
crc >>= 1;
|
||||||
if ((crc & 0x0001) ^ (data & 0x0001))
|
}
|
||||||
crc = (crc >> 1) ^ POLY;
|
} while (--length);
|
||||||
else crc >>= 1;
|
|
||||||
}
|
|
||||||
} while (--length);
|
|
||||||
|
|
||||||
crc = ~crc;
|
|
||||||
data = crc;
|
|
||||||
crc = (crc << 8) | (data >> 8 & 0xff);
|
|
||||||
crc = crc ^ 0xBC3;
|
|
||||||
return (crc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
crc = ~crc;
|
||||||
|
data = crc;
|
||||||
|
crc = (crc << 8) | (data >> 8 & 0xff);
|
||||||
|
crc = crc ^ 0xBC3;
|
||||||
|
return crc;
|
||||||
|
}
|
|
@ -76,6 +76,7 @@
|
||||||
|
|
||||||
uint16_t Iso15693Crc(uint8_t *v, int n);
|
uint16_t Iso15693Crc(uint8_t *v, int n);
|
||||||
int Iso15693AddCrc(uint8_t *req, int n);
|
int Iso15693AddCrc(uint8_t *req, int n);
|
||||||
|
bool Iso15693CheckCrc(uint8_t *d, int n);
|
||||||
char* Iso15693sprintUID(char *target,uint8_t *uid);
|
char* Iso15693sprintUID(char *target,uint8_t *uid);
|
||||||
unsigned short iclass_crc16(char *data_p, unsigned short length);
|
unsigned short iclass_crc16(char *data_p, unsigned short length);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue