]>
git.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 [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 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 %012X", 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
) {
102 getSamples("30000",false);
103 return CmdJablotronDemod(Cmd
);
106 int CmdJablotronClone(const char *Cmd
) {
108 uint64_t fullcode
= 0;
109 uint32_t blocks
[3] = {T55x7_MODULATION_DIPHASE
| T55x7_BITRATE_RF_64
| 2<<T55x7_MAXBLOCK_SHIFT
, 0, 0};
113 memset(bs
, 0, sizeof(bits
));
115 char cmdp
= param_getchar(Cmd
, 0);
116 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_clone();
118 fullcode
= param_get64ex(Cmd
, 0, 0, 16);
121 if (param_getchar(Cmd
, 1) == 'Q' || param_getchar(Cmd
, 1) == 'q') {
122 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
123 blocks
[0] = T5555_MODULATION_BIPHASE
| T5555_INVERT_OUTPUT
| 64<<T5555_BITRATE_SHIFT
| 2<<T5555_MAXBLOCK_SHIFT
;
126 if ((fullcode
& 0xFFFFFFFFFFFF) != fullcode
) {
127 fullcode
&= 0xFFFFFFFFFFFF;
128 PrintAndLog("Card Number Truncated to 40-bits: %u", fullcode
);
131 if ( !getJablotronBits(fullcode
, bs
)) {
132 PrintAndLog("Error with tag bitstream generation.");
137 blocks
[1] = bytebits_to_byte(bs
,32);
138 blocks
[2] = bytebits_to_byte(bs
+32,32);
140 PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %012X", fullcode
);
141 PrintAndLog("Blk | Data ");
142 PrintAndLog("----+------------");
143 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
144 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
145 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
148 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
150 for (int i
=4; i
>=0; i
--) {
151 c
.arg
[0] = blocks
[i
];
153 clearCommandBuffer();
155 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
156 PrintAndLog("Error occurred, device did not respond during write operation.");
163 int CmdJablotronSim(const char *Cmd
) {
164 uint64_t fullcode
= 0;
166 char cmdp
= param_getchar(Cmd
, 0);
167 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_jablotron_sim();
169 fullcode
= param_get64ex(Cmd
, 0, 0, 16);
171 uint8_t clk
= 64, encoding
= 2, separator
= 0, invert
= 1;
174 arg1
= clk
<< 8 | encoding
;
175 arg2
= invert
<< 8 | separator
;
177 PrintAndLog("Simulating Jablotron - FullCode: %012X", fullcode
);
179 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
180 getJablotronBits(fullcode
, c
.d
.asBytes
);
181 clearCommandBuffer();
186 static command_t CommandTable
[] = {
187 {"help", CmdHelp
, 1, "This help"},
188 {"read", CmdJablotronRead
, 0, "Attempt to read and extract tag data"},
189 {"clone", CmdJablotronClone
, 0, "clone jablotron tag"},
190 {"sim", CmdJablotronSim
, 0, "simulate jablotron tag"},
191 {NULL
, NULL
, 0, NULL
}
194 int CmdLFJablotron(const char *Cmd
) {
195 clearCommandBuffer();
196 CmdsParse(CommandTable
, Cmd
);
200 int CmdHelp(const char *Cmd
) {
201 CmdsHelp(CommandTable
);