]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfpcf7931.c
LED D is on while snoop, when user button is pressed snoop is stopped
[proxmark3-svn] / client / cmdlfpcf7931.c
CommitLineData
54a942b0 1//-----------------------------------------------------------------------------
2// Copyright (C) 2012 Chalk <chalk.secu at gmail.com>
dc4300ba
D
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//-----------------------------------------------------------------------------
11
12#include <stdio.h>
13#include <string.h>
54a942b0 14#include "proxmark3.h"
15#include "ui.h"
16#include "graph.h"
17#include "cmdparser.h"
18#include "cmddata.h"
19#include "cmdmain.h"
20#include "cmdlf.h"
21#include "cmdlfpcf7931.h"
22
23static int CmdHelp(const char *Cmd);
24
dc4300ba
D
25struct pcf7931_config configPcf = {{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},17500,{0,0}};
26
54a942b0 27int CmdLFPCF7931Read(const char *Cmd)
28{
29 UsbCommand c = {CMD_PCF7931_READ};
30 SendCommand(&c);
31 UsbCommand resp;
32 WaitForResponse(CMD_ACK,&resp);
33 return 0;
34}
35
dc4300ba
D
36int CmdLFPCF7931Config(const char *Cmd)
37{
38 int res = 0;
39 res = sscanf(Cmd, "%02x %02x %02x %02x %02x %02x %02x %d %d %d", &configPcf.password[0], &configPcf.password[1], &configPcf.password[2], &configPcf.password[3], &configPcf.password[4], &configPcf.password[5], &configPcf.password[6], &configPcf.init_delay, &configPcf.offset[0], &configPcf.offset[1]);
40
41 if (res >= 7 || res < 1){
42 if(res == 7) configPcf.init_delay = 17500; //default value
43
44 if(res<=8){
940d5309
D
45 configPcf.offset[0] = 0; //default value
46 configPcf.offset[1] = 0; //default value
dc4300ba
D
47 }
48
49 if(res < 1){
50 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)>");
51 PrintAndLog("The time offsets could be usefull to correct slew rate generated by the antenna.");
52 }
53
54 PrintAndLog("Current configuration :");
55 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]);
56 PrintAndLog("Tag initialization delay : %d us", configPcf.init_delay);
57 PrintAndLog("Offsets : %d us on the low pulses width, %d us on the low pulses positions", configPcf.offset[0], configPcf.offset[1]);
58
59 return 0;
60 }
61
62 //default values
63 configPcf.password[0] = 0xFF;
64 configPcf.password[1] = 0xFF;
65 configPcf.password[2] = 0xFF;
66 configPcf.password[3] = 0xFF;
67 configPcf.password[4] = 0xFF;
68 configPcf.password[5] = 0xFF;
69 configPcf.password[6] = 0xFF;
70
71 configPcf.init_delay = 17500;
72 configPcf.offset[0] = 0;
73 configPcf.offset[1] = 0;
74
75 PrintAndLog("Incorrect format");
76 PrintAndLog("Examples of right usage : lf pcf7931 config 11 22 33 44 55 66 77 20000");
77 PrintAndLog(" lf pcf7931 config FF FF FF FF FF FF FF 17500 -10 30");
78 return 0;
79}
80
81
82
83int CmdLFPCF7931Write(const char *Cmd)
84{
85 UsbCommand c = {CMD_PCF7931_WRITE};
86
87 int res = 0;
88 res = sscanf(Cmd, "%x %x %x", &c.arg[0], &c.arg[1], &c.arg[2]);
89
90 if(res < 1) {
91 PrintAndLog("Please specify the block address in hex");
92 return 0;
93 }
94 if (res == 1){
95 PrintAndLog("Please specify the byte address in hex");
96 return 0;
97 }
98 if(res == 2) {
99 PrintAndLog("Please specify the data in hex (1 byte)");
100 return 0;
101 }
102 if(res == 3) {
103 uint8_t n=0;
104 for(n=0;n<7;n++) c.d.asDwords[n] = configPcf.password[n];
105 c.d.asDwords[7] = (configPcf.offset[0]+128);
106 c.d.asDwords[8] = (configPcf.offset[1]+128);
107 c.d.asDwords[9] = configPcf.init_delay;
108 SendCommand(&c);
109 return 0;
110 }
111
112 PrintAndLog("INCORRECT FORMAT");
113 return 0;
114}
115
116
54a942b0 117static command_t CommandTable[] =
118{
119 {"help", CmdHelp, 1, "This help"},
120 {"read", CmdLFPCF7931Read, 1, "Read content of a PCF7931 transponder"},
dc4300ba
D
121 {"write", CmdLFPCF7931Write, 1, "Write data on a PCF7931 transponder. Usage : lf pcf7931 write <bloc address> <byte address> <data>"},
122 {"config", CmdLFPCF7931Config, 1, "Configure the password, the tags initialization delay and time offsets (optional)"},
54a942b0 123 {NULL, NULL, 0, NULL}
124};
125
126int CmdLFPCF7931(const char *Cmd)
127{
128 CmdsParse(CommandTable, Cmd);
129 return 0;
130}
131
132int CmdHelp(const char *Cmd)
133{
134 CmdsHelp(CommandTable);
135 return 0;
136}
Impressum, Datenschutz