added hf 14a raw

This commit is contained in:
merlokk 2017-11-28 12:31:10 +02:00
commit f23b3c325f
2 changed files with 43 additions and 91 deletions

View file

@ -17,6 +17,7 @@
#define arg_get_lit(n)(((struct arg_lit*)argtable[n])) #define arg_get_lit(n)(((struct arg_lit*)argtable[n]))
#define arg_get_str(n)(((struct arg_str*)argtable[n])) #define arg_get_str(n)(((struct arg_str*)argtable[n]))
#define arg_get_int(n)(((struct arg_int*)argtable[n]))
extern int CLIParserInit(char *vprogramName, char *vprogramHint); extern int CLIParserInit(char *vprogramName, char *vprogramHint);
extern int CLIParserParseString(const char* str, void* argtable[], size_t vargtableLen, bool allowEmptyExec); extern int CLIParserParseString(const char* str, void* argtable[], size_t vargtableLen, bool allowEmptyExec);

View file

@ -786,102 +786,53 @@ int CmdHF14ACmdRaw(const char *cmd) {
bool bTimeout = false; bool bTimeout = false;
uint32_t timeout = 0; uint32_t timeout = 0;
bool topazmode = false; bool topazmode = false;
char buf[5]="";
int i = 0;
uint8_t data[USB_CMD_DATA_SIZE]; uint8_t data[USB_CMD_DATA_SIZE];
uint16_t datalen = 0; int datalen = 0;
uint32_t temp;
if (strlen(cmd)<2) { // extract parameters
PrintAndLog("Usage: hf 14a raw [-r] [-c] [-p] [-f] [-b] [-t] <number of bits> <0A 0B 0C ... hex>"); CLIParserInit("hf 14a raw", "Send raw hex data to tag");
PrintAndLog(" -r do not read response"); void* argtable[] = {
PrintAndLog(" -c calculate and append CRC"); arg_param_begin,
PrintAndLog(" -p leave the signal field ON after receive"); arg_lit0("rR", "nreply", "do not read response"),
PrintAndLog(" -a active signal field ON without select"); arg_lit0("cC", "crc", "calculate and append CRC"),
PrintAndLog(" -s active signal field ON with select"); arg_lit0("pP", "power", "leave the signal field ON after receive"),
PrintAndLog(" -b number of bits to send. Useful for send partial byte"); arg_lit0("aA", "active", "active signal field ON without select"),
PrintAndLog(" -t timeout in ms"); arg_lit0("sS", "actives", "active signal field ON with select"),
PrintAndLog(" -T use Topaz protocol to send command"); arg_int0("bB", "bits", NULL, "number of bits to send. Useful for send partial byte"),
PrintAndLog(" -3 ISO14443-3 select only (skip RATS)"); arg_int0("t", "timeout", NULL, "timeout in ms"),
arg_lit0("T", "topaz", "use Topaz protocol to send command"),
arg_lit0("3", NULL, "ISO14443-3 select only (skip RATS)"),
arg_str1(NULL, NULL, "<data (hex)>", NULL),
arg_param_end
};
// defaults
arg_get_int(6)->ival[0] = 0;
arg_get_int(7)->ival[0] = 0;
if (CLIParserParseString(cmd, argtable, sizeof(argtable) / sizeof(argtable[0]), false)){
CLIParserFree();
return 0; return 0;
} }
reply = !arg_get_lit(1)->count;
// strip crc = arg_get_lit(2)->count;
while (*cmd==' ' || *cmd=='\t') cmd++; power = arg_get_lit(3)->count;
active = arg_get_lit(4)->count;
while (cmd[i]!='\0') { active_select = arg_get_lit(5)->count;
if (cmd[i]==' ' || cmd[i]=='\t') { i++; continue; } numbits = arg_get_int(6)->ival[0] & 0xFFFF;
if (cmd[i]=='-') { timeout = arg_get_int(7)->ival[0];
switch (cmd[i+1]) { bTimeout = (timeout > 0);
case 'r': topazmode = arg_get_lit(8)->count;
reply = false; no_rats = arg_get_lit(9)->count;
break; // len = data + CRC(2b)
case 'c': if (CLIParamHexToBuf(arg_get_str(10), data, sizeof(data) -2, &datalen)) {
crc = true; CLIParserFree();
break; return 1;
case 'p':
power = true;
break;
case 'a':
active = true;
break;
case 's':
active_select = true;
break;
case 'b':
sscanf(cmd+i+2,"%d",&temp);
numbits = temp & 0xFFFF;
i+=3;
while(cmd[i]!=' ' && cmd[i]!='\0') { i++; }
i-=2;
break;
case 't':
bTimeout = true;
sscanf(cmd+i+2,"%d",&temp);
timeout = temp;
i+=3;
while(cmd[i]!=' ' && cmd[i]!='\0') { i++; }
i-=2;
break;
case 'T':
topazmode = true;
break;
case '3':
no_rats = true;
break;
default:
PrintAndLog("Invalid option");
return 0;
}
i+=2;
continue;
}
if ((cmd[i]>='0' && cmd[i]<='9') ||
(cmd[i]>='a' && cmd[i]<='f') ||
(cmd[i]>='A' && cmd[i]<='F') ) {
buf[strlen(buf)+1]=0;
buf[strlen(buf)]=cmd[i];
i++;
if (strlen(buf)>=2) {
sscanf(buf,"%x",&temp);
data[datalen]=(uint8_t)(temp & 0xff);
*buf=0;
if (datalen > sizeof(data)-1) {
if (crc)
PrintAndLog("Buffer is full, we can't add CRC to your data");
break;
} else {
datalen++;
}
}
continue;
}
PrintAndLog("Invalid char on input");
return 0;
} }
CLIParserFree();
// logic
if(crc && datalen>0 && datalen<sizeof(data)-2) if(crc && datalen>0 && datalen<sizeof(data)-2)
{ {
uint8_t first, second; uint8_t first, second;