]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhf14b.c
fix 'hf iclass sim':
[proxmark3-svn] / client / cmdhf14b.c
CommitLineData
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 ISO14443B commands
9//-----------------------------------------------------------------------------
10
ad939de5 11#include "cmdhf14b.h"
12
7fe9b0b7 13#include <stdio.h>
14#include <stdlib.h>
15#include <stdbool.h>
16#include <string.h>
17#include <stdint.h>
18#include "iso14443crc.h"
ad939de5 19#include "comms.h"
7fe9b0b7 20#include "graph.h"
3fe4ff4f 21#include "util.h"
7fe9b0b7 22#include "ui.h"
23#include "cmdparser.h"
7cf3ef20 24#include "cmdmain.h"
1338d245 25#include "taginfo.h"
26
7fe9b0b7 27
28static int CmdHelp(const char *Cmd);
29
7fe9b0b7 30int CmdHF14BList(const char *Cmd)
31{
388c92bd 32 PrintAndLog("Deprecated command, use 'hf list 14b' instead");
7fe9b0b7 33
388c92bd 34 return 0;
7fe9b0b7 35}
7fe9b0b7 36
132a0217 37int CmdHF14BSim(const char *Cmd)
7fe9b0b7 38{
132a0217 39 UsbCommand c={CMD_SIMULATE_TAG_ISO_14443B};
ff4fdb32 40 clearCommandBuffer();
7fe9b0b7 41 SendCommand(&c);
42 return 0;
43}
44
45int CmdHF14BSnoop(const char *Cmd)
46{
132a0217 47 UsbCommand c = {CMD_SNOOP_ISO_14443B};
ff4fdb32 48 clearCommandBuffer();
7fe9b0b7 49 SendCommand(&c);
50 return 0;
51}
52
53/* New command to read the contents of a SRI512 tag
54 * SRI512 tags are ISO14443-B modulated memory tags,
55 * this command just dumps the contents of the memory
56 */
57int CmdSri512Read(const char *Cmd)
58{
59 UsbCommand c = {CMD_READ_SRI512_TAG, {strtol(Cmd, NULL, 0), 0, 0}};
ff4fdb32 60 clearCommandBuffer();
7fe9b0b7 61 SendCommand(&c);
62 return 0;
63}
64
65/* New command to read the contents of a SRIX4K tag
66 * SRIX4K tags are ISO14443-B modulated memory tags,
67 * this command just dumps the contents of the memory/
68 */
69int CmdSrix4kRead(const char *Cmd)
70{
71 UsbCommand c = {CMD_READ_SRIX4K_TAG, {strtol(Cmd, NULL, 0), 0, 0}};
ff4fdb32 72 clearCommandBuffer();
7fe9b0b7 73 SendCommand(&c);
74 return 0;
75}
76
ff4fdb32 77int rawClose(void){
78 UsbCommand resp;
79 UsbCommand c = {CMD_ISO_14443B_COMMAND, {0, 0, 0}};
80 clearCommandBuffer();
81 SendCommand(&c);
82 if (!WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
83 return 0;
84 }
85 return 0;
86}
87
88int HF14BCmdRaw(bool reply, bool *crc, bool power, uint8_t *data, uint8_t *datalen, bool verbose){
89 UsbCommand resp;
90 UsbCommand c = {CMD_ISO_14443B_COMMAND, {0, 0, 0}}; // len,recv,power
91 if(*crc)
92 {
93 uint8_t first, second;
94 ComputeCrc14443(CRC_14443_B, data, *datalen, &first, &second);
95 data[*datalen] = first;
96 data[*datalen + 1] = second;
97 *datalen += 2;
98 }
99
100 c.arg[0] = *datalen;
101 c.arg[1] = reply;
102 c.arg[2] = power;
103 memcpy(c.d.asBytes,data,*datalen);
104 clearCommandBuffer();
105 SendCommand(&c);
106
107 if (!reply) return 1;
108
109 if (!WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
110 if (verbose) PrintAndLog("timeout while waiting for reply.");
111 return 0;
112 }
113 *datalen = resp.arg[0];
114 if (verbose) PrintAndLog("received %u octets", *datalen);
115 if(*datalen<2) return 0;
116
117 memcpy(data, resp.d.asBytes, *datalen);
118 if (verbose) PrintAndLog("%s", sprint_hex(data, *datalen));
119
120 uint8_t first, second;
121 ComputeCrc14443(CRC_14443_B, data, *datalen-2, &first, &second);
122 if(data[*datalen-2] == first && data[*datalen-1] == second) {
123 if (verbose) PrintAndLog("CRC OK");
124 *crc = true;
125 } else {
126 if (verbose) PrintAndLog("CRC failed");
127 *crc = false;
128 }
129 return 1;
130}
131
132int CmdHF14BCmdRaw (const char *Cmd) {
133 bool reply = true;
134 bool crc = false;
135 bool power = false;
b8edab0f 136 bool select = false;
7ce6e2c0 137 bool SRx = false;
ff4fdb32 138 char buf[5] = "";
139 uint8_t data[100] = {0x00};
140 uint8_t datalen = 0;
141 unsigned int temp;
142 int i = 0;
143 if (strlen(Cmd)<3) {
7ce6e2c0 144 PrintAndLog("Usage: hf 14b raw [-r] [-c] [-p] [-s || -ss] <0A 0B 0C ... hex>");
ff4fdb32 145 PrintAndLog(" -r do not read response");
146 PrintAndLog(" -c calculate and append CRC");
147 PrintAndLog(" -p leave the field on after receive");
b8edab0f 148 PrintAndLog(" -s active signal field ON with select");
7ce6e2c0 149 PrintAndLog(" -ss active signal field ON with select for SRx ST Microelectronics tags");
b8edab0f 150 return 0;
ff4fdb32 151 }
152
153 // strip
154 while (*Cmd==' ' || *Cmd=='\t') Cmd++;
155
156 while (Cmd[i]!='\0') {
157 if (Cmd[i]==' ' || Cmd[i]=='\t') { i++; continue; }
158 if (Cmd[i]=='-') {
159 switch (Cmd[i+1]) {
160 case 'r':
161 case 'R':
162 reply = false;
163 break;
164 case 'c':
165 case 'C':
166 crc = true;
167 break;
168 case 'p':
169 case 'P':
170 power = true;
171 break;
b8edab0f 172 case 's':
173 case 'S':
174 select = true;
7ce6e2c0 175 if (Cmd[i+2]=='s' || Cmd[i+2]=='S') {
176 SRx = true;
177 i++;
178 }
b8edab0f 179 break;
ff4fdb32 180 default:
181 PrintAndLog("Invalid option");
182 return 0;
183 }
184 i+=2;
185 continue;
186 }
187 if ((Cmd[i]>='0' && Cmd[i]<='9') ||
188 (Cmd[i]>='a' && Cmd[i]<='f') ||
189 (Cmd[i]>='A' && Cmd[i]<='F') ) {
190 buf[strlen(buf)+1]=0;
191 buf[strlen(buf)]=Cmd[i];
192 i++;
193
194 if (strlen(buf)>=2) {
195 sscanf(buf,"%x",&temp);
196 data[datalen++]=(uint8_t)(temp & 0xff);
197 *buf=0;
198 }
199 continue;
200 }
201 PrintAndLog("Invalid char on input");
7ce6e2c0 202 return 0;
ff4fdb32 203 }
204 if (datalen == 0)
205 {
206 PrintAndLog("Missing data input");
207 return 0;
208 }
209
1c7d367e 210 if (select){ //auto select 14b tag
b8edab0f 211 uint8_t cmd2[16];
b8edab0f 212 bool crc2 = true;
7ce6e2c0 213 uint8_t cmdLen;
b8edab0f 214
7ce6e2c0 215 if (SRx) {
216 // REQ SRx
217 cmdLen = 2;
218 cmd2[0] = 0x06;
219 cmd2[1] = 0x00;
220 } else {
221 cmdLen = 3;
222 // REQB
223 cmd2[0] = 0x05;
224 cmd2[1] = 0x00;
225 cmd2[2] = 0x08;
226 }
b8edab0f 227
7ce6e2c0 228 if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false)==0) return rawClose();
b8edab0f 229
7ce6e2c0 230 if ( SRx && (cmdLen != 3 || !crc2) ) return rawClose();
231 else if (cmd2[0] != 0x50 || cmdLen != 14 || !crc2) return rawClose();
232
233 uint8_t chipID = 0;
234 if (SRx) {
235 // select
236 chipID = cmd2[0];
237 cmd2[0] = 0x0E;
238 cmd2[1] = chipID;
239 cmdLen = 2;
240 } else {
241 // attrib
242 cmd2[0] = 0x1D;
243 // UID from cmd2[1 - 4]
244 cmd2[5] = 0x00;
245 cmd2[6] = 0x08;
246 cmd2[7] = 0x01;
247 cmd2[8] = 0x00;
248 cmdLen = 9;
249 }
1c7d367e 250
b8edab0f 251 if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false)==0) return rawClose();
252
f3b83bee 253 if (cmdLen != 3 || !crc2) return rawClose();
7ce6e2c0 254 if (SRx && cmd2[0] != chipID) return rawClose();
b8edab0f 255 }
ff4fdb32 256 return HF14BCmdRaw(reply, &crc, power, data, &datalen, true);
7cf3ef20 257}
258
b29d55f2 259// print full atqb info
ff4fdb32 260static void print_atqb_resp(uint8_t *data){
f3b83bee 261 //PrintAndLog (" UID: %s", sprint_hex(data+1,4));
ff4fdb32 262 PrintAndLog (" App Data: %s", sprint_hex(data+5,4));
263 PrintAndLog (" Protocol: %s", sprint_hex(data+9,3));
264 uint8_t BitRate = data[9];
265 if (!BitRate)
266 PrintAndLog (" Bit Rate: 106 kbit/s only PICC <-> PCD");
267 if (BitRate & 0x10)
268 PrintAndLog (" Bit Rate: 212 kbit/s PICC -> PCD supported");
269 if (BitRate & 0x20)
270 PrintAndLog (" Bit Rate: 424 kbit/s PICC -> PCD supported");
271 if (BitRate & 0x40)
272 PrintAndLog (" Bit Rate: 847 kbit/s PICC -> PCD supported");
273 if (BitRate & 0x01)
274 PrintAndLog (" Bit Rate: 212 kbit/s PICC <- PCD supported");
275 if (BitRate & 0x02)
276 PrintAndLog (" Bit Rate: 424 kbit/s PICC <- PCD supported");
277 if (BitRate & 0x04)
278 PrintAndLog (" Bit Rate: 847 kbit/s PICC <- PCD supported");
279 if (BitRate & 0x80)
280 PrintAndLog (" Same bit rate <-> required");
281
282 uint16_t maxFrame = data[10]>>4;
283 if (maxFrame < 5)
284 maxFrame = 8*maxFrame + 16;
285 else if (maxFrame == 5)
286 maxFrame = 64;
287 else if (maxFrame == 6)
288 maxFrame = 96;
289 else if (maxFrame == 7)
290 maxFrame = 128;
291 else if (maxFrame == 8)
292 maxFrame = 256;
293 else
294 maxFrame = 257;
295
f3b83bee 296 PrintAndLog ("Max Frame Size: %u%s",maxFrame, (maxFrame == 257) ? "+ RFU" : "");
ff4fdb32 297
298 uint8_t protocolT = data[10] & 0xF;
299 PrintAndLog (" Protocol Type: Protocol is %scompliant with ISO/IEC 14443-4",(protocolT) ? "" : "not " );
f3b83bee 300 PrintAndLog ("Frame Wait Int: %u", data[11]>>4);
ff4fdb32 301 PrintAndLog (" App Data Code: Application is %s",(data[11]&4) ? "Standard" : "Proprietary");
302 PrintAndLog (" Frame Options: NAD is %ssupported",(data[11]&2) ? "" : "not ");
303 PrintAndLog (" Frame Options: CID is %ssupported",(data[11]&1) ? "" : "not ");
f3b83bee 304 PrintAndLog ("Max Buf Length: %u (MBLI) %s",data[14]>>4, (data[14] & 0xF0) ? "" : "not supported");
ff4fdb32 305
306 return;
307}
308
ff4fdb32 309
cc34cc7b 310int print_ST_Lock_info(uint8_t model){
311 //assume connection open and tag selected...
c3ebcce4 312 uint8_t data[16] = {0x00};
cc34cc7b 313 uint8_t datalen = 2;
314 bool crc = true;
315 uint8_t resplen;
316 uint8_t blk1;
317 data[0] = 0x08;
318
319 if (model == 0x2) { //SR176 has special command:
320 data[1] = 0xf;
321 resplen = 4;
322 } else {
323 data[1] = 0xff;
324 resplen = 6;
325 }
326
327 //std read cmd
328 if (HF14BCmdRaw(true, &crc, true, data, &datalen, false)==0) return rawClose();
329
330 if (datalen != resplen || !crc) return rawClose();
331
332 PrintAndLog("Chip Write Protection Bits:");
333 // now interpret the data
334 switch (model){
335 case 0x0: //fall through (SRIX4K special)
336 case 0x3: //fall through (SRIx4K)
337 case 0x7: // (SRI4K)
338 //only need data[3]
339 blk1 = 9;
8e00825a 340 PrintAndLog(" raw: %s",printBits(1,data+3));
c3ebcce4 341 PrintAndLog(" 07/08:%slocked", (data[3] & 1) ? " not " : " " );
cc34cc7b 342 for (uint8_t i = 1; i<8; i++){
c3ebcce4 343 PrintAndLog(" %02u:%slocked", blk1, (data[3] & (1 << i)) ? " not " : " " );
cc34cc7b 344 blk1++;
345 }
346 break;
347 case 0x4: //fall through (SRIX512)
348 case 0x6: //fall through (SRI512)
349 case 0xC: // (SRT512)
350 //need data[2] and data[3]
351 blk1 = 0;
8e00825a 352 PrintAndLog(" raw: %s",printBits(2,data+2));
cc34cc7b 353 for (uint8_t b=2; b<4; b++){
354 for (uint8_t i=0; i<8; i++){
c3ebcce4 355 PrintAndLog(" %02u:%slocked", blk1, (data[b] & (1 << i)) ? " not " : " " );
cc34cc7b 356 blk1++;
357 }
358 }
359 break;
360 case 0x2: // (SR176)
361 //need data[2]
362 blk1 = 0;
8e00825a 363 PrintAndLog(" raw: %s",printBits(1,data+2));
cc34cc7b 364 for (uint8_t i = 0; i<8; i++){
c3ebcce4 365 PrintAndLog(" %02u/%02u:%slocked", blk1, blk1+1, (data[2] & (1 << i)) ? " " : " not " );
cc34cc7b 366 blk1+=2;
367 }
368 break;
369 default:
370 return rawClose();
371 }
372 return 1;
373}
374
b29d55f2 375// print UID info from SRx chips (ST Microelectronics)
376static void print_st_general_info(uint8_t *data){
ff4fdb32 377 //uid = first 8 bytes in data
cc34cc7b 378 PrintAndLog(" UID: %s", sprint_hex(SwapEndian64(data,8,8),8));
1338d245 379 PrintAndLog(" MFG: %02X, %s", data[6], getManufacturerName(data[6]));
380 PrintAndLog(" Chip: %02X, %s", data[5], getChipInfo(data[6], data[5]));
ff4fdb32 381 return;
382}
383
b29d55f2 384// 14b get and print UID only (general info)
385int HF14BStdReader(uint8_t *data, uint8_t *datalen){
ff4fdb32 386 //05 00 00 = find one tag in field
b8edab0f 387 //1d xx xx xx xx 00 08 01 00 = attrib xx=UID (resp 10 [f9 e0])
388 //a3 = ? (resp 03 [e2 c2])
389 //02 = ? (resp 02 [6a d3])
ff4fdb32 390 // 022b (resp 02 67 00 [29 5b])
391 // 0200a40400 (resp 02 67 00 [29 5b])
392 // 0200a4040c07a0000002480300 (resp 02 67 00 [29 5b])
393 // 0200a4040c07a0000002480200 (resp 02 67 00 [29 5b])
394 // 0200a4040006a0000000010100 (resp 02 6a 82 [4b 4c])
395 // 0200a4040c09d27600002545500200 (resp 02 67 00 [29 5b])
396 // 0200a404000cd2760001354b414e4d30310000 (resp 02 6a 82 [4b 4c])
397 // 0200a404000ca000000063504b43532d313500 (resp 02 6a 82 [4b 4c])
398 // 0200a4040010a000000018300301000000000000000000 (resp 02 6a 82 [4b 4c])
399 //03 = ? (resp 03 [e3 c2])
400 //c2 = ? (resp c2 [66 15])
401 //b2 = ? (resp a3 [e9 67])
f3b83bee 402 //a2 = ? (resp 02 [6a d3])
ff4fdb32 403 bool crc = true;
404 *datalen = 3;
405 //std read cmd
406 data[0] = 0x05;
407 data[1] = 0x00;
14660057 408 data[2] = 0x08;
ff4fdb32 409
f3b83bee 410 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)==0) return rawClose();
ff4fdb32 411
f3b83bee 412 if (data[0] != 0x50 || *datalen != 14 || !crc) return rawClose();
ff4fdb32 413
414 PrintAndLog ("\n14443-3b tag found:");
b29d55f2 415 PrintAndLog (" UID: %s", sprint_hex(data+1,4));
ff4fdb32 416
f3b83bee 417 uint8_t cmd2[16];
418 uint8_t cmdLen = 3;
419 bool crc2 = true;
420
421 cmd2[0] = 0x1D;
422 // UID from data[1 - 4]
423 cmd2[1] = data[1];
424 cmd2[2] = data[2];
425 cmd2[3] = data[3];
426 cmd2[4] = data[4];
427 cmd2[5] = 0x00;
428 cmd2[6] = 0x08;
429 cmd2[7] = 0x01;
430 cmd2[8] = 0x00;
431 cmdLen = 9;
432
433 // attrib
434 if (HF14BCmdRaw(true, &crc2, true, cmd2, &cmdLen, false)==0) return rawClose();
435
436 if (cmdLen != 3 || !crc2) return rawClose();
437 // add attrib responce to data
438 data[14] = cmd2[0];
439 rawClose();
ff4fdb32 440 return 1;
441}
442
8a258b58 443// 14b get and print Full Info (as much as we know)
444int HF14BStdInfo(uint8_t *data, uint8_t *datalen){
445 if (!HF14BStdReader(data,datalen)) return 0;
b29d55f2 446
8a258b58 447 //add more info here
448 print_atqb_resp(data);
b29d55f2 449
f3b83bee 450
b29d55f2 451 return 1;
452}
453
454// SRx get and print general info about SRx chip from UID
cc34cc7b 455int HF14B_ST_Reader(uint8_t *data, uint8_t *datalen, bool closeCon){
ff4fdb32 456 bool crc = true;
457 *datalen = 2;
458 //wake cmd
459 data[0] = 0x06;
460 data[1] = 0x00;
461
462 //leave power on
463 // verbose on for now for testing - turn off when functional
464 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)==0) return rawClose();
465
466 if (*datalen != 3 || !crc) return rawClose();
467
468 uint8_t chipID = data[0];
469 // select
470 data[0] = 0x0E;
471 data[1] = chipID;
472 *datalen = 2;
473
474 //leave power on
ff4fdb32 475 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)==0) return rawClose();
476
477 if (*datalen != 3 || !crc || data[0] != chipID) return rawClose();
478
479 // get uid
480 data[0] = 0x0B;
481 *datalen = 1;
482
cc34cc7b 483 //leave power on
484 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)==0) return rawClose();
c3ebcce4 485
486 if (*datalen != 10 || !crc) return rawClose();
487
cc34cc7b 488 //power off ?
489 if (closeCon) rawClose();
490
ff4fdb32 491 PrintAndLog("\n14443-3b ST tag found:");
b29d55f2 492 print_st_general_info(data);
ff4fdb32 493 return 1;
494}
495
8a258b58 496// SRx get and print full info (needs more info...)
497int HF14B_ST_Info(uint8_t *data, uint8_t *datalen){
cc34cc7b 498 if (!HF14B_ST_Reader(data, datalen, false)) return 0;
8a258b58 499
500 //add locking bit information here.
cc34cc7b 501 if (print_ST_Lock_info(data[5]>>2))
502 rawClose();
8a258b58 503
504 return 1;
505}
506
ff4fdb32 507// test for other 14b type tags (mimic another reader - don't have tags to identify)
b29d55f2 508int HF14B_Other_Reader(uint8_t *data, uint8_t *datalen){
ff4fdb32 509 bool crc = true;
510 *datalen = 4;
511 //std read cmd
512 data[0] = 0x00;
513 data[1] = 0x0b;
514 data[2] = 0x3f;
515 data[3] = 0x80;
516
b29d55f2 517 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)!=0) {
ff4fdb32 518 if (*datalen > 2 || !crc) {
519 PrintAndLog ("\n14443-3b tag found:");
520 PrintAndLog ("Unknown tag type answered to a 0x000b3f80 command ans:");
521 PrintAndLog ("%s",sprint_hex(data,*datalen));
cc34cc7b 522 rawClose();
ff4fdb32 523 return 1;
524 }
525 }
526
527 crc = false;
528 *datalen = 1;
529 data[0] = 0x0a;
530
b29d55f2 531 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)!=0) {
ff4fdb32 532 if (*datalen > 0) {
533 PrintAndLog ("\n14443-3b tag found:");
534 PrintAndLog ("Unknown tag type answered to a 0x0A command ans:");
535 PrintAndLog ("%s",sprint_hex(data,*datalen));
cc34cc7b 536 rawClose();
ff4fdb32 537 return 1;
538 }
539 }
540
541 crc = false;
542 *datalen = 1;
543 data[0] = 0x0c;
544
b29d55f2 545 if (HF14BCmdRaw(true, &crc, true, data, datalen, false)!=0) {
ff4fdb32 546 if (*datalen > 0) {
547 PrintAndLog ("\n14443-3b tag found:");
548 PrintAndLog ("Unknown tag type answered to a 0x0C command ans:");
549 PrintAndLog ("%s",sprint_hex(data,*datalen));
cc34cc7b 550 rawClose();
ff4fdb32 551 return 1;
552 }
553 }
b29d55f2 554 rawClose();
ff4fdb32 555 return 0;
ff4fdb32 556}
557
b29d55f2 558// get and print all info known about any known 14b tag
ff4fdb32 559int HF14BInfo(bool verbose){
560 uint8_t data[100];
561 uint8_t datalen = 5;
562
563 // try std 14b (atqb)
564 if (HF14BStdInfo(data, &datalen)) return 1;
565
566 // try st 14b
567 if (HF14B_ST_Info(data, &datalen)) return 1;
568
569 // try unknown 14b read commands (to be identified later)
570 // could be read of calypso, CEPAS, moneo, or pico pass.
b29d55f2 571 if (HF14B_Other_Reader(data, &datalen)) return 1;
ff4fdb32 572
573 if (verbose) PrintAndLog("no 14443B tag found");
574 return 0;
575}
576
b29d55f2 577// menu command to get and print all info known about any known 14b tag
ff4fdb32 578int CmdHF14Binfo(const char *Cmd){
579 return HF14BInfo(true);
580}
3fe4ff4f 581
b29d55f2 582// get and print general info about all known 14b chips
583int HF14BReader(bool verbose){
584 uint8_t data[100];
585 uint8_t datalen = 5;
586
587 // try std 14b (atqb)
588 if (HF14BStdReader(data, &datalen)) return 1;
589
590 // try st 14b
cc34cc7b 591 if (HF14B_ST_Reader(data, &datalen, true)) return 1;
b29d55f2 592
593 // try unknown 14b read commands (to be identified later)
594 // could be read of calypso, CEPAS, moneo, or pico pass.
595 if (HF14B_Other_Reader(data, &datalen)) return 1;
596
597 if (verbose) PrintAndLog("no 14443B tag found");
598 return 0;
599}
600
601// menu command to get and print general info about all known 14b chips
602int CmdHF14BReader(const char *Cmd){
603 return HF14BReader(true);
604}
605
ff4fdb32 606int CmdSriWrite( const char *Cmd){
3fe4ff4f 607/*
608 * For SRIX4K blocks 00 - 7F
609 * hf 14b raw -c -p 09 $srix4kwblock $srix4kwdata
610 *
611 * For SR512 blocks 00 - 0F
612 * hf 14b raw -c -p 09 $sr512wblock $sr512wdata
613 *
614 * Special block FF = otp_lock_reg block.
615 * Data len 4 bytes-
616 */
617 char cmdp = param_getchar(Cmd, 0);
618 uint8_t blockno = -1;
619 uint8_t data[4] = {0x00};
620 bool isSrix4k = true;
621 char str[20];
622
b5be31f9 623 if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') {
3fe4ff4f 624 PrintAndLog("Usage: hf 14b write <1|2> <BLOCK> <DATA>");
b5be31f9 625 PrintAndLog(" [1 = SRIX4K]");
626 PrintAndLog(" [2 = SRI512]");
627 PrintAndLog(" [BLOCK number depends on tag, special block == FF]");
628 PrintAndLog(" sample: hf 14b write 1 7F 11223344");
629 PrintAndLog(" : hf 14b write 1 FF 11223344");
630 PrintAndLog(" : hf 14b write 2 15 11223344");
631 PrintAndLog(" : hf 14b write 2 FF 11223344");
3fe4ff4f 632 return 0;
633 }
634
b5be31f9 635 if ( cmdp == '2' )
3fe4ff4f 636 isSrix4k = false;
637
b5be31f9 638 //blockno = param_get8(Cmd, 1);
639
640 if ( param_gethex(Cmd,1, &blockno, 2) ) {
641 PrintAndLog("Block number must include 2 HEX symbols");
642 return 0;
643 }
3fe4ff4f 644
645 if ( isSrix4k ){
646 if ( blockno > 0x7f && blockno != 0xff ){
647 PrintAndLog("Block number out of range");
648 return 0;
649 }
650 } else {
651 if ( blockno > 0x0f && blockno != 0xff ){
652 PrintAndLog("Block number out of range");
653 return 0;
654 }
655 }
656
657 if (param_gethex(Cmd, 2, data, 8)) {
658 PrintAndLog("Data must include 8 HEX symbols");
659 return 0;
660 }
661
662 if ( blockno == 0xff)
b5be31f9 663 PrintAndLog("[%s] Write special block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512" , blockno, sprint_hex(data,4) );
3fe4ff4f 664 else
b5be31f9 665 PrintAndLog("[%s] Write block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512", blockno, sprint_hex(data,4) );
3fe4ff4f 666
fe5b3a44 667 sprintf(str, "-c 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
b5be31f9 668
3fe4ff4f 669 CmdHF14BCmdRaw(str);
670 return 0;
671}
672
7fe9b0b7 673static command_t CommandTable[] =
674{
675 {"help", CmdHelp, 1, "This help"},
b29d55f2 676 {"info", CmdHF14Binfo, 0, "Find and print details about a 14443B tag"},
677 {"list", CmdHF14BList, 0, "[Deprecated] List ISO 14443B history"},
678 {"reader", CmdHF14BReader, 0, "Act as a 14443B reader to identify a tag"},
132a0217 679 {"sim", CmdHF14BSim, 0, "Fake ISO 14443B tag"},
680 {"snoop", CmdHF14BSnoop, 0, "Eavesdrop ISO 14443B"},
7cf3ef20 681 {"sri512read", CmdSri512Read, 0, "Read contents of a SRI512 tag"},
682 {"srix4kread", CmdSrix4kRead, 0, "Read contents of a SRIX4K tag"},
ff4fdb32 683 {"sriwrite", CmdSriWrite, 0, "Write data to a SRI512 | SRIX4K tag"},
7cf3ef20 684 {"raw", CmdHF14BCmdRaw, 0, "Send raw hex data to tag"},
7fe9b0b7 685 {NULL, NULL, 0, NULL}
686};
687
688int CmdHF14B(const char *Cmd)
689{
690 CmdsParse(CommandTable, Cmd);
691 return 0;
692}
693
694int CmdHelp(const char *Cmd)
695{
696 CmdsHelp(CommandTable);
697 return 0;
698}
Impressum, Datenschutz