]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhf15.c
fix 'hf 15 csetuid' (#890)
[proxmark3-svn] / client / cmdhf15.c
index 6bcad20124ac54f452d392e2435173c467a99afd..cc86841b2d0d61d0a22fda9e57d82e74940749d0 100644 (file)
@@ -90,34 +90,32 @@ 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
 
 // 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?
        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;
        
        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
                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);
                
                c.arg[0] = reqlen;
        
                SendCommand(&c);
                
-               if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+               if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
                        recv = resp.d.asBytes;
                        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
                        } 
                } 
        } // retry
-       return 0;
+       return false;
 }
 
 
 }
 
 
@@ -139,8 +137,7 @@ static char* TagErrorStr(uint8_t error) {
 
 
 // Mode 3
 
 
 // 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;
        // 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)
 // * 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;
 }
 
        UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693};
        SendCommand(&c);
        return 0;
 }
 
+
 // Record Activity without enabling carrier
 // 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;
 }
 
        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)) {
        uint8_t uid[8];
 
        if (!getUID(uid)) {
@@ -256,16 +251,16 @@ int HF15Reader(const char *Cmd, bool verbose)
        return 1;
 }
 
        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;
 }
 
        UsbCommand c = {CMD_READER_ISO_15693, {strtol(Cmd, NULL, 0), 0, 0}};
        SendCommand(&c);
        return 0;
 }
 
+
 // Simulation is still not working very good
 // 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};
 
        char cmdp = param_getchar(Cmd, 0);
        uint8_t uid[8] = {0x00};
 
@@ -293,17 +288,18 @@ int CmdHF15Sim(const char *Cmd)
        return 0;
 }
 
        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)
 // 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;
 }
 
        UsbCommand c = {CMD_ISO_15693_FIND_AFI, {strtol(Cmd, NULL, 0), 0, 0}};
        SendCommand(&c);
        return 0;
 }
 
+
 // Reads all memory pages
 // 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;
        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?
        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)
 
 
 // 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 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?
        UsbCommand resp;
        uint8_t *recv;
        UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
@@ -560,30 +522,30 @@ int CmdHF15CmdRaw (const char *cmd) {
  * Parameters:
  *  **cmd      command line
  */
  * 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;
        int temp;
-       uint8_t *req=c->d.asBytes;
+       uint8_t *req = c->d.asBytes;
        uint8_t uid[8] = {0x00};
        uint8_t uid[8] = {0x00};
-       uint32_t reqlen=0;
+       uint32_t reqlen = 0;
 
        // strip
        while (**cmd==' ' || **cmd=='\t') (*cmd)++;
        
 
        // 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
        }
 
        // 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
        }
        
        // strip
-       while (**cmd==' ' || **cmd=='\t') (*cmd)++;
+       while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
        
        switch (**cmd) {
                case 0:
        
        switch (**cmd) {
                case 0:
@@ -594,54 +556,54 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle
                case 'S':
                        // you must have selected the tag earlier
                        req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_SELECT;
                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;
                        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;
                        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;
                        }
                        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));
                        PrintAndLog("Detected UID %s",sprintUID(NULL,uid));
-                       reqlen+=8;
+                       reqlen += 8;
                        break;                  
                default:
                        req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_ADDRESS;
                        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]); */
                   
 /*                     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;
                        }                               
                                
                                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           
        }
        // skip to next space           
-       while (**cmd!=' ' && **cmd!='\t') (*cmd)++;
+       while (**cmd != ' ' && **cmd != '\t') (*cmd)++;
        // skip over the space
        // skip over the space
-       while (**cmd==' ' || **cmd=='\t') (*cmd)++;
+       while (**cmd == ' ' || **cmd == '\t') (*cmd)++;
        
        
-       c->arg[0]=reqlen;       
+       c->arg[0] = reqlen;     
        return 1;
 }
 
        return 1;
 }
 
@@ -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
  */
  * 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?
        UsbCommand resp;
        uint8_t *recv;
        UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
@@ -685,9 +647,9 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
 
        SendCommand(&c);
 
 
        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;
                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));
                        if (!(recv[0] & ISO15693_RES_ERROR)) {
                                *output=0; // reset outputstring
                                PrintAndLog("UID:               %s", sprintUID(NULL,recv+2));
@@ -727,11 +689,12 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
        return 0;
 }
 
        return 0;
 }
 
+
 /**
  * Commandline handling: HF15 CMD READMULTI
  * Read multiple blocks at once (not all tags support this)
  */
 /**
  * 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?
        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;
 }
 
        return 0;
 }
 
+
 /**
  * Commandline handling: HF15 CMD READ
  * Reads a single Block
  */
 /**
  * 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?
        UsbCommand resp;
        uint8_t *recv;
        UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
@@ -883,22 +847,21 @@ int CmdHF15CmdRead(const char *Cmd) {
 
 /**
  * Commandline handling: HF15 CMD WRITE
 
 /**
  * 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;
        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 cmdbuf[100];
-       char *cmd=cmdbuf;
+       char *cmd = cmdbuf;
        char *cmd2;
        
        char *cmd2;
        
-       strncpy(cmd,Cmd,99);
+       strncpy(cmd, Cmd, 99);
 
        // usage:
 
        // 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");
                PrintAndLog("Usage:  hf 15 cmd write    [options] <uid|s|u|*> <page#> <hexdata>");
                PrintAndLog("           options:");
                PrintAndLog("               -2        use slower '1 out of 256' mode");
@@ -913,171 +876,207 @@ int CmdHF15CmdWrite(const char *Cmd) {
                return 0;
        }       
        
                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 
        
        // *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++; 
                
        cmd2++; 
                
-       pagenum=strtol(cmd,NULL,0);
+       pagenum = strtol(cmd, NULL, 0);
        /*if (pagenum<0) {
                PrintAndLog("invalid pagenum");
                return 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 
        
        
        while (cmd2[0] && cmd2[1]) { // hexdata, read by 2 hexchars 
-               if (*cmd2==' ') {
+               if (*cmd2 == ' ') {
                        cmd2++; 
                        continue; 
                }
                        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);
 
 
        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 {
                } else {
-                       PrintAndLog("CRC failed");
+                       PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1])); 
                }
        } else {
                }
        } else {
-               PrintAndLog("timeout: no answer - data may be written anyway");
+               PrintAndLog("No answer from Proxmark");
        }
        
        return 0;
 }
 
        }
        
        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;
 }
        CmdsParse(CommandTable15Cmd, Cmd);
        return 0;
 }
-       
-int CmdHF15CmdHelp(const char *Cmd)
-{
+
+
+static int CmdHF15CmdHelp(const char *Cmd) {
        CmdsHelp(CommandTable15Cmd);
        return 0;
 }
 
        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;
+}
+
+
Impressum, Datenschutz