]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfjablotron.c
da4b0040a009d097d635d0122374120470c2af77
1 //-----------------------------------------------------------------------------
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
6 //-----------------------------------------------------------------------------
7 // Low frequency Presco tag commands
8 //-----------------------------------------------------------------------------
9 #include "cmdlfjablotron.h"
11 static int CmdHelp(const char *Cmd
);
13 int usage_lf_jablotron_clone(void){
14 PrintAndLog("clone a Jablotron tag to a T55x7 tag.");
15 PrintAndLog("Usage: lf jablotron clone [h] <card ID> <Q5>");
16 PrintAndLog("Options:");
17 PrintAndLog(" h : This help");
18 PrintAndLog(" <card ID> : jablotron card ID");
19 PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
21 PrintAndLog("Sample: lf jablotron clone d 112233");
25 int usage_lf_jablotron_sim(void) {
26 PrintAndLog("Enables simulation of jablotron card with specified card number.");
27 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
29 PrintAndLog("Usage: lf jablotron sim [h] <card ID>");
30 PrintAndLog("Options:");
31 PrintAndLog(" h : This help");
32 PrintAndLog(" <card ID> : jablotron card ID");
34 PrintAndLog("Sample: lf jablotron sim d 112233");
38 static uint8_t jablontron_chksum(uint8_t *bits
){
40 for (int i
=16; i
< 56; i
+= 8) {
41 chksum
+= bytebits_to_byte(bits
+i
,8);
47 int getJablotronBits(uint64_t fullcode
, uint8_t *bits
) {
49 num_to_bytebits(0xFFFF, 16, bits
);
52 num_to_bytebits(fullcode
, 40, bits
+16);
55 uint8_t chksum
= jablontron_chksum(bits
);
56 num_to_bytebits(chksum
, 8, bits
+56);
60 //see ASKDemod for what args are accepted
61 int CmdJablotronDemod(const char *Cmd
) {
63 //Differential Biphase / di-phase (inverted biphase)
64 //get binary from ask wave
65 if (!ASKbiphaseDemod("0 64 1 0", FALSE
)) {
66 if (g_debugMode
) PrintAndLog("Error Jablotron: ASKbiphaseDemod failed");
69 size_t size
= DemodBufferLen
;
70 int ans
= JablotronDemod(DemodBuffer
, &size
);
74 // PrintAndLog("DEBUG: Error - not enough samples");
76 PrintAndLog("DEBUG: Error - Jablotron too few bits found");
77 // else if (ans == -2)
78 // PrintAndLog("DEBUG: Error - problem during ASK/Biphase demod");
80 PrintAndLog("DEBUG: Error - Jablotron Size not correct: %d", size
);
82 PrintAndLog("DEBUG: Error - Jablotron preamble not found");
84 PrintAndLog("DEBUG: Error - Jablotron checksum failed");
86 PrintAndLog("DEBUG: Error - ans: %d", ans
);
91 setDemodBuf(DemodBuffer
+ans
, 64, 0);
94 uint32_t raw1
= bytebits_to_byte(DemodBuffer
, 32);
95 uint32_t raw2
= bytebits_to_byte(DemodBuffer
+32, 32);
96 uint64_t cardid
= (raw1
& 0xFFFF);
98 cardid
|= (raw2
>> 8);
100 PrintAndLog("Jablotron Tag Found: Card ID %"PRIx64
, cardid
);
101 PrintAndLog("Raw: %08X%08X", raw1
,raw2
);
103 uint8_t chksum
= raw2
& 0xFF;
104 PrintAndLog("Checksum: %02X [%s]",
106 (chksum
== jablontron_chksum(DemodBuffer
)) ? "OK":"FAIL"
109 // Printed format: 1410-nn-nnnn-nnnn
110 PrintAndLog("Printed: 1410-%02X-%04X-%04X",
111 (raw1
& 0x0000FF00) >> 8,
112 (raw1
& 0xFF) << 8 | ((raw2
>> 24) & 0xFF),
113 (raw2
& 0x00FFFF00) >> 8
118 int CmdJablotronRead(const char *Cmd
) {
120 getSamples("30000",false);
121 return CmdJablotronDemod(Cmd
);
124 int CmdJablotronClone(const char *Cmd
) {
126 uint64_t fullcode
= 0;
127 uint32_t blocks
[3] = {T55x7_MODULATION_DIPHASE
| T55x7_BITRATE_RF_64
| 2<<T55x7_MAXBLOCK_SHIFT
, 0, 0};
131 memset(bs
, 0, sizeof(bits
));
133 char cmdp
= param_getchar(Cmd
, 0);
134 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_clone();
136 fullcode
= param_get64ex(Cmd
, 0, 0, 16);
139 if (param_getchar(Cmd
, 1) == 'Q' || param_getchar(Cmd
, 1) == 'q') {
140 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
141 blocks
[0] = T5555_MODULATION_BIPHASE
| T5555_INVERT_OUTPUT
| 64<<T5555_BITRATE_SHIFT
| 2<<T5555_MAXBLOCK_SHIFT
;
144 // clearing the topbit needed for the preambl detection.
145 if ((fullcode
& 0x7FFFFFFFFF) != fullcode
) {
146 fullcode
&= 0x7FFFFFFFFF;
147 PrintAndLog("Card Number Truncated to 40-bits: %"PRIx64
, fullcode
);
150 if ( !getJablotronBits(fullcode
, bs
)) {
151 PrintAndLog("Error with tag bitstream generation.");
156 blocks
[1] = bytebits_to_byte(bs
,32);
157 blocks
[2] = bytebits_to_byte(bs
+32,32);
159 PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %"PRIx64
, fullcode
);
160 PrintAndLog("Blk | Data ");
161 PrintAndLog("----+------------");
162 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
163 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
164 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
167 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
169 for (int i
=4; i
>=0; i
--) {
170 c
.arg
[0] = blocks
[i
];
172 clearCommandBuffer();
174 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
175 PrintAndLog("Error occurred, device did not respond during write operation.");
182 int CmdJablotronSim(const char *Cmd
) {
183 uint64_t fullcode
= 0;
185 char cmdp
= param_getchar(Cmd
, 0);
186 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_sim();
188 fullcode
= param_get64ex(Cmd
, 0, 0, 16);
190 // clearing the topbit needed for the preambl detection.
191 if ((fullcode
& 0x7FFFFFFFFF) != fullcode
) {
192 fullcode
&= 0x7FFFFFFFFF;
193 PrintAndLog("Card Number Truncated to 40-bits: %"PRIx64
, fullcode
);
196 uint8_t clk
= 64, encoding
= 2, separator
= 0, invert
= 1;
199 arg1
= clk
<< 8 | encoding
;
200 arg2
= invert
<< 8 | separator
;
202 PrintAndLog("Simulating Jablotron - FullCode: %"PRIx64
, fullcode
);
204 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
205 getJablotronBits(fullcode
, c
.d
.asBytes
);
206 clearCommandBuffer();
211 static command_t CommandTable
[] = {
212 {"help", CmdHelp
, 1, "This help"},
213 {"read", CmdJablotronRead
, 0, "Attempt to read and extract tag data"},
214 {"clone", CmdJablotronClone
, 0, "clone jablotron tag"},
215 {"sim", CmdJablotronSim
, 0, "simulate jablotron tag"},
216 {NULL
, NULL
, 0, NULL
}
219 int CmdLFJablotron(const char *Cmd
) {
220 clearCommandBuffer();
221 CmdsParse(CommandTable
, Cmd
);
225 int CmdHelp(const char *Cmd
) {
226 CmdsHelp(CommandTable
);