mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
chg: lf fdx clone/sim - added extended data
This commit is contained in:
parent
eb7fd5f8ab
commit
b383b16ded
1 changed files with 36 additions and 25 deletions
|
@ -50,15 +50,14 @@ static int CmdHelp(const char *Cmd);
|
|||
|
||||
static int usage_lf_fdx_clone(void) {
|
||||
PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 tag.");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf fdx clone [h] <country id> <animal id> <Q5>");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf fdx clone [h] <country id> <animal id> <extended> <Q5>");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h : This help");
|
||||
PrintAndLogEx(NORMAL, " <country id> : Country id");
|
||||
PrintAndLogEx(NORMAL, " <animal id> : Animal id");
|
||||
// has extended data?
|
||||
PrintAndLogEx(NORMAL, " <extended> : Extended data");
|
||||
//reserved/rfu
|
||||
//is animal tag
|
||||
// extended data
|
||||
PrintAndLogEx(NORMAL, " <Q5> : Specify write to Q5 (t5555 instead of t55x7)");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
|
@ -70,11 +69,12 @@ static int usage_lf_fdx_sim(void) {
|
|||
PrintAndLogEx(NORMAL, "Enables simulation of FDX-B animal tag");
|
||||
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf fdx sim [h] <country id> <animal id>");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf fdx sim [h] <country id> <animal id> <extended>");
|
||||
PrintAndLogEx(NORMAL, "Options:");
|
||||
PrintAndLogEx(NORMAL, " h : This help");
|
||||
PrintAndLogEx(NORMAL, " <country id> : Country ID");
|
||||
PrintAndLogEx(NORMAL, " <animal id> : Animal ID");
|
||||
PrintAndLogEx(NORMAL, " <extended> : Extended data");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Examples:");
|
||||
PrintAndLogEx(NORMAL, " lf fdx sim 999 112233");
|
||||
|
@ -82,14 +82,14 @@ static int usage_lf_fdx_sim(void) {
|
|||
}
|
||||
|
||||
// clearing the topbit needed for the preambl detection.
|
||||
static void verify_values(uint32_t countryid, uint64_t animalid) {
|
||||
if ((animalid & 0x3FFFFFFFFF) != animalid) {
|
||||
animalid &= 0x3FFFFFFFFF;
|
||||
PrintAndLogEx(INFO, "Animal ID Truncated to 38bits: %"PRIx64, animalid);
|
||||
static void verify_values(uint64_t *animalid, uint32_t *countryid) {
|
||||
if ((*animalid & 0x3FFFFFFFFF) != *animalid) {
|
||||
*animalid &= 0x3FFFFFFFFF;
|
||||
PrintAndLogEx(INFO, "Animal ID Truncated to 38bits: %"PRIx64, *animalid);
|
||||
}
|
||||
if ((countryid & 0x3ff) != countryid) {
|
||||
countryid &= 0x3ff;
|
||||
PrintAndLogEx(INFO, "Country ID Truncated to 10bits: %03d", countryid);
|
||||
if ((*countryid & 0x3ff) != *countryid) {
|
||||
*countryid &= 0x3ff;
|
||||
PrintAndLogEx(INFO, "Country ID Truncated to 10bits: %03d", *countryid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,19 +264,21 @@ static int CmdFdxRead(const char *Cmd) {
|
|||
|
||||
static int CmdFdxClone(const char *Cmd) {
|
||||
|
||||
uint32_t countryid = 0;
|
||||
uint32_t countryid = 0, extended = 0;
|
||||
uint64_t animalid = 0;
|
||||
|
||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_fdx_clone();
|
||||
|
||||
countryid = param_get32ex(Cmd, 0, 0, 10);
|
||||
animalid = param_get64ex(Cmd, 1, 0, 10);
|
||||
extended = param_get32ex(Cmd, 2, 0, 10);
|
||||
|
||||
verify_values(countryid, animalid);
|
||||
verify_values(&animalid, &countryid);
|
||||
|
||||
uint8_t *bits = calloc(128, sizeof(uint8_t));
|
||||
|
||||
if (getFDXBits(animalid, countryid, 1, 0, 0, bits) != PM3_SUCCESS) {
|
||||
if (getFDXBits(animalid, countryid, 1, (extended > 0), extended, bits) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Error with tag bitstream generation.");
|
||||
free(bits);
|
||||
return PM3_ESOFT;
|
||||
|
@ -285,7 +287,7 @@ static int CmdFdxClone(const char *Cmd) {
|
|||
uint32_t blocks[5] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
|
||||
|
||||
//Q5
|
||||
if (param_getchar(Cmd, 2) == 'Q' || param_getchar(Cmd, 2) == 'q')
|
||||
if (tolower(param_getchar(Cmd, 2)) == 'q')
|
||||
blocks[0] = T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT;
|
||||
|
||||
// convert from bit stream to block data
|
||||
|
@ -303,7 +305,7 @@ static int CmdFdxClone(const char *Cmd) {
|
|||
}
|
||||
|
||||
static int CmdFdxSim(const char *Cmd) {
|
||||
uint32_t countryid = 0;
|
||||
uint32_t countryid = 0, extended = 0;
|
||||
uint64_t animalid = 0;
|
||||
|
||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
||||
|
@ -311,25 +313,33 @@ static int CmdFdxSim(const char *Cmd) {
|
|||
|
||||
countryid = param_get32ex(Cmd, 0, 0, 10);
|
||||
animalid = param_get64ex(Cmd, 1, 0, 10);
|
||||
extended = param_get32ex(Cmd, 2, 0 , 10);
|
||||
|
||||
verify_values(countryid, animalid);
|
||||
verify_values(&animalid, &countryid);
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: %04u-%"PRIu64, countryid, animalid);
|
||||
|
||||
uint8_t bs[128];
|
||||
//getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits)
|
||||
getFDXBits(animalid, countryid, 1, 0, 0, bs);
|
||||
uint8_t *bits = calloc(128, sizeof(uint8_t));
|
||||
|
||||
if (getFDXBits(animalid, countryid, 1, (extended > 0), extended, bits) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Error with tag bitstream generation.");
|
||||
free(bits);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
// 32, no STT, BIPHASE INVERTED == diphase
|
||||
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs));
|
||||
lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + 128);
|
||||
payload->encoding = 2;
|
||||
payload->invert = 1;
|
||||
payload->separator = 0;
|
||||
payload->clock = 32;
|
||||
memcpy(payload->data, bs, sizeof(bs));
|
||||
memcpy(payload->data, bits, 128);
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_ASK_SIMULATE, (uint8_t *)payload, sizeof(lf_asksim_t) + sizeof(bs));
|
||||
SendCommandNG(CMD_LF_ASK_SIMULATE, (uint8_t *)payload, sizeof(lf_asksim_t) + 128);
|
||||
|
||||
free(bits);
|
||||
free(payload);
|
||||
|
||||
PacketResponseNG resp;
|
||||
|
@ -338,6 +348,7 @@ static int CmdFdxSim(const char *Cmd) {
|
|||
PrintAndLogEx(INFO, "Done");
|
||||
if (resp.status != PM3_EOPABORTED)
|
||||
return resp.status;
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -379,7 +390,7 @@ int demodFDX(void) {
|
|||
return CmdFdxDemod("");
|
||||
}
|
||||
|
||||
int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits) {
|
||||
int getFDXBits(uint64_t national_id, uint16_t country, uint8_t is_animal, uint8_t is_extended, uint32_t extended, uint8_t *bits) {
|
||||
|
||||
// add preamble ten 0x00 and one 0x01
|
||||
memset(bits, 0x00, 10);
|
||||
|
@ -397,10 +408,10 @@ int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t
|
|||
num_to_bytebitsLSBF(0x00 >> 7, 7, bits + 74);
|
||||
|
||||
// add animal flag - OK
|
||||
bits[65] = isanimal;
|
||||
bits[65] = is_animal;
|
||||
|
||||
// add extended flag - OK
|
||||
bits[81] = isextended;
|
||||
bits[81] = is_extended;
|
||||
|
||||
// add national code 40bits - OK
|
||||
num_to_bytebitsLSBF(national_id >> 0, 8, bits + 11);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue