use defined hexdump istead of rfid_hexdump
[librfid] / win32 / openpcd.h
1 /*************************************************************************/
2 /*                                                                       */
3 /* Mifare support for accessing RFID cards with OpenPCD RFID reader      */
4 /* in WIN32 - see http://www.openpcd.org                                 */
5 /*                                                                       */
6 /* Copyright (C) 2007 Milosch Meriac <meriac@bitmanufaktur.de>           */
7 /*                                                                       */
8 /* Redistribution and use in source and binary forms, with or without    */
9 /* modification, are permitted provided that the following conditions are*/
10 /* met:                                                                  */
11 /*                                                                       */
12 /* Redistributions of source code must retain the above copyright notice,*/
13 /* this list of conditions and the following disclaimer.                 */
14 /* Redistributions in binary form must reproduce the above copyright     */
15 /* notice, this list of conditions and the following disclaimer in the   */
16 /* documentation and/or other materials provided with the distribution.  */
17 /*                                                                       */
18 /* The name of the author may not be used to endorse or promote products */
19 /* derived from this software without specific prior written permission. */
20 /*                                                                       */
21 /* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR  */
22 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED        */
23 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*/
24 /* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,    */
25 /* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
26 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR    */
27 /* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    */
28 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,   */
29 /* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING */
30 /* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE    */
31 /* POSSIBILITY OF SUCH DAMAGE.                                           */
32 /*                                                                       */
33 /*************************************************************************/
34
35 #ifndef __OPENPCD_H__
36 #define __OPENPCD_H__
37
38 #ifdef  __cplusplus
39 extern "C" {
40 #endif/*__cplusplus*/
41
42 #define EXPORT_CONVENTION __stdcall
43 #ifdef  BUILD_DLL
44 /* DLL export */
45 #define EXPORT __declspec(dllexport)
46 #else
47 /* EXE import */
48 #define EXPORT __declspec(dllimport)
49 #endif /*BUILD_DLL*/
50
51 #define PCDERROR_NONE                    0
52 #define PCDERROR_INVALID_PARAMETER      -1
53 #define PCDERROR_KEY_FORMAT             -2
54 #define PCDERROR_KEY_AUTH               -3
55 #define PCDERROR_NO_CARD_FOUND          -4
56 #define PCDERROR_LAYER2_INIT            -5
57 #define PCDERROR_LAYER2_OPEN            -6
58 #define PCDERROR_LAYER3_INIT            -7
59 #define PCDERROR_LAYER3_OPEN            -8
60 #define PCDERROR_SELECT                 -9
61 #define PCDERROR_READ_FAILED            -10
62 #define PCDERROR_WRITE_FAILED           -11
63 #define PCDERROR_CLOSED                 -12
64 #define PCDERROR_NO_READER              -13
65 #define PCDERROR_OUT_OF_MEMORY          -14
66 #define PCDERROR_READER_VERSION         -15
67
68 #define PCDAUTH_KEY_LENGTH 6
69 #define PCDAUTH_KEYID_1A 0
70 #define PCDAUTH_KEYID_1B 1
71
72 typedef void* MIFARE_HANDLE;
73
74 /*************************************************************************/
75 /*                                                                       */
76 /* Six steps for reading/writing to MIFARE cards                         */
77 /*                                                                       */
78 /*************************************************************************/
79
80 /*  Step 1. open reader
81
82     supply the address of your handle variable to retrieve a handle
83     to the current reader.
84  */
85 EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle);
86
87 /*  Step 2. set MIFARE classic key
88
89     if your key differs from the default Infineon key (6*0xFF), you can
90     supply a different key here. The key size is PCDAUTH_KEY_LENGTH bytes.
91     You can chose to set key_id to PCDAUTH_KEYID_1A or *_1B.
92  */
93 EXPORT int EXPORT_CONVENTION openpcd_set_key(MIFARE_HANDLE handle,unsigned int key_id,const void* key);
94
95 /*  Step 3. select card
96     
97     start the anticollosion to select a card in the reader field - retry if
98     it fails. Currently supports only on card in the readerv field.
99  */
100 EXPORT int EXPORT_CONVENTION openpcd_select_card(MIFARE_HANDLE handle);
101
102 /*  Step 4. read/write card
103     
104     read, write from the selected card - specify the page and supply up to
105     16 bytes of payload
106  */
107 EXPORT int EXPORT_CONVENTION openpcd_read(MIFARE_HANDLE handle,int page, void* data, int len);
108 EXPORT int EXPORT_CONVENTION openpcd_write(MIFARE_HANDLE handle,int page,const void *data,int len);
109
110 /*  Step 5. deselect card when done
111  */
112 EXPORT int EXPORT_CONVENTION openpcd_deselect_card(MIFARE_HANDLE handle);
113
114 /*  Step 6. close reader after deselected card
115  */
116 EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle);
117
118
119 /*************************************************************************/
120 /*                                                                       */
121 /* Support functions                                                     */
122 /*                                                                       */
123 /*************************************************************************/
124
125 /*  openpcd_get_error_text:
126
127     Used for converting the error code into a string
128  */
129 EXPORT char* EXPORT_CONVENTION openpcd_get_error_text(int error);
130
131
132 /*  openpcd_get_card_id:
133
134     Get the card id of a selected RFID card
135  */
136 EXPORT int EXPORT_CONVENTION openpcd_get_card_id(MIFARE_HANDLE handle,unsigned int *uid);
137
138 /*  openpcd_get_api_version:
139
140     Get the USB api version of the reader
141  */
142 EXPORT int EXPORT_CONVENTION openpcd_get_api_version(MIFARE_HANDLE handle,unsigned int *version);
143
144 /*  openpcd_reset_reader:
145
146     Reset the attached reader
147  */
148 EXPORT int EXPORT_CONVENTION openpcd_reset_reader(MIFARE_HANDLE handle);
149
150 /*  openpcd_get_environment
151
152     Store the given data to the nonvolatile reader flash
153     Returns read data count at index or error code
154  */
155 EXPORT int EXPORT_CONVENTION openpcd_get_environment(
156     MIFARE_HANDLE handle,
157     unsigned char count,
158     unsigned char* data    
159 );
160     
161 /*  openpcd_set_environment
162
163     Read data from nonvolatile reader flash
164     Returns written data count at index or error code
165  */
166 EXPORT int EXPORT_CONVENTION openpcd_set_environment(
167     MIFARE_HANDLE handle,
168     unsigned char count,
169     const unsigned char* data    
170 );
171
172 #ifdef  __cplusplus
173 }
174 #endif/*__cplusplus*/
175 #endif/*__OPENPCD_H__*/