]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfjablotron.c
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 d <Card-ID> <Q5>");
16 PrintAndLog("Options :");
17 PrintAndLog(" d <Card-ID> : jablotron card ID");
18 PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
20 PrintAndLog("Sample : lf jablotron clone d 123456789");
24 int usage_lf_jablotron_sim(void) {
25 PrintAndLog("Enables simulation of jablotron card with specified card number.");
26 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
27 PrintAndLog("Per jablotron format, the card number is 9 digit number and can contain *# chars. Larger values are truncated.");
29 PrintAndLog("Usage: lf jablotron sim d <Card-ID> or H <hex-ID>");
30 PrintAndLog("Options :");
31 PrintAndLog(" d <Card-ID> : jablotron card number");
32 // PrintAndLog(" H <hex-ID> : 8 digit hex card number");
34 PrintAndLog("Sample : lf jablotron sim d 123456789");
38 int getJablotronBits(uint64_t fullcode
, uint8_t *bits
) {
40 num_to_bytebits(0xFFFF, 16, bits
);
43 num_to_bytebits(fullcode
, 40, bits
+16);
47 for (int i
=16; i
< 56; i
+= 8) {
48 crc
+= bytebits_to_byte(bits
+i
,8);
51 num_to_bytebits(crc
, 8, bits
+56);
56 //see ASKDemod for what args are accepted
57 int CmdJablotronDemod(const char *Cmd
) {
59 //Differential Biphase / di-phase (inverted biphase)
60 //get binary from ask wave
61 if (!ASKbiphaseDemod("0 64 1 0", FALSE
)) {
62 if (g_debugMode
) PrintAndLog("Error Jablotron: ASKbiphaseDemod failed");
65 size_t size
= DemodBufferLen
;
66 int ans
= JablotronDemod(DemodBuffer
, &size
);
70 // PrintAndLog("DEBUG: Error - not enough samples");
71 // else if (ans == -1)
72 // PrintAndLog("DEBUG: Error - only noise found");
73 // else if (ans == -2)
74 // PrintAndLog("DEBUG: Error - problem during ASK/Biphase demod");
76 PrintAndLog("DEBUG: Error - Size not correct: %d", size
);
78 PrintAndLog("DEBUG: Error - Jablotron preamble not found");
80 PrintAndLog("DEBUG: Error - ans: %d", ans
);
85 uint32_t raw1
= bytebits_to_byte(DemodBuffer
+ans
, 32);
86 uint32_t raw2
= bytebits_to_byte(DemodBuffer
+ans
+32, 32);
87 uint64_t cardid
= (raw1
& 0x0000FFFF);
89 cardid
|= (raw2
>> 8);
91 PrintAndLog("Jablotron Tag Found: Card ID %12X", cardid
);
92 PrintAndLog("Raw: %08X%08X", raw1
,raw2
);
94 setDemodBuf(DemodBuffer
+ans
, 64, 0);
96 //PrintAndLog("1410-%u-%u-%08X-%02X", fullcode);
100 int CmdJablotronRead(const char *Cmd
) {
103 // get samples silently
104 getSamples("30000",false);
105 // demod and output Presco ID
106 return CmdJablotronDemod(Cmd
);
109 int CmdJablotronClone(const char *Cmd
) {
111 uint64_t fullcode
= 0;
112 uint32_t blocks
[3] = {T55x7_MODULATION_DIPHASE
| T55x7_BITRATE_RF_64
| 2<<T55x7_MAXBLOCK_SHIFT
, 0, 0};
116 memset(bs
, 0, sizeof(bits
));
118 char cmdp
= param_getchar(Cmd
, 0);
119 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_clone();
121 fullcode
= param_get64ex(Cmd
, 1, 0, 16);
124 if (param_getchar(Cmd
, 2) == 'Q' || param_getchar(Cmd
, 2) == 'q') {
125 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
126 blocks
[0] = T5555_MODULATION_BIPHASE
| T5555_INVERT_OUTPUT
| 64<<T5555_BITRATE_SHIFT
| 2<<T5555_MAXBLOCK_SHIFT
;
129 if ((fullcode
& 0xFFFFFFFFFFFF) != fullcode
) {
130 fullcode
&= 0xFFFFFFFFFFFF;
131 PrintAndLog("Card Number Truncated to 40-bits: %u", fullcode
);
134 if ( !getJablotronBits(fullcode
, bs
)) {
135 PrintAndLog("Error with tag bitstream generation.");
140 blocks
[1] = bytebits_to_byte(bs
,32);
141 blocks
[2] = bytebits_to_byte(bs
+32,32);
143 PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %12X", fullcode
);
144 PrintAndLog("Blk | Data ");
145 PrintAndLog("----+------------");
146 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
147 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
148 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
151 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
153 for (int i
=4; i
>=0; i
--) {
154 c
.arg
[0] = blocks
[i
];
156 clearCommandBuffer();
158 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
159 PrintAndLog("Error occurred, device did not respond during write operation.");
166 int CmdJablotronSim(const char *Cmd
) {
167 uint64_t fullcode
= 0;
169 char cmdp
= param_getchar(Cmd
, 0);
170 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_sim();
172 fullcode
= param_get64ex(Cmd
, 1, 0, 16);
174 uint8_t clk
= 64, encoding
= 2, separator
= 0, invert
= 1;
177 arg1
= clk
<< 8 | encoding
;
178 arg2
= invert
<< 8 | separator
;
180 PrintAndLog("Simulating Jablotron - FullCode: %12X", fullcode
);
182 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
183 getJablotronBits(fullcode
, c
.d
.asBytes
);
184 clearCommandBuffer();
189 static command_t CommandTable
[] = {
190 {"help", CmdHelp
, 1, "This help"},
191 {"read", CmdJablotronRead
, 0, "Attempt to read and Extract tag data"},
192 {"clone", CmdJablotronClone
, 0, "h <hex> [Q5] clone jablotron tag"},
193 {"sim", CmdJablotronSim
, 0, "h <hex> simulate jablotron tag"},
194 {NULL
, NULL
, 0, NULL
}
197 int CmdLFJablotron(const char *Cmd
) {
198 clearCommandBuffer();
199 CmdsParse(CommandTable
, Cmd
);
203 int CmdHelp(const char *Cmd
) {
204 CmdsHelp(CommandTable
);