pcsc-lite  1.8.23
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  *
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10 
11 1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13 2. 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.
16 3. 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 
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS 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() \
44 do { \
45  printf("\n"); \
46 } while(0)
47 
48 #define COMMENT(c) \
49 do { \
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) \
63 do { \
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) \
70 do { \
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) \
77 do { \
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) \
84 do { \
85  CHECK_VALUE((int)offsetof(struct s, m)); \
86 } while(0)
87 
88 #define CHECK_MEMBER_SIZEOF(s,m) \
89 do { \
90  CHECK_VALUE((int)sizeof(((struct s *)0)->m)); \
91 } while(0)
92 
93 #define CHECK_MEMBER(s,m) \
94 do { \
95  CHECK_MEMBER_OFFSET(s, m); \
96  CHECK_MEMBER_SIZEOF(s, m); \
97 } while(0)
98 
99 #define CHECK_STRUCT(s) \
100 do { \
101  COMMENT("Checks for struct "#s); \
102  CHECK_VALUE((int)sizeof(struct s)); \
103 } while(0)
104 
105 static void
106 check_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 
143 static void
144 check_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 
252 int
253 main(/*@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 }
used by SCardBeginTransaction()
Definition: winscard_msg.h:82
contained in SCARD_CONNECT Messages.
Definition: winscard_msg.h:141
wait for a reader state change
Definition: winscard_msg.h:94
contained in SCARD_CANCEL Messages.
Definition: winscard_msg.h:207
contained in SCARD_TRANSMIT Messages.
Definition: winscard_msg.h:229
contained in SCARD_END_TRANSACTION Messages.
Definition: winscard_msg.h:195
#define MAX_BUFFER_SIZE
Maximum Tx/Rx Buffer for short APDU.
Definition: pcsclite.h:297
get the client/server protocol version
Definition: winscard_msg.h:92
used by SCardEstablishContext()
Definition: winscard_msg.h:76
used by SCardEndTransaction()
Definition: winscard_msg.h:83
used by SCardConnect()
Definition: winscard_msg.h:79
#define PROTOCOL_VERSION_MAJOR
Major version of the current message protocol.
Definition: winscard_msg.h:47
contained in SCARD_DISCONNECT Messages.
Definition: winscard_msg.h:172
Information contained in SCARD_RELEASE_CONTEXT Messages.
Definition: winscard_msg.h:130
contained in SCARD_BEGIN_TRANSACTION Messages.
Definition: winscard_msg.h:184
Information contained in SCARD_ESTABLISH_CONTEXT Messages.
Definition: winscard_msg.h:118
get the readers state
Definition: winscard_msg.h:93
Information transmitted in CMD_VERSION Messages.
Definition: winscard_msg.h:54
used by SCardReleaseContext()
Definition: winscard_msg.h:77
contained in SCARD_STATUS Messages.
Definition: winscard_msg.h:218
contained in SCARD_RECONNECT Messages.
Definition: winscard_msg.h:157
contained in SCARD_GET_ATTRIB and Messages.
Definition: winscard_msg.h:261
This defines some structures and #defines to be used over the transport layer.
used by SCardReconnect()
Definition: winscard_msg.h:80
used by SCardTransmit()
Definition: winscard_msg.h:84
This handles card insertion/removal events, updates ATR, protocol, and status information.
This keeps a list of defines for pcsc-lite.
stop waiting for a reader state change
Definition: winscard_msg.h:95
#define PROTOCOL_VERSION_MINOR
Minor version of the current message protocol.
Definition: winscard_msg.h:49
used by SCardControl()
Definition: winscard_msg.h:85
This keeps a list of defines for pcsc-lite.
Define an exported public reader state structure so each application gets instant notification of cha...
Definition: eventhandler.h:48
used by SCardSetAttrib()
Definition: winscard_msg.h:91
used by SCardListReaders()
Definition: winscard_msg.h:78
used by SCardDisconnect()
Definition: winscard_msg.h:81
contained in SCARD_CONTROL Messages.
Definition: winscard_msg.h:246
This keeps track of a list of currently available reader structures.
used by SCardGetAttrib()
Definition: winscard_msg.h:90
#define MAX_ATR_SIZE
Maximum ATR size.
Definition: pcsclite.h:59
used by SCardCancel()
Definition: winscard_msg.h:88
used by SCardStatus()
Definition: winscard_msg.h:86