added hitag bit count output in log

This commit is contained in:
roel@libnfc.org 2013-03-11 15:07:23 +00:00
commit 47e18126ec
2 changed files with 48 additions and 28 deletions

View file

@ -29,6 +29,34 @@ bool bAuthenticating;
bool bPwd; bool bPwd;
bool bSuccessful; bool bSuccessful;
size_t nbytes(size_t nbits) {
return (nbits/8)+((nbits%8)>0);
}
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int bReader)
{
// Return when trace is full
if (traceLen >= TRACE_SIZE) return FALSE;
// Trace the random, i'm curious
rsamples += iSamples;
trace[traceLen++] = ((rsamples >> 0) & 0xff);
trace[traceLen++] = ((rsamples >> 8) & 0xff);
trace[traceLen++] = ((rsamples >> 16) & 0xff);
trace[traceLen++] = ((rsamples >> 24) & 0xff);
if (!bReader) {
trace[traceLen - 1] |= 0x80;
}
trace[traceLen++] = ((dwParity >> 0) & 0xff);
trace[traceLen++] = ((dwParity >> 8) & 0xff);
trace[traceLen++] = ((dwParity >> 16) & 0xff);
trace[traceLen++] = ((dwParity >> 24) & 0xff);
trace[traceLen++] = iBits;
memcpy(trace + traceLen, btBytes, nbytes(iBits));
traceLen += nbytes(iBits);
return TRUE;
}
struct hitag2_tag { struct hitag2_tag {
uint32_t uid; uint32_t uid;
enum { enum {
@ -153,10 +181,6 @@ static u32 _hitag2_byte (u64 * x)
return c; return c;
} }
size_t nbytes(size_t nbits) {
return (nbits/8)+((nbits%8)>0);
}
int hitag2_reset(void) int hitag2_reset(void)
{ {
tag.state = TAG_STATE_RESET; tag.state = TAG_STATE_RESET;
@ -399,8 +423,8 @@ void hitag2_handle_reader_command(byte_t* rx, const size_t rxlen, byte_t* tx, si
break; break;
} }
// LogTrace(rx,nbytes(rxlen),0,0,false); // LogTraceHitag(rx,rxlen,0,0,false);
// LogTrace(tx,nbytes(*txlen),0,0,true); // LogTraceHitag(tx,*txlen,0,0,true);
if(tag.crypto_active) { if(tag.crypto_active) {
hitag2_cipher_transcrypt(&(tag.cs), tx, *txlen/8, *txlen%8); hitag2_cipher_transcrypt(&(tag.cs), tx, *txlen/8, *txlen%8);
@ -853,7 +877,7 @@ void SnoopHitag(uint32_t type) {
// Check if frame was captured // Check if frame was captured
if(rxlen > 0) { if(rxlen > 0) {
frame_count++; frame_count++;
if (!LogTrace(rx,nbytes(rxlen),response,0,reader_frame)) { if (!LogTraceHitag(rx,rxlen,response,0,reader_frame)) {
DbpString("Trace full"); DbpString("Trace full");
break; break;
} }
@ -1016,7 +1040,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
if(rxlen > 4) { if(rxlen > 4) {
frame_count++; frame_count++;
if (!bQuiet) { if (!bQuiet) {
if (!LogTrace(rx,nbytes(rxlen),response,0,true)) { if (!LogTraceHitag(rx,rxlen,response,0,true)) {
DbpString("Trace full"); DbpString("Trace full");
if (bQuitTraceFull) { if (bQuitTraceFull) {
break; break;
@ -1045,7 +1069,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
hitag_send_frame(tx,txlen); hitag_send_frame(tx,txlen);
// Store the frame in the trace // Store the frame in the trace
if (!bQuiet) { if (!bQuiet) {
if (!LogTrace(tx,nbytes(txlen),0,0,false)) { if (!LogTraceHitag(tx,txlen,0,0,false)) {
DbpString("Trace full"); DbpString("Trace full");
if (bQuitTraceFull) { if (bQuitTraceFull) {
break; break;
@ -1226,7 +1250,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
if(rxlen > 0) { if(rxlen > 0) {
frame_count++; frame_count++;
if (!bQuiet) { if (!bQuiet) {
if (!LogTrace(rx,nbytes(rxlen),response,0,false)) { if (!LogTraceHitag(rx,rxlen,response,0,false)) {
DbpString("Trace full"); DbpString("Trace full");
if (bQuitTraceFull) { if (bQuitTraceFull) {
break; break;
@ -1280,7 +1304,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
frame_count++; frame_count++;
if (!bQuiet) { if (!bQuiet) {
// Store the frame in the trace // Store the frame in the trace
if (!LogTrace(tx,nbytes(txlen),HITAG_T_WAIT_2,0,true)) { if (!LogTraceHitag(tx,txlen,HITAG_T_WAIT_2,0,true)) {
if (bQuitTraceFull) { if (bQuitTraceFull) {
break; break;
} else { } else {

View file

@ -24,6 +24,10 @@
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
size_t nbytes(size_t nbits) {
return (nbits/8)+((nbits%8)>0);
}
int CmdLFHitagList(const char *Cmd) int CmdLFHitagList(const char *Cmd)
{ {
uint8_t got[3000]; uint8_t got[3000];
@ -31,8 +35,8 @@ int CmdLFHitagList(const char *Cmd)
WaitForResponse(CMD_ACK,NULL); WaitForResponse(CMD_ACK,NULL);
PrintAndLog("recorded activity:"); PrintAndLog("recorded activity:");
PrintAndLog(" ETU :rssi: who bytes"); PrintAndLog(" ETU :nbits: who bytes");
PrintAndLog("---------+----+----+-----------"); PrintAndLog("---------+-----+----+-----------");
int i = 0; int i = 0;
int prev = -1; int prev = -1;
@ -54,7 +58,6 @@ int CmdLFHitagList(const char *Cmd)
isResponse = 0; isResponse = 0;
} }
int metric = 0;
int parityBits = *((uint32_t *)(got+i+4)); int parityBits = *((uint32_t *)(got+i+4));
// 4 bytes of additional information... // 4 bytes of additional information...
// maximum of 32 additional parity bit information // maximum of 32 additional parity bit information
@ -63,7 +66,8 @@ int CmdLFHitagList(const char *Cmd)
// at each quarter bit period we can send power level (16 levels) // at each quarter bit period we can send power level (16 levels)
// or each half bit period in 256 levels. // or each half bit period in 256 levels.
int len = got[i+8]; int bits = got[i+8];
int len = nbytes(got[i+8]);
if (len > 100) { if (len > 100) {
break; break;
@ -96,27 +100,19 @@ int CmdLFHitagList(const char *Cmd)
} }
} }
char metricString[100]; PrintAndLog(" +%7d: %3d: %s %s",
if (isResponse) {
sprintf(metricString, "%3d", metric);
} else {
strcpy(metricString, " ");
}
PrintAndLog(" +%7d: %s: %s %s",
(prev < 0 ? 0 : (timestamp - prev)), (prev < 0 ? 0 : (timestamp - prev)),
metricString, bits,
(isResponse ? "TAG" : " "), (isResponse ? "TAG" : " "),
line); line);
if (pf) { if (pf) {
fprintf(pf," +%7d: %s: %s %s %s", fprintf(pf," +%7d: %3d: %s %s\n",
(prev < 0 ? 0 : (timestamp - prev)), (prev < 0 ? 0 : (timestamp - prev)),
metricString, bits,
(isResponse ? "TAG" : " "), (isResponse ? "TAG" : " "),
line, line);
"\n");
} }
prev = timestamp; prev = timestamp;