setSamplingConfig((sample_config *) c->d.asBytes);
break;
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
- cmd_send(CMD_ACK,SampleLF(c->arg[0]),0,0,0,0);
+ cmd_send(CMD_ACK,SampleLF(c->arg[0], c->arg[1]),0,0,0,0);
break;
case CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K:
ModThenAcquireRawAdcSamples125k(c->arg[0],c->arg[1],c->arg[2],c->d.asBytes);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
// now do the read
- DoAcquisition_config(false);
+ DoAcquisition_config(false, 0);
}
/* blank r/w tag data stream
switch(rawsignal) {
case 0: doCotagAcquisition(50000); break;
case 1: doCotagAcquisitionManchester(); break;
- case 2: DoAcquisition_config(TRUE); break;
+ case 2: DoAcquisition_config(true, 0); break;
}
// Turn the field off
{
return DoAcquisition(1,8,0,trigger_threshold,silent,0);
}
-uint32_t DoAcquisition_config( bool silent)
+uint32_t DoAcquisition_config(bool silent, int sample_size)
{
return DoAcquisition(config.decimation
,config.bits_per_sample
,config.averaging
,config.trigger_threshold
,silent
- ,0);
+ ,sample_size);
}
uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size) {
return DoAcquisition(1,8,0,trigger_threshold,silent,sample_size);
}
-uint32_t ReadLF(bool activeField, bool silent)
+uint32_t ReadLF(bool activeField, bool silent, int sample_size)
{
if (!silent) printConfig();
LFSetupFPGAForADC(config.divisor, activeField);
// Now call the acquisition routine
- return DoAcquisition_config(silent);
+ return DoAcquisition_config(silent, sample_size);
}
/**
* Initializes the FPGA for reader-mode (field on), and acquires the samples.
* @return number of bits sampled
**/
-uint32_t SampleLF(bool printCfg)
+uint32_t SampleLF(bool printCfg, int sample_size)
{
- uint32_t ret = ReadLF(true, printCfg);
+ uint32_t ret = ReadLF(true, printCfg, sample_size);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
return ret;
}
uint32_t SnoopLF()
{
- uint32_t ret = ReadLF(false, true);
+ uint32_t ret = ReadLF(false, true, 0);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
return ret;
}
* Initializes the FPGA for reader-mode (field on), and acquires the samples.
* @return number of bits sampled
**/
-uint32_t SampleLF(bool silent);
+uint32_t SampleLF(bool silent, int sample_size);
/**
* Initializes the FPGA for snoop-mode (field off), and acquires the samples.
* @return number of bits sampled
*/
-uint32_t DoAcquisition_config( bool silent);
+uint32_t DoAcquisition_config(bool silent, int sample_size);
/**
* Setup the FPGA to listen for samples. This method downloads the FPGA bitstream
return;
}
+bool getDemodBuf(uint8_t *buff, size_t *size) {
+ if (buff == NULL) return false;
+ if (size == NULL) return false;
+ if (*size == 0) return false;
+
+ *size = (*size > DemodBufferLen) ? DemodBufferLen : *size;
+
+ memcpy(buff, DemodBuffer, *size);
+ return true;
+}
+
// option '1' to save DemodBuffer any other to restore
void save_restoreDB(uint8_t saveOpt)
{
memcpy(SavedDB, DemodBuffer, sizeof(DemodBuffer));
SavedDBlen = DemodBufferLen;
DB_Saved=true;
- } else if (DB_Saved){ //restore
+ } else if (DB_Saved) { //restore
memcpy(DemodBuffer, SavedDB, sizeof(DemodBuffer));
DemodBufferLen = SavedDBlen;
}
bool st = false;
size_t ststart = 0, stend = 0;
if (*stCheck) st = DetectST_ext(BitStream, &BitLen, &foundclk, &ststart, &stend);
+ *stCheck = st;
if (st) {
- *stCheck = st;
clk = (clk == 0) ? foundclk : clk;
CursorCPos = ststart;
CursorDPos = stend;
return 0;
}
sscanf(Cmd, "%i %i %i", &offset, &invert, &maxErr);
- if (DemodBufferLen==0){
+ if (DemodBufferLen==0) {
PrintAndLog("DemodBuffer Empty - run 'data rawdemod ar' first");
return 0;
}
uint8_t BitStream[MAX_GRAPH_TRACE_LEN]={0};
- memcpy(BitStream, DemodBuffer, DemodBufferLen);
- size = DemodBufferLen;
+ size = sizeof(BitStream);
+ if ( !getDemodBuf(BitStream, &size) ) return 0;
errCnt=BiphaseRawDecode(BitStream, &size, offset, invert);
if (errCnt<0){
PrintAndLog("Error during decode:%d", errCnt);
return val;
}
-int getSamples(const char *Cmd, bool silent)
+int getSamples(int n, bool silent)
{
//If we get all but the last byte in bigbuf,
// we don't have to worry about remaining trash
uint8_t got[BIGBUF_SIZE-1] = { 0 };
- int n = strtol(Cmd, NULL, 0);
-
if (n == 0 || n > sizeof(got))
n = sizeof(got);
- PrintAndLog("Reading %d bytes from device memory\n", n);
+ if (!silent) PrintAndLog("Reading %d bytes from device memory\n", n);
GetFromBigBuf(got,n,0);
- PrintAndLog("Data fetched");
+ if (!silent) PrintAndLog("Data fetched");
UsbCommand response;
WaitForResponse(CMD_ACK, &response);
uint8_t bits_per_sample = 8;
}
if(bits_per_sample < 8)
{
- PrintAndLog("Unpacking...");
+ if (!silent) PrintAndLog("Unpacking...");
BitstreamIn bout = { got, bits_per_sample * n, 0};
int j =0;
for (j = 0; j * bits_per_sample < n * 8 && j < n; j++) {
int CmdSamples(const char *Cmd)
{
- return getSamples(Cmd, false);
+ int n = strtol(Cmd, NULL, 0);
+ return getSamples(n, false);
}
int CmdTuneSamples(const char *Cmd)
int CmdData(const char *Cmd);
void printDemodBuff(void);
void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx);
+bool getDemodBuf(uint8_t *buff, size_t *size);
void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore
int CmdPrintDemodBuff(const char *Cmd);
int Cmdaskrawdemod(const char *Cmd);
int FSKrawDemod(const char *Cmd, bool verbose);
int PSKDemod(const char *Cmd, bool verbose);
int NRZrawDemod(const char *Cmd, bool verbose);
-int getSamples(const char *Cmd, bool silent);
+int getSamples(int n, bool silent);
#define MAX_DEMOD_BUF_LEN (1024*128)
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <stdbool.h>
+#include <stdint.h>
#include "proxmark3.h"
#include "cmdlf.h"
#include "lfdemod.h" // for psk2TOpsk1
PrintAndLog("Options: ");
PrintAndLog(" h This help");
PrintAndLog(" s silent run no printout");
- PrintAndLog("This function takes no arguments. ");
+ PrintAndLog(" [# samples] # samples to collect (optional)");
PrintAndLog("Use 'lf config' to set parameters.");
return 0;
}
return 0;
}
+bool lf_read(bool silent, uint32_t samples) {
+ if (offline) return false;
+ UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {silent,samples,0}};
+ clearCommandBuffer();
+ //And ship it to device
+ SendCommand(&c);
+
+ UsbCommand resp;
+ if (g_lf_threshold_set) {
+ WaitForResponse(CMD_ACK,&resp);
+ } else {
+ if ( !WaitForResponseTimeout(CMD_ACK,&resp,2500) ) {
+ PrintAndLog("command execution time out");
+ return false;
+ }
+ }
+ getSamples(resp.arg[0], silent);
+
+ return true;
+}
+
int CmdLFRead(const char *Cmd)
{
- if (offline) return 0;
uint8_t cmdp = 0;
- bool arg1 = false;
+ bool silent = false;
if (param_getchar(Cmd, cmdp) == 'h')
{
return usage_lf_read();
}
- if (param_getchar(Cmd, cmdp) == 's') arg1 = true; //suppress print
- //And ship it to device
- UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {arg1,0,0}};
- clearCommandBuffer();
- SendCommand(&c);
- if (g_lf_threshold_set) {
- WaitForResponse(CMD_ACK,NULL);
- } else {
- if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
- PrintAndLog("command execution time out");
- return 1;
- }
+ if (param_getchar(Cmd, cmdp) == 's') {
+ silent = true; //suppress print
+ cmdp++;
}
- return 0;
+ uint32_t samples = param_get32ex(Cmd, cmdp, 0, 10);
+ return lf_read(silent, samples);
}
int CmdLFSnoop(const char *Cmd)
clearCommandBuffer();
SendCommand(&c);
WaitForResponse(CMD_ACK,NULL);
+ getSamples(0, true);
+
return 0;
}
return 0;
}
- if (!offline && (cmdp != '1')){
- CmdLFRead("s");
- getSamples("30000",false);
+ if (!offline && (cmdp != '1')) {
+ lf_read(true, 30000);
} else if (GraphTraceLen < minLength) {
PrintAndLog("Data in Graphbuffer was too small.");
return 0;
if (ans>0) {
PrintAndLog("Possible unknown PSK1 Modulated Tag Found above!\n\nCould also be PSK2 - try 'data rawdemod p2'");
PrintAndLog("\nCould also be PSK3 - [currently not supported]");
- PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod");
+ PrintAndLog("\nCould also be NRZ - try 'data nrzrawdemod'");
return 1;
}
PrintAndLog("\nNo Data Found!\n");
#ifndef CMDLF_H__
#define CMDLF_H__
-int CmdLF(const char *Cmd);
+#include <stdbool.h>
+#include <stdint.h>
-int CmdLFCommandRead(const char *Cmd);
-int CmdFlexdemod(const char *Cmd);
-int CmdIndalaDemod(const char *Cmd);
-int CmdIndalaClone(const char *Cmd);
-int CmdLFRead(const char *Cmd);
-int CmdLFSim(const char *Cmd);
-int CmdLFaskSim(const char *Cmd);
-int CmdLFfskSim(const char *Cmd);
-int CmdLFpskSim(const char *Cmd);
-int CmdLFSimBidir(const char *Cmd);
-int CmdLFSnoop(const char *Cmd);
-int CmdVchDemod(const char *Cmd);
-int CmdLFfind(const char *Cmd);
+extern int CmdLF(const char *Cmd);
+
+extern int CmdLFCommandRead(const char *Cmd);
+extern int CmdFlexdemod(const char *Cmd);
+extern int CmdIndalaDemod(const char *Cmd);
+extern int CmdIndalaClone(const char *Cmd);
+extern int CmdLFRead(const char *Cmd);
+extern int CmdLFSim(const char *Cmd);
+extern int CmdLFaskSim(const char *Cmd);
+extern int CmdLFfskSim(const char *Cmd);
+extern int CmdLFpskSim(const char *Cmd);
+extern int CmdLFSimBidir(const char *Cmd);
+extern int CmdLFSnoop(const char *Cmd);
+extern int CmdVchDemod(const char *Cmd);
+extern int CmdLFfind(const char *Cmd);
+extern bool lf_read(bool silent, uint32_t samples);
#endif
// the license.
//-----------------------------------------------------------------------------
// Low frequency AWID26 commands
+// FSK2a, RF/50, 96 bits (complete)
//-----------------------------------------------------------------------------
#include <string.h>
case 2: {
CmdPlot("");
CmdGrid("384");
- getSamples("", true); break;
+ getSamples(0, true); break;
}
case 1: {
GetFromBigBuf(DemodBuffer, COTAG_BITS, 0);
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;
printf("\naborted via keyboard!\n");
break;
}
-
- CmdLFRead("s");
- getSamples("8201",true);
+ lf_read(true, 8201);
} while (!CmdAskEM410xDemod(""));
return 0;
// the license.
//-----------------------------------------------------------------------------
// Low frequency fdx-b tag commands
+// Differential Biphase, rf/32, 128 bits (known)
//-----------------------------------------------------------------------------
#include "cmdlffdx.h"
}
int CmdFdxRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("10000", true);
+ lf_read(true, 10000);
return CmdFdxDemod(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency G Prox II tag commands
+// Biphase, rf/ , 96 bits (unknown key calc + some bits)
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
//see ASKDemod for what args are accepted
int CmdG_Prox_II_Read(const char *Cmd) {
// read lf silently
- CmdLFRead("s");
- // get samples silently
- getSamples("10000",false);
+ lf_read(true, 10000);
// demod and output viking ID
return CmdG_Prox_II_Demod(Cmd);
}
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
-// Low frequency HID commands
+// Low frequency HID commands (known)
//-----------------------------------------------------------------------------
#include <stdio.h>
// the license.
//-----------------------------------------------------------------------------
// Low frequency Indala commands
+// PSK1, rf/32, 64 or 224 bits (known)
//-----------------------------------------------------------------------------
#include <stdio.h>
}
int CmdIndalaRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("30000",false);
+ lf_read(true, 30000);
return CmdIndalaDecode("");
}
+//-----------------------------------------------------------------------------
+//
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,
+// at your option, any later version. See the LICENSE.txt file for the text of
+// the license.
+//-----------------------------------------------------------------------------
+// Low frequency ioProx commands
+// FSK2a, rf/64, 64 bits (complete)
+//-----------------------------------------------------------------------------
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// the license.
//-----------------------------------------------------------------------------
// Low frequency jablotron tag commands
-// Differential Biphase, RF/64, 64 bits long
+// Differential Biphase, RF/64, 64 bits long (complete)
//-----------------------------------------------------------------------------
#include "cmdlfjablotron.h"
}
int CmdJablotronRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("10000", true);
+ lf_read(true, 10000);
return CmdJablotronDemod(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Honeywell NexWatch tag commands
-// PSK1 RF/16, RF/2, 128 bits long
+// PSK1 RF/16, RF/2, 128 bits long (known)
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
//see ASKDemod for what args are accepted
int CmdNexWatchRead(const char *Cmd) {
// read lf silently
- CmdLFRead("s");
- // get samples silently
- getSamples("10000",false);
+ lf_read(true, 10000);
// demod and output viking ID
return CmdPSKNexWatch(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Noralsy tag commands
-// ASK/Manchester, STT, RF/32, 96 bits long
+// ASK/Manchester, STT, RF/32, 96 bits long (some bits unknown)
//-----------------------------------------------------------------------------
#include "cmdlfnoralsy.h"
#include <string.h>
/*
*
* 2520116 | BB0214FF2529900116360000 | 10111011 00000011 00010100 11111111 00100101 00101001 10010000 00000001 00010110 00110110 00000000 00000000
-* aaaaaaaaiii***iiiicc---- iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
+* aaa*aaaaiiiYY*iiiicc---- **** iiiiiiii iiiiYYYY YYYY**** iiiiiiii iiiiiiii cccccccc
*
-* a = fixed value BB0314FF
+* a = fixed value BB0*14FF
* i = printed id, BCD-format
* Y = year
* c = checksum
-*
+* * = unknown
+*
**/
//see ASKDemod for what args are accepted
}
int CmdNoralsyRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("8000",true);
+ lf_read(true, 8000);
return CmdNoralsyDemod(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Paradox tag commands
+// FSK2a, rf/50, 96 bits (completely known)
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
//see ASKDemod for what args are accepted
int CmdParadoxRead(const char *Cmd) {
// read lf silently
- CmdLFRead("s");
- // get samples silently
- getSamples("10000",false);
+ lf_read(true, 10000);
// demod and output viking ID
return CmdFSKdemodParadox(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Presco tag commands
+// ASK/Manchester, rf/32, 128 bits (complete)
//-----------------------------------------------------------------------------
#include <string.h>
#include <inttypes.h>
return 0;
}
size_t size = DemodBufferLen;
- //call lfdemod.c demod for Viking
+ //call lfdemod.c demod for presco
int ans = PrescoDemod(DemodBuffer, &size);
if (ans < 0) {
if (g_debugMode) PrintAndLog("Error Presco_Demod %d", ans);
// Presco Number: 123456789 --> Sitecode 30 | usercode 8665
// read lf silently
- CmdLFRead("s");
- // get samples silently
- getSamples("30000",false);
+ lf_read(true, 10000);
// demod and output Presco ID
return CmdPrescoDemod(Cmd);
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Farpoint / Pyramid tag commands
+// FSK2a, rf/50, 128 bits (complete)
//-----------------------------------------------------------------------------
#include <string.h>
#include <inttypes.h>
}
int CmdPyramidRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("30000",false);
+ lf_read(true, 15000);
return CmdFSKdemodPyramid("");
}
// the license.
//-----------------------------------------------------------------------------
// Low frequency Securakey tag commands
-// ASK/Manchester, RF/40, 96 bits long
+// ASK/Manchester, RF/40, 96 bits long (unknown cs)
//-----------------------------------------------------------------------------
#include "cmdlfsecurakey.h"
#include <string.h>
}
int CmdSecurakeyRead(const char *Cmd) {
- CmdLFRead("s");
- getSamples("8000",true);
+ lf_read(true, 8000);
return CmdSecurakeyDemod(Cmd);
}
if (!testBitRate(bitRate, clk)) continue;\r
} else { //extended mode bitrate = same function to calc bitrate as em4x05\r
if (EM4x05_GET_BITRATE(bitRate) != clk) continue;\r
+\r
}\r
//test modulation\r
if (!testModulation(mode, modread)) continue;\r
int printConfiguration( t55xx_conf_block_t b){\r
PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");\r
PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
- PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE)) );\r
+ PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE && (b.block0>>28==6 || b.block0>>28==9))) );\r
PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );\r
PrintAndLog("Offset : %d", b.offset);\r
PrintAndLog("Seq. Term. : %s", (b.ST) ? "Yes" : "No" );\r
PrintAndLog("command execution time out");\r
return 0;\r
}\r
-\r
- uint8_t got[12000];\r
- GetFromBigBuf(got,sizeof(got),0);\r
- WaitForResponse(CMD_ACK,NULL);\r
- setGraphBuf(got, sizeof(got));\r
+ getSamples(12000,true);\r
return 1;\r
}\r
\r
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
-// Low frequency Viking tag commands
+// Low frequency Viking tag commands (AKA FDI Matalec Transit)
+// ASK/Manchester, RF/32, 64 bits (complete)
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
//see ASKDemod for what args are accepted
int CmdVikingRead(const char *Cmd) {
// read lf silently
- CmdLFRead("s");
- // get samples silently
- getSamples("10000",false);
+ lf_read(true, 10000);
// demod and output viking ID
return CmdVikingDemod(Cmd);
}
//-----------------------------------------------------------------------------
// Low frequency visa 2000 tag commands
// by iceman
+// ASK/Manchester, RF/64, STT, 96 bits (complete)
//-----------------------------------------------------------------------------
#include "cmdlfvisa2000.h"
/**
*
* 56495332 00096ebd 00000077 —> tag id 618173
-* aaaaaaaa iiiiiiii -----..c
+* aaaaaaaa iiiiiiii -----ppc
*
* a = fixed value ascii 'VIS2'
* i = card id
+* p = even parity bit for each nibble in card id.
* c = checksum (xor of card id)
-* . = unknown
*
**/
//see ASKDemod for what args are accepted
}
int CmdVisa2kRead(const char *Cmd) {
- CmdLFRead("s");
//64*96*2=12288 samples just in case we just missed the first preamble we can still catch 2 of them
- getSamples("12500",true);
+ lf_read(true, 12500);
return CmdVisa2kDemod(Cmd);
}
if (data[in_index]<10)
sprintf(tmp++, "%u", (unsigned int) data[in_index]);
// check if a line break is needed and we have room to print it in our array
- if ( (breaks > 0) && !((in_index+1) % breaks) && (out_index+1 != max_len) ) {
+ if ( (breaks > 0) && !((in_index+1) % breaks) && (out_index+1 < max_len) ) {
// increment and print line break
out_index++;
sprintf(tmp++, "%s","\n");