]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhf15.c
small improvements in auth (#694)
[proxmark3-svn] / client / cmdhf15.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 // Modified 2010-2012 by <adrian -at- atrox.at>
4 // Modified 2012 by <vsza at vsza.hu>
5 //
6 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
7 // at your option, any later version. See the LICENSE.txt file for the text of
8 // the license.
9 //-----------------------------------------------------------------------------
10 // High frequency ISO15693 commands
11 //-----------------------------------------------------------------------------
12 // There are three basic operation modes, depending on which device (proxmark/pc)
13 // the signal processing, (de)modulation, transmission protocol and logic is done.
14 // Mode 1:
15 // All steps are done on the proxmark, the output of the commands is returned via
16 // USB-debug-print commands.
17 // Mode 2:
18 // The protocol is done on the PC, passing only Iso15693 data frames via USB. This
19 // allows direct communication with a tag on command level
20 // Mode 3:
21 // The proxmark just samples the antenna and passes this "analog" data via USB to
22 // the client. Signal Processing & decoding is done on the pc. This is the slowest
23 // variant, but offers the possibility to analyze the waveforms directly.
24
25 #include "cmdhf15.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdint.h>
31
32 #include "comms.h"
33 #include "graph.h"
34 #include "ui.h"
35 #include "util.h"
36 #include "cmdparser.h"
37 #include "iso15693tools.h"
38 #include "cmdmain.h"
39
40 #define FrameSOF Iso15693FrameSOF
41 #define Logic0 Iso15693Logic0
42 #define Logic1 Iso15693Logic1
43 #define FrameEOF Iso15693FrameEOF
44
45 #define Crc(data,datalen) Iso15693Crc(data,datalen)
46 #define AddCrc(data,datalen) Iso15693AddCrc(data,datalen)
47 #define sprintUID(target,uid) Iso15693sprintUID(target,uid)
48
49 // structure and database for uid -> tagtype lookups
50 typedef struct {
51 uint64_t uid;
52 int mask; // how many MSB bits used
53 char* desc;
54 } productName;
55
56
57 const productName uidmapping[] = {
58
59 // UID, #significant Bits, "Vendor(+Product)"
60 { 0xE001000000000000LL, 16, "Motorola UK" },
61
62 // E0 02 xx
63 // 02 = ST Microelectronics
64 // XX = IC id (Chip ID Family)
65 { 0xE002000000000000LL, 16, "ST Microelectronics SA France" },
66 { 0xE002050000000000LL, 24, "ST Microelectronics; LRI64 [IC id = 05]"},
67 { 0xE002080000000000LL, 24, "ST Microelectronics; LRI2K [IC id = 08]"},
68 { 0xE0020A0000000000LL, 24, "ST Microelectronics; LRIS2K [IC id = 10]"},
69 { 0xE002440000000000LL, 24, "ST Microelectronics; LRIS64K [IC id = 68]"},
70
71 { 0xE003000000000000LL, 16, "Hitachi, Ltd Japan" },
72
73 // E0 04 xx
74 // 04 = Manufacturer code (Philips/NXP)
75 // XX = IC id (Chip ID Family)
76 //I-Code SLI SL2 ICS20 [IC id = 01]
77 //I-Code SLI-S [IC id = 02]
78 //I-Code SLI-L [IC id = 03]
79 //I-Code SLIX [IC id = 01 + bit36 set to 1 (starting from bit0 - different from normal SLI)]
80 //I-Code SLIX-S [IC id = 02 + bit36 set to 1]
81 //I-Code SLIX-L [IC id = 03 + bit36 set to 1]
82 { 0xE004000000000000LL, 16, "NXP Semiconductors Germany (Philips)" },
83 { 0xE004010000000000LL, 24, "NXP(Philips); IC SL2 ICS20/ICS21(SLI) ICS2002/ICS2102(SLIX)" },
84 { 0xE004020000000000LL, 24, "NXP(Philips); IC SL2 ICS53/ICS54(SLI-S) ICS5302/ICS5402(SLIX-S)" },
85 { 0xE004030000000000LL, 24, "NXP(Philips); IC SL2 ICS50/ICS51(SLI-L) ICS5002/ICS5102(SLIX-L)" },
86
87 // E0 05 XX .. .. ..
88 // 05 = Manufacturer code (Infineon)
89 // XX = IC id (Chip ID Family)
90 { 0xE005000000000000LL, 16, "Infineon Technologies AG Germany" },
91 { 0xE005A10000000000LL, 24, "Infineon; SRF55V01P [IC id = 161] plain mode 1kBit"},
92 { 0xE005A80000000000LL, 24, "Infineon; SRF55V01P [IC id = 168] pilot series 1kBit"},
93 { 0xE005400000000000LL, 24, "Infineon; SRF55V02P [IC id = 64] plain mode 2kBit"},
94 { 0xE005000000000000LL, 24, "Infineon; SRF55V10P [IC id = 00] plain mode 10KBit"},
95 { 0xE005500000000000LL, 24, "Infineon; SRF55V02S [IC id = 80] secure mode 2kBit"},
96 { 0xE005100000000000LL, 24, "Infineon; SRF55V10S [IC id = 16] secure mode 10KBit"},
97 { 0xE0051E0000000000LL, 23, "Infineon; SLE66r01P [IC id = 3x = My-d Move or My-d move NFC]"},
98 { 0xE005200000000000LL, 21, "Infineon; SLE66r01P [IC id = 3x = My-d Move or My-d move NFC]"},
99
100 { 0xE006000000000000LL, 16, "Cylink USA" },
101
102
103 // E0 07 xx
104 // 07 = Texas Instruments
105 // XX = from bit 41 to bit 43 = product configuration - from bit 44 to bit 47 IC id (Chip ID Family)
106 //Tag IT RFIDType-I Plus, 2kBit, TI Inlay
107 //Tag-it HF-I Plus Inlay [IC id = 00] -> b'0000 000 2kBit
108 //Tag-it HF-I Plus Chip [IC id = 64] -> b'1000 000 2kBit
109 //Tag-it HF-I Standard Chip / Inlays [IC id = 96] -> b'1100 000 256Bit
110 //Tag-it HF-I Pro Chip / Inlays [IC id = 98] -> b'1100 010 256Bit, Password protection
111 { 0xE007000000000000LL, 16, "Texas Instrument France" },
112 { 0xE007000000000000LL, 20, "Texas Instrument; Tag-it HF-I Plus Inlay; 64x32bit" },
113 { 0xE007100000000000LL, 20, "Texas Instrument; Tag-it HF-I Plus Chip; 64x32bit" },
114 { 0xE007800000000000LL, 23, "Texas Instrument; Tag-it HF-I Plus (RF-HDT-DVBB tag or Third Party Products)" },
115 { 0xE007C00000000000LL, 23, "Texas Instrument; Tag-it HF-I Standard; 8x32bit" },
116 { 0xE007C40000000000LL, 23, "Texas Instrument; Tag-it HF-I Pro; 8x23bit; password" },
117
118 { 0xE008000000000000LL, 16, "Fujitsu Limited Japan" },
119 { 0xE009000000000000LL, 16, "Matsushita Electronics Corporation, Semiconductor Company Japan" },
120 { 0xE00A000000000000LL, 16, "NEC Japan" },
121 { 0xE00B000000000000LL, 16, "Oki Electric Industry Co. Ltd Japan" },
122 { 0xE00C000000000000LL, 16, "Toshiba Corp. Japan" },
123 { 0xE00D000000000000LL, 16, "Mitsubishi Electric Corp. Japan" },
124 { 0xE00E000000000000LL, 16, "Samsung Electronics Co. Ltd Korea" },
125 { 0xE00F000000000000LL, 16, "Hynix / Hyundai, Korea" },
126 { 0xE010000000000000LL, 16, "LG-Semiconductors Co. Ltd Korea" },
127 { 0xE011000000000000LL, 16, "Emosyn-EM Microelectronics USA" },
128
129 { 0xE012000000000000LL, 16, "HID Corporation" },
130 { 0xE012000000000000LL, 16, "INSIDE Technology France" },
131 { 0xE013000000000000LL, 16, "ORGA Kartensysteme GmbH Germany" },
132 { 0xE014000000000000LL, 16, "SHARP Corporation Japan" },
133 { 0xE015000000000000LL, 16, "ATMEL France" },
134
135 { 0xE016000000000000LL, 16, "EM Microelectronic-Marin SA Switzerland (Skidata)"},
136 { 0xE016040000000000LL, 24, "EM-Marin SA (Skidata Keycard-eco); EM4034 [IC id = 01] (Read/Write - no AFI)"},
137 { 0xE0160C0000000000LL, 24, "EM-Marin SA (Skidata); EM4035 [IC id = 03] (Read/Write - replaced by 4233)"},
138 { 0xE016100000000000LL, 24, "EM-Marin SA (Skidata); EM4135 [IC id = 04] (Read/Write - replaced by 4233) 36x64bit start page 13"},
139 { 0xE016140000000000LL, 24, "EM-Marin SA (Skidata); EM4036 [IC id = 05] 28pF"},
140 { 0xE016180000000000LL, 24, "EM-Marin SA (Skidata); EM4006 [IC id = 06] (Read Only)"},
141 { 0xE0161C0000000000LL, 24, "EM-Marin SA (Skidata); EM4133 [IC id = 07] 23,5pF (Read/Write)"},
142 { 0xE016200000000000LL, 24, "EM-Marin SA (Skidata); EM4033 [IC id = 08] 23,5pF (Read Only - no AFI / no DSFID / no security blocks)"},
143 { 0xE016240000000000LL, 24, "EM-Marin SA (Skidata); EM4233 [IC id = 09] 23,5pF CustomerID-102"},
144 { 0xE016280000000000LL, 24, "EM-Marin SA (Skidata); EM4233 SLIC [IC id = 10] 23,5pF (1Kb flash memory - not provide High Security mode and QuietStorage feature)" },
145 { 0xE0163C0000000000LL, 24, "EM-Marin SA (Skidata); EM4237 [IC id = 15] 23,5pF"},
146 { 0xE0167C0000000000LL, 24, "EM-Marin SA (Skidata); EM4233 [IC id = 31] 95pF"},
147 { 0xE016940000000000LL, 24, "EM-Marin SA (Skidata); EM4036 [IC id = 37] 95pF 51x64bit "},
148 { 0xE0169c0000000000LL, 24, "EM-Marin SA (Skidata); EM4133 [IC id = 39] 95pF (Read/Write)" },
149 { 0xE016A80000000000LL, 24, "EM-Marin SA (Skidata); EM4233 SLIC [IC id = 42] 97pF" },
150 { 0xE016BC0000000000LL, 24, "EM-Marin SA (Skidata); EM4237 [IC id = 47] 97pF" },
151
152 { 0xE017000000000000LL, 16, "KSW Microtec GmbH Germany" },
153 { 0xE018000000000000LL, 16, "ZMD AG Germany" },
154 { 0xE019000000000000LL, 16, "XICOR, Inc. USA" },
155 { 0xE01A000000000000LL, 16, "Sony Corporation Japan Identifier Company Country" },
156 { 0xE01B000000000000LL, 16, "Malaysia Microelectronic Solutions Sdn. Bhd Malaysia" },
157 { 0xE01C000000000000LL, 16, "Emosyn USA" },
158 { 0xE01D000000000000LL, 16, "Shanghai Fudan Microelectronics Co. Ltd. P.R. China" },
159 { 0xE01E000000000000LL, 16, "Magellan Technology Pty Limited Australia" },
160 { 0xE01F000000000000LL, 16, "Melexis NV BO Switzerland" },
161 { 0xE020000000000000LL, 16, "Renesas Technology Corp. Japan" },
162 { 0xE021000000000000LL, 16, "TAGSYS France" },
163 { 0xE022000000000000LL, 16, "Transcore USA" },
164 { 0xE023000000000000LL, 16, "Shanghai belling corp., ltd. China" },
165 { 0xE024000000000000LL, 16, "Masktech Germany Gmbh Germany" },
166 { 0xE025000000000000LL, 16, "Innovision Research and Technology Plc UK" },
167 { 0xE026000000000000LL, 16, "Hitachi ULSI Systems Co., Ltd. Japan" },
168 { 0xE027000000000000LL, 16, "Cypak AB Sweden" },
169 { 0xE028000000000000LL, 16, "Ricoh Japan" },
170 { 0xE029000000000000LL, 16, "ASK France" },
171 { 0xE02A000000000000LL, 16, "Unicore Microsystems, LLC Russian Federation" },
172 { 0xE02B000000000000LL, 16, "Dallas Semiconductor/Maxim USA" },
173 { 0xE02C000000000000LL, 16, "Impinj, Inc. USA" },
174 { 0xE02D000000000000LL, 16, "RightPlug Alliance USA" },
175 { 0xE02E000000000000LL, 16, "Broadcom Corporation USA" },
176 { 0xE02F000000000000LL, 16, "MStar Semiconductor, Inc Taiwan, ROC" },
177 { 0xE030000000000000LL, 16, "BeeDar Technology Inc. USA" },
178 { 0xE031000000000000LL, 16, " RFIDsec Denmark" },
179 { 0xE032000000000000LL, 16, " Schweizer Electronic AG Germany" },
180 { 0xE033000000000000LL, 16, " AMIC Technology Corp Taiwan" },
181 { 0xE034000000000000LL, 16, "Mikron JSC Russia" },
182 { 0xE035000000000000LL, 16, "Fraunhofer Institute for Photonic Microsystems Germany" },
183 { 0xE036000000000000LL, 16, "IDS Microchip AG Switzerland" },
184 { 0xE037000000000000LL, 16, "Kovio USA" },
185 { 0xE038000000000000LL, 16, "HMT Microelectronic Ltd Switzerland Identifier Company Country" },
186 { 0xE039000000000000LL, 16, "Silicon Craft Technology Thailand" },
187 { 0xE03A000000000000LL, 16, "Advanced Film Device Inc. Japan" },
188 { 0xE03B000000000000LL, 16, "Nitecrest Ltd UK" },
189 { 0xE03C000000000000LL, 16, "Verayo Inc. USA" },
190 { 0xE03D000000000000LL, 16, "HID Global USA" },
191 { 0xE03E000000000000LL, 16, "Productivity Engineering Gmbh Germany" },
192 { 0xE03F000000000000LL, 16, "Austriamicrosystems AG (reserved) Austria" },
193 { 0xE040000000000000LL, 16, "Gemalto SA France" },
194 { 0xE041000000000000LL, 16, "Renesas Electronics Corporation Japan" },
195 { 0xE042000000000000LL, 16, "3Alogics Inc Korea" },
196 { 0xE043000000000000LL, 16, "Top TroniQ Asia Limited Hong Kong" },
197 { 0xE044000000000000LL, 16, "Gentag Inc (USA) USA" },
198 { 0,0,"no tag-info available" } // must be the last entry
199 };
200
201
202 // fast method to just read the UID of a tag (collission detection not supported)
203 // *buf should be large enough to fit the 64bit uid
204 // returns 1 if suceeded
205 int getUID(uint8_t *buf)
206 {
207 UsbCommand resp;
208 uint8_t *recv;
209 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
210 uint8_t *req=c.d.asBytes;
211 int reqlen=0;
212
213 for (int retry=0;retry<3; retry++) { // don't give up the at the first try
214
215 req[0]= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
216 ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
217 req[1]=ISO15_CMD_INVENTORY;
218 req[2]=0; // mask length
219 reqlen=AddCrc(req,3);
220 c.arg[0]=reqlen;
221
222 SendCommand(&c);
223
224 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
225 recv = resp.d.asBytes;
226 if (resp.arg[0]>=12 && ISO15_CRC_CHECK==Crc(recv,12)) {
227 memcpy(buf,&recv[2],8);
228 return 1;
229 }
230 }
231 } // retry
232 return 0;
233 }
234
235
236
237 // get a product description based on the UID
238 // uid[8] tag uid
239 // returns description of the best match
240 static char* getTagInfo(uint8_t *uid) {
241 uint64_t myuid,mask;
242 int i=0, best=-1;
243 memcpy(&myuid,uid,sizeof(uint64_t));
244 while (uidmapping[i].mask>0) {
245 mask=(~0LL) <<(64-uidmapping[i].mask);
246 if ((myuid & mask) == uidmapping[i].uid) {
247 if (best==-1) {
248 best=i;
249 } else {
250 if (uidmapping[i].mask>uidmapping[best].mask) {
251 best=i;
252 }
253 }
254 }
255 i++;
256 }
257
258 if (best>=0) return uidmapping[best].desc;
259
260 return uidmapping[i].desc;
261 }
262
263
264 // return a clear-text message to an errorcode
265 static char* TagErrorStr(uint8_t error) {
266 switch (error) {
267 case 0x01: return "The command is not supported";
268 case 0x02: return "The command is not recognised";
269 case 0x03: return "The option is not supported.";
270 case 0x0f: return "Unknown error.";
271 case 0x10: return "The specified block is not available (doesn't exist).";
272 case 0x11: return "The specified block is already -locked and thus cannot be locked again";
273 case 0x12: return "The specified block is locked and its content cannot be changed.";
274 case 0x13: return "The specified block was not successfully programmed.";
275 case 0x14: return "The specified block was not successfully locked.";
276 default: return "Reserved for Future Use or Custom command error.";
277 }
278 }
279
280
281 // Mode 3
282 int CmdHF15Demod(const char *Cmd)
283 {
284 // The sampling rate is 106.353 ksps/s, for T = 18.8 us
285
286 int i, j;
287 int max = 0, maxPos = 0;
288
289 int skip = 2;
290
291 if (GraphTraceLen < 2000) return 0;
292
293 // First, correlate for SOF
294 for (i = 0; i < 200; i++) {
295 int corr = 0;
296 for (j = 0; j < arraylen(FrameSOF); j += skip) {
297 corr += FrameSOF[j] * GraphBuffer[i + (j / skip)];
298 }
299 if (corr > max) {
300 max = corr;
301 maxPos = i;
302 }
303 }
304 PrintAndLog("SOF at %d, correlation %d", maxPos,
305 max / (arraylen(FrameSOF) / skip));
306
307 i = maxPos + arraylen(FrameSOF) / skip;
308 int k = 0;
309 uint8_t outBuf[20];
310 memset(outBuf, 0, sizeof(outBuf));
311 uint8_t mask = 0x01;
312 for (;;) {
313 int corr0 = 0, corr00 = 0, corr01 = 0, corr1 = 0, corrEOF = 0;
314 for(j = 0; j < arraylen(Logic0); j += skip) {
315 corr0 += Logic0[j]*GraphBuffer[i+(j/skip)];
316 }
317 corr01 = corr00 = corr0;
318 for(j = 0; j < arraylen(Logic0); j += skip) {
319 corr00 += Logic0[j]*GraphBuffer[i+arraylen(Logic0)/skip+(j/skip)];
320 corr01 += Logic1[j]*GraphBuffer[i+arraylen(Logic0)/skip+(j/skip)];
321 }
322 for(j = 0; j < arraylen(Logic1); j += skip) {
323 corr1 += Logic1[j]*GraphBuffer[i+(j/skip)];
324 }
325 for(j = 0; j < arraylen(FrameEOF); j += skip) {
326 corrEOF += FrameEOF[j]*GraphBuffer[i+(j/skip)];
327 }
328 // Even things out by the length of the target waveform.
329 corr00 *= 2;
330 corr01 *= 2;
331 corr0 *= 4;
332 corr1 *= 4;
333
334 if(corrEOF > corr1 && corrEOF > corr00 && corrEOF > corr01) {
335 PrintAndLog("EOF at %d", i);
336 break;
337 } else if (corr1 > corr0) {
338 i += arraylen(Logic1) / skip;
339 outBuf[k] |= mask;
340 } else {
341 i += arraylen(Logic0) / skip;
342 }
343 mask <<= 1;
344 if (mask == 0) {
345 k++;
346 mask = 0x01;
347 }
348 if ((i + (int)arraylen(FrameEOF)) >= GraphTraceLen) {
349 PrintAndLog("ran off end!");
350 break;
351 }
352 }
353 if (mask != 0x01) {
354 PrintAndLog("error, uneven octet! (discard extra bits!)");
355 PrintAndLog(" mask=%02x", mask);
356 }
357 PrintAndLog("%d octets", k);
358
359 for (i = 0; i < k; i++) {
360 PrintAndLog("# %2d: %02x ", i, outBuf[i]);
361 }
362 PrintAndLog("CRC=%04x", Iso15693Crc(outBuf, k - 2));
363 return 0;
364 }
365
366
367
368 // * Acquire Samples as Reader (enables carrier, sends inquiry)
369 int CmdHF15Read(const char *Cmd)
370 {
371 UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693};
372 SendCommand(&c);
373 return 0;
374 }
375
376 // Record Activity without enabling carrier
377 // TODO: currently it DOES enable the carrier
378 int CmdHF15Record(const char *Cmd)
379 {
380 UsbCommand c = {CMD_RECORD_RAW_ADC_SAMPLES_ISO_15693};
381 SendCommand(&c);
382 return 0;
383 }
384
385 int HF15Reader(const char *Cmd, bool verbose)
386 {
387 uint8_t uid[8];
388
389 if (!getUID(uid)) {
390 if (verbose) PrintAndLog("No Tag found.");
391 return 0;
392 }
393
394 PrintAndLog("Tag UID : %s",sprintUID(NULL,uid));
395 PrintAndLog("Tag Info: %s",getTagInfo(uid));
396 return 1;
397 }
398
399 int CmdHF15Reader(const char *Cmd)
400 {
401 UsbCommand c = {CMD_READER_ISO_15693, {strtol(Cmd, NULL, 0), 0, 0}};
402 SendCommand(&c);
403 return 0;
404 }
405
406 // Simulation is still not working very good
407 int CmdHF15Sim(const char *Cmd)
408 {
409 char cmdp = param_getchar(Cmd, 0);
410 uint8_t uid[8] = {0x00};
411
412 //E0 16 24 00 00 00 00 00
413 if (cmdp == 'h' || cmdp == 'H') {
414 PrintAndLog("Usage: hf 15 sim <UID>");
415 PrintAndLog("");
416 PrintAndLog(" sample: hf 15 sim E016240000000000");
417 return 0;
418 }
419
420 if (param_gethex(Cmd, 0, uid, 16)) {
421 PrintAndLog("UID must include 16 HEX symbols");
422 return 0;
423 }
424
425 PrintAndLog("Starting simulating UID %02X %02X %02X %02X %02X %02X %02X %02X",
426 uid[0],uid[1],uid[2],uid[3],uid[4], uid[5], uid[6], uid[7]);
427
428 UsbCommand c = {CMD_SIMTAG_ISO_15693, {0, 0, 0}};
429 memcpy(c.d.asBytes,uid,8);
430
431 SendCommand(&c);
432 return 0;
433 }
434
435 // finds the AFI (Application Family Idendifier) of a card, by trying all values
436 // (There is no standard way of reading the AFI, allthough some tags support this)
437 int CmdHF15Afi(const char *Cmd)
438 {
439 UsbCommand c = {CMD_ISO_15693_FIND_AFI, {strtol(Cmd, NULL, 0), 0, 0}};
440 SendCommand(&c);
441 return 0;
442 }
443
444 // Reads all memory pages
445 int CmdHF15DumpMem(const char*Cmd) {
446 UsbCommand resp;
447 uint8_t uid[8];
448 uint8_t *recv=NULL;
449 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
450 uint8_t *req=c.d.asBytes;
451 int reqlen=0;
452 int blocknum=0;
453 char output[80];
454
455 if (!getUID(uid)) {
456 PrintAndLog("No Tag found.");
457 return 0;
458 }
459
460 PrintAndLog("Reading memory from tag UID=%s",sprintUID(NULL,uid));
461 PrintAndLog("Tag Info: %s",getTagInfo(uid));
462
463 for (int retry=0; retry<5; retry++) {
464
465 req[0]= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
466 ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
467 req[1]=ISO15_CMD_READ;
468 memcpy(&req[2],uid,8);
469 req[10]=blocknum;
470 reqlen=AddCrc(req,11);
471 c.arg[0]=reqlen;
472
473 SendCommand(&c);
474
475 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
476 recv = resp.d.asBytes;
477 if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
478 if (!(recv[0] & ISO15_RES_ERROR)) {
479 retry=0;
480 *output=0; // reset outputstring
481 sprintf(output, "Block %02x ",blocknum);
482 for ( int i=1; i<resp.arg[0]-2; i++) { // data in hex
483 sprintf(output+strlen(output),"%02X ",recv[i]);
484 }
485 strcat(output," ");
486 for ( int i=1; i<resp.arg[0]-2; i++) { // data in cleaned ascii
487 sprintf(output+strlen(output),"%c",(recv[i]>31 && recv[i]<127)?recv[i]:'.');
488 }
489 PrintAndLog("%s",output);
490 blocknum++;
491 // PrintAndLog("bn=%i",blocknum);
492 } else {
493 PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
494 return 1;
495 }
496 } // else PrintAndLog("crc");
497 } // else PrintAndLog("r null");
498 } // retry
499 // TODO: need fix
500 // if (resp.arg[0]<3)
501 // PrintAndLog("Lost Connection");
502 // else if (ISO15_CRC_CHECK!=Crc(resp.d.asBytes,resp.arg[0]))
503 // PrintAndLog("CRC Failed");
504 // else
505 // PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
506 return 1;
507 }
508
509
510 // "HF 15" interface
511
512 static command_t CommandTable15[] =
513 {
514 {"help", CmdHF15Help, 1, "This help"},
515 {"demod", CmdHF15Demod, 1, "Demodulate ISO15693 from tag"},
516 {"read", CmdHF15Read, 0, "Read HF tag (ISO 15693)"},
517 {"record", CmdHF15Record, 0, "Record Samples (ISO 15693)"}, // atrox
518 {"reader", CmdHF15Reader, 0, "Act like an ISO15693 reader"},
519 {"sim", CmdHF15Sim, 0, "Fake an ISO15693 tag"},
520 {"cmd", CmdHF15Cmd, 0, "Send direct commands to ISO15693 tag"},
521 {"findafi", CmdHF15Afi, 0, "Brute force AFI of an ISO15693 tag"},
522 {"dumpmemory", CmdHF15DumpMem, 0, "Read all memory pages of an ISO15693 tag"},
523 {NULL, NULL, 0, NULL}
524 };
525
526 int CmdHF15(const char *Cmd)
527 {
528 CmdsParse(CommandTable15, Cmd);
529 return 0;
530 }
531
532 int CmdHF15Help(const char *Cmd)
533 {
534 CmdsHelp(CommandTable15);
535 return 0;
536 }
537
538
539 // "HF 15 Cmd" Interface
540 // Allows direct communication with the tag on command level
541
542 int CmdHF15CmdInquiry(const char *Cmd)
543 {
544 UsbCommand resp;
545 uint8_t *recv;
546 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
547 uint8_t *req=c.d.asBytes;
548 int reqlen=0;
549
550 req[0]= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
551 ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
552 req[1]=ISO15_CMD_INVENTORY;
553 req[2]=0; // mask length
554 reqlen=AddCrc(req,3);
555 c.arg[0]=reqlen;
556
557 SendCommand(&c);
558
559 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
560 if (resp.arg[0]>=12) {
561 recv = resp.d.asBytes;
562 PrintAndLog("UID=%s",sprintUID(NULL,&recv[2]));
563 PrintAndLog("Tag Info: %s",getTagInfo(&recv[2]));
564 } else {
565 PrintAndLog("Response to short, just %i bytes. No tag?\n",resp.arg[0]);
566 }
567 } else {
568 PrintAndLog("timeout.");
569 }
570 return 0;
571 }
572
573
574 // Turns debugging on(1)/off(0)
575 int CmdHF15CmdDebug( const char *cmd) {
576 int debug = atoi(cmd);
577 if (strlen(cmd) < 1) {
578 PrintAndLog("Usage: hf 15 debug <0|1>");
579 PrintAndLog(" 0 no debugging");
580 PrintAndLog(" 1 turn debugging on");
581 return 0;
582 }
583
584 UsbCommand c = {CMD_ISO_15693_DEBUG, {debug, 0, 0}};
585 SendCommand(&c);
586 return 0;
587 }
588
589
590 int CmdHF15CmdRaw (const char *cmd) {
591 UsbCommand resp;
592 uint8_t *recv;
593 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
594 int reply=1;
595 int fast=1;
596 int crc=0;
597 char buf[5]="";
598 int i=0;
599 uint8_t data[100];
600 unsigned int datalen=0, temp;
601 char *hexout;
602
603
604 if (strlen(cmd)<3) {
605 PrintAndLog("Usage: hf 15 cmd raw [-r] [-2] [-c] <0A 0B 0C ... hex>");
606 PrintAndLog(" -r do not read response");
607 PrintAndLog(" -2 use slower '1 out of 256' mode");
608 PrintAndLog(" -c calculate and append CRC");
609 PrintAndLog(" Tip: turn on debugging for verbose output");
610 return 0;
611 }
612
613 // strip
614 while (*cmd==' ' || *cmd=='\t') cmd++;
615
616 while (cmd[i]!='\0') {
617 if (cmd[i]==' ' || cmd[i]=='\t') { i++; continue; }
618 if (cmd[i]=='-') {
619 switch (cmd[i+1]) {
620 case 'r':
621 case 'R':
622 reply=0;
623 break;
624 case '2':
625 fast=0;
626 break;
627 case 'c':
628 case 'C':
629 crc=1;
630 break;
631 default:
632 PrintAndLog("Invalid option");
633 return 0;
634 }
635 i+=2;
636 continue;
637 }
638 if ((cmd[i]>='0' && cmd[i]<='9') ||
639 (cmd[i]>='a' && cmd[i]<='f') ||
640 (cmd[i]>='A' && cmd[i]<='F') ) {
641 buf[strlen(buf)+1]=0;
642 buf[strlen(buf)]=cmd[i];
643 i++;
644
645 if (strlen(buf)>=2) {
646 sscanf(buf,"%x",&temp);
647 data[datalen]=(uint8_t)(temp & 0xff);
648 datalen++;
649 *buf=0;
650 }
651 continue;
652 }
653 PrintAndLog("Invalid char on input");
654 return 0;
655 }
656 if (crc) datalen=AddCrc(data,datalen);
657
658 c.arg[0]=datalen;
659 c.arg[1]=fast;
660 c.arg[2]=reply;
661 memcpy(c.d.asBytes,data,datalen);
662
663 SendCommand(&c);
664
665 if (reply) {
666 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
667 recv = resp.d.asBytes;
668 PrintAndLog("received %i octets",resp.arg[0]);
669 hexout = (char *)malloc(resp.arg[0] * 3 + 1);
670 if (hexout != NULL) {
671 for (int i = 0; i < resp.arg[0]; i++) { // data in hex
672 sprintf(&hexout[i * 3], "%02X ", recv[i]);
673 }
674 PrintAndLog("%s", hexout);
675 free(hexout);
676 }
677 } else {
678 PrintAndLog("timeout while waiting for reply.");
679 }
680
681 } // if reply
682 return 0;
683 }
684
685
686 /**
687 * parses common HF 15 CMD parameters and prepares some data structures
688 * Parameters:
689 * **cmd command line
690 */
691 int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) {
692 int temp;
693 uint8_t *req=c->d.asBytes;
694 uint8_t uid[8] = {0x00};
695 uint32_t reqlen=0;
696
697 // strip
698 while (**cmd==' ' || **cmd=='\t') (*cmd)++;
699
700 if (strstr(*cmd,"-2")==*cmd) {
701 c->arg[1]=0; // use 1of256
702 (*cmd)+=2;
703 }
704
705 // strip
706 while (**cmd==' ' || **cmd=='\t') (*cmd)++;
707
708 if (strstr(*cmd,"-o")==*cmd) {
709 req[reqlen]=ISO15_REQ_OPTION;
710 (*cmd)+=2;
711 }
712
713 // strip
714 while (**cmd==' ' || **cmd=='\t') (*cmd)++;
715
716 switch (**cmd) {
717 case 0:
718 PrintAndLog("missing addr");
719 return 0;
720 break;
721 case 's':
722 case 'S':
723 // you must have selected the tag earlier
724 req[reqlen++]|= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
725 ISO15_REQ_NONINVENTORY | ISO15_REQ_SELECT;
726 memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
727 reqlen+=iso15cmdlen;
728 break;
729 case 'u':
730 case 'U':
731 // unaddressed mode may not be supported by all vendors
732 req[reqlen++]|= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
733 ISO15_REQ_NONINVENTORY;
734 memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
735 reqlen+=iso15cmdlen;
736 break;
737 case '*':
738 // we scan for the UID ourself
739 req[reqlen++]|= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
740 ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
741 memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
742 reqlen+=iso15cmdlen;
743 if (!getUID(uid)) {
744 PrintAndLog("No Tag found");
745 return 0;
746 }
747 memcpy(req+reqlen,uid,8);
748 PrintAndLog("Detected UID %s",sprintUID(NULL,uid));
749 reqlen+=8;
750 break;
751 default:
752 req[reqlen++]|= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH |
753 ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS;
754 memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen);
755 reqlen+=iso15cmdlen;
756
757 /* sscanf(cmd,"%hX%hX%hX%hX%hX%hX%hX%hX",
758 (short unsigned int *)&uid[7],(short unsigned int *)&uid[6],
759 (short unsigned int *)&uid[5],(short unsigned int *)&uid[4],
760 (short unsigned int *)&uid[3],(short unsigned int *)&uid[2],
761 (short unsigned int *)&uid[1],(short unsigned int *)&uid[0]); */
762 for (int i=0;i<8 && (*cmd)[i*2] && (*cmd)[i*2+1];i++) { // parse UID
763 sscanf((char[]){(*cmd)[i*2],(*cmd)[i*2+1],0},"%X",&temp);
764 uid[7-i]=temp&0xff;
765 }
766
767 PrintAndLog("Using UID %s",sprintUID(NULL,uid));
768 memcpy(&req[reqlen],&uid[0],8);
769 reqlen+=8;
770 }
771 // skip to next space
772 while (**cmd!=' ' && **cmd!='\t') (*cmd)++;
773 // skip over the space
774 while (**cmd==' ' || **cmd=='\t') (*cmd)++;
775
776 c->arg[0]=reqlen;
777 return 1;
778 }
779
780 /**
781 * Commandline handling: HF15 CMD SYSINFO
782 * get system information from tag/VICC
783 */
784 int CmdHF15CmdSysinfo(const char *Cmd) {
785 UsbCommand resp;
786 uint8_t *recv;
787 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
788 uint8_t *req=c.d.asBytes;
789 int reqlen=0;
790 char cmdbuf[100];
791 char *cmd=cmdbuf;
792 char output[2048]="";
793 int i;
794
795 strncpy(cmd,Cmd,99);
796
797 // usage:
798 if (strlen(cmd)<1) {
799 PrintAndLog("Usage: hf 15 cmd sysinfo [options] <uid|s|u|*>");
800 PrintAndLog(" options:");
801 PrintAndLog(" -2 use slower '1 out of 256' mode");
802 PrintAndLog(" uid (either): ");
803 PrintAndLog(" <8B hex> full UID eg E011223344556677");
804 PrintAndLog(" s selected tag");
805 PrintAndLog(" u unaddressed mode");
806 PrintAndLog(" * scan for tag");
807 PrintAndLog(" start#: page number to start 0-255");
808 PrintAndLog(" count#: number of pages");
809 return 0;
810 }
811
812 prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15_CMD_SYSINFO},1);
813 reqlen=c.arg[0];
814
815 reqlen=AddCrc(req,reqlen);
816 c.arg[0]=reqlen;
817
818 SendCommand(&c);
819
820 if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
821 recv = resp.d.asBytes;
822 if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
823 if (!(recv[0] & ISO15_RES_ERROR)) {
824 *output=0; // reset outputstring
825 for ( i=1; i<resp.arg[0]-2; i++) {
826 sprintf(output+strlen(output),"%02X ",recv[i]);
827 }
828 strcat(output,"\n\r");
829 strcat(output,"UID = ");
830 strcat(output,sprintUID(NULL,recv+2));
831 strcat(output,"\n\r");
832 strcat(output,getTagInfo(recv+2)); //ABC
833 strcat(output,"\n\r");
834 i=10;
835 if (recv[1] & 0x01)
836 sprintf(output+strlen(output),"DSFID supported, set to %02X\n\r",recv[i++]);
837 else
838 strcat(output,"DSFID not supported\n\r");
839 if (recv[1] & 0x02)
840 sprintf(output+strlen(output),"AFI supported, set to %03X\n\r",recv[i++]);
841 else
842 strcat(output,"AFI not supported\n\r");
843 if (recv[1] & 0x04) {
844 strcat(output,"Tag provides info on memory layout (vendor dependent)\n\r");
845 sprintf(output+strlen(output)," %i (or %i) bytes/page x %i pages \n\r",
846 (recv[i+1]&0x1F)+1, (recv[i+1]&0x1F), recv[i]+1);
847 i+=2;
848 } else
849 strcat(output,"Tag does not provide information on memory layout\n\r");
850 if (recv[1] & 0x08) sprintf(output+strlen(output),"IC reference given: %02X\n\r",recv[i++]);
851 else strcat(output,"IC reference not given\n\r");
852
853
854 PrintAndLog("%s",output);
855 } else {
856 PrintAndLog("Tag returned Error %i: %s",recv[0],TagErrorStr(recv[0]));
857 }
858 } else {
859 PrintAndLog("CRC failed");
860 }
861 } else {
862 PrintAndLog("timeout: no answer");
863 }
864
865 return 0;
866 }
867
868 /**
869 * Commandline handling: HF15 CMD READMULTI
870 * Read multiple blocks at once (not all tags support this)
871 */
872 int CmdHF15CmdReadmulti(const char *Cmd) {
873 UsbCommand resp;
874 uint8_t *recv;
875 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
876 uint8_t *req=c.d.asBytes;
877 int reqlen=0, pagenum,pagecount;
878 char cmdbuf[100];
879 char *cmd=cmdbuf;
880 char output[2048]="";
881
882 strncpy(cmd,Cmd,99);
883
884 // usage:
885 if (strlen(cmd)<3) {
886 PrintAndLog("Usage: hf 15 cmd readmulti [options] <uid|s|u|*> <start#> <count#>");
887 PrintAndLog(" options:");
888 PrintAndLog(" -2 use slower '1 out of 256' mode");
889 PrintAndLog(" uid (either): ");
890 PrintAndLog(" <8B hex> full UID eg E011223344556677");
891 PrintAndLog(" s selected tag");
892 PrintAndLog(" u unaddressed mode");
893 PrintAndLog(" * scan for tag");
894 PrintAndLog(" start#: page number to start 0-255");
895 PrintAndLog(" count#: number of pages");
896 return 0;
897 }
898
899 prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15_CMD_READMULTI},1);
900 reqlen=c.arg[0];
901
902 pagenum=strtol(cmd,NULL,0);
903
904 // skip to next space
905 while (*cmd!=' ' && *cmd!='\t') cmd++;
906 // skip over the space
907 while (*cmd==' ' || *cmd=='\t') cmd++;
908
909 pagecount=strtol(cmd,NULL,0);
910 if (pagecount>0) pagecount--; // 0 means 1 page, 1 means 2 pages, ...
911
912 req[reqlen++]=(uint8_t)pagenum;
913 req[reqlen++]=(uint8_t)pagecount;
914
915 reqlen=AddCrc(req,reqlen);
916
917 c.arg[0]=reqlen;
918
919 SendCommand(&c);
920
921 if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
922 recv = resp.d.asBytes;
923 if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
924 if (!(recv[0] & ISO15_RES_ERROR)) {
925 *output=0; // reset outputstring
926 for ( int i=1; i<resp.arg[0]-2; i++) {
927 sprintf(output+strlen(output),"%02X ",recv[i]);
928 }
929 strcat(output," ");
930 for ( int i=1; i<resp.arg[0]-2; i++) {
931 sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
932 }
933 PrintAndLog("%s",output);
934 } else {
935 PrintAndLog("Tag returned Error %i: %s",recv[0],TagErrorStr(recv[0]));
936 }
937 } else {
938 PrintAndLog("CRC failed");
939 }
940 } else {
941 PrintAndLog("no answer");
942 }
943
944 return 0;
945 }
946
947 /**
948 * Commandline handling: HF15 CMD READ
949 * Reads a single Block
950 */
951 int CmdHF15CmdRead(const char *Cmd) {
952 UsbCommand resp;
953 uint8_t *recv;
954 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
955 uint8_t *req=c.d.asBytes;
956 int reqlen=0, pagenum;
957 char cmdbuf[100];
958 char *cmd=cmdbuf;
959 char output[100]="";
960
961 strncpy(cmd,Cmd,99);
962
963 // usage:
964 if (strlen(cmd)<3) {
965 PrintAndLog("Usage: hf 15 cmd read [options] <uid|s|u|*> <page#>");
966 PrintAndLog(" options:");
967 PrintAndLog(" -2 use slower '1 out of 256' mode");
968 PrintAndLog(" uid (either): ");
969 PrintAndLog(" <8B hex> full UID eg E011223344556677");
970 PrintAndLog(" s selected tag");
971 PrintAndLog(" u unaddressed mode");
972 PrintAndLog(" * scan for tag");
973 PrintAndLog(" page#: page number 0-255");
974 return 0;
975 }
976
977 prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15_CMD_READ},1);
978 reqlen=c.arg[0];
979
980 pagenum=strtol(cmd,NULL,0);
981 /*if (pagenum<0) {
982 PrintAndLog("invalid pagenum");
983 return 0;
984 } */
985
986 req[reqlen++]=(uint8_t)pagenum;
987
988 reqlen=AddCrc(req,reqlen);
989
990 c.arg[0]=reqlen;
991
992 SendCommand(&c);
993
994 if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
995 recv = resp.d.asBytes;
996 if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
997 if (!(recv[0] & ISO15_RES_ERROR)) {
998 *output=0; // reset outputstring
999 //sprintf(output, "Block %2i ",blocknum);
1000 for ( int i=1; i<resp.arg[0]-2; i++) {
1001 sprintf(output+strlen(output),"%02X ",recv[i]);
1002 }
1003 strcat(output," ");
1004 for ( int i=1; i<resp.arg[0]-2; i++) {
1005 sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
1006 }
1007 PrintAndLog("%s",output);
1008 } else {
1009 PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
1010 }
1011 } else {
1012 PrintAndLog("CRC failed");
1013 }
1014 } else {
1015 PrintAndLog("no answer");
1016 }
1017
1018 return 0;
1019 }
1020
1021
1022 /**
1023 * Commandline handling: HF15 CMD WRITE
1024 * Writes a single Block - might run into timeout, even when successful
1025 */
1026 int CmdHF15CmdWrite(const char *Cmd) {
1027 UsbCommand resp;
1028 uint8_t *recv;
1029 UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
1030 uint8_t *req=c.d.asBytes;
1031 int reqlen=0, pagenum, temp;
1032 char cmdbuf[100];
1033 char *cmd=cmdbuf;
1034 char *cmd2;
1035
1036 strncpy(cmd,Cmd,99);
1037
1038 // usage:
1039 if (strlen(cmd)<3) {
1040 PrintAndLog("Usage: hf 15 cmd write [options] <uid|s|u|*> <page#> <hexdata>");
1041 PrintAndLog(" options:");
1042 PrintAndLog(" -2 use slower '1 out of 256' mode");
1043 PrintAndLog(" -o set OPTION Flag (needed for TI)");
1044 PrintAndLog(" uid (either): ");
1045 PrintAndLog(" <8B hex> full UID eg E011223344556677");
1046 PrintAndLog(" s selected tag");
1047 PrintAndLog(" u unaddressed mode");
1048 PrintAndLog(" * scan for tag");
1049 PrintAndLog(" page#: page number 0-255");
1050 PrintAndLog(" hexdata: data to be written eg AA BB CC DD");
1051 return 0;
1052 }
1053
1054 prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15_CMD_WRITE},1);
1055 reqlen=c.arg[0];
1056
1057 // *cmd -> page num ; *cmd2 -> data
1058 cmd2=cmd;
1059 while (*cmd2!=' ' && *cmd2!='\t' && *cmd2) cmd2++;
1060 *cmd2=0;
1061 cmd2++;
1062
1063 pagenum=strtol(cmd,NULL,0);
1064 /*if (pagenum<0) {
1065 PrintAndLog("invalid pagenum");
1066 return 0;
1067 } */
1068 req[reqlen++]=(uint8_t)pagenum;
1069
1070
1071 while (cmd2[0] && cmd2[1]) { // hexdata, read by 2 hexchars
1072 if (*cmd2==' ') {
1073 cmd2++;
1074 continue;
1075 }
1076 sscanf((char[]){cmd2[0],cmd2[1],0},"%X",&temp);
1077 req[reqlen++]=temp & 0xff;
1078 cmd2+=2;
1079 }
1080
1081 reqlen=AddCrc(req,reqlen);
1082
1083 c.arg[0]=reqlen;
1084
1085 SendCommand(&c);
1086
1087 if (WaitForResponseTimeout(CMD_ACK,&resp,2000) && resp.arg[0]>2) {
1088 recv = resp.d.asBytes;
1089 if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
1090 if (!(recv[0] & ISO15_RES_ERROR)) {
1091 PrintAndLog("OK");
1092 } else {
1093 PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
1094 }
1095 } else {
1096 PrintAndLog("CRC failed");
1097 }
1098 } else {
1099 PrintAndLog("timeout: no answer - data may be written anyway");
1100 }
1101
1102 return 0;
1103 }
1104
1105
1106
1107 static command_t CommandTable15Cmd[] =
1108 {
1109 {"help", CmdHF15CmdHelp, 1, "This Help"},
1110 {"inquiry", CmdHF15CmdInquiry, 0, "Search for tags in range"},
1111 /*
1112 {"select", CmdHF15CmdSelect, 0, "Select an tag with a specific UID for further commands"},
1113 */
1114 {"read", CmdHF15CmdRead, 0, "Read a block"},
1115 {"write", CmdHF15CmdWrite, 0, "Write a block"},
1116 {"readmulti",CmdHF15CmdReadmulti, 0, "Reads multiple Blocks"},
1117 {"sysinfo",CmdHF15CmdSysinfo, 0, "Get Card Information"},
1118 {"raw", CmdHF15CmdRaw, 0, "Send raw hex data to tag"},
1119 {"debug", CmdHF15CmdDebug, 0, "Turn debugging on/off"},
1120 {NULL, NULL, 0, NULL}
1121 };
1122
1123 int CmdHF15Cmd(const char *Cmd)
1124 {
1125 CmdsParse(CommandTable15Cmd, Cmd);
1126 return 0;
1127 }
1128
1129 int CmdHF15CmdHelp(const char *Cmd)
1130 {
1131 CmdsHelp(CommandTable15Cmd);
1132 return 0;
1133 }
1134
Impressum, Datenschutz