#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;
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
}
-// 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
crc = Iso15693Crc(cmd, 3);
cmd[3] = crc & 0xff;
cmd[4] = crc >> 8;
-
- CodeIso15693AsReader(cmd, sizeof(cmd));
}
// 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();
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);
// 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
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;
// 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();
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, 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, ISO15693_READER_TIMEOUT, eof_time);
+ answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, timeout, eof_time);
}
return answerLen;
set_tracing(true);
- int answerLen = 0;
uint8_t TagUID[8] = {0x00};
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// 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];
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);
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);
}
}
- // 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();
// 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];
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) {
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) {
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
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
//
//-----------------------------------------------------------------------------
-// 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;
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();
}
// 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?
- uint8_t *req=c.d.asBytes;
+ uint8_t *req = c.d.asBytes;
int reqlen=0;
- for (int retry=0;retry<3; retry++) { // don't give up the at the first try
-
+ 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
- reqlen = AddCrc(req,3);
+ reqlen = AddCrc(req, 3);
c.arg[0] = reqlen;
SendCommand(&c);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+ if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
recv = resp.d.asBytes;
- if (resp.arg[0]>=12 && ISO15693_CRC_CHECK==Crc(recv,12)) {
- memcpy(buf,&recv[2],8);
- return 1;
+ if (resp.arg[0] >= 12 && ISO15693_CRC_CHECK == Crc(recv, 12)) {
+ memcpy(buf, &recv[2], 8);
+ return true;
}
}
} // retry
- return 0;
+ return false;
}
// 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;
}
-
// * 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)) {
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};
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;
}
-// "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?
// 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>");
}
-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?
* 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 *req = c->d.asBytes;
uint8_t uid[8] = {0x00};
- uint32_t reqlen=0;
+ uint32_t reqlen = 0;
// strip
while (**cmd==' ' || **cmd=='\t') (*cmd)++;
- if (strstr(*cmd,"-2")==*cmd) {
- c->arg[1]=0; // use 1of256
- (*cmd)+=2;
+ if (strstr(*cmd, "-2") == *cmd) {
+ c->arg[1] = 0; // use 1of256
+ (*cmd) += 2;
}
// strip
- while (**cmd==' ' || **cmd=='\t') (*cmd)++;
+ while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
- if (strstr(*cmd,"-o")==*cmd) {
- req[reqlen]=ISO15693_REQ_OPTION;
- (*cmd)+=2;
+ if (strstr(*cmd, "-o") == *cmd) {
+ req[reqlen] = ISO15693_REQ_OPTION;
+ (*cmd) += 2;
}
// strip
- while (**cmd==' ' || **cmd=='\t') (*cmd)++;
+ while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
switch (**cmd) {
case 0:
case 'S':
// you must have selected the tag earlier
req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_SELECT;
- memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
+ memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen);
reqlen += iso15cmdlen;
break;
case 'u':
case 'U':
// unaddressed mode may not be supported by all vendors
req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH;
- memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
+ memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen);
reqlen += iso15cmdlen;
break;
case '*':
// we scan for the UID ourself
req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_ADDRESS;
- memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
- reqlen+=iso15cmdlen;
+ memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen);
+ reqlen += iso15cmdlen;
if (!getUID(uid)) {
PrintAndLog("No Tag found");
return 0;
}
- memcpy(req+reqlen,uid,8);
+ memcpy(req+reqlen ,uid, 8);
PrintAndLog("Detected UID %s",sprintUID(NULL,uid));
- reqlen+=8;
+ reqlen += 8;
break;
default:
req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_ADDRESS;
- memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
- reqlen+=iso15cmdlen;
+ memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen);
+ reqlen += iso15cmdlen;
/* sscanf(cmd,"%hX%hX%hX%hX%hX%hX%hX%hX",
(short unsigned int *)&uid[7],(short unsigned int *)&uid[6],
(short unsigned int *)&uid[5],(short unsigned int *)&uid[4],
(short unsigned int *)&uid[3],(short unsigned int *)&uid[2],
(short unsigned int *)&uid[1],(short unsigned int *)&uid[0]); */
- for (int i=0;i<8 && (*cmd)[i*2] && (*cmd)[i*2+1];i++) { // parse UID
+ for (int i=0; i<8 && (*cmd)[i*2] && (*cmd)[i*2+1]; i++) { // parse UID
sscanf((char[]){(*cmd)[i*2],(*cmd)[i*2+1],0},"%X",&temp);
uid[7-i]=temp&0xff;
}
- PrintAndLog("Using UID %s",sprintUID(NULL,uid));
- memcpy(&req[reqlen],&uid[0],8);
- reqlen+=8;
+ PrintAndLog("Using UID %s", sprintUID(NULL, uid));
+ memcpy(&req[reqlen], &uid[0], 8);
+ reqlen += 8;
}
// skip to next space
- while (**cmd!=' ' && **cmd!='\t') (*cmd)++;
+ while (**cmd != ' ' && **cmd != '\t') (*cmd)++;
// skip over the space
- while (**cmd==' ' || **cmd=='\t') (*cmd)++;
+ while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
- c->arg[0]=reqlen;
+ c->arg[0] = reqlen;
return 1;
}
* 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?
SendCommand(&c);
- if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
+ if (WaitForResponseTimeout(CMD_ACK, &resp, 1000) && resp.arg[0] > 2) {
recv = resp.d.asBytes;
- if (ISO15693_CRC_CHECK==Crc(recv,resp.arg[0])) {
+ if (ISO15693_CRC_CHECK == Crc(recv, resp.arg[0])) {
if (!(recv[0] & ISO15693_RES_ERROR)) {
*output=0; // reset outputstring
PrintAndLog("UID: %s", sprintUID(NULL,recv+2));
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?
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?
/**
* 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?
- uint8_t *req=c.d.asBytes;
- int reqlen=0, pagenum, temp;
+ 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];
- char *cmd=cmdbuf;
+ char *cmd = cmdbuf;
char *cmd2;
- strncpy(cmd,Cmd,99);
+ strncpy(cmd, Cmd, 99);
// usage:
- if (strlen(cmd)<3) {
+ if (strlen(cmd) < 3) {
PrintAndLog("Usage: hf 15 cmd write [options] <uid|s|u|*> <page#> <hexdata>");
PrintAndLog(" options:");
PrintAndLog(" -2 use slower '1 out of 256' mode");
return 0;
}
- prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15693_WRITEBLOCK},1);
- reqlen=c.arg[0];
+ prepareHF15Cmd(&cmd, &c, (uint8_t[]){ISO15693_WRITEBLOCK}, 1);
+ reqlen = c.arg[0];
// *cmd -> page num ; *cmd2 -> data
- cmd2=cmd;
- while (*cmd2!=' ' && *cmd2!='\t' && *cmd2) cmd2++;
- *cmd2=0;
+ cmd2 = cmd;
+ while (*cmd2 != ' ' && *cmd2 != '\t' && *cmd2) cmd2++;
+ *cmd2 = 0;
cmd2++;
- pagenum=strtol(cmd,NULL,0);
+ pagenum = strtol(cmd, NULL, 0);
/*if (pagenum<0) {
PrintAndLog("invalid pagenum");
return 0;
} */
- req[reqlen++]=(uint8_t)pagenum;
+ req[reqlen++] = (uint8_t)pagenum;
while (cmd2[0] && cmd2[1]) { // hexdata, read by 2 hexchars
- if (*cmd2==' ') {
+ if (*cmd2 == ' ') {
cmd2++;
continue;
}
- sscanf((char[]){cmd2[0],cmd2[1],0},"%X",&temp);
- req[reqlen++]=temp & 0xff;
- cmd2+=2;
+ sscanf((char[]){cmd2[0], cmd2[1], 0}, "%X", &temp);
+ req[reqlen++] = temp & 0xff;
+ cmd2 += 2;
}
- reqlen=AddCrc(req,reqlen);
-
- c.arg[0]=reqlen;
+ 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");
- } else {
- PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
- }
+ 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("CRC failed");
+ PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1]));
}
} else {
- PrintAndLog("timeout: no answer - data may be written anyway");
+ PrintAndLog("No answer from Proxmark");
}
return 0;
}
-int CmdHF15CSetUID(const char *Cmd)
-{
- uint8_t uid[8] = {0x00};
- uint8_t oldUid[8], newUid[8] = {0x00};
-
- uint8_t needHelp = 0;
- char cmdp = 1;
-
- if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 16)) {
- PrintAndLog("UID must include 16 HEX symbols");
- return 1;
- }
-
- if (uid[0] != 0xe0) {
- PrintAndLog("UID must begin with the byte 'E0'");
- return 1;
- }
-
- while(param_getchar(Cmd, cmdp) != 0x00)
- {
- switch(param_getchar(Cmd, cmdp))
- {
- case 'h':
- case 'H':
- needHelp = 1;
- break;
- default:
- PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp));
- needHelp = 1;
- break;
- }
- cmdp++;
- }
-
- if (strlen(Cmd) < 1 || needHelp) {
- PrintAndLog("");
- PrintAndLog("Usage: hf 15 csetuid <UID 16 hex symbols>");
- PrintAndLog("sample: hf 15 csetuid E004013344556677");
- PrintAndLog("Set UID for magic Chinese card (only works with such cards)");
- return 0;
- }
-
- PrintAndLog("");
- PrintAndLog("new UID | %s", sprint_hex(uid, 8));
- PrintAndLog("Using backdoor Magic tag function");
-
- if (!getUID(oldUid)) {
- PrintAndLog("Can't get old UID.");
- return 1;
- }
-
- UsbCommand resp;
- uint8_t *recv;
- char *hexout;
- UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}};
- memcpy(c.d.asBytes, uid, 8);
+
+static int CmdHF15CSetUID(const char *Cmd) {
+ uint8_t uid[8] = {0x00};
+ uint8_t oldUid[8], newUid[8] = {0x00};
+
+ uint8_t needHelp = 0;
+ char cmdp = 1;
+
+ if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 16)) {
+ PrintAndLog("UID must include 16 HEX symbols");
+ return 1;
+ }
+
+ if (uid[0] != 0xe0) {
+ PrintAndLog("UID must begin with the byte 'E0'");
+ return 1;
+ }
+
+ while (param_getchar(Cmd, cmdp) != 0x00) {
+ switch (param_getchar(Cmd, cmdp)) {
+ case 'h':
+ case 'H':
+ needHelp = 1;
+ break;
+ default:
+ PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+ needHelp = 1;
+ break;
+ }
+ cmdp++;
+ }
+
+ if (strlen(Cmd) < 1 || needHelp) {
+ PrintAndLog("");
+ PrintAndLog("Usage: hf 15 csetuid <UID 16 hex symbols>");
+ PrintAndLog("sample: hf 15 csetuid E004013344556677");
+ PrintAndLog("Set UID for magic Chinese card (only works with such cards)");
+ return 0;
+ }
+
+ PrintAndLog("Using backdoor Magic tag function");
+
+ if (!getUID(oldUid)) {
+ PrintAndLog("Can't get old UID.");
+ return 1;
+ }
+
+ UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}};
+ memcpy(c.d.asBytes, uid, 8);
+
+ SendCommand(&c);
+
+ 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("No answer from Proxmark");
+ }
+
+ if (!getUID(newUid)) {
+ PrintAndLog("Can't get new UID.");
+ return 1;
+ }
- 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);
- }
- } else {
- PrintAndLog("timeout while waiting for reply.");
- }
- }
-
- if (!getUID(newUid)) {
- PrintAndLog("Can't get new UID.");
- return 1;
- }
-
- PrintAndLog("");
- PrintAndLog("old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]);
- PrintAndLog("new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]);
- return 0;
+ PrintAndLog("");
+ PrintAndLog("old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]);
+ PrintAndLog("new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]);
+ return 0;
}
-static command_t CommandTable15Cmd[] =
-{
- {"help", CmdHF15CmdHelp, 1, "This Help"},
- {"inquiry", CmdHF15CmdInquiry, 0, "Search for tags in range"},
+// "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"},
/*
- {"select", CmdHF15CmdSelect, 0, "Select an tag with a specific UID for further commands"},
+ {"select", CmdHF15CmdSelect, 0, "Select an tag with a specific UID for further commands"},
*/
- {"read", CmdHF15CmdRead, 0, "Read a block"},
- {"write", CmdHF15CmdWrite, 0, "Write a block"},
- {"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}
+ {"read", CmdHF15CmdRead, 0, "Read a block"},
+ {"write", CmdHF15CmdWrite, 0, "Write a block"},
+ {"readmulti", CmdHF15CmdReadmulti, 0, "Reads multiple Blocks"},
+ {"sysinfo", CmdHF15CmdSysinfo, 0, "Get Card Information"},
+ {"raw", CmdHF15CmdRaw, 0, "Send raw hex data to tag"},
+ {"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;
+}
+
+