]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfio.c
826a26b2f443c0650cfea6027ca3e99c152d99c1
3 static int CmdHelp(const char *Cmd
);
5 int usage_lf_io_fskdemod(void) {
6 PrintAndLog("Enables IOProx compatible reader mode printing details of scanned tags.");
7 PrintAndLog("By default, values are printed and logged until the button is pressed or another USB command is issued.");
8 PrintAndLog("If the [1] option is provided, reader mode is exited after reading a single card.");
10 PrintAndLog("Usage: lf io fskdemod [h] [1]");
11 PrintAndLog("Options :");
12 PrintAndLog(" h : This help");
13 PrintAndLog(" 1 : (optional) stop after reading a single card");
15 PrintAndLog("Samples");
16 PrintAndLog(" lf io fskdemod");
17 PrintAndLog(" lf io fskdemod 1");
21 int usage_lf_io_sim(void) {
22 PrintAndLog("Enables simulation of IOProx card with specified facility-code and card number.");
23 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
25 PrintAndLog("Usage: lf io sim [h] <version> <facility-code> <card-number>");
26 PrintAndLog("Options :");
27 PrintAndLog(" h : This help");
28 PrintAndLog(" <version> : 8bit version");
29 PrintAndLog(" <facility-code> : 8bit value facility code");
30 PrintAndLog(" <card number> : 16bit value card number");
32 PrintAndLog("Samples");
33 PrintAndLog(" lf io sim 26 101 1337");
37 int usage_lf_io_clone(void) {
38 PrintAndLog("Enables cloning of IOProx card with specified facility-code and card number onto T55x7.");
39 PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
41 PrintAndLog("Usage: lf awid clone [h] <version> <facility-code> <card-number> [Q5]");
42 PrintAndLog("Options :");
43 PrintAndLog(" h : This help");
44 PrintAndLog(" <version> : 8bit version");
45 PrintAndLog(" <facility-code> : 8bit value facility code");
46 PrintAndLog(" <card number> : 16bit value card number");
47 PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip");
49 PrintAndLog("Samples");
50 PrintAndLog(" lf io clone 26 101 1337");
54 int CmdIODemodFSK(const char *Cmd
) {
55 if (Cmd
[0] == 'h' || Cmd
[0] == 'H') return usage_lf_io_fskdemod();
56 int findone
= (Cmd
[0]=='1') ? 1 : 0;
57 UsbCommand c
= {CMD_IO_DEMOD_FSK
};
64 int CmdIOProxDemod(const char *Cmd){
65 if (GraphTraceLen < 4800) {
66 PrintAndLog("too short; need at least 4800 samples");
70 for (int i = 0; i < GraphTraceLen; ++i) {
71 GraphBuffer[i] = (GraphBuffer[i] < 0) ? 0 : 1;
81 //01234567 8 90123456 7 89012345 6 78901234 5 67890123 4 56789012 3 45678901 23
82 //-----------------------------------------------------------------------------
83 //00000000 0 11110000 1 facility 1 version* 1 code*one 1 code*two 1 ???????? 11
84 //XSF(version)facility:codeone+codetwo (raw)
85 int getIOProxBits(uint8_t version
, uint8_t fc
, uint16_t cn
, uint8_t *bits
) {
88 // the return bits, preamble 0000 0000 0
90 memset(pre
, 0, sizeof(pre
));
92 // skip 9 zeros as preamble
95 // another fixed byte 11110000 = 0xF0
96 num_to_bytebits(0xF0, 8, pre
+pos
);
102 num_to_bytebits(fc
, 8, pre
+pos
);
104 pre
[pos
] = SEPARATOR
;
108 num_to_bytebits(version
, 8, pre
+pos
);
110 pre
[pos
] = SEPARATOR
;
113 // cardnumber high byte
114 num_to_bytebits( ((cn
& 0xFF00)>>8), 8, pre
+pos
);
116 pre
[pos
] = SEPARATOR
;
119 // cardnumber low byte
120 num_to_bytebits( (cn
& 0xFF), 8, pre
+pos
);
122 pre
[pos
] = SEPARATOR
;
125 // calculate and add CRC
127 for (uint8_t i
=1; i
<6; ++i
)
128 crc
+= bytebits_to_byte(pre
+9*i
, 8);
132 num_to_bytebits(crc
, 8, pre
+pos
);
136 pre
[pos
] = SEPARATOR
;
137 pre
[++pos
] = SEPARATOR
;
139 memcpy(bits
, pre
, sizeof(pre
));
143 int CmdIOSim(const char *Cmd
) {
145 uint8_t version
= 0, fc
= 0;
148 size_t size
= sizeof(bits
);
149 memset(bs
, 0x00, size
);
151 uint64_t arg1
= ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8
152 uint64_t arg2
= (64 << 8)| + 1; // clk RF/64 invert=1
154 char cmdp
= param_getchar(Cmd
, 0);
155 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_io_sim();
157 version
= param_get8(Cmd
, 0);
158 fc
= param_get8(Cmd
, 1);
159 cn
= param_get32ex(Cmd
, 2, 0, 10);
161 if ( !version
| !fc
|| !cn
) return usage_lf_io_sim();
163 if ((cn
& 0xFFFF) != cn
) {
165 PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn
);
168 PrintAndLog("Emulating IOProx Version: %u FC: %u; CN: %u\n", version
, fc
, cn
);
169 PrintAndLog("Press pm3-button to abort simulation or run another command");
171 if ( !getIOProxBits(version
, fc
, cn
, bs
)) {
172 PrintAndLog("Error with tag bitstream generation.");
175 // IOProx uses: fcHigh: 10, fcLow: 8, clk: 64, invert: 1
176 // arg1 --- fcHigh<<8 + fcLow
177 // arg2 --- Inversion and clk setting
178 // 64 --- Bitstream length: 64-bits == 8 bytes
179 UsbCommand c
= {CMD_FSK_SIM_TAG
, {arg1
, arg2
, size
}};
180 memcpy(c
.d
.asBytes
, bs
, size
);
181 clearCommandBuffer();
186 int CmdIOClone(const char *Cmd
) {
188 uint32_t blocks
[3] = {T55x7_MODULATION_FSK2a
| T55x7_BITRATE_RF_64
| 2<<T55x7_MAXBLOCK_SHIFT
, 0, 0};
190 uint8_t version
= 0, fc
= 0;
193 memset(bs
,0,sizeof(bits
));
195 char cmdp
= param_getchar(Cmd
, 0);
196 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_io_clone();
198 version
= param_get8(Cmd
, 0);
199 fc
= param_get8(Cmd
, 1);
200 cn
= param_get32ex(Cmd
, 2, 0, 10);
202 if ( !version
| !fc
|| !cn
) return usage_lf_io_clone();
204 if ((cn
& 0xFFFF) != cn
) {
206 PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn
);
209 // if (param_getchar(Cmd, 4) == 'Q' || param_getchar(Cmd, 4) == 'q')
210 //t5555 (Q5) BITRATE = (RF-2)/2 (iceman)
211 // blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT;
213 if ( !getIOProxBits(version
, fc
, cn
, bs
)) {
214 PrintAndLog("Error with tag bitstream generation.");
218 blocks
[1] = bytebits_to_byte(bs
,32);
219 blocks
[2] = bytebits_to_byte(bs
+32,32);
221 PrintAndLog("Preparing to clone IOProx to T55x7 with Version: %u FC: %u, CN: %u", version
, fc
, cn
);
222 PrintAndLog("Blk | Data ");
223 PrintAndLog("----+------------");
224 PrintAndLog(" 00 | 0x%08x", blocks
[0]);
225 PrintAndLog(" 01 | 0x%08x", blocks
[1]);
226 PrintAndLog(" 02 | 0x%08x", blocks
[2]);
227 //UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
228 UsbCommand c
= {CMD_IO_CLONE_TAG
, {blocks
[1],blocks
[2],0}};
229 clearCommandBuffer();
234 static command_t CommandTable
[] = {
235 {"help", CmdHelp
, 1, "This help"},
236 //{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
237 {"fskdemod",CmdIODemodFSK
, 0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
238 {"sim", CmdIOSim
, 0, "<version> <facility-code> <card number> -- IOProx tag simulator"},
239 {"clone", CmdIOClone
, 0, "<version> <facility-code> <card number> <Q5> -- Clone IOProx to T55x7"},
240 {NULL
, NULL
, 0, NULL
}
243 int CmdLFIO(const char *Cmd
){
244 clearCommandBuffer();
245 CmdsParse(CommandTable
, Cmd
);
249 int CmdHelp(const char *Cmd
) {
250 CmdsHelp(CommandTable
);