mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
monster merge...
all those changes marshmellow did.. and more...
This commit is contained in:
parent
208550823d
commit
f28da2da6e
107 changed files with 5087 additions and 3777 deletions
|
@ -4,7 +4,8 @@
|
|||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Low frequency Presco tag commands
|
||||
// Low frequency fdx-b tag commands
|
||||
// Differential Biphase, rf/32, 128 bits (known)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "cmdlffdx.h"
|
||||
|
@ -32,7 +33,7 @@ static int CmdHelp(const char *Cmd);
|
|||
|
||||
int usage_lf_fdx_clone(void){
|
||||
PrintAndLog("Clone a FDX-B animal tag to a T55x7 tag.");
|
||||
PrintAndLog("Usage: lf animal clone [h] <country id> <animal id> <Q5>");
|
||||
PrintAndLog("Usage: lf fdx clone [h] <country id> <animal id> <Q5>");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : This help");
|
||||
PrintAndLog(" <country id> : Country id");
|
||||
|
@ -43,7 +44,7 @@ int usage_lf_fdx_clone(void){
|
|||
// extended data
|
||||
PrintAndLog(" <Q5> : Specify write to Q5 (t5555 instead of t55x7)");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample: lf animal clone 999 112233");
|
||||
PrintAndLog("Sample: lf fdx clone 999 112233");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -51,15 +52,31 @@ int usage_lf_fdx_sim(void) {
|
|||
PrintAndLog("Enables simulation of FDX-B animal tag");
|
||||
PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: lf animal sim [h] <country id> <animal id>");
|
||||
PrintAndLog("Usage: lf fdx sim [h] <country id> <animal id>");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : This help");
|
||||
PrintAndLog(" <country id> : Country ID");
|
||||
PrintAndLog(" <animal id> : Animal ID");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Sample: lf animal sim 999 112233");
|
||||
PrintAndLog("Sample: lf fdx sim 999 112233");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Ask/Biphase Demod then try to locate an ISO 11784/85 ID
|
||||
// BitStream must contain previously askrawdemod and biphasedemoded data
|
||||
int detectFDXB(uint8_t *dest, size_t *size) {
|
||||
//make sure buffer has enough data
|
||||
if (*size < 128*2) return -1;
|
||||
size_t startIdx = 0;
|
||||
uint8_t preamble[] = {0,0,0,0,0,0,0,0,0,0,1};
|
||||
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||
return -2; //preamble not found
|
||||
if (*size != 128) return -3; //wrong demoded size
|
||||
//return start position
|
||||
return (int)startIdx;
|
||||
}
|
||||
|
||||
// clearing the topbit needed for the preambl detection.
|
||||
static void verify_values(uint32_t countryid, uint64_t animalid){
|
||||
if ((animalid & 0x3FFFFFFFFF) != animalid) {
|
||||
|
@ -122,6 +139,98 @@ int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t
|
|||
return 1;
|
||||
}
|
||||
|
||||
// FDX-B ISO11784/85 demod (aka animal tag) BIPHASE, inverted, rf/32, with preamble of 00000000001 (128bits)
|
||||
// 8 databits + 1 parity (1)
|
||||
// CIITT 16 chksum
|
||||
// NATIONAL CODE, ICAR database
|
||||
// COUNTRY CODE (ISO3166) or http://cms.abvma.ca/uploads/ManufacturersISOsandCountryCodes.pdf
|
||||
// FLAG (animal/non-animal)
|
||||
/*
|
||||
38 IDbits
|
||||
10 country code
|
||||
1 extra app bit
|
||||
14 reserved bits
|
||||
1 animal bit
|
||||
16 ccitt CRC chksum over 64bit ID CODE.
|
||||
24 appli bits.
|
||||
|
||||
-- sample: 985121004515220 [ 37FF65B88EF94 ]
|
||||
*/
|
||||
int CmdFDXBdemodBI(const char *Cmd){
|
||||
|
||||
int invert = 1;
|
||||
int clk = 32;
|
||||
int errCnt = 0;
|
||||
int offset = 0, maxErr = 0;
|
||||
uint8_t BitStream[MAX_DEMOD_BUF_LEN];
|
||||
size_t size = getFromGraphBuf(BitStream);
|
||||
|
||||
errCnt = askdemod(BitStream, &size, &clk, &invert, maxErr, 0, 0);
|
||||
if ( errCnt < 0 || errCnt > maxErr ) {
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - FDXB no data or error found %d, clock: %d", errCnt, clk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
errCnt = BiphaseRawDecode(BitStream, &size, &offset, 1);
|
||||
if (errCnt < 0 || errCnt > maxErr ) {
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - FDXB BiphaseRawDecode: %d", errCnt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int preambleIndex = detectFDXB(BitStream, &size);
|
||||
if (preambleIndex < 0){
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - FDXB preamble not found :: %d",preambleIndex);
|
||||
return 0;
|
||||
}
|
||||
if (size != 128) {
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - FDXB incorrect data length found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
setDemodBuf(BitStream, 128, preambleIndex);
|
||||
|
||||
// remove marker bits (1's every 9th digit after preamble) (pType = 2)
|
||||
size = removeParity(BitStream, preambleIndex + 11, 9, 2, 117);
|
||||
if ( size != 104 ) {
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - FDXB error removeParity:: %d", size);
|
||||
return 0;
|
||||
}
|
||||
PrintAndLog("\nFDX-B / ISO 11784/5 Animal Tag ID Found:");
|
||||
|
||||
//got a good demod
|
||||
uint64_t NationalCode = ((uint64_t)(bytebits_to_byteLSBF(BitStream+32,6)) << 32) | bytebits_to_byteLSBF(BitStream,32);
|
||||
uint32_t countryCode = bytebits_to_byteLSBF(BitStream+38,10);
|
||||
uint8_t dataBlockBit = BitStream[48];
|
||||
uint32_t reservedCode = bytebits_to_byteLSBF(BitStream+49,14);
|
||||
uint8_t animalBit = BitStream[63];
|
||||
uint32_t crc16 = bytebits_to_byteLSBF(BitStream+64,16);
|
||||
uint32_t extended = bytebits_to_byteLSBF(BitStream+80,24);
|
||||
|
||||
uint64_t rawid = ((uint64_t)bytebits_to_byte(BitStream,32)<<32) | bytebits_to_byte(BitStream+32,32);
|
||||
uint8_t raw[8];
|
||||
num_to_bytes(rawid, 8, raw);
|
||||
|
||||
if (g_debugMode) PrintAndLog("Raw ID Hex: %s", sprint_hex(raw,8));
|
||||
|
||||
uint16_t calcCrc = crc16_ccitt_kermit(raw, 8);
|
||||
PrintAndLog("Animal ID: %04u-%012" PRIu64, countryCode, NationalCode);
|
||||
PrintAndLog("National Code: %012" PRIu64, NationalCode);
|
||||
PrintAndLog("CountryCode: %04u", countryCode);
|
||||
|
||||
PrintAndLog("Reserved/RFU: %u", reservedCode);
|
||||
PrintAndLog("Animal Tag: %s", animalBit ? "True" : "False");
|
||||
PrintAndLog("Has extended data: %s [0x%X]", dataBlockBit ? "True" : "False", extended);
|
||||
PrintAndLog("CRC: 0x%04X - [%04X] - %s", crc16, calcCrc, (calcCrc == crc16) ? "Passed" : "Failed");
|
||||
|
||||
if (g_debugMode) {
|
||||
PrintAndLog("Start marker %d; Size %d", preambleIndex, size);
|
||||
char *bin = sprint_bin_break(BitStream,size,16);
|
||||
PrintAndLog("DEBUG BinStream:\n%s",bin);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//see ASKDemod for what args are accepted
|
||||
//almost the same demod as cmddata.c/CmdFDXBdemodBI
|
||||
int CmdFdxDemod(const char *Cmd) {
|
||||
|
@ -133,23 +242,24 @@ int CmdFdxDemod(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
size_t size = DemodBufferLen;
|
||||
int ans = FDXBdemodBI(DemodBuffer, &size);
|
||||
if (ans < 0){
|
||||
int preambleIndex = detectFDXB(DemodBuffer, &size);
|
||||
if (preambleIndex < 0){
|
||||
if (g_debugMode){
|
||||
if (ans == -1)
|
||||
if (preambleIndex == -1)
|
||||
PrintAndLog("DEBUG: Error - FDX-B too few bits found");
|
||||
else if (ans == -2)
|
||||
else if (preambleIndex == -2)
|
||||
PrintAndLog("DEBUG: Error - FDX-B preamble not found");
|
||||
else if (ans == -3)
|
||||
else if (preambleIndex == -3)
|
||||
PrintAndLog("DEBUG: Error - FDX-B Size not correct: %d", size);
|
||||
else
|
||||
PrintAndLog("DEBUG: Error - FDX-B ans: %d", ans);
|
||||
PrintAndLog("DEBUG: Error - FDX-B ans: %d", preambleIndex);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
setDemodBuf(DemodBuffer, 128, ans);
|
||||
setGrid_Clock(32);
|
||||
// set and leave DemodBuffer intact
|
||||
setDemodBuf(DemodBuffer, 128, preambleIndex);
|
||||
setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex*g_DemodClock));
|
||||
// remove marker bits (1's every 9th digit after preamble) (pType = 2)
|
||||
size = removeParity(DemodBuffer, 11, 9, 2, 117);
|
||||
if ( size != 104 ) {
|
||||
|
@ -165,14 +275,11 @@ int CmdFdxDemod(const char *Cmd) {
|
|||
uint8_t animalBit = DemodBuffer[63];
|
||||
uint32_t crc16 = bytebits_to_byteLSBF(DemodBuffer+64,16);
|
||||
uint32_t extended = bytebits_to_byteLSBF(DemodBuffer+80,24);
|
||||
uint64_t rawid = ((uint64_t)
|
||||
//bytebits_to_byte(DemodBuffer, 8) << 96) |
|
||||
//bytebits_to_byte(DemodBuffer,32) << 64) |
|
||||
bytebits_to_byte(DemodBuffer,32) << 32) |
|
||||
bytebits_to_byte(DemodBuffer+32, 32);
|
||||
uint64_t rawid = (uint64_t)(bytebits_to_byte(DemodBuffer,32)) << 32 | bytebits_to_byte(DemodBuffer+32, 32);
|
||||
uint8_t raw[8];
|
||||
num_to_bytes(rawid, 8, raw);
|
||||
|
||||
|
||||
uint16_t calcCrc = crc16_ccitt_kermit(raw, 8);
|
||||
|
||||
PrintAndLog("\nFDX-B / ISO 11784/5 Animal Tag ID Found: Raw : %s", sprint_hex(raw, 8));
|
||||
|
@ -180,22 +287,24 @@ int CmdFdxDemod(const char *Cmd) {
|
|||
PrintAndLog("National Code %012" PRIu64 " (0x%" PRIx64 ")", NationalCode, NationalCode);
|
||||
PrintAndLog("Country Code %04u", countryCode);
|
||||
PrintAndLog("Reserved/RFU %u (0x04%X)", reservedCode, reservedCode);
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Animal Tag %s", animalBit ? "True" : "False");
|
||||
PrintAndLog("Has extended data %s [0x%X]", dataBlockBit ? "True" : "False", extended);
|
||||
PrintAndLog("CRC-16 0x%04X - 0x%04X [%s]", crc16, calcCrc, (calcCrc == crc16) ? "Ok" : "Failed");
|
||||
|
||||
if (g_debugMode) {
|
||||
PrintAndLog("Start marker %d; Size %d", ans, size);
|
||||
PrintAndLog("Start marker %d; Size %d", preambleIndex, size);
|
||||
char *bin = sprint_bin_break(DemodBuffer, size, 16);
|
||||
PrintAndLog("DEBUG bin stream:\n%s", bin);
|
||||
}
|
||||
|
||||
// set block 0 for later
|
||||
//g_DemodConfig = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CmdFdxRead(const char *Cmd) {
|
||||
CmdLFRead("s");
|
||||
getSamples("12000", true);
|
||||
lf_read(true, 10000);
|
||||
return CmdFdxDemod(Cmd);
|
||||
}
|
||||
|
||||
|
@ -290,9 +399,9 @@ int CmdFdxSim(const char *Cmd) {
|
|||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"demod", CmdFdxDemod,1, "Attempt to extract tag data from graphbuf"},
|
||||
{"read", CmdFdxRead, 0, "Attempt to read and extract tag data"},
|
||||
{"clone", CmdFdxClone,0, "Clone animal ID tag to T55x7"},
|
||||
{"demod", CmdFdxDemod, 1, "Attempt to extract FDX-B ISO11784/85 data from the GraphBuffer"},
|
||||
{"read", CmdFdxRead, 0, "Attempt to read and extract FDX-B ISO11784/85 data"},
|
||||
{"clone", CmdFdxClone, 0, "Clone animal ID tag to T55x7 (or to q5/T5555)"},
|
||||
{"sim", CmdFdxSim, 0, "Animal ID tag simulator"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue