]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - common/lfdemod.c
Merge pull request #254 from marshmellow42/master
[proxmark3-svn] / common / lfdemod.c
index 801d651b6e97c17c814cbb67e96843f0311bc15f..eb84203e040b0f83f3d6b162dcadc0562aa13f24 100644 (file)
@@ -41,6 +41,7 @@
 //**********************************************************************************************
 #define LOWEST_DEFAULT_CLOCK 32
 #define FSK_PSK_THRESHOLD   123
+
 //to allow debug print calls when used not on device
 void dummy(char *fmt, ...){}
 #ifndef ON_DEVICE
@@ -307,15 +308,17 @@ uint32_t manchesterEncode2Bytes(uint16_t datain) {
 
 //by marshmellow
 //encode binary data into binary manchester 
-//NOTE: BitStream must have double the size available in memory to do the swap
+//NOTE: BitStream must have triple the size of "size" available in memory to do the swap
 int ManchesterEncode(uint8_t *BitStream, size_t size) {
-       size_t modIdx=size, i=0;
-       if (size>modIdx) return -1;
+       //allow up to 4K out (means BitStream must be at least 2048+4096 to handle the swap)
+       size = (size>2048) ? 2048 : size;
+       size_t modIdx = size;
+       size_t i;
        for (size_t idx=0; idx < size; idx++){
                BitStream[idx+modIdx++] = BitStream[idx];
                BitStream[idx+modIdx++] = BitStream[idx]^1;
        }
-       for (; i<(size*2); i++){
+       for (i=0; i<(size*2); i++){
                BitStream[i] = BitStream[i+size];
        }
        return i;
@@ -1700,6 +1703,8 @@ int FDXBdemodBI(uint8_t *dest, size_t *size) {
 
        uint8_t errChk = preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx);
        if (errChk == 0) return -2; //preamble not found
+       if (*size != 128) return -3; //wrong size for fdxb
+       //return start position
        return (int)startIdx;
 }
 
Impressum, Datenschutz