~ubuntu-branches/ubuntu/jaunty/pcsc-lite/jaunty-security

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
 * MUSCLE SmartCard Development ( http://www.linuxnet.com )
 *
 * Copyright (C) 2001-2004
 *  David Corcoran <corcoran@linuxnet.com>
 *  Damien Sauveron <damien.sauveron@labri.fr>
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
 *
 * $Id: winscard_msg.h 1695 2005-10-29 16:27:33Z rousseau $
 */

/**
 * @file
 * @brief This defines some structures and \#defines to be used over
 * the transport layer.
 */

#ifndef __winscard_msg_h__
#define __winscard_msg_h__

/** Major version of the current message protocol */
#define PROTOCOL_VERSION_MAJOR 2
/** Minor version of the current message protocol */
#define PROTOCOL_VERSION_MINOR 0

#ifdef __cplusplus
extern "C"
{
#endif

	/**
	 * @brief General structure for client/serve message data exchange.
	 *
	 * It is used in the calls of \c SHMMessageSend and \c SHMMessageReceive.
	 * The field \c data is interpreted according to the values of the fields
	 * \c mtype and \c command. The possible structs the \c data field can
	 * represent are: \c version_struct \c client_struct \c establish_struct
	 * \c release_struct \c connect_struct \c reconnect_struct
	 * \c disconnect_struct \c begin_struct \c end_struct \c cancel_struct
	 * \c status_struct \c transmit_struct \c control_struct \c getset_struct
	 */
	typedef struct rxSharedSegment
	{
		unsigned int mtype;		/** one of the \c pcsc_adm_commands */
		unsigned int user_id;
		unsigned int group_id;
		unsigned int command;	/** one of the \c pcsc_msg_commands */
		unsigned int dummy;	/* was request_id in pcsc-lite <= 1.2.0 */
		time_t date;
		unsigned char key[PCSCLITE_MSG_KEY_LEN];
		unsigned char data[PCSCLITE_MAX_MESSAGE_SIZE];
	}
	sharedSegmentMsg, *psharedSegmentMsg;

	/**
	 * Command types available to use in the field \c sharedSegmentMsg.mtype.
	 */
	enum pcsc_adm_commands
	{
		CMD_FUNCTION = 0xF1,
		CMD_FAILED = 0xF2,
		CMD_SERVER_DIED = 0xF3,
		CMD_CLIENT_DIED = 0xF4,
		CMD_READER_EVENT = 0xF5,
		CMD_SYN = 0xF6,
		CMD_ACK = 0xF7,
		CMD_VERSION = 0xF8
	};

	/**
	 * @brief Commands available to use in the field \c sharedSegmentMsg.command.
	 */
	enum pcsc_msg_commands
	{
		SCARD_ESTABLISH_CONTEXT = 0x01,
		SCARD_RELEASE_CONTEXT = 0x02,
		SCARD_LIST_READERS = 0x03,
		SCARD_CONNECT = 0x04,
		SCARD_RECONNECT = 0x05,
		SCARD_DISCONNECT = 0x06,
		SCARD_BEGIN_TRANSACTION = 0x07,
		SCARD_END_TRANSACTION = 0x08,
		SCARD_TRANSMIT = 0x09,
		SCARD_CONTROL = 0x0A,
		SCARD_STATUS = 0x0B,
		SCARD_GET_STATUS_CHANGE = 0x0C,
		SCARD_CANCEL = 0x0D,
		SCARD_CANCEL_TRANSACTION = 0x0E,
		SCARD_GET_ATTRIB = 0x0F,
		SCARD_SET_ATTRIB = 0x10
	};

	/**
	 * @brief Information transmitted in \c CMD_VERSION Messages.
	 */
	struct version_struct
	{
		int major;
		int minor;
		LONG rv;
	};
	typedef struct version_struct version_struct;

	struct client_struct
	{
		SCARDCONTEXT hContext;
	};
	typedef struct client_struct client_struct;

	/**
	 * @brief Information contained in \c SCARD_ESTABLISH_CONTEXT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct establish_struct
	{
		DWORD dwScope;
		SCARDCONTEXT phContext;
		LONG rv;
	};
	typedef struct establish_struct establish_struct;

	/**
	 * @brief Information contained in \c SCARD_RELEASE_CONTEXT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct release_struct
	{
		SCARDCONTEXT hContext;
		LONG rv;
	};
	typedef struct release_struct release_struct;

	/**
	 * @brief contained in \c SCARD_CONNECT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct connect_struct
	{
		SCARDCONTEXT hContext;
		char szReader[MAX_READERNAME];
		DWORD dwShareMode;
		DWORD dwPreferredProtocols;
		SCARDHANDLE phCard;
		DWORD pdwActiveProtocol;
		LONG rv;
	};
	typedef struct connect_struct connect_struct;

	/**
	 * @brief contained in \c SCARD_RECONNECT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct reconnect_struct
	{
		SCARDHANDLE hCard;
		DWORD dwShareMode;
		DWORD dwPreferredProtocols;
		DWORD dwInitialization;
		DWORD pdwActiveProtocol;
		LONG rv;
	};
	typedef struct reconnect_struct reconnect_struct;

	/**
	 * @brief contained in \c SCARD_DISCONNECT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct disconnect_struct
	{
		SCARDHANDLE hCard;
		DWORD dwDisposition;
		LONG rv;
	};
	typedef struct disconnect_struct disconnect_struct;

	/**
	 * @brief contained in \c SCARD_BEGIN_TRANSACTION Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct begin_struct
	{
		SCARDHANDLE hCard;
		LONG rv;
	};
	typedef struct begin_struct begin_struct;

	/**
	 * @brief contained in \c SCARD_END_TRANSACTION Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct end_struct
	{
		SCARDHANDLE hCard;
		DWORD dwDisposition;
		LONG rv;
	};
	typedef struct end_struct end_struct;

	/**
	 * @brief contained in \c SCARD_CANCEL Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct cancel_struct
	{
		SCARDHANDLE hCard;
		LONG rv;
	};
	typedef struct cancel_struct cancel_struct;

	/**
	 * @brief contained in \c SCARD_STATUS Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct status_struct
	{
		SCARDHANDLE hCard;
		char mszReaderNames[MAX_READERNAME];
		DWORD pcchReaderLen;
		DWORD pdwState;
		DWORD pdwProtocol;
		UCHAR pbAtr[MAX_ATR_SIZE];
		DWORD pcbAtrLen;
		LONG rv;
	};
	typedef struct status_struct status_struct;

	/**
	 * @brief contained in \c SCARD_TRANSMIT Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct transmit_struct
	{
		SCARDHANDLE hCard;
		SCARD_IO_REQUEST pioSendPci;
		UCHAR pbSendBuffer[MAX_BUFFER_SIZE];
		DWORD cbSendLength;
		SCARD_IO_REQUEST pioRecvPci;
		BYTE pbRecvBuffer[MAX_BUFFER_SIZE];
		DWORD pcbRecvLength;
		LONG rv;
	};
	typedef struct transmit_struct transmit_struct;

	/**
	 * @brief contained in \c SCARD_CONTROL Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct control_struct
	{
		SCARDHANDLE hCard;
		DWORD dwControlCode;
		UCHAR pbSendBuffer[MAX_BUFFER_SIZE];
		DWORD cbSendLength;
		UCHAR pbRecvBuffer[MAX_BUFFER_SIZE];
		DWORD cbRecvLength;
		DWORD dwBytesReturned;
		LONG rv;
	};
	typedef struct control_struct control_struct;

	/**
	 * @brief contained in \c SCARD_GET_ATTRIB and \c  Messages.
	 *
	 * These data are passed throw the field \c sharedSegmentMsg.data.
	 */
	struct getset_struct
	{
		SCARDHANDLE hCard;
		DWORD dwAttrId;
		UCHAR pbAttr[MAX_BUFFER_SIZE];
		DWORD cbAttrLen;
		LONG rv;
	};
	typedef struct getset_struct getset_struct;

	/*
	 * Now some function definitions 
	 */

	int SHMClientRead(psharedSegmentMsg, DWORD, int);
	int SHMClientSetupSession(PDWORD);
	int SHMClientCloseSession(DWORD);
	int SHMInitializeCommonSegment(void);
	int SHMProcessEventsContext(PDWORD, psharedSegmentMsg, int);
	int SHMProcessEventsServer(PDWORD, int);
	int SHMMessageSend(psharedSegmentMsg, int, int);
	int SHMMessageReceive(psharedSegmentMsg, int, int);
	int WrapSHMWrite(unsigned int, DWORD, unsigned int,
		unsigned int, void *);
	void SHMCleanupSharedSegment(int, char *);

#ifdef __cplusplus
}
#endif

#endif