use defined hexdump istead of rfid_hexdump
[librfid] / python / 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 #define EXPORT extern
42 #define EXPORT_CONVENTION
43
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
60
61 #define PCDAUTH_KEY_LENGTH 6
62 #define PCDAUTH_KEYID_1A 0
63 #define PCDAUTH_KEYID_1B 1
64
65 typedef void* MIFARE_HANDLE;
66
67 /*************************************************************************/
68 /*                                                                       */
69 /* Six steps for reading/writing to MIFARE cards                         */
70 /*                                                                       */
71 /*************************************************************************/
72
73 /*  Step 1. open reader
74
75     supply the address of your handle variable to retrieve a handle
76     to the current reader.
77  */
78 EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle);
79
80 /*  Step 2. set MIFARE classic key
81
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.
85  */
86 EXPORT int EXPORT_CONVENTION openpcd_set_key(MIFARE_HANDLE handle,unsigned int key_id,const void* key);
87
88 /*  Step 3. select card
89     
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.
92  */
93 EXPORT int EXPORT_CONVENTION openpcd_select_card(MIFARE_HANDLE handle);
94
95 /*  Step 4. read/write card
96     
97     read, write from the selected card - specify the page and supply up to
98     16 bytes of payload
99  */
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);
102
103 /*  Step 5. deselect card when done
104  */
105 EXPORT int EXPORT_CONVENTION openpcd_deselect_card(MIFARE_HANDLE handle);
106
107 /*  Step 6. close reader after deselected card
108  */
109 EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle);
110
111
112 /*************************************************************************/
113 /*                                                                       */
114 /* Support functions                                                     */
115 /*                                                                       */
116 /*************************************************************************/
117
118 /*  openpcd_get_error_text:
119
120     Used for converting the error code into a string
121  */
122 EXPORT char* EXPORT_CONVENTION openpcd_get_error_text(int error);
123
124
125 /*  openpcd_get_card_id:
126
127     Get the card id of a selected RFID card
128  */
129 EXPORT int EXPORT_CONVENTION openpcd_get_card_id(MIFARE_HANDLE handle,unsigned int *uid);
130
131
132 /*  openpcd_reset_reader:
133
134     Reset the attached reader
135  */
136 EXPORT int EXPORT_CONVENTION openpcd_reset_reader(MIFARE_HANDLE handle);
137
138 #ifdef  __cplusplus
139 }
140 #endif/*__cplusplus*/
141 #endif/*__OPENPCD_H__*/