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
44 #define PCDERROR_NONE 0
45 #define PCDERROR_INVALID_PARAMETER -1
46 #define PCDERROR_KEY_FORMAT -2
47 #define PCDERROR_KEY_AUTH -3
48 #define PCDERROR_NO_CARD_FOUND -4
49 #define PCDERROR_LAYER2_INIT -5
50 #define PCDERROR_LAYER2_OPEN -6
51 #define PCDERROR_LAYER3_INIT -7
52 #define PCDERROR_LAYER3_OPEN -8
53 #define PCDERROR_SELECT -9
54 #define PCDERROR_READ_FAILED -10
55 #define PCDERROR_WRITE_FAILED -11
56 #define PCDERROR_CLOSED -12
57 #define PCDERROR_NO_READER -13
58 #define PCDERROR_OUT_OF_MEMORY -14
59 #define PCDERROR_READER_VERSION -15
61 #define PCDAUTH_KEY_LENGTH 6
62 #define PCDAUTH_KEYID_1A 0
63 #define PCDAUTH_KEYID_1B 1
65 typedef void* MIFARE_HANDLE;
67 /*************************************************************************/
69 /* Six steps for reading/writing to MIFARE cards */
71 /*************************************************************************/
73 /* Step 1. open reader
75 supply the address of your handle variable to retrieve a handle
76 to the current reader.
78 EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle);
80 /* Step 2. set MIFARE classic key
82 if your key differs from the default Infineon key (6*0xFF), you can
83 supply a different key here. The key size is PCDAUTH_KEY_LENGTH bytes.
84 You can chose to set key_id to PCDAUTH_KEYID_1A or *_1B.
86 EXPORT int EXPORT_CONVENTION openpcd_set_key(MIFARE_HANDLE handle,unsigned int key_id,const void* key);
88 /* Step 3. select card
90 start the anticollosion to select a card in the reader field - retry if
91 it fails. Currently supports only on card in the readerv field.
93 EXPORT int EXPORT_CONVENTION openpcd_select_card(MIFARE_HANDLE handle);
95 /* Step 4. read/write card
97 read, write from the selected card - specify the page and supply up to
100 EXPORT int EXPORT_CONVENTION openpcd_read(MIFARE_HANDLE handle,int page, void* data, int len);
101 EXPORT int EXPORT_CONVENTION openpcd_write(MIFARE_HANDLE handle,int page,const void *data,int len);
103 /* Step 5. deselect card when done
105 EXPORT int EXPORT_CONVENTION openpcd_deselect_card(MIFARE_HANDLE handle);
107 /* Step 6. close reader after deselected card
109 EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle);
112 /*************************************************************************/
114 /* Support functions */
116 /*************************************************************************/
118 /* openpcd_get_error_text:
120 Used for converting the error code into a string
122 EXPORT char* EXPORT_CONVENTION openpcd_get_error_text(int error);
125 /* openpcd_get_card_id:
127 Get the card id of a selected RFID card
129 EXPORT int EXPORT_CONVENTION openpcd_get_card_id(MIFARE_HANDLE handle,unsigned int *uid);
132 /* openpcd_reset_reader:
134 Reset the attached reader
136 EXPORT int EXPORT_CONVENTION openpcd_reset_reader(MIFARE_HANDLE handle);
140 #endif/*__cplusplus*/
141 #endif/*__OPENPCD_H__*/