]>
Commit | Line | Data |
---|---|---|
1 | #include "cmdlfio.h" | |
2 | ||
3 | static int CmdHelp(const char *Cmd); | |
4 | ||
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."); | |
9 | PrintAndLog(""); | |
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"); | |
14 | PrintAndLog(""); | |
15 | PrintAndLog("Samples"); | |
16 | PrintAndLog(" lf io fskdemod"); | |
17 | PrintAndLog(" lf io fskdemod 1"); | |
18 | return 0; | |
19 | } | |
20 | ||
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."); | |
24 | PrintAndLog(""); | |
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"); | |
31 | PrintAndLog(""); | |
32 | PrintAndLog("Samples"); | |
33 | PrintAndLog(" lf io sim 26 101 1337"); | |
34 | return 0; | |
35 | } | |
36 | ||
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."); | |
40 | PrintAndLog(""); | |
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"); | |
48 | PrintAndLog(""); | |
49 | PrintAndLog("Samples"); | |
50 | PrintAndLog(" lf io clone 26 101 1337"); | |
51 | return 0; | |
52 | } | |
53 | ||
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}; | |
58 | c.arg[0] = findone; | |
59 | clearCommandBuffer(); | |
60 | SendCommand(&c); | |
61 | return 0; | |
62 | } | |
63 | /* | |
64 | int CmdIOProxDemod(const char *Cmd){ | |
65 | if (GraphTraceLen < 4800) { | |
66 | PrintAndLog("too short; need at least 4800 samples"); | |
67 | return 0; | |
68 | } | |
69 | GraphTraceLen = 4800; | |
70 | for (int i = 0; i < GraphTraceLen; ++i) { | |
71 | GraphBuffer[i] = (GraphBuffer[i] < 0) ? 0 : 1; | |
72 | } | |
73 | RepaintGraphWindow(); | |
74 | return 0; | |
75 | } | |
76 | */ | |
77 | ||
78 | //Index map | |
79 | //0 10 20 30 40 50 60 | |
80 | //| | | | | | | | |
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) { | |
86 | #define SEPARATOR 1 | |
87 | uint8_t pos=0; | |
88 | // the return bits, preamble 0000 0000 0 | |
89 | uint8_t pre[64]; | |
90 | memset(pre, 0, sizeof(pre)); | |
91 | ||
92 | // skip 9 zeros as preamble | |
93 | pos = 9; | |
94 | ||
95 | // another fixed byte 11110000 = 0xF0 | |
96 | num_to_bytebits(0xF0, 8, pre+pos); | |
97 | pos += 8; | |
98 | pre[pos] = SEPARATOR; | |
99 | pos++; | |
100 | ||
101 | // add facilitycode | |
102 | num_to_bytebits(fc, 8, pre+pos); | |
103 | pos += 8; | |
104 | pre[pos] = SEPARATOR; | |
105 | pos++; | |
106 | ||
107 | // add version | |
108 | num_to_bytebits(version, 8, pre+pos); | |
109 | pos += 8; | |
110 | pre[pos] = SEPARATOR; | |
111 | pos++; | |
112 | ||
113 | // cardnumber high byte | |
114 | num_to_bytebits( ((cn & 0xFF00)>>8), 8, pre+pos); | |
115 | pos += 8; | |
116 | pre[pos] = SEPARATOR; | |
117 | pos++; | |
118 | ||
119 | // cardnumber low byte | |
120 | num_to_bytebits( (cn & 0xFF), 8, pre+pos); | |
121 | pos += 8; | |
122 | pre[pos] = SEPARATOR; | |
123 | pos++; | |
124 | ||
125 | // calculate and add CRC | |
126 | uint16_t crc = 0; | |
127 | for (uint8_t i=1; i<6; ++i) | |
128 | crc += bytebits_to_byte(pre+9*i, 8); | |
129 | ||
130 | crc &= 0xFF; | |
131 | crc = 0xff - crc; | |
132 | num_to_bytebits(crc, 8, pre+pos); | |
133 | pos += 8; | |
134 | ||
135 | // Final two ONES | |
136 | pre[pos] = SEPARATOR; | |
137 | pre[++pos] = SEPARATOR; | |
138 | ||
139 | memcpy(bits, pre, sizeof(pre)); | |
140 | return 1; | |
141 | } | |
142 | ||
143 | int CmdIOSim(const char *Cmd) { | |
144 | uint16_t cn = 0; | |
145 | uint8_t version = 0, fc = 0; | |
146 | uint8_t bits[64]; | |
147 | uint8_t *bs = bits; | |
148 | size_t size = sizeof(bits); | |
149 | memset(bs, 0x00, size); | |
150 | ||
151 | uint64_t arg1 = ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8 | |
152 | uint64_t arg2 = (64 << 8)| + 1; // clk RF/64 invert=1 | |
153 | ||
154 | char cmdp = param_getchar(Cmd, 0); | |
155 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_io_sim(); | |
156 | ||
157 | version = param_get8(Cmd, 0); | |
158 | fc = param_get8(Cmd, 1); | |
159 | cn = param_get32ex(Cmd, 2, 0, 10); | |
160 | ||
161 | if ( !version | !fc || !cn) return usage_lf_io_sim(); | |
162 | ||
163 | if ((cn & 0xFFFF) != cn) { | |
164 | cn &= 0xFFFF; | |
165 | PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn); | |
166 | } | |
167 | ||
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"); | |
170 | ||
171 | if ( !getIOProxBits(version, fc, cn, bs)) { | |
172 | PrintAndLog("Error with tag bitstream generation."); | |
173 | return 1; | |
174 | } | |
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(); | |
182 | SendCommand(&c); | |
183 | return 0; | |
184 | } | |
185 | ||
186 | int CmdIOClone(const char *Cmd) { | |
187 | ||
188 | uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2<<T55x7_MAXBLOCK_SHIFT, 0, 0}; | |
189 | uint16_t cn = 0; | |
190 | uint8_t version = 0, fc = 0; | |
191 | uint8_t bits[64]; | |
192 | uint8_t *bs=bits; | |
193 | memset(bs,0,sizeof(bits)); | |
194 | ||
195 | char cmdp = param_getchar(Cmd, 0); | |
196 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_io_clone(); | |
197 | ||
198 | version = param_get8(Cmd, 0); | |
199 | fc = param_get8(Cmd, 1); | |
200 | cn = param_get32ex(Cmd, 2, 0, 10); | |
201 | ||
202 | if ( !version | !fc || !cn) return usage_lf_io_clone(); | |
203 | ||
204 | if ((cn & 0xFFFF) != cn) { | |
205 | cn &= 0xFFFF; | |
206 | PrintAndLog("Card Number Truncated to 16-bits (IOProx): %u", cn); | |
207 | } | |
208 | ||
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; | |
212 | ||
213 | if ( !getIOProxBits(version, fc, cn, bs)) { | |
214 | PrintAndLog("Error with tag bitstream generation."); | |
215 | return 1; | |
216 | } | |
217 | ||
218 | blocks[1] = bytebits_to_byte(bs,32); | |
219 | blocks[2] = bytebits_to_byte(bs+32,32); | |
220 | ||
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(); | |
230 | SendCommand(&c); | |
231 | return 0; | |
232 | } | |
233 | ||
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} | |
241 | }; | |
242 | ||
243 | int CmdLFIO(const char *Cmd){ | |
244 | clearCommandBuffer(); | |
245 | CmdsParse(CommandTable, Cmd); | |
246 | return 0; | |
247 | } | |
248 | ||
249 | int CmdHelp(const char *Cmd) { | |
250 | CmdsHelp(CommandTable); | |
251 | return 0; | |
252 | } |