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