]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlfem4x.c
align clock grid with demods on graph
[proxmark3-svn] / client / cmdlfem4x.c
index e5bea0683a4723dab9b51d333d3e7b860cf06520..6b1fa8838a033d0e3e14377eb2e772bd2678108a 100644 (file)
@@ -146,17 +146,18 @@ void printEM410x(uint32_t hi, uint64_t id)
 int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo )
 {
        size_t idx = 0;
-       size_t BitLen = DemodBufferLen;
-       uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
-       memcpy(BitStream, DemodBuffer, BitLen); 
-       if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)){
+       uint8_t BitStream[512]={0};
+       size_t BitLen = sizeof(BitStream);
+       if ( !getDemodBuf(BitStream, &BitLen) ) return 0;
+
+       if (Em410xDecode(BitStream, &BitLen, &idx, hi, lo)) {
                //set GraphBuffer for clone or sim command
                setDemodBuf(BitStream, BitLen, idx);
-               if (g_debugMode){
+               if (g_debugMode) {
                        PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, BitLen);
                        printDemodBuff();
                }
-               if (verbose){
+               if (verbose) {
                        PrintAndLog("EM410x pattern found: ");
                        printEM410x(*hi, *lo);
                        g_em410xId = *lo;
@@ -298,9 +299,7 @@ int CmdEM410xWatch(const char *Cmd)
                        printf("\naborted via keyboard!\n");
                        break;
                }
-               
-               CmdLFRead("s");
-               getSamples("8201",true); 
+               lf_read(true, 8201);
        } while (!CmdAskEM410xDemod(""));
 
        return 0;
@@ -914,6 +913,9 @@ int usage_lf_em_write(void) {
        return 0;
 }
 
+// note: em4x05 doesn't have a way to invert data output so we must invert the data prior to writing
+//         it if invertion is needed. (example FSK2a vs FSK)
+//       also em4x05 requires swapping word data when compared to the data used for t55xx chips.
 int EM4x05WriteWord(uint8_t addr, uint32_t data, uint32_t pwd, bool usePwd, bool swap, bool invert) {
        if (swap) data = SwapBits(data, 32);
 
@@ -962,7 +964,7 @@ int CmdEM4x05WriteWord(const char *Cmd) {
        bool swap = false;
        bool invert = false;
        uint8_t addr = 16; // default to invalid address
-
+       bool gotData = false;
        char cmdp = 0;
        while(param_getchar(Cmd, cmdp) != 0x00)
        {
@@ -979,6 +981,7 @@ int CmdEM4x05WriteWord(const char *Cmd) {
                case 'd':
                case 'D':
                        data = param_get32ex(Cmd, cmdp+1, 0, 16);
+                       gotData = true;
                        cmdp += 2;
                        break;
                case 'i':
@@ -1013,6 +1016,10 @@ int CmdEM4x05WriteWord(const char *Cmd) {
 
        if ( strlen(Cmd) == 0 ) return usage_lf_em_write();
 
+       if (!gotData) {
+               PrintAndLog("You must enter the data you want to write");
+               return usage_lf_em_write();
+       }
        return EM4x05WriteWord(addr, data, pwd, usePwd, swap, invert);
 }
 
Impressum, Datenschutz