]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfpcf7931.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2012 Chalk <chalk.secu at gmail.com>
3 // 2015 Dake <thomas.cayrou at gmail.com>
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
8 //-----------------------------------------------------------------------------
9 // Low frequency PCF7931 commands
10 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
16 #include "cmdparser.h"
20 #include "cmdlfpcf7931.h"
22 static int CmdHelp ( const char * Cmd
);
24 struct pcf7931_config configPcf
= {{ 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF }, 17500 ,{ 0 , 0 }};
26 int usage_pcf7931_read ()
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" );
37 int CmdLFPCF7931Read ( const char * Cmd
)
41 if ( param_getchar ( Cmd
, cmdp
) == 'H' || param_getchar ( Cmd
, cmdp
) == 'h' )
42 return usage_pcf7931_read ();
44 UsbCommand c
= { CMD_PCF7931_READ
};
48 WaitForResponse ( CMD_ACK
,& resp
);
52 int CmdLFPCF7931Config ( const char * 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]);
68 if ( res
>= 7 || res
< 1 ){
69 if ( res
== 7 ) configPcf
. init_delay
= 17500 ; //default value
72 configPcf
. offset
[ 0 ] = 0 ; //default value
73 configPcf
. offset
[ 1 ] = 0 ; //default value
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." );
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 ]);
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 ;
98 configPcf
. init_delay
= 17500 ;
99 configPcf
. offset
[ 0 ] = 0 ;
100 configPcf
. offset
[ 1 ] = 0 ;
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" );
108 int CmdLFPCF7931Write ( const char * Cmd
)
110 UsbCommand c
= { CMD_PCF7931_WRITE
};
113 res
= sscanf ( Cmd
, "%" SCNu64
" %" SCNu64
" %" SCNu64
, & c
. arg
[ 0 ], & c
. arg
[ 1 ], & c
. arg
[ 2 ]);
116 PrintAndLog ( "Please specify the block address in hex" );
120 PrintAndLog ( "Please specify the byte address in hex" );
124 PrintAndLog ( "Please specify the data in hex (1 byte)" );
129 memcpy ( c
. d
. asDwords
, configPcf
. password
, 7 );
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
;
135 clearCommandBuffer ();
140 PrintAndLog ( "INCORRECT FORMAT" );
145 static command_t CommandTable
[] =
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
}
154 int CmdLFPCF7931 ( const char * Cmd
)
156 CmdsParse ( CommandTable
, Cmd
);
160 int CmdHelp ( const char * Cmd
)
162 CmdsHelp ( CommandTable
);