pcsc-lite 2.3.0
pcsc-wirecheck-gen.c
1/*
2 * Copyright (C) 2007
3 * Jacob Berkman
4 * Copyright (C) 2007-2010
5 * Ludovic Rousseau <ludovic.rousseau@free.fr>
6 *
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions
9are met:
10
111. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
132. 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.
163. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 */
31
32#include <stdio.h>
33#include <sys/types.h>
34#include <sys/wait.h>
35#include <stddef.h>
36
37#include "PCSC/pcsclite.h"
38#include "pcscd.h"
39#include "winscard_msg.h"
40#include "readerfactory.h"
41#include "eventhandler.h"
42
43#define BLANK_LINE() \
44do { \
45 printf("\n"); \
46} while(0)
47
48#define COMMENT(c) \
49do { \
50 printf(" /* "c" */\n"); \
51} while(0)
52
53#define STRINGIFY(a) #a
54
55
56#define CHECK_CDEFINE(a) \
57 printf(" CLASSERT("#a" == "STRINGIFY(a) ");\n")
58
59#define CHECK_CVALUE(a) \
60 printf(" CLASSERT("#a" == %lld);\n", (long long)a)
61
62#define CHECK_DEFINE(a) \
63do { \
64 printf(" LASSERTF("#a" == "STRINGIFY(a) \
65 ",\" found %%lld\\n\",\n " \
66 "(long long)"#a");\n"); \
67} while(0)
68
69#define CHECK_VALUE(a) \
70do { \
71 printf(" LASSERTF("#a \
72 " == %lld, \" found %%lld\\n\",\n "\
73 "(long long)"#a");\n", (long long)a); \
74} while(0)
75
76#define CHECK_VALUE_64(a) \
77do { \
78 printf(" LASSERTF("#a \
79 " == %lldULL, \" found %%lld\\n\",\n "\
80 "(long long)"#a");\n", (long long)a); \
81} while(0)
82
83#define CHECK_MEMBER_OFFSET(s,m) \
84do { \
85 CHECK_VALUE((int)offsetof(struct s, m)); \
86} while(0)
87
88#define CHECK_MEMBER_SIZEOF(s,m) \
89do { \
90 CHECK_VALUE((int)sizeof(((struct s *)0)->m)); \
91} while(0)
92
93#define CHECK_MEMBER(s,m) \
94do { \
95 CHECK_MEMBER_OFFSET(s, m); \
96 CHECK_MEMBER_SIZEOF(s, m); \
97} while(0)
98
99#define CHECK_STRUCT(s) \
100do { \
101 COMMENT("Checks for struct "#s); \
102 CHECK_VALUE((int)sizeof(struct s)); \
103} while(0)
104
105static void
106check_constants (void)
107{
108 COMMENT ("Constants...");
109
110 BLANK_LINE ();
111 CHECK_DEFINE (PROTOCOL_VERSION_MAJOR);
112 CHECK_DEFINE (PROTOCOL_VERSION_MINOR);
113
114 BLANK_LINE ();
115 CHECK_DEFINE (MAX_READERNAME);
116 CHECK_DEFINE (MAX_ATR_SIZE);
117 CHECK_DEFINE (MAX_BUFFER_SIZE);
118
119 BLANK_LINE ();
120 COMMENT ("enum pcsc_msg_commands");
121 CHECK_VALUE (SCARD_ESTABLISH_CONTEXT);
122 CHECK_VALUE (SCARD_RELEASE_CONTEXT);
123 CHECK_VALUE (SCARD_LIST_READERS);
124 CHECK_VALUE (SCARD_CONNECT);
125 CHECK_VALUE (SCARD_RECONNECT);
126 CHECK_VALUE (SCARD_DISCONNECT);
127 CHECK_VALUE (SCARD_BEGIN_TRANSACTION);
128 CHECK_VALUE (SCARD_END_TRANSACTION);
129 CHECK_VALUE (SCARD_TRANSMIT);
130 CHECK_VALUE (SCARD_CONTROL);
131 CHECK_VALUE (SCARD_STATUS);
132 CHECK_VALUE (SCARD_GET_STATUS_CHANGE);
133 CHECK_VALUE (SCARD_CANCEL);
134 CHECK_VALUE (SCARD_CANCEL_TRANSACTION);
135 CHECK_VALUE (SCARD_GET_ATTRIB);
136 CHECK_VALUE (SCARD_SET_ATTRIB);
137 CHECK_VALUE (CMD_VERSION);
138 CHECK_VALUE (CMD_GET_READERS_STATE);
139 CHECK_VALUE (CMD_WAIT_READER_STATE_CHANGE);
141}
142
143static void
144check_types (void)
145{
146 COMMENT ("Types...");
147
148 BLANK_LINE ();
149 CHECK_STRUCT (version_struct);
150 CHECK_MEMBER (version_struct, major);
151 CHECK_MEMBER (version_struct, minor);
152 CHECK_MEMBER (version_struct, rv);
153
154 BLANK_LINE ();
155 CHECK_STRUCT (client_struct);
156 CHECK_MEMBER (client_struct, hContext);
157
158 BLANK_LINE ();
159 CHECK_STRUCT (establish_struct);
160 CHECK_MEMBER (establish_struct, dwScope);
161 CHECK_MEMBER (establish_struct, hContext);
162 CHECK_MEMBER (establish_struct, rv);
163
164 BLANK_LINE ();
165 CHECK_STRUCT (release_struct);
166 CHECK_MEMBER (release_struct, hContext);
167 CHECK_MEMBER (release_struct, rv);
168
169 BLANK_LINE ();
170 CHECK_STRUCT (connect_struct);
171 CHECK_MEMBER (connect_struct, hContext);
172 CHECK_MEMBER (connect_struct, szReader);
173 CHECK_MEMBER (connect_struct, dwShareMode);
174 CHECK_MEMBER (connect_struct, dwPreferredProtocols);
175 CHECK_MEMBER (connect_struct, hCard);
176 CHECK_MEMBER (connect_struct, dwActiveProtocol);
177 CHECK_MEMBER (connect_struct, rv);
178
179 BLANK_LINE ();
180 CHECK_STRUCT (reconnect_struct);
181 CHECK_MEMBER (reconnect_struct, hCard);
182 CHECK_MEMBER (reconnect_struct, dwShareMode);
183 CHECK_MEMBER (reconnect_struct, dwPreferredProtocols);
184 CHECK_MEMBER (reconnect_struct, dwInitialization);
185 CHECK_MEMBER (reconnect_struct, dwActiveProtocol);
186 CHECK_MEMBER (reconnect_struct, rv);
187
188 BLANK_LINE ();
189 CHECK_STRUCT (disconnect_struct);
190 CHECK_MEMBER (disconnect_struct, hCard);
191 CHECK_MEMBER (disconnect_struct, dwDisposition);
192 CHECK_MEMBER (disconnect_struct, rv);
193
194 BLANK_LINE ();
195 CHECK_STRUCT (begin_struct);
196 CHECK_MEMBER (begin_struct, hCard);
197 CHECK_MEMBER (begin_struct, rv);
198
199 BLANK_LINE ();
200 CHECK_STRUCT (end_struct);
201 CHECK_MEMBER (end_struct, hCard);
202 CHECK_MEMBER (end_struct, dwDisposition);
203 CHECK_MEMBER (end_struct, rv);
204
205 BLANK_LINE ();
206 CHECK_STRUCT (cancel_struct);
207 CHECK_MEMBER (cancel_struct, hContext);
208 CHECK_MEMBER (cancel_struct, rv);
209
210 BLANK_LINE ();
211 CHECK_STRUCT (status_struct);
212 CHECK_MEMBER (status_struct, hCard);
213 CHECK_MEMBER (status_struct, rv);
214
215 BLANK_LINE ();
216 CHECK_STRUCT (transmit_struct);
217 CHECK_MEMBER (transmit_struct, hCard);
218 CHECK_MEMBER (transmit_struct, ioSendPciProtocol);
219 CHECK_MEMBER (transmit_struct, ioSendPciLength);
220 CHECK_MEMBER (transmit_struct, cbSendLength);
221 CHECK_MEMBER (transmit_struct, ioRecvPciProtocol);
222 CHECK_MEMBER (transmit_struct, ioRecvPciLength);
223 CHECK_MEMBER (transmit_struct, pcbRecvLength);
224 CHECK_MEMBER (transmit_struct, rv);
225
226 BLANK_LINE ();
227 CHECK_STRUCT (control_struct);
228 CHECK_MEMBER (control_struct, hCard);
229 CHECK_MEMBER (control_struct, dwControlCode);
230 CHECK_MEMBER (control_struct, cbSendLength);
231 CHECK_MEMBER (control_struct, cbRecvLength);
232 CHECK_MEMBER (control_struct, dwBytesReturned);
233 CHECK_MEMBER (control_struct, rv);
234
235 BLANK_LINE ();
236 CHECK_STRUCT (getset_struct);
237 CHECK_MEMBER (getset_struct, hCard);
238 CHECK_MEMBER (getset_struct, dwAttrId);
239 CHECK_MEMBER (getset_struct, cbAttrLen);
240 CHECK_MEMBER (getset_struct, rv);
241
242 BLANK_LINE ();
243 CHECK_STRUCT (pubReaderStatesList);
244 CHECK_MEMBER (pubReaderStatesList, readerName);
245 CHECK_MEMBER (pubReaderStatesList, readerState);
246 CHECK_MEMBER (pubReaderStatesList, readerSharing);
247 CHECK_MEMBER (pubReaderStatesList, cardAtr);
248 CHECK_MEMBER (pubReaderStatesList, cardAtrLength);
249 CHECK_MEMBER (pubReaderStatesList, cardProtocol);
250}
251
252int
253main(/*@unused@*/ int argc, /*@unused@*/ char **argv)
254{
255 (void)argc;
256 (void)argv;
257
258 printf ("#include <sys/types.h>\n"
259 "#include <time.h>\n"
260 "#include <stddef.h>\n\n"
261 "#include \"PCSC/pcsclite.h\"\n"
262 "#include \"pcscd.h\"\n"
263 "#include \"readerfactory.h\"\n"
264 "#include \"eventhandler.h\"\n"
265 "#include \"winscard_msg.h\"\n\n"
266 "#include \"lassert.h\"\n\n"
267 "int pcsc_assert_wire_constants(void);\n"
268 "int pcsc_assert_wire_constants(void)\n"
269 "{\n");
270
271 BLANK_LINE ();
272
273 check_constants ();
274 check_types ();
275
276 BLANK_LINE ();
277
278 printf ("return 0;\n");
279 printf ("}\n");
280
281 return 0;
282}
This handles card insertion/removal events, updates ATR, protocol, and status information.
#define MAX_ATR_SIZE
Maximum ATR size.
Definition pcsclite.h:59
#define MAX_BUFFER_SIZE
Maximum Tx/Rx Buffer for short APDU.
Definition pcsclite.h:298
This keeps track of a list of currently available reader structures.
contained in SCARD_BEGIN_TRANSACTION Messages.
contained in SCARD_CANCEL Messages.
contained in SCARD_CONNECT Messages.
contained in SCARD_CONTROL Messages.
contained in SCARD_DISCONNECT Messages.
contained in SCARD_END_TRANSACTION Messages.
Information contained in SCARD_ESTABLISH_CONTEXT Messages.
contained in SCARD_GET_ATTRIB and Messages.
Define an exported public reader state structure so each application gets instant notification of cha...
contained in SCARD_RECONNECT Messages.
Information contained in SCARD_RELEASE_CONTEXT Messages.
contained in SCARD_STATUS Messages.
contained in SCARD_TRANSMIT Messages.
Information transmitted in CMD_VERSION Messages.
This defines some structures and #defines to be used over the transport layer.
#define PROTOCOL_VERSION_MAJOR
Major version of the current message protocol.
#define PROTOCOL_VERSION_MINOR
Minor version of the current message protocol.
@ SCARD_DISCONNECT
used by SCardDisconnect()
@ SCARD_SET_ATTRIB
used by SCardSetAttrib()
@ SCARD_RELEASE_CONTEXT
used by SCardReleaseContext()
@ CMD_STOP_WAITING_READER_STATE_CHANGE
stop waiting for a reader state change
@ CMD_GET_READERS_STATE
get the readers state
@ SCARD_GET_STATUS_CHANGE
not used
@ SCARD_CONTROL
used by SCardControl()
@ CMD_VERSION
get the client/server protocol version
@ CMD_WAIT_READER_STATE_CHANGE
wait for a reader state change
@ SCARD_RECONNECT
used by SCardReconnect()
@ SCARD_STATUS
used by SCardStatus()
@ SCARD_GET_ATTRIB
used by SCardGetAttrib()
@ SCARD_BEGIN_TRANSACTION
used by SCardBeginTransaction()
@ SCARD_TRANSMIT
used by SCardTransmit()
@ SCARD_LIST_READERS
used by SCardListReaders()
@ SCARD_END_TRANSACTION
used by SCardEndTransaction()
@ SCARD_CANCEL
used by SCardCancel()
@ SCARD_CANCEL_TRANSACTION
not used
@ SCARD_CONNECT
used by SCardConnect()
@ SCARD_ESTABLISH_CONTEXT
used by SCardEstablishContext()