-int CmdVchDemod(const char *Cmd)
-{
- // Is this the entire sync pattern, or does this also include some
- // data bits that happen to be the same everywhere? That would be
- // lovely to know.
- static const int SyncPattern[] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- };
-
- // So first, we correlate for the sync pattern, and mark that.
- int bestCorrel = 0, bestPos = 0;
- int i;
- // It does us no good to find the sync pattern, with fewer than
- // 2048 samples after it...
- for (i = 0; i < (GraphTraceLen-2048); i++) {
- int sum = 0;
- int j;
- for (j = 0; j < arraylen(SyncPattern); j++) {
- sum += GraphBuffer[i+j]*SyncPattern[j];
- }
- if (sum > bestCorrel) {
- bestCorrel = sum;
- bestPos = i;
- }
- }
- PrintAndLog("best sync at %d [metric %d]", bestPos, bestCorrel);
-
- char bits[257];
- bits[256] = '\0';
-
- int worst = INT_MAX;
- int worstPos = 0;
-
- for (i = 0; i < 2048; i += 8) {
- int sum = 0;
- int j;
- for (j = 0; j < 8; j++) {
- sum += GraphBuffer[bestPos+i+j];
- }
- if (sum < 0) {
- bits[i/8] = '.';
- } else {
- bits[i/8] = '1';
- }
- if(abs(sum) < worst) {
- worst = abs(sum);
- worstPos = i;
- }
- }
- PrintAndLog("bits:");
- PrintAndLog("%s", bits);
- PrintAndLog("worst metric: %d at pos %d", worst, worstPos);
-
- if (strcmp(Cmd, "clone")==0) {
- GraphTraceLen = 0;
- char *s;
- for(s = bits; *s; s++) {
- int j;
- for(j = 0; j < 16; j++) {
- GraphBuffer[GraphTraceLen++] = (*s == '1') ? 1 : 0;
- }
- }
- RepaintGraphWindow();
- }
- return 0;
+int CmdVchDemod(const char *Cmd) {
+ // Is this the entire sync pattern, or does this also include some
+ // data bits that happen to be the same everywhere? That would be
+ // lovely to know.
+ static const int SyncPattern[] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ };
+
+ // So first, we correlate for the sync pattern, and mark that.
+ int bestCorrel = 0, bestPos = 0;
+ int i, j, sum = 0;
+
+ // It does us no good to find the sync pattern, with fewer than 2048 samples after it.
+
+ for (i = 0; i < (GraphTraceLen - 2048); i++) {
+ for (j = 0; j < ARRAYLEN(SyncPattern); j++) {
+ sum += GraphBuffer[i+j] * SyncPattern[j];
+ }
+ if (sum > bestCorrel) {
+ bestCorrel = sum;
+ bestPos = i;
+ }
+ }
+ PrintAndLog("best sync at %d [metric %d]", bestPos, bestCorrel);
+
+ char bits[257];
+ bits[256] = '\0';
+
+ int worst = INT_MAX, worstPos = 0;
+
+ for (i = 0; i < 2048; i += 8) {
+ sum = 0;
+ for (j = 0; j < 8; j++)
+ sum += GraphBuffer[bestPos+i+j];
+
+ if (sum < 0)
+ bits[i/8] = '.';
+ else
+ bits[i/8] = '1';
+
+ if(abs(sum) < worst) {
+ worst = abs(sum);
+ worstPos = i;
+ }
+ }
+ PrintAndLog("bits:");
+ PrintAndLog("%s", bits);
+ PrintAndLog("worst metric: %d at pos %d", worst, worstPos);
+
+ // clone
+ if (strcmp(Cmd, "clone")==0) {
+ GraphTraceLen = 0;
+ char *s;
+ for(s = bits; *s; s++) {
+ for(j = 0; j < 16; j++) {
+ GraphBuffer[GraphTraceLen++] = (*s == '1') ? 1 : 0;
+ }
+ }
+ RepaintGraphWindow();
+ }
+ return 0;
+}
+
+
+//by marshmellow
+int CheckChipset(bool getDeviceData) {
+
+ if (!getDeviceData) return 0;
+
+ uint32_t word = 0;
+ save_restoreGB(1);
+
+ //check for em4x05/em4x69 chips first
+ if (EM4x05IsBlock0(&word)) {
+ save_restoreGB(0);
+ PrintAndLog("\nValid EM4x05/EM4x69 Chipset found\nTry `lf em 4x05` commands\n");
+ return 1;
+ }
+
+ //TODO check for t55xx chip...
+ // if ( t55xxIsBlock0(() {
+ // save_restoreGB(0);
+ // PrintAndLog("\nValid T55xx Chipset found\nTry `lf t55xx` commands\n");
+ // return 1;
+ // }
+
+ save_restoreGB(0);
+ return 0;