]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
added hitag bit count output in log
authorroel@libnfc.org <roel@libnfc.org@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Mon, 11 Mar 2013 15:07:23 +0000 (15:07 +0000)
committerroel@libnfc.org <roel@libnfc.org@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Mon, 11 Mar 2013 15:07:23 +0000 (15:07 +0000)
armsrc/hitag2.c
client/cmdlfhitag.c

index a2c1d82323ab7a65abb1f830a201926d5143cea5..37c2e3eb41aa17188a7fdb606a39a34cb28824df 100644 (file)
@@ -29,6 +29,34 @@ bool bAuthenticating;
 bool bPwd;
 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 {
        uint32_t uid;
        enum {
@@ -153,10 +181,6 @@ static u32 _hitag2_byte (u64 * x)
        return c;
 }
 
-size_t nbytes(size_t nbits) {
-       return (nbits/8)+((nbits%8)>0);
-}
-
 int hitag2_reset(void)
 {
        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;
        }
 
-//     LogTrace(rx,nbytes(rxlen),0,0,false);
-//     LogTrace(tx,nbytes(*txlen),0,0,true);
+//     LogTraceHitag(rx,rxlen,0,0,false);
+//     LogTraceHitag(tx,*txlen,0,0,true);
        
        if(tag.crypto_active) {
                hitag2_cipher_transcrypt(&(tag.cs), tx, *txlen/8, *txlen%8);
@@ -853,7 +877,7 @@ void SnoopHitag(uint32_t type) {
                // Check if frame was captured
                if(rxlen > 0) {
                        frame_count++;
-                       if (!LogTrace(rx,nbytes(rxlen),response,0,reader_frame)) {
+                       if (!LogTraceHitag(rx,rxlen,response,0,reader_frame)) {
                                DbpString("Trace full");
                                break;
                        }
@@ -1016,7 +1040,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
                if(rxlen > 4) {
                        frame_count++;
                        if (!bQuiet) {
-                               if (!LogTrace(rx,nbytes(rxlen),response,0,true)) {
+                               if (!LogTraceHitag(rx,rxlen,response,0,true)) {
                                        DbpString("Trace full");
                                        if (bQuitTraceFull) {
                                                break;
@@ -1045,7 +1069,7 @@ void SimulateHitagTag(bool tag_mem_supplied, byte_t* data) {
                                hitag_send_frame(tx,txlen);
                                // Store the frame in the trace
                                if (!bQuiet) {
-                                       if (!LogTrace(tx,nbytes(txlen),0,0,false)) {
+                                       if (!LogTraceHitag(tx,txlen,0,0,false)) {
                                                DbpString("Trace full");
                                                if (bQuitTraceFull) {
                                                        break;
@@ -1226,7 +1250,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
                if(rxlen > 0) {
                        frame_count++;
                        if (!bQuiet) {
-                               if (!LogTrace(rx,nbytes(rxlen),response,0,false)) {
+                               if (!LogTraceHitag(rx,rxlen,response,0,false)) {
                                        DbpString("Trace full");
                                        if (bQuitTraceFull) {
                                                break;
@@ -1280,7 +1304,7 @@ void ReaderHitag(hitag_function htf, hitag_data* htd) {
                        frame_count++;
                        if (!bQuiet) {
                                // 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) {
                                                break;
                                        } else {
index c648f6a5912862697219d76f735b3f73ce00a0f9..ab279dcb32e30b94b75ea88f5708db46b1d317bf 100644 (file)
 
 static int CmdHelp(const char *Cmd);
 
+size_t nbytes(size_t nbits) {
+       return (nbits/8)+((nbits%8)>0);
+}
+
 int CmdLFHitagList(const char *Cmd)
 {
   uint8_t got[3000];
@@ -31,8 +35,8 @@ int CmdLFHitagList(const char *Cmd)
   WaitForResponse(CMD_ACK,NULL);
 
   PrintAndLog("recorded activity:");
-  PrintAndLog(" ETU     :rssi: who bytes");
-  PrintAndLog("---------+----+----+-----------");
+  PrintAndLog(" ETU     :nbits: who bytes");
+  PrintAndLog("---------+-----+----+-----------");
 
   int i = 0;
   int prev = -1;
@@ -54,7 +58,6 @@ int CmdLFHitagList(const char *Cmd)
       isResponse = 0;
     }
 
-    int metric = 0;
     int parityBits = *((uint32_t *)(got+i+4));
     // 4 bytes of additional 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)
     // 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) {
       break;
@@ -96,27 +100,19 @@ int CmdLFHitagList(const char *Cmd)
       }
     }
 
-    char metricString[100];
-    if (isResponse) {
-      sprintf(metricString, "%3d", metric);
-    } else {
-      strcpy(metricString, "   ");
-    }
-
-    PrintAndLog(" +%7d: %s: %s %s",
+    PrintAndLog(" +%7d:  %3d: %s %s",
       (prev < 0 ? 0 : (timestamp - prev)),
-      metricString,
+      bits,
       (isResponse ? "TAG" : "   "),
       line);
 
 
    if (pf) {
-      fprintf(pf," +%7d: %s: %s %s %s",
+      fprintf(pf," +%7d:  %3d: %s %s\n",
                                        (prev < 0 ? 0 : (timestamp - prev)),
-                                       metricString,
+                                       bits,
                                        (isResponse ? "TAG" : "   "),
-                                       line,
-                                       "\n");
+                                       line);
     }
        
     prev = timestamp;
Impressum, Datenschutz