+//-----------------------------------------------------------------------------\r
+//\r
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,\r
+// at your option, any later version. See the LICENSE.txt file for the text of\r
+// the license.\r
+//-----------------------------------------------------------------------------\r
+// Low frequency T55xx commands\r
+//-----------------------------------------------------------------------------\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <inttypes.h>\r
+#include "proxusb.h"\r
+#include "ui.h"\r
+#include "graph.h"\r
+#include "cmdparser.h"\r
+#include "cmddata.h"\r
+#include "cmdlf.h"\r
+#include "cmdlft55xx.h"\r
+\r
+static int CmdHelp(const char *Cmd);\r
+\r
+\r
+int CmdReadBlk(const char *Cmd)\r
+{\r
+ int Block = 8; //default to invalid block\r
+ UsbCommand c;\r
+\r
+ sscanf(Cmd, "%d", &Block);\r
+\r
+ if (Block > 7) {\r
+ PrintAndLog("Block must be between 0 and 7");\r
+ return 1;\r
+ } \r
+\r
+ PrintAndLog("Reading block %d", Block);\r
+\r
+ c.cmd = CMD_T55XX_READ_BLOCK;\r
+ c.d.asBytes[0] = 0x0; //Normal mode\r
+ c.arg[0] = 0;\r
+ c.arg[1] = Block;\r
+ c.arg[2] = 0;\r
+ SendCommand(&c);\r
+ return 0;\r
+}\r
+\r
+int CmdReadBlkPWD(const char *Cmd)\r
+{\r
+ int Block = 8; //default to invalid block\r
+ int Password = 0xFFFFFFFF; //default to blank Block 7\r
+ UsbCommand c;\r
+\r
+ sscanf(Cmd, "%d %x", &Block, &Password);\r
+\r
+ if (Block > 7) {\r
+ PrintAndLog("Block must be between 0 and 7");\r
+ return 1;\r
+ } \r
+\r
+ PrintAndLog("Reading block %d with password %08X", Block, Password);\r
+\r
+ c.cmd = CMD_T55XX_READ_BLOCK;\r
+ c.d.asBytes[0] = 0x1; //Password mode\r
+ c.arg[0] = 0;\r
+ c.arg[1] = Block;\r
+ c.arg[2] = Password;\r
+ SendCommand(&c);\r
+ return 0;\r
+}\r
+\r
+int CmdWriteBlk(const char *Cmd)\r
+{\r
+ int Block = 8; //default to invalid block\r
+ int Data = 0xFFFFFFFF; //default to blank Block \r
+ UsbCommand c;\r
+\r
+ sscanf(Cmd, "%x %d", &Data, &Block);\r
+\r
+ if (Block > 7) {\r
+ PrintAndLog("Block must be between 0 and 7");\r
+ return 1;\r
+ } \r
+\r
+ PrintAndLog("Writting block %d with data %08X", Block, Data);\r
+\r
+ c.cmd = CMD_T55XX_WRITE_BLOCK;\r
+ c.d.asBytes[0] = 0x0; //Normal mode\r
+ c.arg[0] = Data;\r
+ c.arg[1] = Block;\r
+ c.arg[2] = 0;\r
+ SendCommand(&c);\r
+ return 0;\r
+}\r
+\r
+int CmdWriteBlkPWD(const char *Cmd)\r
+{\r
+ int Block = 8; //default to invalid block\r
+ int Data = 0xFFFFFFFF; //default to blank Block \r
+ int Password = 0xFFFFFFFF; //default to blank Block 7\r
+ UsbCommand c;\r
+\r
+ sscanf(Cmd, "%x %d %x", &Data, &Block, &Password);\r
+\r
+ if (Block > 7) {\r
+ PrintAndLog("Block must be between 0 and 7");\r
+ return 1;\r
+ } \r
+\r
+ PrintAndLog("Writting block %d with data %08X and password %08X", Block, Data, Password);\r
+\r
+ c.cmd = CMD_T55XX_WRITE_BLOCK;\r
+ c.d.asBytes[0] = 0x1; //Password mode\r
+ c.arg[0] = Data;\r
+ c.arg[1] = Block;\r
+ c.arg[2] = Password;\r
+ SendCommand(&c);\r
+ return 0;\r
+}\r
+\r
+int CmdReadTrace(const char *Cmd)\r
+{\r
+\r
+ PrintAndLog("Reading traceability data");\r
+\r
+ UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r
+ SendCommand(&c);\r
+ return 0;\r
+}\r
+\r
+static command_t CommandTable[] =\r
+{\r
+ {"help", CmdHelp, 1, "This help"},\r
+ {"readblock", CmdReadBlk, 1, "<Block> -- Read T55xx block data (page 0)"},\r
+ {"readblockPWD", CmdReadBlkPWD, 1, "<Block> <Password> -- Read T55xx block data in password mode(page 0)"},\r
+ {"writeblock", CmdWriteBlk, 1, "<Data> <Block> -- Write T55xx block data (page 0)"},\r
+ {"writeblockPWD", CmdWriteBlkPWD, 1, "<Data> <Block> <Password> -- Write T55xx block data in password mode(page 0)"},\r
+ {"readtrace", CmdReadTrace, 1, "Read T55xx traceability data (page 1)"},\r
+ {NULL, NULL, 0, NULL}\r
+};\r
+\r
+int CmdLFT55XX(const char *Cmd)\r
+{\r
+ CmdsParse(CommandTable, Cmd);\r
+ return 0;\r
+}\r
+\r
+int CmdHelp(const char *Cmd)\r
+{\r
+ CmdsHelp(CommandTable);\r
+ return 0;\r
+}\r