1 /*************************************************************************/
3 /* Mifare support for accessing RFID cards with OpenPCD RFID reader */
4 /* in WIN32 - see http://www.openpcd.org */
6 /* Copyright (C) 2007 Milosch Meriac <meriac@bitmanufaktur.de> */
8 /* Redistribution and use in source and binary forms, with or without */
9 /* modification, are permitted provided that the following conditions are*/
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. */
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. */
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. */
33 /*************************************************************************/
42 #define EXPORT_CONVENTION __stdcall
45 #define EXPORT __declspec(dllexport)
48 #define EXPORT __declspec(dllimport)
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
68 #define PCDAUTH_KEY_LENGTH 6
69 #define PCDAUTH_KEYID_1A 0
70 #define PCDAUTH_KEYID_1B 1
72 typedef void* MIFARE_HANDLE;
74 /*************************************************************************/
76 /* Six steps for reading/writing to MIFARE cards */
78 /*************************************************************************/
80 /* Step 1. open reader
82 supply the address of your handle variable to retrieve a handle
83 to the current reader.
85 EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle);
87 /* Step 2. set MIFARE classic key
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.
93 EXPORT int EXPORT_CONVENTION openpcd_set_key(MIFARE_HANDLE handle,unsigned int key_id,const void* key);
95 /* Step 3. select card
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.
100 EXPORT int EXPORT_CONVENTION openpcd_select_card(MIFARE_HANDLE handle);
102 /* Step 4. read/write card
104 read, write from the selected card - specify the page and supply up to
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);
110 /* Step 5. deselect card when done
112 EXPORT int EXPORT_CONVENTION openpcd_deselect_card(MIFARE_HANDLE handle);
114 /* Step 6. close reader after deselected card
116 EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle);
119 /*************************************************************************/
121 /* Support functions */
123 /*************************************************************************/
125 /* openpcd_get_error_text:
127 Used for converting the error code into a string
129 EXPORT char* EXPORT_CONVENTION openpcd_get_error_text(int error);
132 /* openpcd_get_card_id:
134 Get the card id of a selected RFID card
136 EXPORT int EXPORT_CONVENTION openpcd_get_card_id(MIFARE_HANDLE handle,unsigned int *uid);
138 /* openpcd_get_api_version:
140 Get the USB api version of the reader
142 EXPORT int EXPORT_CONVENTION openpcd_get_api_version(MIFARE_HANDLE handle,unsigned int *version);
144 /* openpcd_reset_reader:
146 Reset the attached reader
148 EXPORT int EXPORT_CONVENTION openpcd_reset_reader(MIFARE_HANDLE handle);
150 /* openpcd_get_environment
152 Store the given data to the nonvolatile reader flash
153 Returns read data count at index or error code
155 EXPORT int EXPORT_CONVENTION openpcd_get_environment(
156 MIFARE_HANDLE handle,
161 /* openpcd_set_environment
163 Read data from nonvolatile reader flash
164 Returns written data count at index or error code
166 EXPORT int EXPORT_CONVENTION openpcd_set_environment(
167 MIFARE_HANDLE handle,
169 const unsigned char* data
174 #endif/*__cplusplus*/
175 #endif/*__OPENPCD_H__*/