+// LED_A_ON();\r
+ GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
+// LED_A_OFF();\r
+\r
+ if (Demod.len == 0) {\r
+ DbpString("No response from tag");\r
+ return;\r
+ } else {\r
+ DbpString("Randomly generated UID from tag (+ 2 byte CRC):");\r
+ DbpIntegers(Demod.output[0], Demod.output[1],Demod.output[2]);\r
+ }\r
+ // There is a response, SELECT the uid\r
+ DbpString("Now SELECT tag:");\r
+ cmd1[0] = 0x0E; // 0x0E is SELECT\r
+ cmd1[1] = Demod.output[0];\r
+ ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);\r
+ CodeIso14443bAsReader(cmd1, sizeof(cmd1));\r
+ TransmitFor14443();\r
+// LED_A_ON();\r
+ GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
+// LED_A_OFF();\r
+ if (Demod.len != 3) {\r
+ DbpString("Expected 3 bytes from tag, got:");\r
+ DbpIntegers(Demod.len,0x0,0x0);\r
+ return;\r
+ }\r
+ // Check the CRC of the answer:\r
+ ComputeCrc14443(CRC_14443_B, Demod.output, 1 , &cmd1[2], &cmd1[3]);\r
+ if(cmd1[2] != Demod.output[1] || cmd1[3] != Demod.output[2]) {\r
+ DbpString("CRC Error reading select response.");\r
+ return;\r
+ }\r
+ // Check response from the tag: should be the same UID as the command we just sent:\r
+ if (cmd1[1] != Demod.output[0]) {\r
+ DbpString("Bad response to SELECT from Tag, aborting:");\r
+ DbpIntegers(cmd1[1],Demod.output[0],0x0);\r
+ return;\r
+ }\r
+ // Tag is now selected,\r
+ // First get the tag's UID:\r
+ cmd1[0] = 0x0B;\r
+ ComputeCrc14443(CRC_14443_B, cmd1, 1 , &cmd1[1], &cmd1[2]);\r
+ CodeIso14443bAsReader(cmd1, 3); // Only first three bytes for this one\r
+ TransmitFor14443();\r
+// LED_A_ON();\r
+ GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
+// LED_A_OFF();\r
+ if (Demod.len != 10) {\r
+ DbpString("Expected 10 bytes from tag, got:");\r
+ DbpIntegers(Demod.len,0x0,0x0);\r
+ return;\r
+ }\r
+ // The check the CRC of the answer (use cmd1 as temporary variable):\r
+ ComputeCrc14443(CRC_14443_B, Demod.output, 8, &cmd1[2], &cmd1[3]);\r
+ if(cmd1[2] != Demod.output[8] || cmd1[3] != Demod.output[9]) {\r
+ DbpString("CRC Error reading block! - Below: expected, got");\r
+ DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[8]<<8)+Demod.output[9],0);\r
+ // Do not return;, let's go on... (we should retry, maybe ?)\r
+ }\r
+ DbpString("Tag UID (64 bits):");\r
+ DbpIntegers((Demod.output[7]<<24) + (Demod.output[6]<<16) + (Demod.output[5]<<8) + Demod.output[4], (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], 0);\r
+\r
+ // Now loop to read all 16 blocks, address from 0 to 15\r
+ DbpString("Tag memory dump, block 0 to 15");\r
+ cmd1[0] = 0x08;\r
+ i = 0x00;\r
+ dwLast++;
+ for (;;) {\r
+ if (i == dwLast) {
+ DbpString("System area block (0xff):");\r
+ i = 0xff;\r
+ }\r
+ cmd1[1] = i;\r
+ ComputeCrc14443(CRC_14443_B, cmd1, 2, &cmd1[2], &cmd1[3]);\r
+ CodeIso14443bAsReader(cmd1, sizeof(cmd1));\r
+ TransmitFor14443();\r
+// LED_A_ON();\r
+ GetSamplesFor14443Demod(TRUE, 2000,TRUE);\r
+// LED_A_OFF();\r
+ if (Demod.len != 6) { // Check if we got an answer from the tag\r
+ DbpString("Expected 6 bytes from tag, got less...");\r
+ return;\r
+ }\r
+ // The check the CRC of the answer (use cmd1 as temporary variable):\r
+ ComputeCrc14443(CRC_14443_B, Demod.output, 4, &cmd1[2], &cmd1[3]);\r
+ if(cmd1[2] != Demod.output[4] || cmd1[3] != Demod.output[5]) {\r
+ DbpString("CRC Error reading block! - Below: expected, got");\r
+ DbpIntegers( (cmd1[2]<<8)+cmd1[3], (Demod.output[4]<<8)+Demod.output[5],0);\r
+ // Do not return;, let's go on... (we should retry, maybe ?)\r
+ }\r
+ // Now print out the memory location:\r
+ DbpString("Address , Contents, CRC");\r
+ DbpIntegers(i, (Demod.output[3]<<24) + (Demod.output[2]<<16) + (Demod.output[1]<<8) + Demod.output[0], (Demod.output[4]<<8)+Demod.output[5]);\r
+ if (i == 0xff) {\r
+ break;\r
+ }\r
+ i++;\r
+ }\r