]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfhid.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Low frequency HID commands (known)
9 //-----------------------------------------------------------------------------
18 #include "cmdparser.h"
19 #include "cmddata.h" //for g_debugMode, demodbuff cmds
20 #include "lfdemod.h" // for HIDdemodFSK
22 static int CmdHelp(const char *Cmd
);
24 //by marshmellow (based on existing demod + holiman's refactor)
25 //HID Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded)
26 //print full HID Prox ID and some bit format details if found
27 int CmdFSKdemodHID(const char *Cmd
)
29 //raw fsk demod no manchester decoding no start bit finding just get binary from wave
30 uint32_t hi2
=0, hi
=0, lo
=0;
32 uint8_t BitStream
[MAX_GRAPH_TRACE_LEN
]={0};
33 size_t BitLen
= getFromGraphBuf(BitStream
);
34 if (BitLen
==0) return 0;
35 //get binary from fsk wave
37 int idx
= HIDdemodFSK(BitStream
,&BitLen
,&hi2
,&hi
,&lo
, &waveIdx
);
41 PrintAndLog("DEBUG: Just Noise Detected");
42 } else if (idx
== -2) {
43 PrintAndLog("DEBUG: Error demoding fsk");
44 } else if (idx
== -3) {
45 PrintAndLog("DEBUG: Preamble not found");
46 } else if (idx
== -4) {
47 PrintAndLog("DEBUG: Error in Manchester data, SIZE: %d", BitLen
);
49 PrintAndLog("DEBUG: Error demoding fsk %d", idx
);
54 if (hi2
==0 && hi
==0 && lo
==0) {
55 if (g_debugMode
) PrintAndLog("DEBUG: Error - no values found");
58 if (hi2
!= 0){ //extra large HID tags
59 PrintAndLog("HID Prox TAG ID: %x%08x%08x (%d)",
60 (unsigned int) hi2
, (unsigned int) hi
, (unsigned int) lo
, (unsigned int) (lo
>>1) & 0xFFFF);
62 else { //standard HID tags <38 bits
66 if (((hi
>>5)&1)==1){//if bit 38 is set then < 37 bit format is used
68 lo2
=(((hi
& 31) << 12) | (lo
>>20)); //get bits 21-37 to check for format len bit
70 while(lo2
>1){ //find last bit set to 1 (format len bit)
78 cardnum
= (lo
>>1)&0xFFFF;
82 cardnum
= (lo
>>1)&0xFFFF;
83 fc
= ((hi
&1)<<15)|(lo
>>17);
86 cardnum
= (lo
>>1)&0xFFFFF;
87 fc
= ((hi
&1)<<11)|(lo
>>21);
90 else { //if bit 38 is not set then 37 bit format is used
95 cardnum
= (lo
>>1)&0x7FFFF;
96 fc
= ((hi
&0xF)<<12)|(lo
>>20);
99 PrintAndLog("HID Prox TAG ID: %x%08x (%d) - Format Len: %dbit - FC: %d - Card: %d",
100 (unsigned int) hi
, (unsigned int) lo
, (unsigned int) (lo
>>1) & 0xFFFF,
101 (unsigned int) fmtLen
, (unsigned int) fc
, (unsigned int) cardnum
);
103 setDemodBuf(BitStream
,BitLen
,idx
);
104 setClockGrid(50, waveIdx
+ (idx
*50));
106 PrintAndLog("DEBUG: idx: %d, Len: %d, Printing Demod Buffer:", idx
, BitLen
);
112 int CmdHIDReadFSK(const char *Cmd
)
115 if(Cmd
[0]=='1') findone
=1;
116 UsbCommand c
={CMD_HID_DEMOD_FSK
};
122 int CmdHIDSim(const char *Cmd
)
124 uint32_t hi
= 0, lo
= 0;
127 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
128 hi
= (hi
<< 4) | (lo
>> 28);
129 lo
= (lo
<< 4) | (n
& 0xf);
132 PrintAndLog("Emulating tag with ID %x%08x", hi
, lo
);
133 PrintAndLog("Press pm3-button to abort simulation");
135 UsbCommand c
= {CMD_HID_SIM_TAG
, {hi
, lo
, 0}};
140 int CmdHIDClone(const char *Cmd
)
142 unsigned int hi2
= 0, hi
= 0, lo
= 0;
146 if (strchr(Cmd
,'l') != 0) {
147 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
148 hi2
= (hi2
<< 4) | (hi
>> 28);
149 hi
= (hi
<< 4) | (lo
>> 28);
150 lo
= (lo
<< 4) | (n
& 0xf);
153 PrintAndLog("Cloning tag with long ID %x%08x%08x", hi2
, hi
, lo
);
158 while (sscanf(&Cmd
[i
++], "%1x", &n
) == 1) {
159 hi
= (hi
<< 4) | (lo
>> 28);
160 lo
= (lo
<< 4) | (n
& 0xf);
163 PrintAndLog("Cloning tag with ID %x%08x", hi
, lo
);
169 c
.cmd
= CMD_HID_CLONE_TAG
;
178 static command_t CommandTable
[] =
180 {"help", CmdHelp
, 1, "This help"},
181 {"demod", CmdFSKdemodHID
, 1, "Demodulate HID Prox from GraphBuffer"},
182 {"read", CmdHIDReadFSK
, 0, "['1'] Realtime HID FSK Read from antenna (option '1' for one tag only)"},
183 {"sim", CmdHIDSim
, 0, "<ID> -- HID tag simulator"},
184 {"clone", CmdHIDClone
, 0, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
185 {NULL
, NULL
, 0, NULL
}
188 int CmdLFHID(const char *Cmd
)
190 CmdsParse(CommandTable
, Cmd
);
194 int CmdHelp(const char *Cmd
)
196 CmdsHelp(CommandTable
);