]>
Commit | Line | Data |
---|---|---|
a553f267 | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2010 iZsh <izsh at fail0verflow.com> | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // High frequency commands | |
9 | //----------------------------------------------------------------------------- | |
10 | ||
7fe9b0b7 | 11 | #include <stdio.h> |
4c3de57a | 12 | #include <string.h> |
902cb3c0 | 13 | #include "proxmark3.h" |
7fe9b0b7 | 14 | #include "graph.h" |
15 | #include "ui.h" | |
16 | #include "cmdparser.h" | |
17 | #include "cmdhf.h" | |
18 | #include "cmdhf14a.h" | |
19 | #include "cmdhf14b.h" | |
20 | #include "cmdhf15.h" | |
5acd09bd | 21 | #include "cmdhfepa.h" |
7fe9b0b7 | 22 | #include "cmdhflegic.h" |
cee5a30d | 23 | #include "cmdhficlass.h" |
9ca155ba | 24 | #include "cmdhfmf.h" |
5ee70129 | 25 | #include "cmdhfmfu.h" |
b67f7ec3 | 26 | #include "protocols.h" |
7fe9b0b7 | 27 | |
28 | static int CmdHelp(const char *Cmd); | |
29 | ||
30 | int CmdHFTune(const char *Cmd) | |
31 | { | |
32 | UsbCommand c={CMD_MEASURE_ANTENNA_TUNING_HF}; | |
33 | SendCommand(&c); | |
34 | return 0; | |
35 | } | |
4c3de57a | 36 | |
4c3de57a MHS |
37 | |
38 | void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) | |
39 | { | |
40 | switch(cmd[0]) | |
41 | { | |
41fdd0f0 MHS |
42 | case ISO14443A_CMD_WUPA: snprintf(exp,size,"WUPA"); break; |
43 | case ISO14443A_CMD_ANTICOLL_OR_SELECT:{ | |
4df54240 MHS |
44 | // 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor) |
45 | // 93 70 = Select (usage: 9370+5bytes 9320 answer - answer: 1byte SAK) | |
383608a6 | 46 | if(cmd[1] == 0x70) |
4c3de57a MHS |
47 | { |
48 | snprintf(exp,size,"SELECT_UID"); break; | |
49 | }else | |
50 | { | |
4df54240 MHS |
51 | snprintf(exp,size,"ANTICOLL"); break; |
52 | } | |
53 | } | |
41fdd0f0 | 54 | case ISO14443A_CMD_ANTICOLL_OR_SELECT_2:{ |
4df54240 MHS |
55 | //95 20 = Anticollision of cascade level2 |
56 | //95 70 = Select of cascade level2 | |
57 | if(cmd[2] == 0x70) | |
58 | { | |
59 | snprintf(exp,size,"SELECT_UID-2"); break; | |
60 | }else | |
61 | { | |
62 | snprintf(exp,size,"ANTICOLL-2"); break; | |
4c3de57a MHS |
63 | } |
64 | } | |
16a95d76 | 65 | case ISO14443A_CMD_REQA: snprintf(exp,size,"REQA"); break; |
66 | case ISO14443A_CMD_READBLOCK: snprintf(exp,size,"READBLOCK(%d)",cmd[1]); break; | |
67 | case ISO14443A_CMD_WRITEBLOCK: snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]); break; | |
68 | case ISO14443A_CMD_HALT: snprintf(exp,size,"HALT"); break; | |
69 | case ISO14443A_CMD_RATS: snprintf(exp,size,"RATS"); break; | |
70 | case MIFARE_CMD_INC: snprintf(exp,size,"INC(%d)",cmd[1]); break; | |
71 | case MIFARE_CMD_DEC: snprintf(exp,size,"DEC(%d)",cmd[1]); break; | |
72 | case MIFARE_CMD_RESTORE: snprintf(exp,size,"RESTORE(%d)",cmd[1]); break; | |
73 | case MIFARE_CMD_TRANSFER: snprintf(exp,size,"TRANSFER(%d)",cmd[1]); break; | |
74 | case MIFARE_AUTH_KEYA: snprintf(exp,size,"AUTH-A(%d)",cmd[1]); break; | |
75 | case MIFARE_AUTH_KEYB: snprintf(exp,size,"AUTH-B(%d)",cmd[1]); break; | |
76 | case MIFARE_MAGICWUPC1: snprintf(exp,size,"MAGIC WUPC1"); break; | |
77 | case MIFARE_MAGICWUPC2: snprintf(exp,size,"MAGIC WUPC2"); break; | |
78 | case MIFARE_MAGICWIPEC: snprintf(exp,size,"MAGIC WIPEC"); break; | |
79 | default: snprintf(exp,size,"?"); break; | |
4c3de57a MHS |
80 | } |
81 | return; | |
82 | } | |
83 | ||
84 | void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) | |
85 | { | |
4c3de57a MHS |
86 | switch(cmd[0]) |
87 | { | |
337818f7 | 88 | case ICLASS_CMD_ACTALL: snprintf(exp,size,"ACTALL"); break; |
4df54240 MHS |
89 | case ICLASS_CMD_READ_OR_IDENTIFY:{ |
90 | if(cmdsize > 1){ | |
91 | snprintf(exp,size,"READ(%d)",cmd[1]); | |
92 | }else{ | |
93 | snprintf(exp,size,"IDENTIFY"); | |
94 | } | |
95 | break; | |
96 | } | |
337818f7 | 97 | case ICLASS_CMD_SELECT: snprintf(exp,size,"SELECT"); break; |
49726b40 MHS |
98 | case ICLASS_CMD_PAGESEL: snprintf(exp,size,"PAGESEL(%d)", cmd[1]); break; |
99 | case ICLASS_CMD_READCHECK_KC:snprintf(exp,size,"READCHECK[Kc](%d)", cmd[1]); break; | |
100 | case ICLASS_CMD_READCHECK_KD:snprintf(exp,size,"READCHECK[Kd](%d)", cmd[1]); break; | |
337818f7 | 101 | case ICLASS_CMD_CHECK: snprintf(exp,size,"CHECK"); break; |
49726b40 | 102 | case ICLASS_CMD_DETECT: snprintf(exp,size,"DETECT"); break; |
337818f7 | 103 | case ICLASS_CMD_HALT: snprintf(exp,size,"HALT"); break; |
49726b40 MHS |
104 | case ICLASS_CMD_UPDATE: snprintf(exp,size,"UPDATE(%d)",cmd[1]); break; |
105 | case ICLASS_CMD_ACT: snprintf(exp,size,"ACT"); break; | |
106 | case ICLASS_CMD_READ4: snprintf(exp,size,"READ4(%d)",cmd[1]); break; | |
337818f7 | 107 | default: snprintf(exp,size,"?"); break; |
4c3de57a MHS |
108 | } |
109 | return; | |
110 | } | |
111 | ||
4df54240 MHS |
112 | void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) |
113 | { | |
114 | ||
115 | if(cmd[0] == 0x26) | |
116 | { | |
117 | switch(cmd[1]){ | |
118 | case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");break; | |
119 | case ISO15693_STAYQUIET :snprintf(exp, size, "STAY_QUIET");break; | |
120 | default: snprintf(exp,size,"?"); break; | |
4c3de57a | 121 | |
4df54240 MHS |
122 | } |
123 | }else if(cmd[0] == 0x02) | |
124 | { | |
125 | switch(cmd[1]) | |
126 | { | |
127 | case ISO15693_READBLOCK :snprintf(exp, size, "READBLOCK");break; | |
128 | case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");break; | |
129 | case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");break; | |
130 | case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");break; | |
131 | case ISO15693_SELECT :snprintf(exp, size, "SELECT");break; | |
132 | case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");break; | |
133 | case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");break; | |
134 | case ISO15693_LOCK_AFI :snprintf(exp, size, "LOCK_AFI");break; | |
135 | case ISO15693_WRITE_DSFID :snprintf(exp, size, "WRITE_DSFID");break; | |
136 | case ISO15693_LOCK_DSFID :snprintf(exp, size, "LOCK_DSFID");break; | |
137 | case ISO15693_GET_SYSTEM_INFO :snprintf(exp, size, "GET_SYSTEM_INFO");break; | |
138 | case ISO15693_READ_MULTI_SECSTATUS :snprintf(exp, size, "READ_MULTI_SECSTATUS");break; | |
41fdd0f0 | 139 | default: snprintf(exp,size,"?"); break; |
4df54240 MHS |
140 | } |
141 | } | |
142 | } | |
08e8317c | 143 | |
ee1eadee | 144 | |
145 | void annotateTopaz(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) | |
146 | { | |
147 | ||
148 | switch(cmd[0]) { | |
149 | case TOPAZ_REQA :snprintf(exp, size, "REQA");break; | |
150 | case TOPAZ_WUPA :snprintf(exp, size, "WUPA");break; | |
151 | case TOPAZ_RID :snprintf(exp, size, "RID");break; | |
152 | case TOPAZ_RALL :snprintf(exp, size, "RALL");break; | |
153 | case TOPAZ_READ :snprintf(exp, size, "READ");break; | |
154 | case TOPAZ_WRITE_E :snprintf(exp, size, "WRITE-E");break; | |
155 | case TOPAZ_WRITE_NE :snprintf(exp, size, "WRITE-NE");break; | |
156 | default: snprintf(exp,size,"?"); break; | |
157 | } | |
158 | } | |
159 | ||
160 | ||
08e8317c MHS |
161 | /** |
162 | 06 00 = INITIATE | |
163 | 0E xx = SELECT ID (xx = Chip-ID) | |
164 | 0B = Get UID | |
165 | 08 yy = Read Block (yy = block number) | |
166 | 09 yy dd dd dd dd = Write Block (yy = block number; dd dd dd dd = data to be written) | |
167 | 0C = Reset to Inventory | |
168 | 0F = Completion | |
169 | 0A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate) | |
170 | **/ | |
171 | ||
41fdd0f0 MHS |
172 | void annotateIso14443b(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) |
173 | { | |
174 | switch(cmd[0]){ | |
175 | case ISO14443B_REQB : snprintf(exp,size,"REQB");break; | |
176 | case ISO14443B_ATTRIB : snprintf(exp,size,"ATTRIB");break; | |
177 | case ISO14443B_HALT : snprintf(exp,size,"HALT");break; | |
08e8317c MHS |
178 | case ISO14443B_INITIATE : snprintf(exp,size,"INITIATE");break; |
179 | case ISO14443B_SELECT : snprintf(exp,size,"SELECT(%d)",cmd[1]);break; | |
180 | case ISO14443B_GET_UID : snprintf(exp,size,"GET UID");break; | |
181 | case ISO14443B_READ_BLK : snprintf(exp,size,"READ_BLK(%d)", cmd[1]);break; | |
182 | case ISO14443B_WRITE_BLK : snprintf(exp,size,"WRITE_BLK(%d)",cmd[1]);break; | |
183 | case ISO14443B_RESET : snprintf(exp,size,"RESET");break; | |
184 | case ISO14443B_COMPLETION : snprintf(exp,size,"COMPLETION");break; | |
185 | case ISO14443B_AUTHENTICATE : snprintf(exp,size,"AUTHENTICATE");break; | |
186 | default : snprintf(exp,size ,"?");break; | |
41fdd0f0 MHS |
187 | } |
188 | ||
189 | } | |
190 | ||
191 | /** | |
192 | * @brief iso14443B_CRC_Ok Checks CRC in command or response | |
193 | * @param isResponse | |
194 | * @param data | |
195 | * @param len | |
196 | * @return 0 : CRC-command, CRC not ok | |
197 | * 1 : CRC-command, CRC ok | |
198 | * 2 : Not crc-command | |
199 | */ | |
200 | ||
201 | uint8_t iso14443B_CRC_check(bool isResponse, uint8_t* data, uint8_t len) | |
202 | { | |
203 | uint8_t b1,b2; | |
204 | ||
205 | if(len <= 2) return 2; | |
206 | ||
207 | ComputeCrc14443(CRC_14443_B, data, len-2, &b1, &b2); | |
208 | if(b1 != data[len-2] || b2 != data[len-1]) { | |
209 | return 0; | |
210 | } | |
211 | return 1; | |
212 | } | |
213 | ||
49726b40 MHS |
214 | /** |
215 | * @brief iclass_CRC_Ok Checks CRC in command or response | |
216 | * @param isResponse | |
217 | * @param data | |
218 | * @param len | |
219 | * @return 0 : CRC-command, CRC not ok | |
220 | * 1 : CRC-command, CRC ok | |
221 | * 2 : Not crc-command | |
222 | */ | |
41fdd0f0 | 223 | uint8_t iclass_CRC_check(bool isResponse, uint8_t* data, uint8_t len) |
49726b40 MHS |
224 | { |
225 | if(len < 4) return 2;//CRC commands (and responses) are all at least 4 bytes | |
226 | ||
227 | uint8_t b1, b2; | |
228 | ||
229 | if(!isResponse)//Commands to tag | |
230 | { | |
231 | /** | |
232 | These commands should have CRC. Total length leftmost | |
233 | 4 READ | |
234 | 4 READ4 | |
235 | 12 UPDATE - unsecured, ends with CRC16 | |
236 | 14 UPDATE - secured, ends with signature instead | |
237 | 4 PAGESEL | |
238 | **/ | |
239 | if(len == 4 || len == 12)//Covers three of them | |
240 | { | |
241 | //Don't include the command byte | |
242 | ComputeCrc14443(CRC_ICLASS, (data+1), len-3, &b1, &b2); | |
243 | return b1 == data[len -2] && b2 == data[len-1]; | |
244 | } | |
245 | return 2; | |
246 | }else{ | |
247 | /** | |
248 | These tag responses should have CRC. Total length leftmost | |
249 | ||
250 | 10 READ data[8] crc[2] | |
251 | 34 READ4 data[32]crc[2] | |
252 | 10 UPDATE data[8] crc[2] | |
253 | 10 SELECT csn[8] crc[2] | |
254 | 10 IDENTIFY asnb[8] crc[2] | |
255 | 10 PAGESEL block1[8] crc[2] | |
256 | 10 DETECT csn[8] crc[2] | |
257 | ||
258 | These should not | |
259 | ||
260 | 4 CHECK chip_response[4] | |
261 | 8 READCHECK data[8] | |
262 | 1 ACTALL sof[1] | |
263 | 1 ACT sof[1] | |
264 | ||
265 | In conclusion, without looking at the command; any response | |
266 | of length 10 or 34 should have CRC | |
267 | **/ | |
268 | if(len != 10 && len != 34) return true; | |
269 | ||
270 | ComputeCrc14443(CRC_ICLASS, data, len-2, &b1, &b2); | |
271 | return b1 == data[len -2] && b2 == data[len-1]; | |
272 | } | |
273 | } | |
4c3de57a | 274 | |
ee1eadee | 275 | |
276 | uint16_t merge_topaz_reader_frames(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t *topaz_reader_command, uint16_t *data_len) | |
277 | { | |
278 | return tracepos; | |
279 | } | |
280 | ||
281 | ||
f71f4deb | 282 | uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t protocol, bool showWaitCycles) |
4c3de57a MHS |
283 | { |
284 | bool isResponse; | |
f71f4deb | 285 | uint16_t duration, data_len, parity_len; |
ee1eadee | 286 | uint8_t topaz_reader_command[9]; |
4c3de57a MHS |
287 | uint32_t timestamp, first_timestamp, EndOfTransmissionTimestamp; |
288 | char explanation[30] = {0}; | |
289 | ||
f71f4deb | 290 | if (tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen) return traceLen; |
291 | ||
4c3de57a MHS |
292 | first_timestamp = *((uint32_t *)(trace)); |
293 | timestamp = *((uint32_t *)(trace + tracepos)); | |
4c3de57a MHS |
294 | |
295 | tracepos += 4; | |
296 | duration = *((uint16_t *)(trace + tracepos)); | |
297 | tracepos += 2; | |
298 | data_len = *((uint16_t *)(trace + tracepos)); | |
299 | tracepos += 2; | |
300 | ||
301 | if (data_len & 0x8000) { | |
302 | data_len &= 0x7fff; | |
303 | isResponse = true; | |
304 | } else { | |
305 | isResponse = false; | |
306 | } | |
307 | parity_len = (data_len-1)/8 + 1; | |
308 | ||
f71f4deb | 309 | if (tracepos + data_len + parity_len > traceLen) { |
310 | return traceLen; | |
4c3de57a | 311 | } |
4c3de57a MHS |
312 | uint8_t *frame = trace + tracepos; |
313 | tracepos += data_len; | |
314 | uint8_t *parityBytes = trace + tracepos; | |
315 | tracepos += parity_len; | |
316 | ||
ee1eadee | 317 | if (protocol == TOPAZ && !isResponse) { |
318 | // topaz reader commands come in 1 or 9 separate frames with 8 Bits each. | |
319 | // merge them: | |
320 | tracepos = merge_topaz_reader_frames(tracepos, traceLen, trace, topaz_reader_command, &data_len); | |
321 | } | |
322 | ||
27eabcdc MHS |
323 | //Check the CRC status |
324 | uint8_t crcStatus = 2; | |
325 | ||
326 | if (data_len > 2) { | |
327 | uint8_t b1, b2; | |
ee1eadee | 328 | switch (protocol) { |
329 | case ICLASS: | |
330 | crcStatus = iclass_CRC_check(isResponse, frame, data_len); | |
331 | break; | |
332 | case ISO_14443B: | |
333 | case TOPAZ: | |
334 | crcStatus = iso14443B_CRC_check(isResponse, topaz_reader_command, data_len); | |
335 | break; | |
336 | case ISO_14443A: | |
337 | ComputeCrc14443(CRC_14443_A, frame, data_len-2, &b1, &b2); | |
338 | if (b1 != frame[data_len-2] || b2 != frame[data_len-1]) { | |
339 | if(!(isResponse & (data_len < 6))) { | |
27eabcdc | 340 | crcStatus = 0; |
ee1eadee | 341 | } |
27eabcdc | 342 | } |
ee1eadee | 343 | break; |
344 | default: | |
345 | break; | |
27eabcdc MHS |
346 | } |
347 | } | |
348 | //0 CRC-command, CRC not ok | |
349 | //1 CRC-command, CRC ok | |
350 | //2 Not crc-command | |
9e8255d4 | 351 | |
4c3de57a | 352 | //--- Draw the data column |
9e8255d4 | 353 | //char line[16][110]; |
4c3de57a | 354 | char line[16][110]; |
9e8255d4 MHS |
355 | |
356 | for (int j = 0; j < data_len && j/16 < 16; j++) { | |
357 | ||
4c3de57a MHS |
358 | int oddparity = 0x01; |
359 | int k; | |
360 | ||
361 | for (k=0 ; k<8 ; k++) { | |
362 | oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01); | |
363 | } | |
4c3de57a | 364 | uint8_t parityBits = parityBytes[j>>3]; |
4c3de57a | 365 | if (isResponse && (oddparity != ((parityBits >> (7-(j&0x0007))) & 0x01))) { |
9e8255d4 MHS |
366 | snprintf(line[j/16]+(( j % 16) * 4),110, "%02x! ", frame[j]); |
367 | ||
4c3de57a | 368 | } else { |
8b9393d3 | 369 | snprintf(line[j/16]+(( j % 16) * 4),110, "%02x ", frame[j]); |
9e8255d4 | 370 | } |
27eabcdc MHS |
371 | |
372 | } | |
373 | if(crcStatus == 1) | |
374 | {//CRC-command | |
375 | char *pos1 = line[(data_len-2)/16]+(((data_len-2) % 16) * 4)-1; | |
376 | (*pos1) = '['; | |
377 | char *pos2 = line[(data_len)/16]+(((data_len) % 16) * 4)-2; | |
378 | (*pos2) = ']'; | |
9e8255d4 MHS |
379 | } |
380 | if(data_len == 0) | |
381 | { | |
382 | if(data_len == 0){ | |
383 | sprintf(line[0],"<empty trace - possible error>"); | |
4c3de57a MHS |
384 | } |
385 | } | |
386 | //--- Draw the CRC column | |
4c3de57a | 387 | |
49726b40 | 388 | char *crc = (crcStatus == 0 ? "!crc" : (crcStatus == 1 ? " ok " : " ")); |
4c3de57a MHS |
389 | |
390 | EndOfTransmissionTimestamp = timestamp + duration; | |
391 | ||
392 | if(!isResponse) | |
393 | { | |
ee1eadee | 394 | switch(protocol) { |
395 | case ICLASS: annotateIclass(explanation,sizeof(explanation),frame,data_len); break; | |
396 | case ISO_14443A: annotateIso14443a(explanation,sizeof(explanation),frame,data_len); break; | |
397 | case ISO_14443B: annotateIso14443b(explanation,sizeof(explanation),frame,data_len); break; | |
398 | case TOPAZ: annotateTopaz(explanation,sizeof(explanation),frame,data_len); break; | |
399 | default: break; | |
400 | } | |
4c3de57a MHS |
401 | } |
402 | ||
9e8255d4 MHS |
403 | int num_lines = MIN((data_len - 1)/16 + 1, 16); |
404 | for (int j = 0; j < num_lines ; j++) { | |
4c3de57a MHS |
405 | if (j == 0) { |
406 | PrintAndLog(" %9d | %9d | %s | %-64s| %s| %s", | |
407 | (timestamp - first_timestamp), | |
408 | (EndOfTransmissionTimestamp - first_timestamp), | |
409 | (isResponse ? "Tag" : "Rdr"), | |
410 | line[j], | |
411 | (j == num_lines-1) ? crc : " ", | |
412 | (j == num_lines-1) ? explanation : ""); | |
413 | } else { | |
414 | PrintAndLog(" | | | %-64s| %s| %s", | |
415 | line[j], | |
ee1eadee | 416 | (j == num_lines-1) ? crc : " ", |
4c3de57a MHS |
417 | (j == num_lines-1) ? explanation : ""); |
418 | } | |
419 | } | |
420 | ||
f71f4deb | 421 | if (tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen) return traceLen; |
422 | ||
4c3de57a MHS |
423 | bool next_isResponse = *((uint16_t *)(trace + tracepos + 6)) & 0x8000; |
424 | ||
425 | if (showWaitCycles && !isResponse && next_isResponse) { | |
426 | uint32_t next_timestamp = *((uint32_t *)(trace + tracepos)); | |
427 | if (next_timestamp != 0x44444444) { | |
428 | PrintAndLog(" %9d | %9d | %s | fdt (Frame Delay Time): %d", | |
429 | (EndOfTransmissionTimestamp - first_timestamp), | |
430 | (next_timestamp - first_timestamp), | |
431 | " ", | |
432 | (next_timestamp - EndOfTransmissionTimestamp)); | |
433 | } | |
434 | } | |
f71f4deb | 435 | |
4c3de57a MHS |
436 | return tracepos; |
437 | } | |
438 | ||
f71f4deb | 439 | |
4c3de57a MHS |
440 | int CmdHFList(const char *Cmd) |
441 | { | |
442 | bool showWaitCycles = false; | |
443 | char type[40] = {0}; | |
444 | int tlen = param_getstr(Cmd,0,type); | |
445 | char param = param_getchar(Cmd, 1); | |
446 | bool errors = false; | |
b689b842 | 447 | uint8_t protocol = 0; |
4c3de57a | 448 | //Validate params |
b689b842 | 449 | if(tlen == 0) |
4c3de57a MHS |
450 | { |
451 | errors = true; | |
452 | } | |
453 | if(param == 'h' || (param !=0 && param != 'f')) | |
454 | { | |
455 | errors = true; | |
456 | } | |
b689b842 MHS |
457 | if(!errors) |
458 | { | |
ee1eadee | 459 | if(strcmp(type, "iclass") == 0) { |
b689b842 | 460 | protocol = ICLASS; |
ee1eadee | 461 | } else if(strcmp(type, "14a") == 0) { |
b689b842 | 462 | protocol = ISO_14443A; |
ee1eadee | 463 | } else if(strcmp(type, "14b") == 0) { |
b689b842 | 464 | protocol = ISO_14443B; |
ee1eadee | 465 | } else if(strcmp(type,"topaz")== 0) { |
466 | protocol = TOPAZ; | |
467 | } else if(strcmp(type,"raw")== 0) { | |
b689b842 | 468 | protocol = -1;//No crc, no annotations |
ee1eadee | 469 | } else { |
b689b842 MHS |
470 | errors = true; |
471 | } | |
472 | } | |
4c3de57a MHS |
473 | |
474 | if (errors) { | |
475 | PrintAndLog("List protocol data in trace buffer."); | |
92623113 MHS |
476 | PrintAndLog("Usage: hf list <protocol> [f]"); |
477 | PrintAndLog(" f - show frame delay times as well"); | |
478 | PrintAndLog("Supported <protocol> values:"); | |
479 | PrintAndLog(" raw - just show raw data without annotations"); | |
337818f7 | 480 | PrintAndLog(" 14a - interpret data as iso14443a communications"); |
41fdd0f0 | 481 | PrintAndLog(" 14b - interpret data as iso14443b communications"); |
4c3de57a | 482 | PrintAndLog(" iclass - interpret data as iclass communications"); |
ee1eadee | 483 | PrintAndLog(" topaz - interpret data as topaz communications"); |
4c3de57a MHS |
484 | PrintAndLog(""); |
485 | PrintAndLog("example: hf list 14a f"); | |
486 | PrintAndLog("example: hf list iclass"); | |
487 | return 0; | |
488 | } | |
b689b842 | 489 | |
4c3de57a MHS |
490 | |
491 | if (param == 'f') { | |
492 | showWaitCycles = true; | |
493 | } | |
494 | ||
495 | ||
f71f4deb | 496 | uint8_t *trace; |
4c3de57a | 497 | uint16_t tracepos = 0; |
f71f4deb | 498 | trace = malloc(USB_CMD_DATA_SIZE); |
499 | ||
500 | // Query for the size of the trace | |
501 | UsbCommand response; | |
502 | GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0); | |
503 | WaitForResponse(CMD_ACK, &response); | |
504 | uint16_t traceLen = response.arg[2]; | |
505 | if (traceLen > USB_CMD_DATA_SIZE) { | |
506 | uint8_t *p = realloc(trace, traceLen); | |
507 | if (p == NULL) { | |
508 | PrintAndLog("Cannot allocate memory for trace"); | |
509 | free(trace); | |
510 | return 2; | |
511 | } | |
512 | trace = p; | |
513 | GetFromBigBuf(trace, traceLen, 0); | |
514 | WaitForResponse(CMD_ACK, NULL); | |
515 | } | |
516 | ||
517 | PrintAndLog("Recorded Activity (TraceLen = %d bytes)", traceLen); | |
4c3de57a MHS |
518 | PrintAndLog(""); |
519 | PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer"); | |
520 | PrintAndLog("iso14443a - All times are in carrier periods (1/13.56Mhz)"); | |
521 | PrintAndLog("iClass - Timings are not as accurate"); | |
522 | PrintAndLog(""); | |
523 | PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |"); | |
524 | PrintAndLog("-----------|-----------|-----|-----------------------------------------------------------------|-----|--------------------|"); | |
525 | ||
f71f4deb | 526 | while(tracepos < traceLen) |
4c3de57a | 527 | { |
f71f4deb | 528 | tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles); |
4c3de57a | 529 | } |
f71f4deb | 530 | |
531 | free(trace); | |
4c3de57a MHS |
532 | return 0; |
533 | } | |
534 | ||
7fe9b0b7 | 535 | |
536 | static command_t CommandTable[] = | |
537 | { | |
538 | {"help", CmdHelp, 1, "This help"}, | |
37239a7c | 539 | {"14a", CmdHF14A, 1, "{ ISO14443A RFIDs... }"}, |
540 | {"14b", CmdHF14B, 1, "{ ISO14443B RFIDs... }"}, | |
541 | {"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"}, | |
5acd09bd | 542 | {"epa", CmdHFEPA, 1, "{ German Identification Card... }"}, |
8e220a91 | 543 | {"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"}, |
cee5a30d | 544 | {"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"}, |
4c3de57a | 545 | {"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"}, |
5ee70129 | 546 | {"mfu", CmdHFMFUltra, 1, "{ MIFARE Ultralight RFIDs... }"}, |
c59c3405 | 547 | {"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"}, |
4c3de57a MHS |
548 | {"list", CmdHFList, 1, "List protocol data in trace buffer"}, |
549 | {NULL, NULL, 0, NULL} | |
7fe9b0b7 | 550 | }; |
551 | ||
552 | int CmdHF(const char *Cmd) | |
553 | { | |
554 | CmdsParse(CommandTable, Cmd); | |
555 | return 0; | |
556 | } | |
557 | ||
558 | int CmdHelp(const char *Cmd) | |
559 | { | |
560 | CmdsHelp(CommandTable); | |
561 | return 0; | |
562 | } |