mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-31 12:00:10 -07:00
fix 'hf 15 csetuid' (#890)
* fix 'hf 15 csetuid' * check for error codes, prevent client crash * some include file refactoring * some whitespace fixes * allow longer timeout for write commands * add function to send EOF only * modify 'hf list 15' to display "<EOF>" * add tracing of Reader commands * if REQ_OPTION is set on write commands, send separate EOF to request tag response * use #defines instead of hex constants * switch off field after UID update * return last tag response (if there is any) * iso15693: decode WRITE_MULTI_BLOCK in 'hf list 15'
This commit is contained in:
parent
e73c9f1bd4
commit
1f4789fe53
6 changed files with 364 additions and 334 deletions
|
@ -75,6 +75,12 @@
|
|||
#define DELAY_TAG_TO_ARM_SNOOP 32
|
||||
#define DELAY_READER_TO_ARM_SNOOP 32
|
||||
|
||||
// times in samples @ 212kHz when acting as reader
|
||||
//#define ISO15693_READER_TIMEOUT 80 // 80/212kHz = 378us, nominal t1_max=313,9us
|
||||
#define ISO15693_READER_TIMEOUT 330 // 330/212kHz = 1558us, should be even enough for iClass tags responding to ACTALL
|
||||
#define ISO15693_READER_TIMEOUT_WRITE 4700 // 4700/212kHz = 22ms, nominal 20ms
|
||||
|
||||
|
||||
static int DEBUG = 0;
|
||||
|
||||
|
||||
|
@ -140,6 +146,15 @@ void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
|||
ToSendMax++;
|
||||
}
|
||||
|
||||
|
||||
// Encode EOF only
|
||||
static void CodeIso15693AsReaderEOF() {
|
||||
ToSendReset();
|
||||
ToSend[++ToSendMax] = 0x20;
|
||||
ToSendMax++;
|
||||
}
|
||||
|
||||
|
||||
// encode data using "1 out of 256" scheme
|
||||
// data rate is 1,66 kbit/s (fc/8192)
|
||||
// is designed for more robust communication over longer distances
|
||||
|
@ -1105,16 +1120,12 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
|
|||
}
|
||||
|
||||
|
||||
// Encode (into the ToSend buffers) an identify request, which is the first
|
||||
// Construct an identify (Inventory) request, which is the first
|
||||
// thing that you must send to a tag to get a response.
|
||||
static void BuildIdentifyRequest(void)
|
||||
{
|
||||
uint8_t cmd[5];
|
||||
|
||||
static void BuildIdentifyRequest(uint8_t *cmd) {
|
||||
uint16_t crc;
|
||||
// one sub-carrier, inventory, 1 slot, fast rate
|
||||
// AFI is at bit 5 (1<<4) when doing an INVENTORY
|
||||
cmd[0] = (1 << 2) | (1 << 5) | (1 << 1);
|
||||
cmd[0] = ISO15693_REQ_INVENTORY | ISO15693_REQINV_SLOT1 | ISO15693_REQ_DATARATE_HIGH;
|
||||
// inventory command code
|
||||
cmd[1] = 0x01;
|
||||
// no mask
|
||||
|
@ -1123,8 +1134,6 @@ static void BuildIdentifyRequest(void)
|
|||
crc = Iso15693Crc(cmd, 3);
|
||||
cmd[3] = crc & 0xff;
|
||||
cmd[4] = crc >> 8;
|
||||
|
||||
CodeIso15693AsReader(cmd, sizeof(cmd));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1133,8 +1142,7 @@ static void BuildIdentifyRequest(void)
|
|||
// for the response. The response is not demodulated, just left in the buffer
|
||||
// so that it can be downloaded to a PC and processed there.
|
||||
//-----------------------------------------------------------------------------
|
||||
void AcquireRawAdcSamplesIso15693(void)
|
||||
{
|
||||
void AcquireRawAdcSamplesIso15693(void) {
|
||||
LED_A_ON();
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
@ -1145,7 +1153,9 @@ void AcquireRawAdcSamplesIso15693(void)
|
|||
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER);
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
|
||||
BuildIdentifyRequest();
|
||||
uint8_t cmd[5];
|
||||
BuildIdentifyRequest(cmd);
|
||||
CodeIso15693AsReader(cmd, sizeof(cmd));
|
||||
|
||||
// Give the tags time to energize
|
||||
SpinDelay(100);
|
||||
|
@ -1371,10 +1381,7 @@ void Iso15693InitReader() {
|
|||
|
||||
|
||||
// uid is in transmission order (which is reverse of display order)
|
||||
static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber )
|
||||
{
|
||||
uint8_t cmd[13];
|
||||
|
||||
static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber, uint8_t *cmd) {
|
||||
uint16_t crc;
|
||||
// If we set the Option_Flag in this request, the VICC will respond with the security status of the block
|
||||
// followed by the block data
|
||||
|
@ -1398,13 +1405,11 @@ static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber )
|
|||
cmd[11] = crc & 0xff;
|
||||
cmd[12] = crc >> 8;
|
||||
|
||||
CodeIso15693AsReader(cmd, sizeof(cmd));
|
||||
}
|
||||
|
||||
|
||||
// Now the VICC>VCD responses when we are simulating a tag
|
||||
static void BuildInventoryResponse(uint8_t *uid)
|
||||
{
|
||||
static void BuildInventoryResponse(uint8_t *uid) {
|
||||
uint8_t cmd[12];
|
||||
|
||||
uint16_t crc;
|
||||
|
@ -1433,7 +1438,7 @@ static void BuildInventoryResponse(uint8_t *uid)
|
|||
// speed ... 0 low speed, 1 hi speed
|
||||
// *recv will contain the tag's answer
|
||||
// return: length of received data, or -1 for timeout
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint32_t *eof_time) {
|
||||
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
if (init) {
|
||||
Iso15693InitReader();
|
||||
|
@ -1442,19 +1447,40 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *recv,
|
|||
|
||||
int answerLen = 0;
|
||||
|
||||
if (!speed) {
|
||||
// low speed (1 out of 256)
|
||||
CodeIso15693AsReader256(send, sendlen);
|
||||
} else {
|
||||
if (speed_fast) {
|
||||
// high speed (1 out of 4)
|
||||
CodeIso15693AsReader(send, sendlen);
|
||||
} else {
|
||||
// low speed (1 out of 256)
|
||||
CodeIso15693AsReader256(send, sendlen);
|
||||
}
|
||||
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
uint32_t end_time = start_time + 32*(8*ToSendMax-4); // substract the 4 padding bits after EOF
|
||||
LogTrace_ISO15693(send, sendlen, start_time*4, end_time*4, NULL, true);
|
||||
|
||||
// Now wait for a response
|
||||
if (recv != NULL) {
|
||||
answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, ISO15693_READER_TIMEOUT, eof_time);
|
||||
answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, timeout, eof_time);
|
||||
}
|
||||
|
||||
return answerLen;
|
||||
}
|
||||
|
||||
|
||||
int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) {
|
||||
|
||||
int answerLen = 0;
|
||||
|
||||
CodeIso15693AsReaderEOF();
|
||||
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
uint32_t end_time = start_time + 32*(8*ToSendMax-4); // substract the 4 padding bits after EOF
|
||||
LogTrace_ISO15693(NULL, 0, start_time*4, end_time*4, NULL, true);
|
||||
|
||||
// Now wait for a response
|
||||
if (recv != NULL) {
|
||||
answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, timeout, eof_time);
|
||||
}
|
||||
|
||||
return answerLen;
|
||||
|
@ -1546,7 +1572,6 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
|
||||
set_tracing(true);
|
||||
|
||||
int answerLen = 0;
|
||||
uint8_t TagUID[8] = {0x00};
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
@ -1572,17 +1597,14 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
|
||||
|
||||
// Now send the IDENTIFY command
|
||||
BuildIdentifyRequest();
|
||||
uint8_t cmd[5];
|
||||
BuildIdentifyRequest(cmd);
|
||||
uint32_t start_time = 0;
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
|
||||
// Now wait for a response
|
||||
uint32_t eof_time;
|
||||
answerLen = GetIso15693AnswerFromTag(answer, sizeof(answer), DELAY_ISO15693_VCD_TO_VICC_READER * 2, &eof_time) ;
|
||||
int answerLen = SendDataTag(cmd, sizeof(cmd), true, true, answer, sizeof(answer), start_time, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
|
||||
if (answerLen >=12) // we should do a better check than this
|
||||
{
|
||||
if (answerLen >= 12) { // we should do a better check than this
|
||||
TagUID[0] = answer[2];
|
||||
TagUID[1] = answer[3];
|
||||
TagUID[2] = answer[4];
|
||||
|
@ -1591,7 +1613,6 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
TagUID[5] = answer[7];
|
||||
TagUID[6] = answer[8]; // IC Manufacturer code
|
||||
TagUID[7] = answer[9]; // always E0
|
||||
|
||||
}
|
||||
|
||||
Dbprintf("%d octets read from IDENTIFY request:", answerLen);
|
||||
|
@ -1604,21 +1625,12 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
TagUID[7],TagUID[6],TagUID[5],TagUID[4],
|
||||
TagUID[3],TagUID[2],TagUID[1],TagUID[0]);
|
||||
|
||||
|
||||
// Dbprintf("%d octets read from SELECT request:", answerLen2);
|
||||
// DbdecodeIso15693Answer(answerLen2,answer2);
|
||||
// Dbhexdump(answerLen2,answer2,true);
|
||||
|
||||
// Dbprintf("%d octets read from XXX request:", answerLen3);
|
||||
// DbdecodeIso15693Answer(answerLen3,answer3);
|
||||
// Dbhexdump(answerLen3,answer3,true);
|
||||
|
||||
// read all pages
|
||||
if (answerLen >= 12 && DEBUG) {
|
||||
for (int i = 0; i < 32; i++) { // sanity check, assume max 32 pages
|
||||
BuildReadBlockRequest(TagUID, i);
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &start_time);
|
||||
int answerLen = GetIso15693AnswerFromTag(answer, sizeof(answer), DELAY_ISO15693_VCD_TO_VICC_READER * 2, &eof_time);
|
||||
uint8_t cmd[13];
|
||||
BuildReadBlockRequest(TagUID, i, cmd);
|
||||
answerLen = SendDataTag(cmd, sizeof(cmd), false, true, answer, sizeof(answer), start_time, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
if (answerLen > 0) {
|
||||
Dbprintf("READ SINGLE BLOCK %d returned %d octets:", i, answerLen);
|
||||
|
@ -1629,7 +1641,7 @@ void ReaderIso15693(uint32_t parameter) {
|
|||
}
|
||||
}
|
||||
|
||||
// for the time being, switch field off to protect rdv4.0
|
||||
// for the time being, switch field off to protect RDV4
|
||||
// note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LED_D_OFF();
|
||||
|
@ -1680,8 +1692,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid) {
|
|||
|
||||
// Since there is no standardized way of reading the AFI out of a tag, we will brute force it
|
||||
// (some manufactures offer a way to read the AFI, though)
|
||||
void BruteforceIso15693Afi(uint32_t speed)
|
||||
{
|
||||
void BruteforceIso15693Afi(uint32_t speed) {
|
||||
LED_A_ON();
|
||||
|
||||
uint8_t data[6];
|
||||
|
@ -1697,7 +1708,7 @@ void BruteforceIso15693Afi(uint32_t speed)
|
|||
data[2] = 0; // mask length
|
||||
datalen = Iso15693AddCrc(data,3);
|
||||
uint32_t start_time = GetCountSspClk();
|
||||
recvlen = SendDataTag(data, datalen, true, speed, recv, sizeof(recv), 0, &eof_time);
|
||||
recvlen = SendDataTag(data, datalen, true, speed, recv, sizeof(recv), 0, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
WDT_HIT();
|
||||
if (recvlen>=12) {
|
||||
|
@ -1714,7 +1725,7 @@ void BruteforceIso15693Afi(uint32_t speed)
|
|||
for (int i = 0; i < 256; i++) {
|
||||
data[2] = i & 0xFF;
|
||||
datalen = Iso15693AddCrc(data,4);
|
||||
recvlen = SendDataTag(data, datalen, false, speed, recv, sizeof(recv), start_time, &eof_time);
|
||||
recvlen = SendDataTag(data, datalen, false, speed, recv, sizeof(recv), start_time, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
WDT_HIT();
|
||||
if (recvlen >= 12) {
|
||||
|
@ -1738,12 +1749,34 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint
|
|||
uint8_t recvbuf[ISO15693_MAX_RESPONSE_LENGTH];
|
||||
uint32_t eof_time;
|
||||
|
||||
uint16_t timeout;
|
||||
bool request_answer = false;
|
||||
|
||||
switch (data[1]) {
|
||||
case ISO15693_WRITEBLOCK:
|
||||
case ISO15693_LOCKBLOCK:
|
||||
case ISO15693_WRITE_MULTI_BLOCK:
|
||||
case ISO15693_WRITE_AFI:
|
||||
case ISO15693_LOCK_AFI:
|
||||
case ISO15693_WRITE_DSFID:
|
||||
case ISO15693_LOCK_DSFID:
|
||||
timeout = ISO15693_READER_TIMEOUT_WRITE;
|
||||
request_answer = data[0] & ISO15693_REQ_OPTION;
|
||||
break;
|
||||
default:
|
||||
timeout = ISO15693_READER_TIMEOUT;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Dbprintf("SEND:");
|
||||
Dbhexdump(datalen, data, false);
|
||||
}
|
||||
|
||||
recvlen = SendDataTag(data, datalen, true, speed, (recv?recvbuf:NULL), sizeof(recvbuf), 0, &eof_time);
|
||||
recvlen = SendDataTag(data, datalen, true, speed, (recv?recvbuf:NULL), sizeof(recvbuf), 0, timeout, &eof_time);
|
||||
|
||||
if (request_answer) { // send a single EOF to get the tag response
|
||||
recvlen = SendDataTagEOF((recv?recvbuf:NULL), sizeof(recvbuf), 0, ISO15693_READER_TIMEOUT, &eof_time);
|
||||
}
|
||||
|
||||
// for the time being, switch field off to protect rdv4.0
|
||||
// note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway
|
||||
|
@ -1772,16 +1805,16 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Set the UID to the tag (based on Iceman work).
|
||||
// Set the UID on Magic ISO15693 tag (based on Iceman's LUA-script).
|
||||
void SetTag15693Uid(uint8_t *uid) {
|
||||
|
||||
LED_A_ON();
|
||||
|
||||
uint8_t cmd[4][9] = {
|
||||
{0x02, 0x21, 0x3e, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x02, 0x21, 0x3f, 0x69, 0x96, 0x00, 0x00},
|
||||
{0x02, 0x21, 0x38},
|
||||
{0x02, 0x21, 0x39}
|
||||
{ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3e, 0x00, 0x00, 0x00, 0x00},
|
||||
{ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3f, 0x69, 0x96, 0x00, 0x00},
|
||||
{ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x38},
|
||||
{ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x39}
|
||||
};
|
||||
|
||||
uint16_t crc;
|
||||
|
@ -1802,30 +1835,35 @@ void SetTag15693Uid(uint8_t *uid) {
|
|||
cmd[3][5] = uid[1];
|
||||
cmd[3][6] = uid[0];
|
||||
|
||||
uint32_t start_time = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Add the CRC
|
||||
crc = Iso15693Crc(cmd[i], 7);
|
||||
cmd[i][7] = crc & 0xff;
|
||||
cmd[i][8] = crc >> 8;
|
||||
|
||||
recvlen = SendDataTag(cmd[i], sizeof(cmd[i]), i==0?true:false, true, recvbuf, sizeof(recvbuf), start_time, ISO15693_READER_TIMEOUT_WRITE, &eof_time);
|
||||
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
|
||||
if (DEBUG) {
|
||||
Dbprintf("SEND:");
|
||||
Dbhexdump(sizeof(cmd[i]), cmd[i], false);
|
||||
}
|
||||
|
||||
recvlen = SendDataTag(cmd[i], sizeof(cmd[i]), true, 1, recvbuf, sizeof(recvbuf), 0, &eof_time);
|
||||
|
||||
if (DEBUG) {
|
||||
Dbprintf("RECV:");
|
||||
if (recvlen > 0) {
|
||||
Dbhexdump(recvlen, recvbuf, false);
|
||||
DbdecodeIso15693Answer(recvlen, recvbuf);
|
||||
}
|
||||
}
|
||||
|
||||
cmd_send(CMD_ACK, recvlen>ISO15693_MAX_RESPONSE_LENGTH?ISO15693_MAX_RESPONSE_LENGTH:recvlen, 0, 0, recvbuf, ISO15693_MAX_RESPONSE_LENGTH);
|
||||
// Note: need to know if we expect an answer from one of the magic commands
|
||||
// if (recvlen < 0) {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LED_D_OFF();
|
||||
|
||||
cmd_send(CMD_ACK, recvlen, 0, 0, recvbuf, recvlen);
|
||||
LED_A_OFF();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
//SSP_CLK runs at 13.56MHz / 4 = 3,39MHz when acting as reader. All values should be multiples of 16
|
||||
#define DELAY_ISO15693_VCD_TO_VICC_READER 1056 // 1056/3,39MHz = 311.5us from end of command EOF to start of tag response
|
||||
#define DELAY_ISO15693_VICC_TO_VCD_READER 1024 // 1024/3.39MHz = 302.1us between end of tag response and next reader command
|
||||
// times in samples @ 212kHz when acting as reader
|
||||
#define ISO15693_READER_TIMEOUT 330 // 330/212kHz = 1558us, should be even enough for iClass tags responding to ACTALL
|
||||
|
||||
void Iso15693InitReader();
|
||||
void CodeIso15693AsReader(uint8_t *cmd, int n);
|
||||
|
|
217
client/cmdhf15.c
217
client/cmdhf15.c
|
@ -90,9 +90,8 @@ static const int Iso15693FrameEOF[] = {
|
|||
|
||||
// fast method to just read the UID of a tag (collission detection not supported)
|
||||
// *buf should be large enough to fit the 64bit uid
|
||||
// returns 1 if suceeded
|
||||
int getUID(uint8_t *buf)
|
||||
{
|
||||
// returns true if suceeded
|
||||
static bool getUID(uint8_t *buf) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -100,7 +99,6 @@ int getUID(uint8_t *buf)
|
|||
int reqlen=0;
|
||||
|
||||
for (int retry = 0;retry < 3; retry++) { // don't give up the at the first try
|
||||
|
||||
req[0] = ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_INVENTORY | ISO15693_REQINV_SLOT1;
|
||||
req[1] = ISO15693_INVENTORY;
|
||||
req[2] = 0; // mask length
|
||||
|
@ -113,11 +111,11 @@ int getUID(uint8_t *buf)
|
|||
recv = resp.d.asBytes;
|
||||
if (resp.arg[0] >= 12 && ISO15693_CRC_CHECK == Crc(recv, 12)) {
|
||||
memcpy(buf, &recv[2], 8);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // retry
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,8 +137,7 @@ static char* TagErrorStr(uint8_t error) {
|
|||
|
||||
|
||||
// Mode 3
|
||||
int CmdHF15Demod(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15Demod(const char *Cmd) {
|
||||
// The sampling rate is 106.353 ksps/s, for T = 18.8 us
|
||||
|
||||
int i, j;
|
||||
|
@ -224,25 +221,23 @@ int CmdHF15Demod(const char *Cmd)
|
|||
}
|
||||
|
||||
|
||||
|
||||
// * Acquire Samples as Reader (enables carrier, sends inquiry)
|
||||
int CmdHF15Read(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15Read(const char *Cmd) {
|
||||
UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Record Activity without enabling carrier
|
||||
int CmdHF15Snoop(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15Snoop(const char *Cmd) {
|
||||
UsbCommand c = {CMD_SNOOP_ISO_15693};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HF15Reader(const char *Cmd, bool verbose)
|
||||
{
|
||||
|
||||
int HF15Reader(const char *Cmd, bool verbose) {
|
||||
uint8_t uid[8];
|
||||
|
||||
if (!getUID(uid)) {
|
||||
|
@ -256,16 +251,16 @@ int HF15Reader(const char *Cmd, bool verbose)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int CmdHF15Reader(const char *Cmd)
|
||||
{
|
||||
|
||||
static int CmdHF15Reader(const char *Cmd) {
|
||||
UsbCommand c = {CMD_READER_ISO_15693, {strtol(Cmd, NULL, 0), 0, 0}};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Simulation is still not working very good
|
||||
int CmdHF15Sim(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15Sim(const char *Cmd) {
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
uint8_t uid[8] = {0x00};
|
||||
|
||||
|
@ -293,17 +288,18 @@ int CmdHF15Sim(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// finds the AFI (Application Family Idendifier) of a card, by trying all values
|
||||
// (There is no standard way of reading the AFI, allthough some tags support this)
|
||||
int CmdHF15Afi(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15Afi(const char *Cmd) {
|
||||
UsbCommand c = {CMD_ISO_15693_FIND_AFI, {strtol(Cmd, NULL, 0), 0, 0}};
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Reads all memory pages
|
||||
int CmdHF15DumpMem(const char*Cmd) {
|
||||
static int CmdHF15DumpMem(const char*Cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t uid[8];
|
||||
uint8_t *recv=NULL;
|
||||
|
@ -369,41 +365,7 @@ int CmdHF15DumpMem(const char*Cmd) {
|
|||
}
|
||||
|
||||
|
||||
// "HF 15" interface
|
||||
|
||||
static command_t CommandTable15[] =
|
||||
{
|
||||
{"help", CmdHF15Help, 1, "This help"},
|
||||
{"demod", CmdHF15Demod, 1, "Demodulate ISO15693 from tag"},
|
||||
{"read", CmdHF15Read, 0, "Read HF tag (ISO 15693)"},
|
||||
{"snoop", CmdHF15Snoop, 0, "Eavesdrop ISO 15693 communications"},
|
||||
{"reader", CmdHF15Reader, 0, "Act like an ISO15693 reader"},
|
||||
{"sim", CmdHF15Sim, 0, "Fake an ISO15693 tag"},
|
||||
{"cmd", CmdHF15Cmd, 0, "Send direct commands to ISO15693 tag"},
|
||||
{"findafi", CmdHF15Afi, 0, "Brute force AFI of an ISO15693 tag"},
|
||||
{"dumpmemory", CmdHF15DumpMem, 0, "Read all memory pages of an ISO15693 tag"},
|
||||
{"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdHF15(const char *Cmd)
|
||||
{
|
||||
CmdsParse(CommandTable15, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHF15Help(const char *Cmd)
|
||||
{
|
||||
CmdsHelp(CommandTable15);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// "HF 15 Cmd" Interface
|
||||
// Allows direct communication with the tag on command level
|
||||
|
||||
int CmdHF15CmdInquiry(const char *Cmd)
|
||||
{
|
||||
static int CmdHF15CmdInquiry(const char *Cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -435,7 +397,7 @@ int CmdHF15CmdInquiry(const char *Cmd)
|
|||
|
||||
|
||||
// Turns debugging on(1)/off(0)
|
||||
int CmdHF15CmdDebug( const char *cmd) {
|
||||
static int CmdHF15CmdDebug( const char *cmd) {
|
||||
int debug = atoi(cmd);
|
||||
if (strlen(cmd) < 1) {
|
||||
PrintAndLog("Usage: hf 15 debug <0|1>");
|
||||
|
@ -450,7 +412,7 @@ int CmdHF15CmdDebug( const char *cmd) {
|
|||
}
|
||||
|
||||
|
||||
int CmdHF15CmdRaw (const char *cmd) {
|
||||
static int CmdHF15CmdRaw (const char *cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -560,7 +522,7 @@ int CmdHF15CmdRaw (const char *cmd) {
|
|||
* Parameters:
|
||||
* **cmd command line
|
||||
*/
|
||||
int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
|
||||
static int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
|
||||
int temp;
|
||||
uint8_t *req = c->d.asBytes;
|
||||
uint8_t uid[8] = {0x00};
|
||||
|
@ -649,7 +611,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle
|
|||
* Commandline handling: HF15 CMD SYSINFO
|
||||
* get system information from tag/VICC
|
||||
*/
|
||||
int CmdHF15CmdSysinfo(const char *Cmd) {
|
||||
static int CmdHF15CmdSysinfo(const char *Cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -727,11 +689,12 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Commandline handling: HF15 CMD READMULTI
|
||||
* Read multiple blocks at once (not all tags support this)
|
||||
*/
|
||||
int CmdHF15CmdReadmulti(const char *Cmd) {
|
||||
static int CmdHF15CmdReadmulti(const char *Cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -806,11 +769,12 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Commandline handling: HF15 CMD READ
|
||||
* Reads a single Block
|
||||
*/
|
||||
int CmdHF15CmdRead(const char *Cmd) {
|
||||
static int CmdHF15CmdRead(const char *Cmd) {
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -883,12 +847,11 @@ int CmdHF15CmdRead(const char *Cmd) {
|
|||
|
||||
/**
|
||||
* Commandline handling: HF15 CMD WRITE
|
||||
* Writes a single Block - might run into timeout, even when successful
|
||||
*/
|
||||
int CmdHF15CmdWrite(const char *Cmd) {
|
||||
* Writes a single Block
|
||||
**/
|
||||
static int CmdHF15CmdWrite(const char *Cmd) {
|
||||
UsbCommand resp;
|
||||
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;
|
||||
int reqlen = 0, pagenum, temp;
|
||||
char cmdbuf[100];
|
||||
|
@ -941,31 +904,35 @@ int CmdHF15CmdWrite(const char *Cmd) {
|
|||
}
|
||||
|
||||
reqlen = AddCrc(req, reqlen);
|
||||
|
||||
c.arg[0] = reqlen;
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,2000) && resp.arg[0]>2) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15693_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15693_RES_ERROR)) {
|
||||
PrintAndLog("OK");
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||
int recv_len = resp.arg[0];
|
||||
uint8_t *recv = resp.d.asBytes;
|
||||
if (recv_len == 0) {
|
||||
PrintAndLog("Received SOF only. Maybe Picopass/iCLASS?");
|
||||
} else if (recv_len == -1) {
|
||||
PrintAndLog("Tag didn't respond");
|
||||
} else if (recv_len == -2) {
|
||||
PrintAndLog("Receive buffer overflow");
|
||||
} else if (ISO15693_CRC_CHECK != Crc(recv, resp.arg[0])) {
|
||||
PrintAndLog("CRC check failed on Tag response");
|
||||
} else if (!(recv[0] & ISO15693_RES_ERROR)) {
|
||||
PrintAndLog("Tag returned OK");
|
||||
} else {
|
||||
PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1]));
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("CRC failed");
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("timeout: no answer - data may be written anyway");
|
||||
PrintAndLog("No answer from Proxmark");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHF15CSetUID(const char *Cmd)
|
||||
{
|
||||
|
||||
static int CmdHF15CSetUID(const char *Cmd) {
|
||||
uint8_t uid[8] = {0x00};
|
||||
uint8_t oldUid[8], newUid[8] = {0x00};
|
||||
|
||||
|
@ -982,10 +949,8 @@ int CmdHF15CSetUID(const char *Cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
while(param_getchar(Cmd, cmdp) != 0x00)
|
||||
{
|
||||
switch(param_getchar(Cmd, cmdp))
|
||||
{
|
||||
while (param_getchar(Cmd, cmdp) != 0x00) {
|
||||
switch (param_getchar(Cmd, cmdp)) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
needHelp = 1;
|
||||
|
@ -1006,8 +971,6 @@ int CmdHF15CSetUID(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("");
|
||||
PrintAndLog("new UID | %s", sprint_hex(uid, 8));
|
||||
PrintAndLog("Using backdoor Magic tag function");
|
||||
|
||||
if (!getUID(oldUid)) {
|
||||
|
@ -1015,29 +978,30 @@ int CmdHF15CSetUID(const char *Cmd)
|
|||
return 1;
|
||||
}
|
||||
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
char *hexout;
|
||||
UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}};
|
||||
memcpy(c.d.asBytes, uid, 8);
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
recv = resp.d.asBytes;
|
||||
PrintAndLog("received %i octets",resp.arg[0]);
|
||||
hexout = (char *)malloc(resp.arg[0] * 3 + 1);
|
||||
if (hexout != NULL) {
|
||||
for (int i = 0; i < resp.arg[0]; i++) { // data in hex
|
||||
sprintf(&hexout[i * 3], "%02X ", recv[i]);
|
||||
}
|
||||
PrintAndLog("%s", hexout);
|
||||
free(hexout);
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||
int recv_len = resp.arg[0];
|
||||
uint8_t *recv = resp.d.asBytes;
|
||||
if (recv_len == 0) {
|
||||
PrintAndLog("Received SOF only. Maybe Picopass/iCLASS?");
|
||||
} else if (recv_len == -1) {
|
||||
PrintAndLog("Tag didn't respond");
|
||||
} else if (recv_len == -2) {
|
||||
PrintAndLog("Receive buffer overflow");
|
||||
} else if (ISO15693_CRC_CHECK != Crc(recv, recv_len)) {
|
||||
PrintAndLog("CRC check failed on Tag response");
|
||||
} else if (!(recv[0] & ISO15693_RES_ERROR)) {
|
||||
PrintAndLog("Tag returned OK");
|
||||
} else {
|
||||
PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1]));
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("timeout while waiting for reply.");
|
||||
}
|
||||
PrintAndLog("No answer from Proxmark");
|
||||
}
|
||||
|
||||
if (!getUID(newUid)) {
|
||||
|
@ -1052,8 +1016,12 @@ int CmdHF15CSetUID(const char *Cmd)
|
|||
}
|
||||
|
||||
|
||||
static command_t CommandTable15Cmd[] =
|
||||
{
|
||||
// "HF 15 Cmd" Interface
|
||||
// Allows direct communication with the tag on command level
|
||||
|
||||
static int CmdHF15CmdHelp(const char*Cmd);
|
||||
|
||||
static command_t CommandTable15Cmd[] = {
|
||||
{"help", CmdHF15CmdHelp, 1, "This Help"},
|
||||
{"inquiry", CmdHF15CmdInquiry, 0, "Search for tags in range"},
|
||||
/*
|
||||
|
@ -1064,20 +1032,51 @@ static command_t CommandTable15Cmd[] =
|
|||
{"readmulti", CmdHF15CmdReadmulti, 0, "Reads multiple Blocks"},
|
||||
{"sysinfo", CmdHF15CmdSysinfo, 0, "Get Card Information"},
|
||||
{"raw", CmdHF15CmdRaw, 0, "Send raw hex data to tag"},
|
||||
{"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"},
|
||||
{"debug", CmdHF15CmdDebug, 0, "Turn debugging on/off"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdHF15Cmd(const char *Cmd)
|
||||
{
|
||||
|
||||
static int CmdHF15Cmd(const char *Cmd) {
|
||||
CmdsParse(CommandTable15Cmd, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHF15CmdHelp(const char *Cmd)
|
||||
{
|
||||
|
||||
static int CmdHF15CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable15Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// "HF 15" interface
|
||||
|
||||
static int CmdHF15Help(const char*Cmd);
|
||||
|
||||
static command_t CommandTable15[] = {
|
||||
{"help", CmdHF15Help, 1, "This help"},
|
||||
{"demod", CmdHF15Demod, 1, "Demodulate ISO15693 from tag"},
|
||||
{"read", CmdHF15Read, 0, "Read HF tag (ISO 15693)"},
|
||||
{"snoop", CmdHF15Snoop, 0, "Eavesdrop ISO 15693 communications"},
|
||||
{"reader", CmdHF15Reader, 0, "Act like an ISO15693 reader"},
|
||||
{"sim", CmdHF15Sim, 0, "Fake an ISO15693 tag"},
|
||||
{"cmd", CmdHF15Cmd, 0, "Send direct commands to ISO15693 tag"},
|
||||
{"findafi", CmdHF15Afi, 0, "Brute force AFI of an ISO15693 tag"},
|
||||
{"dumpmemory", CmdHF15DumpMem, 0, "Read all memory pages of an ISO15693 tag"},
|
||||
{"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
int CmdHF15(const char *Cmd) {
|
||||
CmdsParse(CommandTable15, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int CmdHF15Help(const char *Cmd) {
|
||||
CmdsHelp(CommandTable15);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,17 +13,7 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
int CmdHF15(const char *Cmd);
|
||||
|
||||
int CmdHF15Demod(const char *Cmd);
|
||||
int CmdHF15Read(const char *Cmd);
|
||||
int HF15Reader(const char *Cmd, bool verbose);
|
||||
int CmdHF15Reader(const char *Cmd);
|
||||
int CmdHF15Sim(const char *Cmd);
|
||||
int CmdHF15Record(const char *Cmd);
|
||||
int CmdHF15Cmd(const char*Cmd);
|
||||
int CmdHF15CSetUID(const char *Cmd);
|
||||
int CmdHF15CmdHelp(const char*Cmd);
|
||||
int CmdHF15Help(const char*Cmd);
|
||||
extern int CmdHF15(const char *Cmd);
|
||||
extern int HF15Reader(const char *Cmd, bool verbose);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -243,8 +243,8 @@ void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) {
|
|||
}
|
||||
|
||||
|
||||
void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
||||
{
|
||||
void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) {
|
||||
if (cmdsize >= 2) {
|
||||
switch (cmd[1]) {
|
||||
// Mandatory Commands, all Tags must support them:
|
||||
case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");return;
|
||||
|
@ -254,6 +254,7 @@ void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|||
case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");return;
|
||||
case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");return;
|
||||
case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");return;
|
||||
case ISO15693_WRITE_MULTI_BLOCK :snprintf(exp, size, "WRITE_MULTI_BLOCK");return;
|
||||
case ISO15693_SELECT :snprintf(exp, size, "SELECT");return;
|
||||
case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");return;
|
||||
case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");return;
|
||||
|
@ -270,6 +271,7 @@ void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
|||
else if ( cmd[1] >= 0xA0 && cmd[1] <= 0xDF ) snprintf(exp, size, "Custom command");
|
||||
else if ( cmd[1] >= 0xE0 && cmd[1] <= 0xFF ) snprintf(exp, size, "Proprietary command");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void annotateTopaz(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
|
||||
|
@ -969,6 +971,8 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
|
|||
if (data_len == 0) {
|
||||
if (protocol == ICLASS && duration == 2048) {
|
||||
sprintf(line[0], " <SOF>");
|
||||
} else if (protocol == ISO_15693 && duration == 512) {
|
||||
sprintf(line[0], " <EOF>");
|
||||
} else {
|
||||
sprintf(line[0], " <empty trace - possible error>");
|
||||
}
|
||||
|
|
|
@ -187,6 +187,7 @@ NXP/Philips CUSTOM COMMANDS
|
|||
#define ISO15693_WRITEBLOCK 0x21
|
||||
#define ISO15693_LOCKBLOCK 0x22
|
||||
#define ISO15693_READ_MULTI_BLOCK 0x23
|
||||
#define ISO15693_WRITE_MULTI_BLOCK 0x24
|
||||
#define ISO15693_SELECT 0x25
|
||||
#define ISO15693_RESET_TO_READY 0x26
|
||||
#define ISO15693_WRITE_AFI 0x27
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue