]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfjablotron.c
CHG: textual changes to help text.
[proxmark3-svn] / client / cmdlfjablotron.c
CommitLineData
6c283951 1//-----------------------------------------------------------------------------
2//
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
5// the license.
6//-----------------------------------------------------------------------------
7// Low frequency Presco tag commands
8//-----------------------------------------------------------------------------
9#include "cmdlfjablotron.h"
10
11static int CmdHelp(const char *Cmd);
12
13int usage_lf_jablotron_clone(void){
14 PrintAndLog("clone a Jablotron tag to a T55x7 tag.");
8ae9b358 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)");
6c283951 20 PrintAndLog("");
8ae9b358 21 PrintAndLog("Sample: lf jablotron clone d 112233");
6c283951 22 return 0;
23}
24
25int 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.");
6c283951 28 PrintAndLog("");
8ae9b358 29 PrintAndLog("Usage: lf jablotron sim [h] <card ID>");
30 PrintAndLog("Options:");
31 PrintAndLog(" h : This help");
32 PrintAndLog(" <card ID> : jablotron card ID");
6c283951 33 PrintAndLog("");
8ae9b358 34 PrintAndLog("Sample: lf jablotron sim d 112233");
6c283951 35 return 0;
36}
37
38int getJablotronBits(uint64_t fullcode, uint8_t *bits) {
39 //preamp
40 num_to_bytebits(0xFFFF, 16, bits);
41
42 //fullcode
43 num_to_bytebits(fullcode, 40, bits+16);
44
45 //chksum byte
46 uint8_t crc = 0;
47 for (int i=16; i < 56; i += 8) {
48 crc += bytebits_to_byte(bits+i,8);
49 }
50 crc ^= 0x3A;
51 num_to_bytebits(crc, 8, bits+56);
52
53 return 1;
54}
55
56//see ASKDemod for what args are accepted
57int CmdJablotronDemod(const char *Cmd) {
58
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");
63 return 0;
64 }
65 size_t size = DemodBufferLen;
66 int ans = JablotronDemod(DemodBuffer, &size);
67 if (ans < 0){
68 if (g_debugMode){
69 // if (ans == -5)
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");
75 if (ans == -3)
76 PrintAndLog("DEBUG: Error - Size not correct: %d", size);
77 else if (ans == -4)
78 PrintAndLog("DEBUG: Error - Jablotron preamble not found");
79 else
80 PrintAndLog("DEBUG: Error - ans: %d", ans);
81 }
82 return 0;
83 }
84 //got a good demod
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);
88 cardid <<= 32;
89 cardid |= (raw2 >> 8);
90
8ae9b358 91 PrintAndLog("Jablotron Tag Found: Card ID %012X", cardid);
6c283951 92 PrintAndLog("Raw: %08X%08X", raw1 ,raw2);
93
94 setDemodBuf(DemodBuffer+ans, 64, 0);
95
96 //PrintAndLog("1410-%u-%u-%08X-%02X", fullcode);
97 return 1;
98}
99
100int CmdJablotronRead(const char *Cmd) {
6c283951 101 CmdLFRead("s");
6c283951 102 getSamples("30000",false);
6c283951 103 return CmdJablotronDemod(Cmd);
104}
105
106int CmdJablotronClone(const char *Cmd) {
107
108 uint64_t fullcode = 0;
109 uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2<<T55x7_MAXBLOCK_SHIFT, 0, 0};
110
111 uint8_t bits[64];
112 uint8_t *bs = bits;
113 memset(bs, 0, sizeof(bits));
114
115 char cmdp = param_getchar(Cmd, 0);
116 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_clone();
117
8ae9b358 118 fullcode = param_get64ex(Cmd, 0, 0, 16);
6c283951 119
120 //Q5
8ae9b358 121 if (param_getchar(Cmd, 1) == 'Q' || param_getchar(Cmd, 1) == 'q') {
6c283951 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;
124 }
125
126 if ((fullcode & 0xFFFFFFFFFFFF) != fullcode) {
127 fullcode &= 0xFFFFFFFFFFFF;
128 PrintAndLog("Card Number Truncated to 40-bits: %u", fullcode);
129 }
130
131 if ( !getJablotronBits(fullcode, bs)) {
132 PrintAndLog("Error with tag bitstream generation.");
133 return 1;
134 }
135
136 //
137 blocks[1] = bytebits_to_byte(bs,32);
138 blocks[2] = bytebits_to_byte(bs+32,32);
139
8ae9b358 140 PrintAndLog("Preparing to clone Jablotron to T55x7 with FullCode: %012X", fullcode);
6c283951 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]);
146
147 UsbCommand resp;
148 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
149
150 for (int i=4; i>=0; i--) {
151 c.arg[0] = blocks[i];
152 c.arg[1] = i;
153 clearCommandBuffer();
154 SendCommand(&c);
155 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
156 PrintAndLog("Error occurred, device did not respond during write operation.");
157 return -1;
158 }
159 }
160 return 0;
161}
162
163int CmdJablotronSim(const char *Cmd) {
164 uint64_t fullcode = 0;
165
166 char cmdp = param_getchar(Cmd, 0);
167 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_jablotron_sim();
168
8ae9b358 169 fullcode = param_get64ex(Cmd, 0, 0, 16);
6c283951 170
171 uint8_t clk = 64, encoding = 2, separator = 0, invert = 1;
172 uint16_t arg1, arg2;
173 size_t size = 64;
174 arg1 = clk << 8 | encoding;
175 arg2 = invert << 8 | separator;
176
8ae9b358 177 PrintAndLog("Simulating Jablotron - FullCode: %012X", fullcode);
6c283951 178
179 UsbCommand c = {CMD_ASK_SIM_TAG, {arg1, arg2, size}};
180 getJablotronBits(fullcode, c.d.asBytes);
181 clearCommandBuffer();
182 SendCommand(&c);
183 return 0;
184}
185
186static command_t CommandTable[] = {
187 {"help", CmdHelp, 1, "This help"},
8ae9b358 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"},
6c283951 191 {NULL, NULL, 0, NULL}
192};
193
194int CmdLFJablotron(const char *Cmd) {
195 clearCommandBuffer();
196 CmdsParse(CommandTable, Cmd);
197 return 0;
198}
199
200int CmdHelp(const char *Cmd) {
201 CmdsHelp(CommandTable);
202 return 0;
203}
Impressum, Datenschutz