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.

149 lines
5.5 KiB

  1. //-------------------------------------------------------------------
  2. // This is abstract class for generic device
  3. // Specific devices should use it as a parent device
  4. // Author: Sergey Ivanov
  5. // Log:
  6. // 08/11/99 - implemented
  7. //-------------------------------------------------------------------
  8. #ifndef __SMART_CARD__
  9. #define __SMART_CARD__
  10. #include "generic.h"
  11. #include "kernel.h"
  12. //
  13. // - IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE defines a specific IOCTL for the Gemplus
  14. // Reader to exchange data with the reader without control of the driver.
  15. // - IOCTL_SMARTCARD_VENDOR_GET_ATTRIBUTE defines a specific IOCTL for the Gemplus
  16. // Reader to gets vendor attributes.
  17. // - IOCTL_SMARTCARD_VENDOR_SET_ATTRIBUTE defines a specific IOCTL for the Gemplus
  18. // Reader to sets vendor attributes.
  19. //
  20. #define IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE CTL_CODE(FILE_DEVICE_SMARTCARD,2048,0,0)
  21. #define IOCTL_SMARTCARD_VENDOR_GET_ATTRIBUTE CTL_CODE(FILE_DEVICE_SMARTCARD,2049,0,0)
  22. #define IOCTL_SMARTCARD_VENDOR_SET_ATTRIBUTE CTL_CODE(FILE_DEVICE_SMARTCARD,2050,0,0)
  23. // 2051 is reserved for Gcr420 keyboard reader.
  24. #define IOCTL_SMARTCARD_VENDOR_SWITCH_SPEED CTL_CODE(FILE_DEVICE_SMARTCARD,2052,0,0)
  25. //
  26. // - SCARD_CLASS is a macro to know the class of a Tag.
  27. //
  28. #define SCARD_CLASS(Value) (ULONG) (((ULONG)(Value)) >> 16)
  29. //
  30. // - SCARD_ATTR_SPEC_BAUD_RATE is the Tag to acces at the value of the baud rate (PC/IFD).
  31. // - SCARD_ATTR_SPEC_CMD_TIMEOUT is the Tag to access at the value of the Cmd Timeout.
  32. // - SCARD_ATTR_SPEC_POWER_TIMEOUT is the Tag to access at the value of the Power
  33. // Timeout.
  34. // - SCARD_ATTR_SPEC_APDU_TIMEOUT is the Tag to access at the value of the APDU
  35. // Timeout.
  36. //
  37. #define SCARD_ATTR_SPEC_BAUD_RATE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0180)
  38. #define SCARD_ATTR_SPEC_CMD_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0181)
  39. #define SCARD_ATTR_SPEC_POWER_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0182)
  40. #define SCARD_ATTR_SPEC_APDU_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0183)
  41. //
  42. // To give possibility for recognition of driver
  43. //
  44. #define SCARD_ATTR_MANUFACTURER_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0190)
  45. #define SCARD_ATTR_ORIGINAL_FILENAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0191)
  46. #define GBCLASS_OPEN_SESSION 0x3001
  47. #define GBCLASS_CLOSE_SESSION 0x3002
  48. #define GBCLASS_DRIVER_SCNAME 0x3003
  49. #define GBCLASS_CONNECTION_TYPE 0x3004
  50. #define IOCTL_OPEN_SESSION CTL_CODE(FILE_DEVICE_BUS_EXTENDER,GBCLASS_OPEN_SESSION,METHOD_BUFFERED,FILE_ANY_ACCESS)
  51. #define IOCTL_CLOSE_SESSION CTL_CODE(FILE_DEVICE_BUS_EXTENDER,GBCLASS_CLOSE_SESSION,METHOD_BUFFERED,FILE_ANY_ACCESS)
  52. #define IOCTL_DRIVER_SCNAME CTL_CODE(FILE_DEVICE_BUS_EXTENDER,GBCLASS_DRIVER_SCNAME,METHOD_BUFFERED,FILE_ANY_ACCESS)
  53. #define IOCTL_GET_CONNECTION_TYPE CTL_CODE(FILE_DEVICE_BUS_EXTENDER,GBCLASS_CONNECTION_TYPE,METHOD_BUFFERED,FILE_ANY_ACCESS)
  54. #define ATTR_MANUFACTURER_NAME "Gemplus"
  55. #define ATTR_ORIGINAL_FILENAME "GrClass.sys"
  56. #define ATTR_LENGTH 32
  57. #define SC_IFD_DEFAULT_CLK_FREQUENCY 4000
  58. #define SC_IFD_MAXIMUM_CLK_FREQUENCY 4000
  59. #define SC_IFD_DEFAULT_DATA_RATE 10753
  60. #define SC_IFD_MAXIMUM_DATA_RATE 125000
  61. #define SC_IFD_MAXIMUM_IFSD 253// To correct problem with SMCLIB!
  62. #define SC_IFD_T0_MAXIMUM_LEX 256
  63. #define SC_IFD_T0_MAXIMUM_LC 255
  64. // PTS mode parameters
  65. #define PROTOCOL_MODE_DEFAULT 0
  66. #define PROTOCOL_MODE_MANUALLY 1
  67. static ULONG
  68. dataRatesSupported[] = {
  69. 10753, 14337, 15625, 17204,
  70. 20833, 21505, 28674, 31250,
  71. 34409, 41667, 43011, 57348,
  72. 62500, 83333, 86022, 114695,
  73. 125000
  74. };
  75. #define GRCLASS_DRIVER_NAME "GRClass"
  76. #define GRCLASS_VENDOR_NAME "Gemplus"
  77. #define GRCLASS_READER_TYPE "GemPC430"
  78. #define REQUEST_TO_NOTIFY_INSERTION 1
  79. #define REQUEST_TO_NOTIFY_REMOVAL 2
  80. #pragma LOCKEDCODE
  81. // Declare Smclib system callbacks...
  82. #ifdef __cplusplus
  83. extern "C"{
  84. #endif
  85. NTSTATUS smartCard_Transmit(PSMARTCARD_EXTENSION SmartcardExtension);
  86. NTSTATUS smartCard_CancelTracking(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp);
  87. NTSTATUS smartCard_Tracking(PSMARTCARD_EXTENSION SmartcardExtension);
  88. NTSTATUS smartCard_VendorIoctl(PSMARTCARD_EXTENSION SmartcardExtension);
  89. NTSTATUS smartCard_Power(PSMARTCARD_EXTENSION SmartcardExtension);
  90. NTSTATUS smartCard_SetProtocol(PSMARTCARD_EXTENSION SmartcardExtension);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #pragma PAGEDCODE
  95. class CUSBReader;//TO CHANGE LATER...
  96. class CSmartCard
  97. {
  98. public:
  99. NTSTATUS m_Status;
  100. SAFE_DESTRUCTORS();
  101. virtual VOID dispose(){self_delete();};
  102. private:
  103. CUSBReader* reader;
  104. CDebug* debug;
  105. CMemory* memory;
  106. CLock* lock;
  107. CSystem* system;
  108. CIrp* irp;
  109. KEVENT evCanceled;// set when tracking is canceled...
  110. PIRP poolingIrp;
  111. UNICODE_STRING DosDeviceName;//Used only at Win9x
  112. public:
  113. KSPIN_LOCK CardLock;
  114. protected:
  115. virtual ~CSmartCard();
  116. public:
  117. CSmartCard();
  118. virtual CUSBReader* getReader() {return reader;};//TO CHANGE LATER...
  119. virtual BOOL smartCardConnect(CUSBReader* reader);
  120. virtual VOID smartCardDisconnect();
  121. virtual BOOL smartCardStart();
  122. virtual PKSPIN_LOCK getCardLock(){return &CardLock;};
  123. virtual VOID completeCardTracking();
  124. virtual VOID setPoolingIrp(PIRP Irp){poolingIrp = Irp;};
  125. virtual PIRP getPoolingIrp(){return poolingIrp;};
  126. virtual BOOLEAN CheckSpecificMode(BYTE* ATR, DWORD ATRLength);
  127. };
  128. #endif