summaryrefslogtreecommitdiff
path: root/win32/openpcd.h
blob: 9cedcf21a65dca5cf9d199088bc028c6c483f7b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*************************************************************************/
/*                                                                       */
/* Mifare support for accessing RFID cards with OpenPCD RFID reader      */
/* in WIN32 - see http://www.openpcd.org                                 */
/*                                                                       */
/* Copyright (C) 2007 Milosch Meriac <meriac@bitmanufaktur.de>           */
/*                                                                       */
/* Redistribution and use in source and binary forms, with or without    */
/* modification, are permitted provided that the following conditions are*/
/* met:                                                                  */
/*                                                                       */
/* Redistributions of source code must retain the above copyright notice,*/
/* this list of conditions and the following disclaimer.                 */
/* Redistributions in binary form must reproduce the above copyright     */
/* notice, this list of conditions and the following disclaimer in the   */
/* documentation and/or other materials provided with the distribution.  */
/*                                                                       */
/* The name of the author may not be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/*                                                                       */
/* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR  */
/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED        */
/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*/
/* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,    */
/* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR    */
/* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    */
/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,   */
/* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING */
/* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE    */
/* POSSIBILITY OF SUCH DAMAGE.                                           */
/*                                                                       */
/*************************************************************************/

#ifndef __OPENPCD_H__
#define __OPENPCD_H__

#ifdef  __cplusplus
extern "C" {
#endif/*__cplusplus*/

#define EXPORT_CONVENTION __stdcall
#ifdef  BUILD_DLL
/* DLL export */
#define EXPORT __declspec(dllexport)
#else
/* EXE import */
#define EXPORT __declspec(dllimport)
#endif /*BUILD_DLL*/

#define PCDERROR_NONE			 0
#define PCDERROR_INVALID_PARAMETER	-1
#define PCDERROR_KEY_FORMAT		-2
#define PCDERROR_KEY_AUTH		-3
#define PCDERROR_NO_CARD_FOUND		-4
#define PCDERROR_LAYER2_INIT		-5
#define PCDERROR_LAYER2_OPEN		-6
#define PCDERROR_LAYER3_INIT		-7
#define PCDERROR_LAYER3_OPEN		-8
#define PCDERROR_SELECT			-9
#define PCDERROR_READ_FAILED		-10
#define PCDERROR_WRITE_FAILED		-11
#define PCDERROR_CLOSED			-12
#define PCDERROR_NO_READER		-13
#define PCDERROR_OUT_OF_MEMORY		-14
#define	PCDERROR_READER_VERSION		-15

#define PCDAUTH_KEY_LENGTH 6
#define PCDAUTH_KEYID_1A 0
#define PCDAUTH_KEYID_1B 1

typedef void* MIFARE_HANDLE;

/*************************************************************************/
/*                                                                       */
/* Six steps for reading/writing to MIFARE cards                         */
/*                                                                       */
/*************************************************************************/

/*  Step 1. open reader

    supply the address of your handle variable to retrieve a handle
    to the current reader.
 */
EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle);

/*  Step 2. set MIFARE classic key

    if your key differs from the default Infineon key (6*0xFF), you can
    supply a different key here. The key size is PCDAUTH_KEY_LENGTH bytes.
    You can chose to set key_id to PCDAUTH_KEYID_1A or *_1B.
 */
EXPORT int EXPORT_CONVENTION openpcd_set_key(MIFARE_HANDLE handle,unsigned int key_id,const void* key);

/*  Step 3. select card
    
    start the anticollosion to select a card in the reader field - retry if
    it fails. Currently supports only on card in the readerv field.
 */
EXPORT int EXPORT_CONVENTION openpcd_select_card(MIFARE_HANDLE handle);

/*  Step 4. read/write card
    
    read, write from the selected card - specify the page and supply up to
    16 bytes of payload
 */
EXPORT int EXPORT_CONVENTION openpcd_read(MIFARE_HANDLE handle,int page, void* data, int len);
EXPORT int EXPORT_CONVENTION openpcd_write(MIFARE_HANDLE handle,int page,const void *data,int len);

/*  Step 5. deselect card when done
 */
EXPORT int EXPORT_CONVENTION openpcd_deselect_card(MIFARE_HANDLE handle);

/*  Step 6. close reader after deselected card
 */
EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle);


/*************************************************************************/
/*                                                                       */
/* Support functions                                                     */
/*                                                                       */
/*************************************************************************/

/*  openpcd_get_error_text:

    Used for converting the error code into a string
 */
EXPORT char* EXPORT_CONVENTION openpcd_get_error_text(int error);


/*  openpcd_get_card_id:

    Get the card id of a selected RFID card
 */
EXPORT int EXPORT_CONVENTION openpcd_get_card_id(MIFARE_HANDLE handle,unsigned int *uid);

/*  openpcd_get_api_version:

    Get the USB api version of the reader
 */
EXPORT int EXPORT_CONVENTION openpcd_get_api_version(MIFARE_HANDLE handle,unsigned int *version);

/*  openpcd_reset_reader:

    Reset the attached reader
 */
EXPORT int EXPORT_CONVENTION openpcd_reset_reader(MIFARE_HANDLE handle);

/*  openpcd_get_environment

    Store the given data to the nonvolatile reader flash
    Returns read data count at index or error code
 */
EXPORT int EXPORT_CONVENTION openpcd_get_environment(
    MIFARE_HANDLE handle,
    unsigned char count,
    unsigned char* data    
);
    
/*  openpcd_set_environment

    Read data from nonvolatile reader flash
    Returns written data count at index or error code
 */
EXPORT int EXPORT_CONVENTION openpcd_set_environment(
    MIFARE_HANDLE handle,
    unsigned char count,
    const unsigned char* data    
);

#ifdef  __cplusplus
}
#endif/*__cplusplus*/
#endif/*__OPENPCD_H__*/
personal git repositories of Harald Welte. Your mileage may vary