Source code of Windows XP (NT5)
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.

174 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) SCM Microsystems, 1998 - 1999
  6. //
  7. // File: serialnt.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #if !defined( __SERIAL_NT_H__ )
  11. #define __SERIAL_NT_H__
  12. #include "DriverNT.h"
  13. #include <ntddser.h>
  14. #include "SerialIF.h"
  15. #define STC_BUFFER_SIZE 32
  16. #define TPDU_STACK_SIZE 2048
  17. typedef struct _SERIAL_PORT_CONFIG
  18. {
  19. SERIAL_HANDFLOW HandFlow; // flow control
  20. SERIAL_CHARS SerialChars; // special characters
  21. SERIAL_TIMEOUTS Timeouts; // read/write timeouts
  22. SERIAL_BAUD_RATE BaudRate; // Baudrate for reader
  23. SERIAL_LINE_CONTROL LineControl; // Stop bits, parity configuration
  24. ULONG WaitMask, // notification events
  25. Purge;
  26. } SERIAL_PORT_CONFIG, *PSERIAL_PORT_CONFIG;
  27. typedef struct _READER_EXTENSION
  28. {
  29. //
  30. // serial port driver data
  31. //
  32. ULONG SerialPortNumber;
  33. PDEVICE_OBJECT SerialDeviceObject;
  34. PFILE_OBJECT SerialFileObject;
  35. PIO_WORKITEM CloseSerial; // worker thread that closes the serial driver
  36. // back pointer to smart card extension
  37. PSMARTCARD_EXTENSION SmartcardExtension;
  38. // read thread data
  39. UCHAR IOData[ 2 * STC_BUFFER_SIZE ];
  40. UCHAR TPDUStack[ TPDU_STACK_SIZE ];
  41. ULONG Available;
  42. ULONG Expected;
  43. ULONG EventMask;
  44. ULONG ReadTimeout; // read timeout in ms
  45. IO_STATUS_BLOCK IoStatus;
  46. KEVENT IoEvent;
  47. KEVENT DataAvailable;
  48. PIO_WORKITEM ReadWorkItem;
  49. KSPIN_LOCK ReadSpinLock;
  50. // miscellaneous
  51. ULONG ReaderPowerState;
  52. BOOLEAN PowerRequest;
  53. UCHAR FirmwareMajor,
  54. FirmwareMinor;
  55. BOOLEAN CardPresent;
  56. KEVENT SerialCloseDone; // signaled if the connection to the serial driver has been closed
  57. } READER_EXTENSION, *PREADER_EXTENSION;
  58. typedef enum _READER_POWER_STATE
  59. {
  60. PowerReaderUnspecified = 0,
  61. PowerReaderWorking,
  62. PowerReaderOff
  63. } READER_POWER_STATE, *PREADER_POWER_STATE;
  64. //
  65. // CONSTANTS
  66. //
  67. #define SR_VENDOR_NAME "STCS"
  68. #define SR_PRODUCT_NAME "Serial Reader"
  69. //
  70. // serial communication defines
  71. //
  72. #define SR_BAUD_RATE 115200
  73. #define SR_STOP_BITS STOP_BIT_1
  74. #define SR_PARITY NO_PARITY
  75. #define SR_DATA_LENGTH SERIAL_DATABITS_8
  76. //
  77. // COM timeout values in ms
  78. //
  79. #define SR_READ_TOTAL_TIMEOUT_CONSTANT 2000
  80. #define SR_READ_INTERVAL_TIMEOUT 2000
  81. #define SR_WRITE_TOTAL_TIMEOUT_CONSTANT 2000
  82. #define SR_WRITE_TOTAL_TIMEOUT_MULTIPLIER 0
  83. #define SR_FLOW_REPLACE 0
  84. #define SR_HAND_SHAKE 0
  85. #define SR_XON_LIMIT 0
  86. #define SR_XOFF_LIMIT 0
  87. #define SR_ON_CHAR 0x11
  88. #define SR_OFF_CHAR 0x13
  89. #define SR_NOTIFICATION_EVENT ( SERIAL_EV_RXCHAR | SERIAL_EV_DSR )
  90. #define SR_PURGE ( SERIAL_PURGE_RXCLEAR | SERIAL_PURGE_TXCLEAR )
  91. //
  92. // not clear, how these ctl codes are interpreted; the actual command is passed by the IrpStack.MajorFunction
  93. //
  94. #define SERIAL_READ SCARD_CTL_CODE( 0x1000 )
  95. #define SERIAL_WRITE SCARD_CTL_CODE( 0x2000 )
  96. //
  97. // READ THREAD
  98. //
  99. #define RT_FINISH 0x00
  100. #define RT_READ_HEAD 0x01
  101. #define RT_READ_TAIL 0x02
  102. #define RT_READ_MORE 0x03
  103. #define RT_GET_MODEM_STATUS 0x04
  104. #define RT_WAIT_EMPTY 0x05
  105. #define RT_WAIT_DATA 0x06
  106. NTSTATUS
  107. IFReadThreadCallback(
  108. PDEVICE_OBJECT DeviceObject,
  109. PIRP Irp,
  110. PREADER_EXTENSION ReaderExtension
  111. );
  112. //
  113. // LOCAL PROTOTYPES
  114. //
  115. NTSTATUS
  116. IFSerialIoctl(
  117. PREADER_EXTENSION ReaderExtension,
  118. ULONG IoctlCode,
  119. PVOID OutData,
  120. ULONG OutDataLen,
  121. PVOID InData,
  122. ULONG InDataLen
  123. );
  124. NTSTATUS
  125. IFSerialRead(
  126. PREADER_EXTENSION ReaderExtension,
  127. PUCHAR InData,
  128. ULONG InDataLen
  129. );
  130. NTSTATUS
  131. IFSerialWaitOnMask(
  132. PREADER_EXTENSION ReaderExtension
  133. );
  134. VOID
  135. IFReadWorkRoutine(
  136. IN PDEVICE_OBJECT DeviceObject,
  137. IN PREADER_EXTENSION ReaderExtension
  138. );
  139. #endif // !__SERIAL_NT_H__
  140. //---------------------------------------- END OF FILE ----------------------------------------