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