pcsc-lite  1.8.8
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 
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <stddef.h>
12 
13 #include "PCSC/pcsclite.h"
14 #include "pcscd.h"
15 #include "winscard_msg.h"
16 #include "readerfactory.h"
17 #include "eventhandler.h"
18 
19 #define BLANK_LINE() \
20 do { \
21  printf("\n"); \
22 } while(0)
23 
24 #define COMMENT(c) \
25 do { \
26  printf(" /* "c" */\n"); \
27 } while(0)
28 
29 #define STRINGIFY(a) #a
30 
31 
32 #define CHECK_CDEFINE(a) \
33  printf(" CLASSERT("#a" == "STRINGIFY(a) ");\n")
34 
35 #define CHECK_CVALUE(a) \
36  printf(" CLASSERT("#a" == %lld);\n", (long long)a)
37 
38 #define CHECK_DEFINE(a) \
39 do { \
40  printf(" LASSERTF("#a" == "STRINGIFY(a) \
41  ",\" found %%lld\\n\",\n " \
42  "(long long)"#a");\n"); \
43 } while(0)
44 
45 #define CHECK_VALUE(a) \
46 do { \
47  printf(" LASSERTF("#a \
48  " == %lld, \" found %%lld\\n\",\n "\
49  "(long long)"#a");\n", (long long)a); \
50 } while(0)
51 
52 #define CHECK_VALUE_64(a) \
53 do { \
54  printf(" LASSERTF("#a \
55  " == %lldULL, \" found %%lld\\n\",\n "\
56  "(long long)"#a");\n", (long long)a); \
57 } while(0)
58 
59 #define CHECK_MEMBER_OFFSET(s,m) \
60 do { \
61  CHECK_VALUE((int)offsetof(struct s, m)); \
62 } while(0)
63 
64 #define CHECK_MEMBER_SIZEOF(s,m) \
65 do { \
66  CHECK_VALUE((int)sizeof(((struct s *)0)->m)); \
67 } while(0)
68 
69 #define CHECK_MEMBER(s,m) \
70 do { \
71  CHECK_MEMBER_OFFSET(s, m); \
72  CHECK_MEMBER_SIZEOF(s, m); \
73 } while(0)
74 
75 #define CHECK_STRUCT(s) \
76 do { \
77  COMMENT("Checks for struct "#s); \
78  CHECK_VALUE((int)sizeof(struct s)); \
79 } while(0)
80 
81 static void
82 check_constants (void)
83 {
84  COMMENT ("Constants...");
85 
86  BLANK_LINE ();
87  CHECK_DEFINE (PROTOCOL_VERSION_MAJOR);
88  CHECK_DEFINE (PROTOCOL_VERSION_MINOR);
89 
90  BLANK_LINE ();
91  CHECK_DEFINE (MAX_READERNAME);
92  CHECK_DEFINE (MAX_ATR_SIZE);
93  CHECK_DEFINE (MAX_BUFFER_SIZE);
94 
95  BLANK_LINE ();
96  COMMENT ("enum pcsc_msg_commands");
97  CHECK_VALUE (SCARD_ESTABLISH_CONTEXT);
98  CHECK_VALUE (SCARD_RELEASE_CONTEXT);
99  CHECK_VALUE (SCARD_LIST_READERS);
100  CHECK_VALUE (SCARD_CONNECT);
101  CHECK_VALUE (SCARD_RECONNECT);
102  CHECK_VALUE (SCARD_DISCONNECT);
103  CHECK_VALUE (SCARD_BEGIN_TRANSACTION);
104  CHECK_VALUE (SCARD_END_TRANSACTION);
105  CHECK_VALUE (SCARD_TRANSMIT);
106  CHECK_VALUE (SCARD_CONTROL);
107  CHECK_VALUE (SCARD_STATUS);
108  CHECK_VALUE (SCARD_GET_STATUS_CHANGE);
109  CHECK_VALUE (SCARD_CANCEL);
110  CHECK_VALUE (SCARD_CANCEL_TRANSACTION);
111  CHECK_VALUE (SCARD_GET_ATTRIB);
112  CHECK_VALUE (SCARD_SET_ATTRIB);
113  CHECK_VALUE (CMD_VERSION);
114  CHECK_VALUE (CMD_GET_READERS_STATE);
115  CHECK_VALUE (CMD_WAIT_READER_STATE_CHANGE);
117 }
118 
119 static void
120 check_types (void)
121 {
122  COMMENT ("Types...");
123 
124  BLANK_LINE ();
125  CHECK_STRUCT (version_struct);
126  CHECK_MEMBER (version_struct, major);
127  CHECK_MEMBER (version_struct, minor);
128  CHECK_MEMBER (version_struct, rv);
129 
130  BLANK_LINE ();
131  CHECK_STRUCT (client_struct);
132  CHECK_MEMBER (client_struct, hContext);
133 
134  BLANK_LINE ();
135  CHECK_STRUCT (establish_struct);
136  CHECK_MEMBER (establish_struct, dwScope);
137  CHECK_MEMBER (establish_struct, hContext);
138  CHECK_MEMBER (establish_struct, rv);
139 
140  BLANK_LINE ();
141  CHECK_STRUCT (release_struct);
142  CHECK_MEMBER (release_struct, hContext);
143  CHECK_MEMBER (release_struct, rv);
144 
145  BLANK_LINE ();
146  CHECK_STRUCT (connect_struct);
147  CHECK_MEMBER (connect_struct, hContext);
148  CHECK_MEMBER (connect_struct, szReader);
149  CHECK_MEMBER (connect_struct, dwShareMode);
150  CHECK_MEMBER (connect_struct, dwPreferredProtocols);
151  CHECK_MEMBER (connect_struct, hCard);
152  CHECK_MEMBER (connect_struct, dwActiveProtocol);
153  CHECK_MEMBER (connect_struct, rv);
154 
155  BLANK_LINE ();
156  CHECK_STRUCT (reconnect_struct);
157  CHECK_MEMBER (reconnect_struct, hCard);
158  CHECK_MEMBER (reconnect_struct, dwShareMode);
159  CHECK_MEMBER (reconnect_struct, dwPreferredProtocols);
160  CHECK_MEMBER (reconnect_struct, dwInitialization);
161  CHECK_MEMBER (reconnect_struct, dwActiveProtocol);
162  CHECK_MEMBER (reconnect_struct, rv);
163 
164  BLANK_LINE ();
165  CHECK_STRUCT (disconnect_struct);
166  CHECK_MEMBER (disconnect_struct, hCard);
167  CHECK_MEMBER (disconnect_struct, dwDisposition);
168  CHECK_MEMBER (disconnect_struct, rv);
169 
170  BLANK_LINE ();
171  CHECK_STRUCT (begin_struct);
172  CHECK_MEMBER (begin_struct, hCard);
173  CHECK_MEMBER (begin_struct, rv);
174 
175  BLANK_LINE ();
176  CHECK_STRUCT (end_struct);
177  CHECK_MEMBER (end_struct, hCard);
178  CHECK_MEMBER (end_struct, dwDisposition);
179  CHECK_MEMBER (end_struct, rv);
180 
181  BLANK_LINE ();
182  CHECK_STRUCT (cancel_struct);
183  CHECK_MEMBER (cancel_struct, hContext);
184  CHECK_MEMBER (cancel_struct, rv);
185 
186  BLANK_LINE ();
187  CHECK_STRUCT (status_struct);
188  CHECK_MEMBER (status_struct, hCard);
189  CHECK_MEMBER (status_struct, rv);
190 
191  BLANK_LINE ();
192  CHECK_STRUCT (transmit_struct);
193  CHECK_MEMBER (transmit_struct, hCard);
194  CHECK_MEMBER (transmit_struct, ioSendPciProtocol);
195  CHECK_MEMBER (transmit_struct, ioSendPciLength);
196  CHECK_MEMBER (transmit_struct, cbSendLength);
197  CHECK_MEMBER (transmit_struct, ioRecvPciProtocol);
198  CHECK_MEMBER (transmit_struct, ioRecvPciLength);
199  CHECK_MEMBER (transmit_struct, pcbRecvLength);
200  CHECK_MEMBER (transmit_struct, rv);
201 
202  BLANK_LINE ();
203  CHECK_STRUCT (control_struct);
204  CHECK_MEMBER (control_struct, hCard);
205  CHECK_MEMBER (control_struct, dwControlCode);
206  CHECK_MEMBER (control_struct, cbSendLength);
207  CHECK_MEMBER (control_struct, cbRecvLength);
208  CHECK_MEMBER (control_struct, dwBytesReturned);
209  CHECK_MEMBER (control_struct, rv);
210 
211  BLANK_LINE ();
212  CHECK_STRUCT (getset_struct);
213  CHECK_MEMBER (getset_struct, hCard);
214  CHECK_MEMBER (getset_struct, dwAttrId);
215  CHECK_MEMBER (getset_struct, cbAttrLen);
216  CHECK_MEMBER (getset_struct, rv);
217 
218  BLANK_LINE ();
219  CHECK_STRUCT (pubReaderStatesList);
220  CHECK_MEMBER (pubReaderStatesList, readerName);
221  CHECK_MEMBER (pubReaderStatesList, readerState);
222  CHECK_MEMBER (pubReaderStatesList, readerSharing);
223  CHECK_MEMBER (pubReaderStatesList, cardAtr);
224  CHECK_MEMBER (pubReaderStatesList, cardAtrLength);
225  CHECK_MEMBER (pubReaderStatesList, cardProtocol);
226 }
227 
228 int
229 main(/*@unused@*/ int argc, /*@unused@*/ char **argv)
230 {
231  (void)argc;
232  (void)argv;
233 
234  printf ("#include <sys/types.h>\n"
235  "#include <time.h>\n"
236  "#include <stddef.h>\n\n"
237  "#include \"PCSC/pcsclite.h\"\n"
238  "#include \"pcscd.h\"\n"
239  "#include \"readerfactory.h\"\n"
240  "#include \"eventhandler.h\"\n"
241  "#include \"winscard_msg.h\"\n\n"
242  "#include \"lassert.h\"\n\n"
243  "int pcsc_assert_wire_constants(void);\n"
244  "int pcsc_assert_wire_constants(void)\n"
245  "{\n");
246 
247  BLANK_LINE ();
248 
249  check_constants ();
250  check_types ();
251 
252  BLANK_LINE ();
253 
254  printf ("return 0;\n");
255  printf ("}\n");
256 
257  return 0;
258 }
used by SCardBeginTransaction()
Definition: winscard_msg.h:61
contained in SCARD_CONNECT Messages.
Definition: winscard_msg.h:120
wait for a reader state change
Definition: winscard_msg.h:73
contained in SCARD_CANCEL Messages.
Definition: winscard_msg.h:186
contained in SCARD_TRANSMIT Messages.
Definition: winscard_msg.h:208
contained in SCARD_END_TRANSACTION Messages.
Definition: winscard_msg.h:174
#define MAX_BUFFER_SIZE
Maximum Tx/Rx Buffer for short APDU.
Definition: pcsclite.h:208
get the client/server protocol version
Definition: winscard_msg.h:71
used by SCardEstablishContext()
Definition: winscard_msg.h:55
used by SCardEndTransaction()
Definition: winscard_msg.h:62
used by SCardConnect()
Definition: winscard_msg.h:58
#define PROTOCOL_VERSION_MAJOR
Major version of the current message protocol.
Definition: winscard_msg.h:26
contained in SCARD_DISCONNECT Messages.
Definition: winscard_msg.h:151
Information contained in SCARD_RELEASE_CONTEXT Messages.
Definition: winscard_msg.h:109
contained in SCARD_BEGIN_TRANSACTION Messages.
Definition: winscard_msg.h:163
Information contained in SCARD_ESTABLISH_CONTEXT Messages.
Definition: winscard_msg.h:97
get the readers state
Definition: winscard_msg.h:72
Information transmitted in CMD_VERSION Messages.
Definition: winscard_msg.h:33
used by SCardReleaseContext()
Definition: winscard_msg.h:56
contained in SCARD_STATUS Messages.
Definition: winscard_msg.h:197
contained in SCARD_RECONNECT Messages.
Definition: winscard_msg.h:136
contained in SCARD_GET_ATTRIB and Messages.
Definition: winscard_msg.h:240
This defines some structures and #defines to be used over the transport layer.
used by SCardReconnect()
Definition: winscard_msg.h:59
used by SCardTransmit()
Definition: winscard_msg.h:63
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:74
#define PROTOCOL_VERSION_MINOR
Minor version of the current message protocol.
Definition: winscard_msg.h:28
used by SCardControl()
Definition: winscard_msg.h:64
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:27
used by SCardSetAttrib()
Definition: winscard_msg.h:70
used by SCardListReaders()
Definition: winscard_msg.h:57
used by SCardDisconnect()
Definition: winscard_msg.h:60
contained in SCARD_CONTROL Messages.
Definition: winscard_msg.h:225
This keeps track of a list of currently available reader structures.
used by SCardGetAttrib()
Definition: winscard_msg.h:69
#define MAX_ATR_SIZE
Maximum ATR size.
Definition: pcsclite.h:38
used by SCardCancel()
Definition: winscard_msg.h:67
used by SCardStatus()
Definition: winscard_msg.h:65