]>
Commit | Line | Data |
---|---|---|
54a942b0 | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2012 Chalk <chalk.secu at gmail.com> | |
e98572a1 | 3 | // 2015 Dake <thomas.cayrou at gmail.com> |
4 | ||
54a942b0 | 5 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, |
6 | // at your option, any later version. See the LICENSE.txt file for the text of | |
7 | // the license. | |
8 | //----------------------------------------------------------------------------- | |
9 | // Low frequency PCF7931 commands | |
10 | //----------------------------------------------------------------------------- | |
54a942b0 | 11 | #include <stdio.h> |
12 | #include <string.h> | |
54a942b0 | 13 | #include "proxmark3.h" |
14 | #include "ui.h" | |
15 | #include "graph.h" | |
16 | #include "cmdparser.h" | |
17 | #include "cmddata.h" | |
18 | #include "cmdmain.h" | |
19 | #include "cmdlf.h" | |
20 | #include "cmdlfpcf7931.h" | |
21 | ||
22 | static int CmdHelp(const char *Cmd); | |
23 | ||
e98572a1 | 24 | struct pcf7931_config configPcf = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},17500,{0,0}}; |
25 | ||
26 | int usage_pcf7931_read() | |
27 | { | |
28 | PrintAndLog("Usage: lf pcf7931 read [h] "); | |
29 | PrintAndLog("This command tries to read a PCF7931 tag."); | |
30 | PrintAndLog("Options: "); | |
31 | PrintAndLog(" h This help"); | |
32 | PrintAndLog("Examples:"); | |
33 | PrintAndLog(" lf pcf7931 read"); | |
34 | return 0; | |
35 | } | |
36 | ||
54a942b0 | 37 | int CmdLFPCF7931Read(const char *Cmd) |
38 | { | |
e98572a1 | 39 | uint8_t cmdp = 0; |
40 | ||
41 | if (param_getchar(Cmd, cmdp) == 'H' || param_getchar(Cmd, cmdp) == 'h') | |
42 | return usage_pcf7931_read(); | |
43 | ||
44 | UsbCommand c = {CMD_PCF7931_READ}; | |
45 | clearCommandBuffer(); | |
46 | SendCommand(&c); | |
47 | UsbCommand resp; | |
48 | WaitForResponse(CMD_ACK,&resp); | |
49 | return 0; | |
50 | } | |
51 | ||
52 | int CmdLFPCF7931Config(const char *Cmd) | |
53 | { | |
54 | int res = 0; | |
55 | // res = sscanf(Cmd, | |
56 | // "%02x %02x %hu %hu %hu %hu %hu %hhu %hd %hd", | |
57 | // &configPcf.password[0], | |
58 | // &configPcf.password[1], | |
59 | // &configPcf.password[2], | |
60 | // &configPcf.password[3], | |
61 | // &configPcf.password[4], | |
62 | // &configPcf.password[5], | |
63 | // &configPcf.password[6], | |
64 | // &configPcf.init_delay, | |
65 | // &configPcf.offset[0], | |
66 | // &configPcf.offset[1]); | |
67 | ||
68 | if (res >= 7 || res < 1){ | |
69 | if(res == 7) configPcf.init_delay = 17500; //default value | |
70 | ||
71 | if(res<=8){ | |
72 | configPcf.offset[0] = 0; //default value | |
73 | configPcf.offset[1] = 0; //default value | |
74 | } | |
75 | ||
76 | if(res < 1){ | |
77 | PrintAndLog("Usage: <password byte 1 (in hex, lsb first)> <password byte 2 (in hex, lsb first)> [...] <password byte 7 (in hex, lsb first)> <tag initialization delay (in us)> <optional : offset on the low pulses width (in us)> <optional : offset on the low pulses position (in us)>"); | |
78 | PrintAndLog("The time offsets could be usefull to correct slew rate generated by the antenna."); | |
79 | } | |
80 | ||
81 | PrintAndLog("Current configuration :"); | |
82 | PrintAndLog("Password (LSB first on each byte) : %02x %02x %02x %02x %02x %02x %02x", configPcf.password[0], configPcf.password[1], configPcf.password[2], configPcf.password[3], configPcf.password[4], configPcf.password[5], configPcf.password[6]); | |
83 | PrintAndLog("Tag initialization delay : %d us", configPcf.init_delay); | |
84 | PrintAndLog("Offsets : %d us on the low pulses width, %d us on the low pulses positions", configPcf.offset[0], configPcf.offset[1]); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | //default values | |
90 | configPcf.password[0] = 0xFF; | |
91 | configPcf.password[1] = 0xFF; | |
92 | configPcf.password[2] = 0xFF; | |
93 | configPcf.password[3] = 0xFF; | |
94 | configPcf.password[4] = 0xFF; | |
95 | configPcf.password[5] = 0xFF; | |
96 | configPcf.password[6] = 0xFF; | |
97 | ||
98 | configPcf.init_delay = 17500; | |
99 | configPcf.offset[0] = 0; | |
100 | configPcf.offset[1] = 0; | |
101 | ||
102 | PrintAndLog("Incorrect format"); | |
103 | PrintAndLog("Examples of right usage : lf pcf7931 config 11 22 33 44 55 66 77 20000"); | |
104 | PrintAndLog(" lf pcf7931 config FF FF FF FF FF FF FF 17500 -10 30"); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | int CmdLFPCF7931Write(const char *Cmd) | |
109 | { | |
110 | UsbCommand c = {CMD_PCF7931_WRITE}; | |
111 | ||
112 | int res = 0; | |
113 | res = sscanf(Cmd, "%" SCNu64 " %" SCNu64 " %" SCNu64 , &c.arg[0], &c.arg[1], &c.arg[2]); | |
114 | ||
115 | if(res < 1) { | |
116 | PrintAndLog("Please specify the block address in hex"); | |
117 | return 1; | |
118 | } | |
119 | if (res == 1){ | |
120 | PrintAndLog("Please specify the byte address in hex"); | |
121 | return 2; | |
122 | } | |
123 | if(res == 2) { | |
124 | PrintAndLog("Please specify the data in hex (1 byte)"); | |
125 | return 3; | |
126 | } | |
127 | if(res == 3) { | |
128 | ||
129 | memcpy(c.d.asDwords, configPcf.password, 7); | |
130 | ||
131 | c.d.asDwords[7] = (configPcf.offset[0]+128); | |
132 | c.d.asDwords[8] = (configPcf.offset[1]+128); | |
133 | c.d.asDwords[9] = configPcf.init_delay; | |
134 | ||
135 | clearCommandBuffer(); | |
136 | SendCommand(&c); | |
137 | return 0; | |
138 | } | |
139 | ||
140 | PrintAndLog("INCORRECT FORMAT"); | |
54a942b0 | 141 | return 0; |
142 | } | |
143 | ||
e98572a1 | 144 | |
54a942b0 | 145 | static command_t CommandTable[] = |
146 | { | |
e98572a1 | 147 | {"help", CmdHelp, 1, "This help"}, |
148 | {"read", CmdLFPCF7931Read, 1, "Read content of a PCF7931 transponder"}, | |
149 | {"write", CmdLFPCF7931Write, 1, "Write data on a PCF7931 transponder. Usage : lf pcf7931 write <bloc address> <byte address> <data>"}, | |
150 | {"config", CmdLFPCF7931Config, 1, "Configure the password, the tags initialization delay and time offsets (optional)"}, | |
151 | {NULL, NULL, 0, NULL} | |
54a942b0 | 152 | }; |
153 | ||
154 | int CmdLFPCF7931(const char *Cmd) | |
155 | { | |
e98572a1 | 156 | CmdsParse(CommandTable, Cmd); |
157 | return 0; | |
54a942b0 | 158 | } |
159 | ||
160 | int CmdHelp(const char *Cmd) | |
161 | { | |
e98572a1 | 162 | CmdsHelp(CommandTable); |
163 | return 0; | |
54a942b0 | 164 | } |