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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/*++
Copyright (c) 1997 - 1999 SCM Microsystems, Inc.
Module Name:
PscrRdWr.h
Abstract:
Constants & access function prototypes for SCM PSCR smartcard reader
Author:
Andreas Straub
Notes:
The file pscrrdwr.h was reviewed by LCA in June 2011 and per license is
acceptable for Microsoft use under Dealpoint ID 178449.
Revision History:
Andreas Straub 7/16/1997 Initial Version
--*/
#if !defined( __PSCR_RDWR_H__ )
#define __PSCR_RDWR_H__
#pragma pack( 1 )
//
// The usage of the PSCR_REGISTERS struct is a little bit tricky:
// We set the address of that stucture to the IO Base Port, then
// the other reg's can accessed by their address.
// p.E. &PscrRegs = 0x320 --> &PscrRegs->CmdStatusReg = 0x321...
//
typedef struct _PSCR_REGISTERS {
UCHAR DataReg;
UCHAR CmdStatusReg;
UCHAR SizeLSReg;
UCHAR SizeMSReg;
} PSCR_REGISTERS, *PPSCR_REGISTERS;
#define SIZEOF_PSCR_REGISTERS ( sizeof( PSCR_REGISTERS )
#pragma pack()
typedef enum _READER_POWER_STATE {
PowerReaderUnspecified = 0,
PowerReaderWorking,
PowerReaderOff
} READER_POWER_STATE, *PREADER_POWER_STATE;
typedef void ( *PTRACKING_COMPLETION )( PVOID TrackingContext, UCHAR Status, BOOLEAN Wakeup );
#define MAX_DATARATES 4
typedef struct _READER_EXTENSION {
// I/O address where the reader is configured.
PPSCR_REGISTERS IOBase;
ULONG IOWindow;
ULONG MaxIFSD;
// IRQ assigned by the system
ULONG CurrentIRQ;
//
// limit for read timeout. the absolute timeout limit is
// MaxRetries * DELAY_PSCR_WAIT
//
ULONG MaxRetries;
// Source/Destination byte always used by the PCMCIA (PC Card) reader.
UCHAR Device;
// Software revision ID of the SwapSmart firmware.
UCHAR FirmwareMajor, FirmwareMinor, UpdateKey;
//
// Interrupt status; the flag is raised if an freeze event was detected
// and cleared if the interface was cleared (int service routine or
// PscrRead)
//
BOOLEAN FreezePending;
//
// Selected file in the reader file system; the flag is raised if the
// ICC1 status file was selected & is cleared if any generic ioctl was
// issued (in this case another file may be selected)
//
BOOLEAN StatusFileSelected;
// used to cancel a read request
BOOLEAN RequestPending;
// set TRUE if an interrupt is sending, but the reader is busy
BOOLEAN RequestInterrupt;
BOOLEAN InvalidStatus;
BOOLEAN CardPresent;
// Current reader power state.
READER_POWER_STATE ReaderPowerState;
PTRACKING_COMPLETION CompletionRoutine;
PVOID TrackingContext;
ULONG dataRatesSupported[MAX_DATARATES];
} READER_EXTENSION, *PREADER_EXTENSION;
#define SIZEOF_READER_EXTENSION ( sizeof( READER_EXTENSION ))
//
// Constants -----------------------------------------------------------------
//
#define PSCR_ID_STRING "SCM SwapSmart 2."
#define TLV_BUFFER_SIZE 0x20
#define ATR_SIZE 0x40 // TS + 32 + SW + PROLOGUE + EPILOGUE...
#define PSCR_MAX_RETRIES 1000
#define CLEAR_BIT 0x00
#define DEFAULT_WAIT_TIME 0x01
#define PSCR_PROLOGUE_LENGTH 0x03
#define PSCR_EXT_PROLOGUE_LENGTH 0x05
#define PSCR_STATUS_LENGTH 0x02
#define PSCR_LRC_LENGTH 0x01
#define PSCR_CRC_LENGTH 0x02
#define PSCR_EPILOGUE_LENGTH PSCR_LRC_LENGTH
#define PCB_DEFAULT 0x00
#define MAX_T1_BLOCK_SIZE 270
//
// data buffer idx
//
#define PSCR_NAD 0x00
#define PSCR_PCB 0x01
#define PSCR_LEN 0x02
#define PSCR_INF 0x03
#define PSCR_APDU PSCR_INF
//
// device identifier for reset, deactivate
//
#define DEVICE_READER 0x00
#define DEVICE_ICC1 0x01
#define DEVICE_ICC2 0x02
//
// NAD's
//
#define NAD_TO_ICC1 0x02
#define NAD_TO_ICC2 0x42
#define NAD_TO_PSCR 0x12
#define REMOTE_NAD_TO_ICC1 0x03
#define REMOTE_NAD_TO_ICC2 0x43
#define REMOTE_NAD_TO_PSCR 0x13
//
// PSCR Commands
//
#define CLA_SET_INTERFACE_PARAM 0x80
#define CLA_FREEZE 0x80
#define CLA_RESET 0x20
#define CLA_DEACTIVATE 0x20
#define CLA_SELECT_FILE 0x00
#define CLA_READ_BINARY 0x00
#define CLA_WRITE_BINARY 0x00
#define CLA_VERIFY 0x00
#define CLA_WARM_RESET 0x20
#define CLA_SOFTWARE_UPDATE 0x80
#define CLA_SET_MODE 0x80
#define INS_SET_INTERFACE_PARAM 0x60
#define INS_FREEZE 0x70
#define INS_RESET 0x10
#define INS_DEACTIVATE 0x14
#define INS_SELECT_FILE 0xA4
#define INS_READ_BINARY 0xB0
#define INS_WRITE_BINARY 0xD0
#define INS_VERIFY 0x20
#define INS_WARM_RESET 0x1F
#define INS_SOFTWARE_UPDATE 0xFF
#define INS_SET_MODE 0x61
//
// Status Read Only Register
//
#define PSCR_DATA_AVAIL_BIT 0x80
#define PSCR_FREE_BIT 0x40
#define PSCR_WRITE_ERROR_BIT 0x02
#define PSCR_READ_ERROR_BIT 0x01
//
// Command Write Only Register...
//
#define PSCR_RESET_BIT 0x08
#define PSCR_SIZE_READ_BIT 0x04
#define PSCR_SIZE_WRITE_BIT 0x02
#define PSCR_HOST_CONTROL_BIT 0x01
//
// Tags...
//
#define TAG_MODULE 0x02
#define TAG_MEMORY_SIZE 0x03
#define TAG_UPDATE_KEY 0x08
#define TAG_SOFTWARE_REV 0x0F
#define TAG_BLOCK_COMP_OPTION 0x13
#define TAG_READER_MECH_OPTIONS 0x20
#define TAG_READER_STATUS 0x21
#define TAG_ICC_PROTOCOLS 0x22
#define TAG_BI 0x23
#define TAG_FI 0x24
#define TAG_PTS_PARAM 0x25
#define TAG_PROTOCOL_STATUS 0x26
#define TAG_SET_NULL_BYTES 0x2d
#define TAG_FREEZE_EVENTS 0x30
#define TAG_BIT_LENGTH 0x40
#define TAG_CGT 0x41
#define TAG_BWT 0x42
#define TAG_CWT 0x43
#define TAG_PROTOCOL_PARAM 0x44
//
// card power definitions ( Tag 0x21 )
//
#define PSCR_ICC_ABSENT 0x00
#define PSCR_ICC_PRESENT 0x01
#define PSCR_ICC_POWERED 0x02
#define PSCR_ICC_IN_TRANSP_MODE 0xA0
#define PSCR_ICC_UNKNOWN 0xFF
//
// protocol definitions ( Tag 0x22 )
//
#define PSCR_PROTOCOL_UNDEFINED 0x00
#define PSCR_PROTOCOL_T0 0x01
#define PSCR_PROTOCOL_T1 0x02
#define PSCR_PROTOCOL_T14 0x03
#define PSCR_PROTOCOL_I2C 0x80
#define PSCR_PROTOCOL_3WIRE 0x81
#define PSCR_PROTOCOL_2WIRE 0x81
#define WTX_REQUEST 0xC3
#define WTX_REPLY 0xE3
//
// File ID's
//
#define FILE_MASTER 0x3F00
#define FILE_PSCR_CONFIG 0x0020
#define FILE_PSCR_DIR 0x7F60
#define FILE_PSCR_DIR_CONFIG 0x6020
#define FILE_PSCR_DIR_STATUS 0x6021
#define FILE_PSCR_DIR_FREEZE_CONFIG 0x6030
#define FILE_PSCR_DIR_FREEZE_STATUS 0x6031
#define FILE_ICC1_DIR 0x7F70
#define FILE_ICC1_DIR_CONFIG 0x7020
#define FILE_ICC1_DIR_STATUS 0x7021
#define FILE_ICC2_DIR_CONFIG 0x7120
#define FILE_ICC2_DIR_STATUS 0x7121
//
// Status Word Definitions
//
#define PSCR_SW_COMMAND_FAIL 0x6985
#define PSCR_SW_INVALID_PARAM 0x6A80
#define PSCR_SW_INCONSISTENT_DATA 0x6A85
#define PSCR_SW_NO_PROTOCOL_SUPPORT 0x62A3
#define PSCR_SW_SYNC_ATR_SUCCESS 0x9000
#define PSCR_SW_ASYNC_ATR_SUCCESS 0x9001
#define PSCR_SW_NO_PROTOCOL 0x62A5
#define PSCR_SW_NO_ATR 0x62A6
#define PSCR_SW_NO_ATR_OR_PROTOCOL 0x62A7
#define PSCR_SW_NO_ICC 0x64A1
#define PSCR_SW_ICC_NOT_ACTIVE 0x64A2
#define PSCR_SW_NON_SUPPORTED_PROTOCOL 0x64A3
#define PSCR_SW_PROTOCOL_ERROR 0x64A8
#define PSCR_SW_NO_ATR_OR_PROTOCOL2 0x64A7
#define PSCR_SW_FILE_NOT_FOUND 0x6A82
#define PSCR_SW_FILE_NO_ACCEPPTED_AUTH 0x6982
#define PSCR_SW_FILE_NO_ACCESS 0x6985
#define PSCR_SW_FILE_BAD_OFFSET 0x6B00
#define PSCR_SW_END_OF_FILE_READ 0x6282
#define PSCR_SW_END_OF_FILE_WRITE 0x6301
#define PSCR_SW_WRITE_FILE_FAIL 0x6500
#define PSCR_SW_NO_PASSWORD 0x6200
#define PSCR_SW_WRONG_PASSWORD 0x6300
#define PSCR_SW_VERIFY_COUNTER_FAIL 0x6983
#define PSCR_SW_NO_REF_DATA 0x6A88
#define PSCR_SW_FLASH_MEM_ERROR 0x6481
#define PSCR_SW_FLASH_MEM_ERR2 0x6581
#define PSCR_SW_WRONG_LENGTH 0x6700
#define PSCR_SW_UNKNOWN_ICC_ERROR 0x64A0
#define PSCR_SW_UNKNOWN_PROTOCOL_ERROR 0x64A9
#define PSCR_SW_NO_PROTOCOL_SELECTED 0x64A5
#define PSCR_SW_PTS_PROTOCOL_ERROR 0x64AA
#define PSCR_SW_WTX_ERROR 0x64AB
#define PSCR_SW_WTX_ERR2 0x65AB
#define PSCR_SW_INVALID_SOURCE_ADDR 0x6F82
//
// Prototypes for access functions -------------------------------------------
//
VOID
PscrFlushInterface(
PREADER_EXTENSION ReaderExtension // context of call
);
NTSTATUS
PscrRead(
_In_ PREADER_EXTENSION ReaderExtension, // context of call
_Out_writes_bytes_(DataLen) PUCHAR pData, // ptr to data buffer
_In_ ULONG DataLen, // length of data
_Out_ PULONG pNBytes // number of bytes read
);
NTSTATUS
PscrReadDirect(
PREADER_EXTENSION ReaderExtension, // context of call
_Out_writes_bytes_(DataLen) PUCHAR pData, // ptr to data buffer
ULONG DataLen, // length of data
PULONG pNBytes // number of bytes read
);
NTSTATUS
PscrWrite(
PREADER_EXTENSION ReaderExtension, // context of call
PUCHAR pData, // ptr to data buffer
ULONG DataLength, // length of data
PULONG pNBytes // number of bytes written
);
NTSTATUS
PscrWriteDirect(
PREADER_EXTENSION ReaderExtension, // context of call
PUCHAR pData, // ptr to data buffer
ULONG DataLength, // length of data
PULONG pNBytes // number of bytes written
);
UCHAR
PscrCalculateLRC(
PUCHAR pData, // ptr to data buffer
USHORT DataLength // length of data
);
NTSTATUS
PscrWait(
PREADER_EXTENSION ReaderExtension, // context of call
UCHAR Mask // mask of requested bits
);
#endif // __PSCR_RDWR_H__
// ------------------------------- END OF FILE -------------------------------
|