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 //-----------------------------------------------------------------------------
10 #include "cmdlfvisa2000.h"
12 static int CmdHelp(const char *Cmd
);
14 int usage_lf_visa2k_clone(void){
15 PrintAndLog("clone a Visa2000 tag to a T55x7 tag.");
16 PrintAndLog("Usage: lf visa2k clone [h] <card ID> <Q5>");
17 PrintAndLog("Options:");
18 PrintAndLog(" h : This help");
19 PrintAndLog(" <card ID> : Visa2k card ID");
20 PrintAndLog(" <Q5> : specify write to Q5 (t5555 instead of t55x7)");
22 PrintAndLog("Sample: lf visa2k clone 112233");
26 int usage_lf_visa2k_sim(void) {
27 PrintAndLog("Enables simulation of visa2k card with specified card number.");
28 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
30 PrintAndLog("Usage: lf visa2k sim [h] <card ID>");
31 PrintAndLog("Options:");
32 PrintAndLog(" h : This help");
33 PrintAndLog(" <card ID> : Visa2k card ID");
35 PrintAndLog("Sample: lf visa2k sim 112233");
39 //see ASKDemod for what args are accepted
40 int CmdVisa2kDemod(const char *Cmd
) {
44 if (!ASKDemod_ext("64 0 0", FALSE
, FALSE
, 1, &st
)) {
45 if (g_debugMode
) PrintAndLog("DEBUG: Error - Visa2k: ASK/Manchester Demod failed");
48 size_t size
= DemodBufferLen
;
49 int ans
= Visa2kDemod_AM(DemodBuffer
, &size
);
53 PrintAndLog("DEBUG: Error - Visa2k: too few bits found");
55 PrintAndLog("DEBUG: Error - Visa2k: preamble not found");
57 PrintAndLog("DEBUG: Error - Visa2k: Size not correct: %d", size
);
59 PrintAndLog("DEBUG: Error - Visa2k: ans: %d", ans
);
63 setDemodBuf(DemodBuffer
, 96, ans
);
66 uint32_t raw1
= bytebits_to_byte(DemodBuffer
, 32);
67 uint32_t raw2
= bytebits_to_byte(DemodBuffer
+32, 32);
68 uint32_t raw3
= bytebits_to_byte(DemodBuffer
+64, 32);
70 PrintAndLog("Visa2000 Tag Found: Card ID %u, Raw: %08X%08X%08X", raw2
, raw1
,raw2
, raw3
);
74 int CmdVisa2kRead(const char *Cmd
) {
76 getSamples("20000",TRUE
);
77 return CmdVisa2kDemod(Cmd
);
80 int CmdVisa2kClone(const char *Cmd
) {
83 uint32_t blocks
[4] = {T55x7_MODULATION_MANCHESTER
| T55x7_BITRATE_RF_64
| T55x7_ST_TERMINATOR
|3<<T55x7_MAXBLOCK_SHIFT
, 0, 0};
86 // uint8_t *bs = bits;
87 // memset(bs, 0, sizeof(bits));
89 char cmdp
= param_getchar(Cmd
, 0);
90 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_visa2k_clone();
92 id
= param_get32ex(Cmd
, 0, 0, 10);
95 if (param_getchar(Cmd
, 1) == 'Q' || param_getchar(Cmd
, 1) == 'q') {
96 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
97 blocks
[0] = T5555_MODULATION_MANCHESTER
| 64<<T5555_BITRATE_SHIFT
| T5555_ST_TERMINATOR
| 3<<T5555_MAXBLOCK_SHIFT
;
100 // if ( !getJablotronBits(fullcode, bs)) {
101 // PrintAndLog("Error with tag bitstream generation.");
106 blocks
[1] = 0x56495332;
110 PrintAndLog("Preparing to clone Visa2000 to T55x7 with CardId: %u", id
);
111 PrintAndLog("Blk | Data ");
112 PrintAndLog("----+------------");
113 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
114 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
115 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
116 PrintAndLog(" 02 | 0x%08x", blocks
[3]);
119 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
121 for (int i
= 3; i
>= 0; --i
) {
122 c
.arg
[0] = blocks
[i
];
124 clearCommandBuffer();
126 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
127 PrintAndLog("Error occurred, device did not respond during write operation.");
134 int CmdVisa2kSim(const char *Cmd
) {
137 char cmdp
= param_getchar(Cmd
, 0);
138 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_visa2k_sim();
140 id
= param_get32ex(Cmd
, 0, 0, 10);
142 uint8_t clk
= 64, encoding
= 1, separator
= 1, invert
= 0;
145 arg1
= clk
<< 8 | encoding
;
146 arg2
= invert
<< 8 | separator
;
148 PrintAndLog("Simulating Visa2000 - CardId: %u", id
);
150 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
152 uint32_t blocks
[3] = { 0x56495332, id
, 0};
154 for(int i
=0; i
<3; ++i
){
155 num_to_bytebits(blocks
[i
], 32, c
.d
.asBytes
+ i
*32);
157 clearCommandBuffer();
162 static command_t CommandTable
[] = {
163 {"help", CmdHelp
, 1, "This help"},
164 {"read", CmdVisa2kRead
, 0, "Attempt to read and extract tag data"},
165 {"clone", CmdVisa2kClone
, 0, "clone Visa2000 tag"},
166 {"sim", CmdVisa2kSim
, 0, "simulate Visa2000 tag"},
167 {NULL
, NULL
, 0, NULL
}
170 int CmdLFVisa2k(const char *Cmd
) {
171 clearCommandBuffer();
172 CmdsParse(CommandTable
, Cmd
);
176 int CmdHelp(const char *Cmd
) {
177 CmdsHelp(CommandTable
);