mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -10,7 +10,8 @@
|
|||
#include "cmdlfnedap.h"
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
int usage_lf_nedap_clone(void){
|
||||
int usage_lf_nedap_clone(void)
|
||||
{
|
||||
PrintAndLogEx(NORMAL, "clone a NEDAP tag to a T55x7 tag.");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(NORMAL, "Usage: lf nedap clone [h] <Card-Number>");
|
||||
|
@ -24,7 +25,8 @@ int usage_lf_nedap_clone(void){
|
|||
return 0;
|
||||
}
|
||||
|
||||
int usage_lf_nedap_sim(void) {
|
||||
int usage_lf_nedap_sim(void)
|
||||
{
|
||||
PrintAndLogEx(NORMAL, "Enables simulation of NEDAP card with specified card number.");
|
||||
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
@ -39,19 +41,21 @@ int usage_lf_nedap_sim(void) {
|
|||
}
|
||||
|
||||
// find nedap preamble in already demoded data
|
||||
int detectNedap(uint8_t *dest, size_t *size) {
|
||||
int detectNedap(uint8_t *dest, size_t *size)
|
||||
{
|
||||
//make sure buffer has data
|
||||
if (*size < 128) return -3;
|
||||
|
||||
size_t startIdx = 0;
|
||||
//uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0,0,0,1};
|
||||
uint8_t preamble[] = {1,1,1,1,1,1,1,1,1,0};
|
||||
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
|
||||
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||
return -4; //preamble not found
|
||||
return (int) startIdx;
|
||||
}
|
||||
|
||||
int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
|
||||
int GetNedapBits(uint32_t cn, uint8_t *nedapBits)
|
||||
{
|
||||
|
||||
uint8_t pre[128];
|
||||
memset(pre, 0x00, sizeof(pre));
|
||||
|
@ -60,7 +64,7 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
|
|||
num_to_bytebits(0xFF8, 12, pre);
|
||||
|
||||
// fixed tagtype code? 0010 1101 = 0x2D
|
||||
num_to_bytebits(0x2D, 8, pre+10);
|
||||
num_to_bytebits(0x2D, 8, pre + 10);
|
||||
|
||||
// 46 encrypted bits - UNKNOWN ALGO
|
||||
// -- 16 bits checksum. Should be 4x4 checksum, based on UID and 2 constant values.
|
||||
|
@ -77,25 +81,25 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
|
|||
pre[118] = 0;
|
||||
|
||||
// cardnumber (uid)
|
||||
num_to_bytebits( (cn >> 0) & 0xFF, 8, pre+65);
|
||||
num_to_bytebits( (cn >> 8) & 0xFF, 8, pre+74);
|
||||
num_to_bytebits( (cn >> 16) & 0xFF, 8, pre+83);
|
||||
num_to_bytebits((cn >> 0) & 0xFF, 8, pre + 65);
|
||||
num_to_bytebits((cn >> 8) & 0xFF, 8, pre + 74);
|
||||
num_to_bytebits((cn >> 16) & 0xFF, 8, pre + 83);
|
||||
|
||||
// two ?
|
||||
num_to_bytebits( 0, 8, pre+92);
|
||||
num_to_bytebits( 0, 8, pre+101);
|
||||
num_to_bytebits(0, 8, pre + 92);
|
||||
num_to_bytebits(0, 8, pre + 101);
|
||||
|
||||
// chksum
|
||||
num_to_bytebits( (0 >> 0) & 0xFF, 8, pre+110);
|
||||
num_to_bytebits( (0 >> 8) & 0xFF, 8, pre+119);
|
||||
num_to_bytebits((0 >> 0) & 0xFF, 8, pre + 110);
|
||||
num_to_bytebits((0 >> 8) & 0xFF, 8, pre + 119);
|
||||
|
||||
|
||||
// add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
|
||||
addParity(pre, pre+64, 64, 8, 1);
|
||||
addParity(pre+64, pre+64, 64, 8, 1);
|
||||
addParity(pre, pre + 64, 64, 8, 1);
|
||||
addParity(pre + 64, pre + 64, 64, 8, 1);
|
||||
|
||||
pre[63] = GetParity( DemodBuffer, EVEN, 63);
|
||||
pre[127] = GetParity( DemodBuffer+64, EVEN, 63);
|
||||
pre[63] = GetParity(DemodBuffer, EVEN, 63);
|
||||
pre[127] = GetParity(DemodBuffer + 64, EVEN, 63);
|
||||
|
||||
memcpy(nedapBits, pre, 128);
|
||||
|
||||
|
@ -112,7 +116,8 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
|
|||
//NEDAP demod - ASK/Biphase (or Diphase), RF/64 with preamble of 1111111110 (always a 128 bit data stream)
|
||||
//print NEDAP Prox ID, encoding, encrypted ID,
|
||||
|
||||
int CmdLFNedapDemod(const char *Cmd) {
|
||||
int CmdLFNedapDemod(const char *Cmd)
|
||||
{
|
||||
//raw ask demod no start bit finding just get binary from wave
|
||||
if (!ASKbiphaseDemod("0 64 1 0", false)) {
|
||||
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap ASKbiphaseDemod failed");
|
||||
|
@ -120,89 +125,89 @@ int CmdLFNedapDemod(const char *Cmd) {
|
|||
}
|
||||
size_t size = DemodBufferLen;
|
||||
int idx = detectNedap(DemodBuffer, &size);
|
||||
if (idx < 0){
|
||||
if (g_debugMode){
|
||||
if (idx < 0) {
|
||||
if (g_debugMode) {
|
||||
// if (idx == -5)
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - not enough samples");
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - not enough samples");
|
||||
// else if (idx == -1)
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - only noise found");
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - only noise found");
|
||||
// else if (idx == -2)
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - problem during ASK/Biphase demod");
|
||||
// PrintAndLogEx(DEBUG, "DEBUG: Error - problem during ASK/Biphase demod");
|
||||
if (idx == -3)
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap Size not correct: %d", size);
|
||||
else if (idx == -4)
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap preamble not found");
|
||||
else
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap idx: %d",idx);
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap idx: %d", idx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Index map E E
|
||||
preamble enc tag type encrypted uid P d 33 d 90 d 04 d 71 d 40 d 45 d E7 P
|
||||
1111111110 00101101000001011010001100100100001011010100110101100 1 0 00110011 0 10010000 0 00000100 0 01110001 0 01000000 0 01000101 0 11100111 1
|
||||
uid2 uid1 uid0 I I R R
|
||||
1111111110 00101101000001011010001100100100001011010100110101100 1
|
||||
/* Index map E E
|
||||
preamble enc tag type encrypted uid P d 33 d 90 d 04 d 71 d 40 d 45 d E7 P
|
||||
1111111110 00101101000001011010001100100100001011010100110101100 1 0 00110011 0 10010000 0 00000100 0 01110001 0 01000000 0 01000101 0 11100111 1
|
||||
uid2 uid1 uid0 I I R R
|
||||
1111111110 00101101000001011010001100100100001011010100110101100 1
|
||||
|
||||
0 00110011
|
||||
0 10010000
|
||||
0 00000100
|
||||
0 01110001
|
||||
0 01000000
|
||||
0 01000101
|
||||
0 11100111
|
||||
1
|
||||
0 00110011
|
||||
0 10010000
|
||||
0 00000100
|
||||
0 01110001
|
||||
0 01000000
|
||||
0 01000101
|
||||
0 11100111
|
||||
1
|
||||
|
||||
Tag ID is 049033
|
||||
I = Identical on all tags
|
||||
R = Random ?
|
||||
UID2, UID1, UID0 == card number
|
||||
Tag ID is 049033
|
||||
I = Identical on all tags
|
||||
R = Random ?
|
||||
UID2, UID1, UID0 == card number
|
||||
|
||||
*/
|
||||
*/
|
||||
//get raw ID before removing parities
|
||||
uint32_t raw[4] = {0,0,0,0};
|
||||
raw[0] = bytebits_to_byte(DemodBuffer+idx+96,32);
|
||||
raw[1] = bytebits_to_byte(DemodBuffer+idx+64,32);
|
||||
raw[2] = bytebits_to_byte(DemodBuffer+idx+32,32);
|
||||
raw[3] = bytebits_to_byte(DemodBuffer+idx,32);
|
||||
uint32_t raw[4] = {0, 0, 0, 0};
|
||||
raw[0] = bytebits_to_byte(DemodBuffer + idx + 96, 32);
|
||||
raw[1] = bytebits_to_byte(DemodBuffer + idx + 64, 32);
|
||||
raw[2] = bytebits_to_byte(DemodBuffer + idx + 32, 32);
|
||||
raw[3] = bytebits_to_byte(DemodBuffer + idx, 32);
|
||||
setDemodBuf(DemodBuffer, 128, idx);
|
||||
setClockGrid(g_DemodClock, g_DemodStartIdx + (idx*g_DemodClock));
|
||||
setClockGrid(g_DemodClock, g_DemodStartIdx + (idx * g_DemodClock));
|
||||
|
||||
uint8_t firstParity = GetParity( DemodBuffer, EVEN, 63);
|
||||
if ( firstParity != DemodBuffer[63] ) {
|
||||
uint8_t firstParity = GetParity(DemodBuffer, EVEN, 63);
|
||||
if (firstParity != DemodBuffer[63]) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap 1st 64bit parity check failed: %d|%d ", DemodBuffer[63], firstParity);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t secondParity = GetParity( DemodBuffer+64, EVEN, 63);
|
||||
if ( secondParity != DemodBuffer[127] ) {
|
||||
uint8_t secondParity = GetParity(DemodBuffer + 64, EVEN, 63);
|
||||
if (secondParity != DemodBuffer[127]) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap 2st 64bit parity check failed: %d|%d ", DemodBuffer[127], secondParity);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ok valid card found!
|
||||
uint32_t uid = 0;
|
||||
uid = bytebits_to_byte(DemodBuffer+65, 8);
|
||||
uid |= bytebits_to_byte(DemodBuffer+74, 8) << 8;
|
||||
uid |= bytebits_to_byte(DemodBuffer+83, 8) << 16;
|
||||
uid = bytebits_to_byte(DemodBuffer + 65, 8);
|
||||
uid |= bytebits_to_byte(DemodBuffer + 74, 8) << 8;
|
||||
uid |= bytebits_to_byte(DemodBuffer + 83, 8) << 16;
|
||||
|
||||
uint16_t two = 0;
|
||||
two = bytebits_to_byte(DemodBuffer+92, 8);
|
||||
two |= bytebits_to_byte(DemodBuffer+101, 8) << 8;
|
||||
two = bytebits_to_byte(DemodBuffer + 92, 8);
|
||||
two |= bytebits_to_byte(DemodBuffer + 101, 8) << 8;
|
||||
|
||||
uint16_t chksum2 = 0;
|
||||
chksum2 = bytebits_to_byte(DemodBuffer+110, 8);
|
||||
chksum2 |= bytebits_to_byte(DemodBuffer+119, 8) << 8;
|
||||
chksum2 = bytebits_to_byte(DemodBuffer + 110, 8);
|
||||
chksum2 |= bytebits_to_byte(DemodBuffer + 119, 8) << 8;
|
||||
|
||||
PrintAndLogEx(SUCCESS, "NEDAP ID Found - Raw: %08x%08x%08x%08x", raw[3], raw[2], raw[1], raw[0]);
|
||||
PrintAndLogEx(SUCCESS, " - UID: %06X", uid);
|
||||
PrintAndLogEx(SUCCESS, " - i: %04X", two);
|
||||
PrintAndLogEx(SUCCESS, " - Checksum2 %04X", chksum2);
|
||||
|
||||
if (g_debugMode){
|
||||
if (g_debugMode) {
|
||||
PrintAndLogEx(DEBUG, "DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx, 128);
|
||||
printDemodBuff();
|
||||
PrintAndLogEx(DEBUG, "BIN:\n%s", sprint_bin_break( DemodBuffer, 128, 64) );
|
||||
PrintAndLogEx(DEBUG, "BIN:\n%s", sprint_bin_break(DemodBuffer, 128, 64));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -231,7 +236,8 @@ lf t55xx wr b 4 d 4c0003ff
|
|||
|
||||
*/
|
||||
|
||||
int CmdLFNedapRead(const char *Cmd) {
|
||||
int CmdLFNedapRead(const char *Cmd)
|
||||
{
|
||||
lf_read(true, 12000);
|
||||
return CmdLFNedapDemod(Cmd);
|
||||
}
|
||||
|
@ -288,14 +294,15 @@ int CmdLFNedapClone(const char *Cmd) {
|
|||
}
|
||||
*/
|
||||
|
||||
int CmdLFNedapSim(const char *Cmd) {
|
||||
int CmdLFNedapSim(const char *Cmd)
|
||||
{
|
||||
|
||||
uint32_t cardnumber = 0, cn = 0;
|
||||
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_nedap_sim();
|
||||
|
||||
if (sscanf(Cmd, "%u", &cn ) != 1) return usage_lf_nedap_sim();
|
||||
if (sscanf(Cmd, "%u", &cn) != 1) return usage_lf_nedap_sim();
|
||||
|
||||
cardnumber = (cn & 0x00FFFFFF);
|
||||
|
||||
|
@ -309,13 +316,13 @@ int CmdLFNedapSim(const char *Cmd) {
|
|||
arg1 = clk << 8 | encoding;
|
||||
arg2 = invert << 8 | separator;
|
||||
|
||||
if ( !GetNedapBits(cardnumber, bs)) {
|
||||
if (!GetNedapBits(cardnumber, bs)) {
|
||||
PrintAndLogEx(WARNING, "Error with tag bitstream generation.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "bin %s", sprint_bin_break(bs, 128, 32));
|
||||
PrintAndLogEx(SUCCESS, "Simulating Nedap - CardNumber: %u", cardnumber );
|
||||
PrintAndLogEx(SUCCESS, "Simulating Nedap - CardNumber: %u", cardnumber);
|
||||
|
||||
UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
|
||||
memcpy(c.d.asBytes, bs, size);
|
||||
|
@ -324,13 +331,14 @@ int CmdLFNedapSim(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFNedapChk(const char *Cmd){
|
||||
int CmdLFNedapChk(const char *Cmd)
|
||||
{
|
||||
//301600714021BE
|
||||
uint8_t data[256] = { 0x30, 0x16, 0x00, 0x71, 0x40, 0x21, 0xBE};
|
||||
int len = 0;
|
||||
param_gethex_ex(Cmd, 0, data, &len);
|
||||
|
||||
len = ( len == 0 ) ? 5 : len>>1;
|
||||
len = (len == 0) ? 5 : len >> 1;
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Input: [%d] %s", len, sprint_hex(data, len));
|
||||
|
||||
|
@ -340,7 +348,7 @@ int CmdLFNedapChk(const char *Cmd){
|
|||
uint8_t cl = 0x1D, ch = 0x1D, carry = 0;
|
||||
uint8_t al, bl, temp;
|
||||
|
||||
for (int i =len; i >= 0; --i){
|
||||
for (int i = len; i >= 0; --i) {
|
||||
al = data[i];
|
||||
for (int j = 8; j > 0; --j) {
|
||||
|
||||
|
@ -367,13 +375,13 @@ int CmdLFNedapChk(const char *Cmd){
|
|||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Nedap checksum: 0x%X", ((ch << 8) | cl) );
|
||||
PrintAndLogEx(SUCCESS, "Nedap checksum: 0x%X", ((ch << 8) | cl));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "this help"},
|
||||
{"demod", CmdLFNedapDemod,0, "demodulate an Nedap tag from the GraphBuffer"},
|
||||
{"demod", CmdLFNedapDemod, 0, "demodulate an Nedap tag from the GraphBuffer"},
|
||||
{"read", CmdLFNedapRead, 0, "attempt to read and extract tag data"},
|
||||
// {"clone", CmdLFNedapClone,0, "<Card Number> clone nedap tag"},
|
||||
{"sim", CmdLFNedapSim, 0, "simulate nedap tag"},
|
||||
|
@ -381,13 +389,15 @@ static command_t CommandTable[] = {
|
|||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdLFNedap(const char *Cmd) {
|
||||
int CmdLFNedap(const char *Cmd)
|
||||
{
|
||||
clearCommandBuffer();
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd) {
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue