Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1381 lines
28 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. smclib.h
  5. Abstract:
  6. This module contains all definitions for the smart card library.
  7. All defintions are made according to ISO 7816.
  8. Environment:
  9. Kernel mode only.
  10. Notes:
  11. Revision History:
  12. - Created December 1996 by Klaus Schutz
  13. - Jun. 97: Definitions for Windows 9x added
  14. - Feb. 98: PTS struct added
  15. Async./Sync. protocols now combined
  16. --*/
  17. #ifndef _SMCLIB_
  18. #define _SMCLIB_
  19. #if DBG || DEBUG
  20. #undef DEBUG
  21. #define DEBUG 1
  22. #undef DBG
  23. #define DBG 1
  24. #pragma message("Debug is turned on")
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef SMCLIB_VXD
  30. //
  31. // Include windows 9x specific data definitions
  32. //
  33. #include "smcvxd.h"
  34. #elif defined(SMCLIB_CE)
  35. //
  36. // Include Windows CE specific data definitons
  37. //
  38. #include "smcce.h"
  39. #else
  40. //
  41. // Include Windows NT specific data definitions
  42. //
  43. #include "smcnt.h"
  44. #endif
  45. #include "winsmcrd.h"
  46. //
  47. // This name is displayed in debugging messages
  48. //
  49. #ifndef DRIVER_NAME
  50. #define DRIVER_NAME "SMCLIB"
  51. #endif
  52. //
  53. // This version number changes for every change of the device extension.
  54. // (I.e. new fields were added)
  55. // The required version is the version number that the lib is compatible to.
  56. //
  57. #define SMCLIB_VERSION 0x150
  58. #define SMCLIB_VERSION_REQUIRED 0x100
  59. #if DEBUG
  60. #define DEBUG_IOCTL ((ULONG) 0x00000001)
  61. #define DEBUG_ATR ((ULONG) 0x00000002)
  62. #define DEBUG_PROTOCOL ((ULONG) 0x00000004)
  63. #define DEBUG_DRIVER ((ULONG) 0x00000008)
  64. #define DEBUG_TRACE ((ULONG) 0x00000010)
  65. #define DEBUG_ERROR ((ULONG) 0x00000020)
  66. #define DEBUG_INFO DEBUG_ERROR
  67. #define DEBUG_PERF ((ULONG) 0x10000000)
  68. #define DEBUG_T1_TEST ((ULONG) 0x40000000)
  69. #define DEBUG_BREAK ((ULONG) 0x80000000)
  70. #define DEBUG_ALL ((ULONG) 0x0000FFFF)
  71. #endif
  72. #ifdef SMCLIB_VXD
  73. // ****************************************************************************
  74. // Windows 9x definitions
  75. // ****************************************************************************
  76. typedef LONG NTSTATUS;
  77. typedef UCHAR BOOLEAN;
  78. //
  79. // include this file to get nt status codes
  80. //
  81. #include <ntstatus.h>
  82. //
  83. // The following three definition are taken out of the ntddk.h file
  84. // Please refer to this file for a description
  85. //
  86. #define METHOD_BUFFERED 0
  87. #define FILE_ANY_ACCESS 0
  88. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  89. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  90. )
  91. //
  92. // Define the ASSERT macro for Windows 9x
  93. //
  94. #if DEBUG
  95. NTSTATUS
  96. VXDINLINE
  97. SmartcardAssert(
  98. PVOID FailedAssertion,
  99. PVOID FileName,
  100. ULONG LineNumber,
  101. PCHAR Message
  102. );
  103. #define ASSERT( exp ) \
  104. if (!(exp)) { \
  105. SmartcardAssert( #exp, __FILE__, __LINE__, NULL ); \
  106. _asm int 3 \
  107. } else
  108. #define ASSERTMSG( msg, exp ) \
  109. if (!(exp)) { \
  110. SmartcardAssert( #exp, __FILE__, __LINE__, msg ); \
  111. _asm int 3 \
  112. } else
  113. #define SmartcardDebug(LEVEL, STRING) \
  114. { \
  115. if ((LEVEL) & (DEBUG_ERROR | SmartcardGetDebugLevel())) \
  116. _Debug_Printf_Service STRING; \
  117. if (SmartcardGetDebugLevel() & DEBUG_BREAK) \
  118. _asm int 3 \
  119. }
  120. #else
  121. #define ASSERT( exp )
  122. #define ASSERTMSG( msg, exp )
  123. #define SmartcardDebug(LEVEL, STRING)
  124. #endif // DEBUG
  125. #define AccessUnsafeData(Irql)
  126. #define EndAccessUnsafeData(Irql)
  127. #define RtlCopyMemory memcpy
  128. #define RtlZeroMemory(d, c) memset((d), 0, (c))
  129. // ****************************************************************************
  130. // End Windows 9x definitions
  131. // ****************************************************************************
  132. #elif defined(SMCLIB_CE)
  133. // ****************************************************************************
  134. // Windows CE definitions
  135. // ****************************************************************************
  136. // Use the debug message structs and macros from dbgapi.h
  137. // Driver has to define and initialize a DEBUGPARAM struct
  138. #define SmartcardDebug(LEVEL, STRING) DEBUGMSG(dpCurSettings.ulZoneMask & (LEVEL), STRING)
  139. #define SmartcardLockDevice(SmartcardExtension) EnterCriticalSection(&(SmartcardExtension)->OsData->CritSect)
  140. #define SmartcardUnlockDevice(SmartcardExtension) LeaveCriticalSection(&(SmartcardExtension)->OsData->CritSect)
  141. #define AccessUnsafeData(Irql) SmartcardLockDevice(SmartcardExtension)
  142. #define EndAccessUnsafeData(Irql) SmartcardUnlockDevice(SmartcardExtension)
  143. // ****************************************************************************
  144. // End Windows CE definitions
  145. // ****************************************************************************
  146. #else
  147. // ****************************************************************************
  148. // Windows NT definitions
  149. // ****************************************************************************
  150. #if DEBUG
  151. #define SmartcardDebug(LEVEL, STRING) \
  152. { \
  153. if ((LEVEL) & (DEBUG_ERROR | SmartcardGetDebugLevel())) \
  154. DbgPrint STRING; \
  155. if (SmartcardGetDebugLevel() & DEBUG_BREAK) \
  156. DbgBreakPoint(); \
  157. }
  158. #else
  159. #define SmartcardDebug(LEVEL, STRING)
  160. #endif
  161. #define AccessUnsafeData(Irql) \
  162. KeAcquireSpinLock(&SmartcardExtension->OsData->SpinLock, (Irql));
  163. #define EndAccessUnsafeData(Irql) \
  164. KeReleaseSpinLock(&SmartcardExtension->OsData->SpinLock, (Irql));
  165. #ifndef SMART_CARD_READER_GUID_DEFINED
  166. #define SMART_CARD_READER_GUID_DEFINED
  167. #include <initguid.h>
  168. DEFINE_GUID(SmartCardReaderGuid, 0x50DD5230, 0xBA8A, 0x11D1, 0xBF,0x5D,0x00,0x00,0xF8,0x05,0xF5,0x30);
  169. // ****************************************************************************
  170. // End Windows NT definitions
  171. // ****************************************************************************
  172. #endif
  173. #endif
  174. //
  175. // Indexes to the callback functions of the ReaderFunction array
  176. // in the SmartcardExtension
  177. //
  178. #define RDF_CARD_POWER 0
  179. #define RDF_TRANSMIT 1
  180. #define RDF_CARD_EJECT 2
  181. #define RDF_READER_SWALLOW 3
  182. #define RDF_CARD_TRACKING 4
  183. #define RDF_SET_PROTOCOL 5
  184. #define RDF_DEBUG_LEVEL 6
  185. #define RDF_CARD_CONFISCATE 7
  186. #define RDF_IOCTL_VENDOR 8
  187. #define RDF_ATR_PARSE 9
  188. //
  189. // Minimum buffer size for request and reply buffer
  190. //
  191. #define MIN_BUFFER_SIZE 288
  192. //
  193. // This union is used for data type conversion
  194. //
  195. typedef union _LENGTH {
  196. struct {
  197. ULONG l0;
  198. } l;
  199. struct {
  200. UCHAR b0;
  201. UCHAR b1;
  202. UCHAR b2;
  203. UCHAR b3;
  204. } b;
  205. } LENGTH, *PLENGTH;
  206. #define MAXIMUM_ATR_CODES 4
  207. #define MAXIMUM_ATR_LENGTH 33
  208. typedef struct _T0_DATA {
  209. // Number of data bytes in this request
  210. ULONG Lc;
  211. // Number of expected bytes from the card
  212. ULONG Le;
  213. } T0_DATA, *PT0_DATA;
  214. //
  215. // constants for the T=1 i/o function
  216. //
  217. #define T1_INIT 0
  218. #define T1_START 1
  219. #define T1_I_BLOCK 2
  220. #define T1_R_BLOCK 3
  221. #define T1_RESTART 4
  222. #define T1_RESYNCH_REQUEST 0xC0
  223. #define T1_RESYNCH_RESPONSE 0xE0
  224. #define T1_IFS_REQUEST 0xC1
  225. #define T1_IFS_RESPONSE 0xE1
  226. #define T1_ABORT_REQUEST 0xC2
  227. #define T1_ABORT_RESPONSE 0xE2
  228. #define T1_WTX_REQUEST 0xC3
  229. #define T1_WTX_RESPONSE 0xE3
  230. #define T1_VPP_ERROR 0xE4
  231. //
  232. // Information field size the lib uses
  233. //
  234. #define T1_IFSD 254
  235. #define T1_IFSD_DEFAULT 32
  236. //
  237. // Maximum attempts to resend a block in T1
  238. //
  239. #define T1_MAX_RETRIES 2
  240. //
  241. // Bit that indenticates if there are more data to send
  242. //
  243. #define T1_MORE_DATA 0x20
  244. //
  245. // T1 Error values
  246. //
  247. #define T1_ERROR_CHKSUM 1
  248. #define T1_ERROR_OTHER 2
  249. //
  250. // Error detection bit as defined by ISO
  251. //
  252. #define T1_CRC_CHECK 1
  253. //
  254. // Character waiting integer default value as definded by ISO
  255. //
  256. #define T1_CWI_DEFAULT 13
  257. //
  258. // Block waiting integer default value as definded by ISO
  259. //
  260. #define T1_BWI_DEFAULT 4
  261. //
  262. // This struct is used by the lib for processing T1 I/O
  263. // It should not be modified by a driver directly.
  264. //
  265. typedef struct _T1_DATA {
  266. // Current information field size that can be transmitted
  267. UCHAR IFSC;
  268. // Current information field size we can receive
  269. UCHAR IFSD;
  270. // Number of bytes already received from smart card
  271. ULONG BytesReceived;
  272. // Number of bytes already sent to the card;
  273. ULONG BytesSent;
  274. // Total number of bytes still to send
  275. ULONG BytesToSend;
  276. // Type of error
  277. UCHAR LastError;
  278. // This flag is set whenever the IFD has to send more data
  279. BOOLEAN MoreData;
  280. // This is the node address byte to be sent to the card
  281. UCHAR NAD;
  282. // The state before an error occured
  283. ULONG OriginalState;
  284. // Resend counter
  285. UCHAR Resend;
  286. // Resync counter
  287. UCHAR Resynch;
  288. // The 'number' of received I-Blocks
  289. UCHAR RSN;
  290. // The 'number' of sent I-Blocks as defined in ISO 7816-3
  291. UCHAR SSN;
  292. // Current state of protocol
  293. ULONG State;
  294. //
  295. // Waiting time extension requested by the smart card
  296. // This value should be used by the driver to extend block waiting time.
  297. //
  298. UCHAR Wtx;
  299. // Pointer to result buffer
  300. PUCHAR ReplyData;
  301. // This flag indicates that we're waiting for a reply from the card
  302. BOOLEAN WaitForReply;
  303. UCHAR InfBytesSent;
  304. #ifndef _WIN64
  305. // Reserved, do not use
  306. UCHAR Reserved[
  307. 10 -
  308. sizeof(PUCHAR) -
  309. sizeof(BOOLEAN) -
  310. sizeof(UCHAR)];
  311. #endif
  312. } T1_DATA, *PT1_DATA;
  313. //
  314. // This struct is used by the lib for T1 I/O
  315. //
  316. typedef struct _T1_BLOCK_FRAME {
  317. UCHAR Nad;
  318. UCHAR Pcb;
  319. UCHAR Len;
  320. PUCHAR Inf;
  321. } T1_BLOCK_FRAME, *PT1_BLOCK_FRAME;
  322. //
  323. // All lib functions put their data to send in this struct.
  324. // The driver must send this data to the reader.
  325. //
  326. typedef struct _SMARTCARD_REQUEST {
  327. // Data to send
  328. PUCHAR Buffer;
  329. // Allocted size of this buffer
  330. ULONG BufferSize;
  331. // Length of data for this command
  332. ULONG BufferLength;
  333. } SMARTCARD_REQUEST, *PSMARTCARD_REQUEST;
  334. //
  335. // The driver must put the received bytes into this buffer and
  336. // adjust the buffer length to the number of received bytes.
  337. //
  338. typedef struct _SMARTCARD_REPLY {
  339. // Buffer for received smart card data
  340. PUCHAR Buffer;
  341. // Allocted size of this buffer
  342. ULONG BufferSize;
  343. // Number of bytes received from the card
  344. ULONG BufferLength;
  345. } SMARTCARD_REPLY, *PSMARTCARD_REPLY;
  346. //
  347. // Clock rate conversion table according to ISO
  348. //
  349. typedef struct _CLOCK_RATE_CONVERSION {
  350. const ULONG F;
  351. const ULONG fs;
  352. } CLOCK_RATE_CONVERSION, *PCLOCK_RATE_CONVERSION;
  353. //
  354. // Bit rate adjustment factor
  355. // The layout of this table has been slightly modified due to
  356. // the unavailibility of floating point math support in the kernel.
  357. // The value D has beed devided into a numerator and a divisor.
  358. //
  359. typedef struct _BIT_RATE_ADJUSTMENT {
  360. const ULONG DNumerator;
  361. const ULONG DDivisor;
  362. } BIT_RATE_ADJUSTMENT, *PBIT_RATE_ADJUSTMENT;
  363. #ifdef _ISO_TABLES_
  364. #define MHZ * 1000000l
  365. //
  366. // The clock rate conversion table itself.
  367. // All R(eserved)F(or Future)U(se) fields MUST be 0
  368. //
  369. static CLOCK_RATE_CONVERSION ClockRateConversion[] = {
  370. { 372, 4 MHZ },
  371. { 372, 5 MHZ },
  372. { 558, 6 MHZ },
  373. { 744, 8 MHZ },
  374. { 1116, 12 MHZ },
  375. { 1488, 16 MHZ },
  376. { 1860, 20 MHZ },
  377. { 0, 0 },
  378. { 0, 0 },
  379. { 512, 5 MHZ },
  380. { 768, 7500000 },
  381. { 1024, 10 MHZ },
  382. { 1536, 15 MHZ },
  383. { 2048, 20 MHZ },
  384. { 0, 0 },
  385. { 0, 0 }
  386. };
  387. #undef MHZ
  388. //
  389. // The bit rate adjustment table itself.
  390. // All R(eserved)F(or)U(se) fields MUST be 0
  391. //
  392. static BIT_RATE_ADJUSTMENT BitRateAdjustment[] = {
  393. { 0, 0 },
  394. { 1, 1 },
  395. { 2, 1 },
  396. { 4, 1 },
  397. { 8, 1 },
  398. { 16, 1 },
  399. { 32, 1 },
  400. { 0, 0 },
  401. { 12, 1 },
  402. { 20, 1 },
  403. { 0, 0 },
  404. { 0, 0 },
  405. { 0, 0 },
  406. { 0, 0 },
  407. { 0, 0 },
  408. { 0, 0 }
  409. };
  410. #endif
  411. #if defined (DEBUG) && defined (SMCLIB_NT)
  412. typedef struct _PERF_INFO {
  413. ULONG NumTransmissions;
  414. ULONG BytesSent;
  415. ULONG BytesReceived;
  416. LARGE_INTEGER IoTickCount;
  417. LARGE_INTEGER TickStart;
  418. LARGE_INTEGER TickEnd;
  419. } PERF_INFO, *PPERF_INFO;
  420. #endif
  421. //
  422. // structure used for protocol type selection (PTS)
  423. //
  424. typedef struct _PTS_DATA {
  425. #define PTS_TYPE_DEFAULT 0x00
  426. #define PTS_TYPE_OPTIMAL 0x01
  427. #define PTS_TYPE_USER 0x02
  428. UCHAR Type;
  429. // Fl value for PTS
  430. UCHAR Fl;
  431. // Dl value for PTS
  432. UCHAR Dl;
  433. // New clock frequency
  434. ULONG CLKFrequency;
  435. // New baud rate to be used after pts
  436. ULONG DataRate;
  437. // new stop bits to be used after pts
  438. UCHAR StopBits;
  439. } PTS_DATA, *PPTS_DATA;
  440. //
  441. // This struct holds information for the card currently in use
  442. // The driver must store a received ATR into the ATR struct which is
  443. // part of this struct. The lib will get all other information
  444. // out of the ATR.
  445. //
  446. typedef struct _SCARD_CARD_CAPABILITIES{
  447. // Flag that indicates that the current card uses invers convention
  448. BOOLEAN InversConvention;
  449. // Calculated etu
  450. ULONG etu;
  451. //
  452. // Answer To Reset string returned by card.
  453. // Use OsData->SpinLock to access this member
  454. //
  455. struct {
  456. UCHAR Buffer[64];
  457. UCHAR Length;
  458. } ATR;
  459. struct {
  460. UCHAR Buffer[16];
  461. UCHAR Length;
  462. } HistoricalChars;
  463. // !!! DO NOT MODIFY ANY OF THE BELOW VALUES
  464. // OTHERWISE THE LIBRARY WON'T WORK PROPERLY
  465. //
  466. // The following 2 tables are provided to give
  467. // the driver access to the ISO definitions
  468. //
  469. PCLOCK_RATE_CONVERSION ClockRateConversion;
  470. PBIT_RATE_ADJUSTMENT BitRateAdjustment;
  471. // Clock rate conversion
  472. UCHAR Fl;
  473. // Bit rate adjustment
  474. UCHAR Dl;
  475. // Maximum programming current
  476. UCHAR II;
  477. // Programming voltage in .1 Volts
  478. UCHAR P;
  479. // Extra guard time in etu
  480. UCHAR N;
  481. // Calculated guard time in micro seconds
  482. ULONG GT;
  483. struct {
  484. // This is a bit mask of the supported protocols
  485. ULONG Supported;
  486. // The currently selected protocol
  487. ULONG Selected;
  488. } Protocol;
  489. // T=0 specific data
  490. struct {
  491. // Waiting integer
  492. UCHAR WI;
  493. // Waiting time in micro seconds
  494. ULONG WT;
  495. } T0;
  496. // T=1 specific data
  497. struct {
  498. // Information field size of card
  499. UCHAR IFSC;
  500. // Character waiting integer and block waiting integer
  501. UCHAR CWI;
  502. UCHAR BWI;
  503. // Error detection code
  504. UCHAR EDC;
  505. // Character and block waiting time in micro seconds
  506. ULONG CWT;
  507. ULONG BWT;
  508. // Block guarding time in micro seconds
  509. ULONG BGT;
  510. } T1;
  511. PTS_DATA PtsData;
  512. UCHAR Reserved[100 - sizeof(PTS_DATA)];
  513. } SCARD_CARD_CAPABILITIES, *PSCARD_CARD_CAPABILITIES;
  514. //
  515. // structure used for passing configuration info between miniport/class
  516. //
  517. typedef struct _SCARD_READER_CAPABILITIES {
  518. // Supported protocol by the reader/driver (mandatory)
  519. ULONG SupportedProtocols;
  520. ULONG Reserved;
  521. // Type of reader (Serial/USB/PCMCIA/Keyboard etc)
  522. ULONG ReaderType;
  523. // Mechanical characteristics like SCARD_READER_SWALLOWS etc.
  524. ULONG MechProperties;
  525. //
  526. // Current state of reader (card present/removed/activated)
  527. // Use OsData->SpinLock to access this member
  528. // (mandatory)
  529. //
  530. ULONG CurrentState;
  531. //
  532. // The channel id the reader uses depending on the type of reader:
  533. // - Port number for serial reader
  534. // - Port number for par reader
  535. // - Scsi id for scsi reader
  536. // - 0 for keyboard reader
  537. // - device number for USB
  538. //
  539. ULONG Channel;
  540. //
  541. // Clock rates in KHz encoded as little endian
  542. // (I.e. 3.58MHz is encoded as 3580)
  543. // (mandatory)
  544. //
  545. struct {
  546. ULONG Default;
  547. ULONG Max;
  548. } CLKFrequency;
  549. // Data rates in bps encoded as little endian (mandatory)
  550. struct {
  551. ULONG Default;
  552. ULONG Max;
  553. } DataRate;
  554. // Maximum IFSD supported by IFD
  555. ULONG MaxIFSD;
  556. //
  557. // Type of power management the card supports
  558. // (0 = ifd doesn't support pwr mgnt)
  559. //
  560. ULONG PowerMgmtSupport;
  561. // Boolean that indicates that the card has been confiscated
  562. ULONG CardConfiscated;
  563. //
  564. // A list of data rates supported by the ifd.
  565. // If this list is empty, the DataRate struct will be taken
  566. // (optional)
  567. //
  568. struct _DataRatesSupported {
  569. PULONG List;
  570. UCHAR Entries;
  571. } DataRatesSupported;
  572. //
  573. // A list of supported clock frequencies.
  574. // If this list is empty, the CLKFrequency struct will be taken
  575. // (optional)
  576. //
  577. struct _CLKFrequenciesSupported {
  578. PULONG List;
  579. UCHAR Entries;
  580. } CLKFrequenciesSupported;
  581. // Reserved, do not use
  582. UCHAR Reserved1[
  583. 100 -
  584. sizeof(ULONG) -
  585. sizeof(struct _DataRatesSupported) -
  586. sizeof(struct _CLKFrequenciesSupported)
  587. ];
  588. } SCARD_READER_CAPABILITIES, *PSCARD_READER_CAPABILITIES;
  589. //
  590. // This struct holds the mandatory reader info
  591. //
  592. typedef struct _VENDOR_ATTR {
  593. // Manufacturer name (mandatory)
  594. struct {
  595. USHORT Length;
  596. UCHAR Buffer[MAXIMUM_ATTR_STRING_LENGTH];
  597. } VendorName;
  598. // Name (designation) of reader (mandatory)
  599. struct {
  600. USHORT Length;
  601. UCHAR Buffer[MAXIMUM_ATTR_STRING_LENGTH];
  602. } IfdType;
  603. //
  604. // If more than one reader of the same type are installed
  605. // this unit number is used to destinguish these readers
  606. // (mandatory)
  607. //
  608. ULONG UnitNo;
  609. // IFD Version number (optional)
  610. struct {
  611. USHORT BuildNumber;
  612. UCHAR VersionMinor;
  613. UCHAR VersionMajor;
  614. } IfdVersion;
  615. // IFD Serial number (optional)
  616. struct {
  617. USHORT Length;
  618. UCHAR Buffer[MAXIMUM_ATTR_STRING_LENGTH];
  619. } IfdSerialNo;
  620. // Reserved, do not use
  621. ULONG Reserved[25];
  622. } VENDOR_ATTR, *PVENDOR_ATTR;
  623. //
  624. // Forward definitions
  625. //
  626. typedef struct _READER_EXTENSION *PREADER_EXTENSION;
  627. typedef struct _OS_DEP_DATA *POS_DEP_DATA;
  628. typedef struct _SMARTCARD_EXTENSION *PSMARTCARD_EXTENSION;
  629. //
  630. // Define the smartcard portion of the port device extension.
  631. //
  632. typedef struct _SMARTCARD_EXTENSION {
  633. // Version of this structure
  634. ULONG Version;
  635. // Mandatory reader info
  636. VENDOR_ATTR VendorAttr;
  637. // Array of callback reader functions
  638. NTSTATUS (*ReaderFunction[16])(PSMARTCARD_EXTENSION);
  639. // Capabilities of the current inserted card
  640. SCARD_CARD_CAPABILITIES CardCapabilities;
  641. //
  642. // This is used to store the last error of an overlapped operation
  643. // (Used only for Win9x VxD's)
  644. //
  645. ULONG LastError;
  646. // This struct holds the data of the users io request
  647. struct {
  648. // Number of bytes returned
  649. PULONG Information;
  650. // Pointer to data to send to the card
  651. PUCHAR RequestBuffer;
  652. // Number of bytes to send
  653. ULONG RequestBufferLength;
  654. // Pointer to buffer that receives the answer
  655. PUCHAR ReplyBuffer;
  656. // Size of reply buffer
  657. ULONG ReplyBufferLength;
  658. } IoRequest;
  659. // Major and minor io control code for current request
  660. ULONG MajorIoControlCode;
  661. ULONG MinorIoControlCode;
  662. // OS dependent data
  663. POS_DEP_DATA OsData;
  664. // Capabilities of the keyboard-reader
  665. SCARD_READER_CAPABILITIES ReaderCapabilities;
  666. // Reader specific data
  667. PREADER_EXTENSION ReaderExtension;
  668. //
  669. // The reader stores all replies from the card here
  670. // This can be used by the driver for data coming from the reader
  671. //
  672. SMARTCARD_REPLY SmartcardReply;
  673. //
  674. // Current command that will be sent to the smart card
  675. // This can be used by the driver for data to send to the readaer
  676. //
  677. SMARTCARD_REQUEST SmartcardRequest;
  678. // Data for T=0
  679. T0_DATA T0;
  680. // Data for T=1
  681. T1_DATA T1;
  682. #if defined (DEBUG) && defined (SMCLIB_NT)
  683. PPERF_INFO PerfInfo;
  684. #endif
  685. // Reserved, do not use
  686. ULONG Reserved[
  687. 25
  688. #if defined (DEBUG) && defined (SMCLIB_NT)
  689. - sizeof(PPERF_INFO)
  690. #endif
  691. ];
  692. } SMARTCARD_EXTENSION, *PSMARTCARD_EXTENSION;
  693. #ifdef SMCLIB_VXD
  694. // ****************************************************************************
  695. // Windows 95 definitions and prototyping
  696. // ****************************************************************************
  697. #ifndef SMCLIB_DEVICE_ID
  698. #define SMCLIB_DEVICE_ID 0x0004E /* Smart Card port driver */
  699. #else
  700. #if SMCLIB_DEVICE_ID != 0x0004E
  701. #error "Incorrect SMCLIB_DEVICE_ID Definition"
  702. #endif
  703. #endif
  704. #define SMCLIB_Service Declare_Service
  705. #pragma warning(disable:4003)
  706. Begin_Service_Table(SMCLIB)
  707. SMCLIB_Service(SMCLIB_Get_Version)
  708. SMCLIB_Service(SMCLIB_SmartcardCreateLink)
  709. SMCLIB_Service(SMCLIB_SmartcardDeleteLink)
  710. SMCLIB_Service(SMCLIB_SmartcardDeviceControl)
  711. SMCLIB_Service(SMCLIB_SmartcardExit)
  712. SMCLIB_Service(SMCLIB_SmartcardInitialize)
  713. SMCLIB_Service(SMCLIB_SmartcardLogError)
  714. SMCLIB_Service(SMCLIB_SmartcardRawReply)
  715. SMCLIB_Service(SMCLIB_SmartcardRawRequest)
  716. SMCLIB_Service(SMCLIB_SmartcardT0Reply)
  717. SMCLIB_Service(SMCLIB_SmartcardT0Request)
  718. SMCLIB_Service(SMCLIB_SmartcardT1Reply)
  719. SMCLIB_Service(SMCLIB_SmartcardT1Request)
  720. SMCLIB_Service(SMCLIB_SmartcardUpdateCardCapabilities)
  721. SMCLIB_Service(SMCLIB_SmartcardGetDebugLevel)
  722. SMCLIB_Service(SMCLIB_SmartcardSetDebugLevel)
  723. SMCLIB_Service(SMCLIB_MapNtStatusToWinError)
  724. SMCLIB_Service(SMCLIB_Assert)
  725. SMCLIB_Service(SMCLIB_VxD_CreateDevice)
  726. SMCLIB_Service(SMCLIB_VxD_DeleteDevice)
  727. SMCLIB_Service(SMCLIB_SmartcardCompleteCardTracking)
  728. SMCLIB_Service(SMCLIB_SmartcardCompleteRequest)
  729. End_Service_Table(SMCLIB)
  730. PVMMDDB
  731. VXDINLINE
  732. VxD_CreateDevice(
  733. char *Device,
  734. void (*ControlProc)(void)
  735. )
  736. {
  737. _asm push ControlProc
  738. _asm push Device
  739. VxDCall(SMCLIB_VxD_CreateDevice);
  740. _asm add sp, 8
  741. }
  742. BOOL
  743. VXDINLINE
  744. VxD_DeleteDevice(
  745. PVMMDDB pDDB
  746. )
  747. {
  748. _asm push pDDB
  749. VxDCall(SMCLIB_VxD_DeleteDevice);
  750. _asm add sp, 4
  751. }
  752. NTSTATUS
  753. VXDINLINE
  754. SmartcardAssert(
  755. PVOID FailedAssertion,
  756. PVOID FileName,
  757. ULONG LineNumber,
  758. PCHAR Message
  759. )
  760. {
  761. _asm push Message
  762. _asm push LineNumber
  763. _asm push FileName
  764. _asm push FailedAssertion
  765. VxDCall(SMCLIB_Assert);
  766. _asm add sp, 16
  767. }
  768. NTSTATUS
  769. VXDINLINE
  770. SmartcardCreateLink(
  771. PUCHAR LinkName,
  772. PUCHAR DeviceName
  773. )
  774. {
  775. _asm push DeviceName
  776. _asm push LinkName
  777. VxDCall(SMCLIB_SmartcardCreateLink);
  778. _asm add sp, 8
  779. }
  780. NTSTATUS
  781. VXDINLINE
  782. SmartcardDeleteLink(
  783. PUCHAR LinkName
  784. )
  785. {
  786. _asm push LinkName
  787. VxDCall(SMCLIB_SmartcardDeleteLink);
  788. _asm add sp, 4
  789. }
  790. NTSTATUS
  791. VXDINLINE
  792. SmartcardDeviceControl(
  793. PSMARTCARD_EXTENSION SmartcardExtension,
  794. DIOCPARAMETERS *lpDIOCParmas
  795. )
  796. {
  797. _asm push lpDIOCParmas
  798. _asm push SmartcardExtension
  799. VxDCall(SMCLIB_SmartcardDeviceControl);
  800. _asm add sp, 8
  801. }
  802. VOID
  803. VXDINLINE
  804. SmartcardExit(
  805. PSMARTCARD_EXTENSION SmartcardExtension
  806. )
  807. {
  808. _asm push SmartcardExtension
  809. VxDCall(SMCLIB_SmartcardExit);
  810. _asm add sp, 4
  811. }
  812. NTSTATUS
  813. VXDINLINE
  814. SmartcardInitialize(
  815. PSMARTCARD_EXTENSION SmartcardExtension
  816. )
  817. {
  818. _asm push SmartcardExtension
  819. VxDCall(SMCLIB_SmartcardInitialize);
  820. _asm add sp, 4
  821. }
  822. VOID
  823. VXDINLINE
  824. SmartcardLogError(
  825. )
  826. {
  827. VxDCall(SMCLIB_SmartcardLogError);
  828. }
  829. NTSTATUS
  830. VXDINLINE
  831. SmartcardRawReply(
  832. PSMARTCARD_EXTENSION SmartcardExtension
  833. )
  834. {
  835. _asm push SmartcardExtension
  836. VxDCall(SMCLIB_SmartcardRawReply);
  837. _asm add sp, 4
  838. }
  839. NTSTATUS
  840. VXDINLINE
  841. SmartcardRawRequest(
  842. PSMARTCARD_EXTENSION SmartcardExtension
  843. )
  844. {
  845. _asm push SmartcardExtension
  846. VxDCall(SMCLIB_SmartcardRawRequest);
  847. _asm add sp, 4
  848. }
  849. NTSTATUS
  850. VXDINLINE
  851. SmartcardT0Reply(
  852. PSMARTCARD_EXTENSION SmartcardExtension
  853. )
  854. {
  855. _asm push SmartcardExtension
  856. VxDCall(SMCLIB_SmartcardT0Reply);
  857. _asm add sp, 4
  858. }
  859. NTSTATUS
  860. VXDINLINE
  861. SmartcardT0Request(
  862. PSMARTCARD_EXTENSION SmartcardExtension
  863. )
  864. {
  865. _asm push SmartcardExtension
  866. VxDCall(SMCLIB_SmartcardT0Request);
  867. _asm add sp, 4
  868. }
  869. NTSTATUS
  870. VXDINLINE
  871. SmartcardT1Reply(
  872. PSMARTCARD_EXTENSION SmartcardExtension
  873. )
  874. {
  875. _asm push SmartcardExtension
  876. VxDCall(SMCLIB_SmartcardT1Reply);
  877. _asm add sp, 4
  878. }
  879. NTSTATUS
  880. VXDINLINE
  881. SmartcardT1Request(
  882. PSMARTCARD_EXTENSION SmartcardExtension
  883. )
  884. {
  885. _asm push SmartcardExtension
  886. VxDCall(SMCLIB_SmartcardT1Request);
  887. _asm add sp, 4
  888. }
  889. NTSTATUS
  890. VXDINLINE
  891. SmartcardUpdateCardCapabilities(
  892. PSMARTCARD_EXTENSION SmartcardExtension
  893. )
  894. {
  895. _asm push SmartcardExtension
  896. VxDCall(SMCLIB_SmartcardUpdateCardCapabilities);
  897. _asm add sp, 4
  898. }
  899. ULONG
  900. VXDINLINE
  901. SmartcardGetDebugLevel(
  902. void
  903. )
  904. {
  905. VxDCall(SMCLIB_SmartcardGetDebugLevel);
  906. }
  907. void
  908. VXDINLINE
  909. SmartcardSetDebugLevel(
  910. ULONG Level
  911. )
  912. {
  913. _asm push Level
  914. VxDCall(SMCLIB_SmartcardSetDebugLevel);
  915. _asm add sp, 4
  916. }
  917. void
  918. VXDINLINE
  919. SmartcardCompleteCardTracking(
  920. PSMARTCARD_EXTENSION SmartcardExtension
  921. )
  922. {
  923. _asm push SmartcardExtension
  924. VxDCall(SMCLIB_SmartcardCompleteCardTracking);
  925. _asm add sp, 4
  926. }
  927. void
  928. VXDINLINE
  929. SmartcardCompleteRequest(
  930. PSMARTCARD_EXTENSION SmartcardExtension
  931. )
  932. {
  933. _asm push SmartcardExtension
  934. VxDCall(SMCLIB_SmartcardCompleteRequest);
  935. _asm add sp, 4
  936. }
  937. ULONG
  938. VXDINLINE
  939. MapNtStatusToWinError(
  940. NTSTATUS status
  941. )
  942. {
  943. _asm push status
  944. VxDCall(SMCLIB_MapNtStatusToWinError);
  945. _asm add sp, 4
  946. }
  947. VOID
  948. SmartcardInvertData(
  949. PUCHAR Buffer,
  950. ULONG Length
  951. );
  952. #else
  953. // ****************************************************************************
  954. // Windows NT and Windows CE prototyping
  955. // ****************************************************************************
  956. #ifndef _SMCLIBSYSTEM_
  957. #define SMCLIBAPI _declspec(dllimport)
  958. #else
  959. #define SMCLIBAPI
  960. #endif
  961. #ifdef SMCLIB_CE
  962. #define SmartcardLogError(Object,ErrorCode,Insertion,DumpWord)
  963. #else
  964. VOID
  965. SMCLIBAPI
  966. SmartcardLogError(
  967. PVOID Object,
  968. LONG ErrorCode,
  969. PUNICODE_STRING Insertion,
  970. ULONG DumpWord
  971. );
  972. #endif
  973. #ifdef SMCLIB_CE
  974. NTSTATUS
  975. SMCLIBAPI
  976. SmartcardDeviceControl(
  977. PSMARTCARD_EXTENSION SmartcardExtension,
  978. DWORD dwIoControlCode,
  979. PBYTE pInBuf,
  980. DWORD nInBufSize,
  981. PBYTE pOutBuf,
  982. DWORD nOutBufSize,
  983. PDWORD pBytesReturned
  984. );
  985. #else
  986. NTSTATUS
  987. SMCLIBAPI
  988. SmartcardDeviceControl(
  989. PSMARTCARD_EXTENSION SmartcardExtension,
  990. PIRP Irp
  991. );
  992. #endif
  993. VOID
  994. SMCLIBAPI
  995. SmartcardInitializeCardCapabilities(
  996. PSMARTCARD_EXTENSION SmartcardExtension
  997. );
  998. NTSTATUS
  999. SMCLIBAPI
  1000. SmartcardInitialize(
  1001. PSMARTCARD_EXTENSION SmartcardExtension
  1002. );
  1003. VOID
  1004. SMCLIBAPI
  1005. SmartcardCompleteCardTracking(
  1006. PSMARTCARD_EXTENSION SmartcardExtension
  1007. );
  1008. VOID
  1009. SMCLIBAPI
  1010. SmartcardExit(
  1011. PSMARTCARD_EXTENSION SmartcardExtension
  1012. );
  1013. NTSTATUS
  1014. SMCLIBAPI
  1015. SmartcardUpdateCardCapabilities(
  1016. PSMARTCARD_EXTENSION SmartcardExtension
  1017. );
  1018. NTSTATUS
  1019. SMCLIBAPI
  1020. SmartcardRawRequest(
  1021. PSMARTCARD_EXTENSION SmartcardExtension
  1022. );
  1023. NTSTATUS
  1024. SMCLIBAPI
  1025. SmartcardT0Request(
  1026. PSMARTCARD_EXTENSION SmartcardExtension
  1027. );
  1028. NTSTATUS
  1029. SMCLIBAPI
  1030. SmartcardT1Request(
  1031. PSMARTCARD_EXTENSION SmartcardExtension
  1032. );
  1033. NTSTATUS
  1034. SMCLIBAPI
  1035. SmartcardRawReply(
  1036. PSMARTCARD_EXTENSION SmartcardExtension
  1037. );
  1038. NTSTATUS
  1039. SMCLIBAPI
  1040. SmartcardT0Reply(
  1041. PSMARTCARD_EXTENSION SmartcardExtension
  1042. );
  1043. NTSTATUS
  1044. SMCLIBAPI
  1045. SmartcardT1Reply(
  1046. PSMARTCARD_EXTENSION SmartcardExtension
  1047. );
  1048. VOID
  1049. SMCLIBAPI
  1050. SmartcardInvertData(
  1051. PUCHAR Buffer,
  1052. ULONG Length
  1053. );
  1054. #ifndef SMCLIB_CE
  1055. // Following APIs not defined in Windows CE
  1056. NTSTATUS
  1057. SMCLIBAPI
  1058. SmartcardCreateLink(
  1059. IN OUT PUNICODE_STRING LinkName,
  1060. IN PUNICODE_STRING DeviceName
  1061. );
  1062. ULONG
  1063. SMCLIBAPI
  1064. SmartcardGetDebugLevel(
  1065. void
  1066. );
  1067. void
  1068. SMCLIBAPI
  1069. SmartcardSetDebugLevel(
  1070. ULONG Level
  1071. );
  1072. NTSTATUS
  1073. SmartcardAcquireRemoveLock(
  1074. IN PSMARTCARD_EXTENSION SmartcardExtension
  1075. );
  1076. NTSTATUS
  1077. SmartcardAcquireRemoveLockWithTag(
  1078. IN PSMARTCARD_EXTENSION SmartcardExtension,
  1079. IN ULONG Tag
  1080. );
  1081. VOID
  1082. SmartcardReleaseRemoveLock(
  1083. IN PSMARTCARD_EXTENSION SmartcardExtension
  1084. );
  1085. VOID
  1086. SmartcardReleaseRemoveLockWithTag(
  1087. IN PSMARTCARD_EXTENSION SmartcardExtension,
  1088. IN ULONG Tag
  1089. );
  1090. VOID
  1091. SmartcardReleaseRemoveLockAndWait(
  1092. IN PSMARTCARD_EXTENSION SmartcardExtension
  1093. );
  1094. #else
  1095. // WinCE only
  1096. ULONG
  1097. MapNtStatusToWinError(
  1098. NTSTATUS status
  1099. );
  1100. #endif
  1101. #endif
  1102. #ifdef __cplusplus
  1103. }
  1104. #endif
  1105. #endif