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.

641 lines
15 KiB

  1. /*
  2. Copyright (c) 1990-1999 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. ptdrvprt.h
  5. Abstract:
  6. Structures and defines used the RDP remote port driver.
  7. Environment:
  8. Kernel mode.
  9. Revision History:
  10. 02/12/99 - Initial Revision based on pnpi8042 driver
  11. --*/
  12. #ifndef _PTDRVCOM_
  13. #define _PTDRVCOM_
  14. #include <ntddk.h>
  15. #include <ntddkbd.h>
  16. #include <ntddmou.h>
  17. #include <ntdd8042.h>
  18. #include <kbdmou.h>
  19. #include <wmilib.h>
  20. #include "ptdrvstr.h"
  21. //
  22. // Define the device types for the first field in the device extensions
  23. //
  24. #define DEV_TYPE_TERMDD 1
  25. #define DEV_TYPE_PORT 2
  26. #define REMOTE_PORT_POOL_TAG (ULONG) 'PMER'
  27. #ifdef ExAllocatePool
  28. #undef ExAllocatePool
  29. #endif
  30. #define ExAllocatePool(type, size) \
  31. ExAllocatePoolWithTag (type, size, REMOTE_PORT_POOL_TAG)
  32. //
  33. // Set up some debug options
  34. //
  35. #ifdef PAGED_CODE
  36. #undef PAGED_CODE
  37. #endif
  38. #if DBG
  39. #define PTDRV_VERBOSE 1
  40. #define PAGED_CODE() \
  41. if (KeGetCurrentIrql() > APC_LEVEL) { \
  42. KdPrint(( "RemotePrt: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  43. DbgBreakPoint(); \
  44. }
  45. #else
  46. #define PAGED_CODE()
  47. #endif
  48. //
  49. // Define device name for our driver
  50. //
  51. #define RDP_CONSOLE_BASE_NAME0 L"\\Device\\RDP_CONSOLE0"
  52. #define RDP_CONSOLE_BASE_NAME1 L"\\Device\\RDP_CONSOLE1"
  53. //
  54. // Custom resource type used when pruning the fdo's resource lists
  55. //
  56. #define PD_REMOVE_RESOURCE 0xef
  57. //
  58. // Mouse reset IOCTL
  59. //
  60. #define IOCTL_INTERNAL_MOUSE_RESET \
  61. CTL_CODE(FILE_DEVICE_MOUSE, 0x0FFF, METHOD_NEITHER, FILE_ANY_ACCESS)
  62. //
  63. // Default number of function keys, number of LED indicators, and total
  64. // number of keys
  65. //
  66. #define KEYBOARD_NUM_FUNCTION_KEYS 12
  67. #define KEYBOARD_NUM_INDICATORS 3
  68. #define KEYBOARD_NUM_KEYS_TOTAL 101
  69. //
  70. // Default values for keyboard typematic rate and delay.
  71. //
  72. #define KEYBOARD_TYPEMATIC_RATE_DEFAULT 30
  73. #define KEYBOARD_TYPEMATIC_DELAY_DEFAULT 250
  74. //
  75. // Default info for the mouse
  76. //
  77. #define MOUSE_IDENTIFIER MOUSE_I8042_HARDWARE
  78. #define MOUSE_NUM_BUTTONS 2
  79. #define MOUSE_SAMPLE_RATE 60
  80. #define MOUSE_INPUT_QLEN 0
  81. //
  82. // Defines and macros for Globals.ControllerData->HardwarePresent.
  83. //
  84. #define KEYBOARD_HARDWARE_PRESENT 0x001
  85. #define MOUSE_HARDWARE_PRESENT 0x002
  86. #define WHEELMOUSE_HARDWARE_PRESENT 0x008
  87. #define DUP_KEYBOARD_HARDWARE_PRESENT 0x010
  88. #define DUP_MOUSE_HARDWARE_PRESENT 0x020
  89. #define KEYBOARD_HARDWARE_INITIALIZED 0x100
  90. #define MOUSE_HARDWARE_INITIALIZED 0x200
  91. #define TEST_HARDWARE_PRESENT(bits) \
  92. ((Globals.ControllerData->HardwarePresent & (bits)) == (bits))
  93. #define CLEAR_HW_FLAGS(bits) (Globals.ControllerData->HardwarePresent &= ~(bits))
  94. #define SET_HW_FLAGS(bits) (Globals.ControllerData->HardwarePresent |= (bits))
  95. #define KEYBOARD_PRESENT() TEST_HARDWARE_PRESENT(KEYBOARD_HARDWARE_PRESENT)
  96. #define MOUSE_PRESENT() TEST_HARDWARE_PRESENT(MOUSE_HARDWARE_PRESENT)
  97. #define KEYBOARD_INITIALIZED() TEST_HARDWARE_PRESENT(KEYBOARD_HARDWARE_INITIALIZED)
  98. #define MOUSE_INITIALIZED() TEST_HARDWARE_PRESENT(MOUSE_HARDWARE_INITIALIZED)
  99. #define CLEAR_MOUSE_PRESENT() CLEAR_HW_FLAGS(MOUSE_HARDWARE_INITIALIZED | MOUSE_HARDWARE_PRESENT | WHEELMOUSE_HARDWARE_PRESENT)
  100. #define CLEAR_KEYBOARD_PRESENT() CLEAR_HW_FLAGS(KEYBOARD_HARDWARE_INITIALIZED | KEYBOARD_HARDWARE_PRESENT)
  101. #define KBD_POWERED_UP_STARTED 0x0001
  102. #define MOU_POWERED_UP_STARTED 0x0010
  103. #define MOU_POWERED_UP_SUCCESS 0x0100
  104. #define MOU_POWERED_UP_FAILURE 0x0200
  105. #define KBD_POWERED_UP_SUCCESS 0x1000
  106. #define KBD_POWERED_UP_FAILURE 0x2000
  107. #define CLEAR_POWERUP_FLAGS() (Globals.PowerUpFlags = 0x0)
  108. #define SET_PWR_FLAGS(bits) (Globals.PowerUpFlags |= (bits))
  109. #define KEYBOARD_POWERED_UP_STARTED() SET_PWR_FLAGS(KBD_POWERED_UP_STARTED)
  110. #define MOUSE_POWERED_UP_STARTED() SET_PWR_FLAGS(MOU_POWERED_UP_STARTED)
  111. #define KEYBOARD_POWERED_UP_SUCCESSFULLY() SET_PWR_FLAGS(KBD_POWERED_UP_SUCCESS)
  112. #define MOUSE_POWERED_UP_SUCCESSFULLY() SET_PWR_FLAGS(MOU_POWERED_UP_SUCCESS)
  113. #define KEYBOARD_POWERED_UP_FAILED() SET_PWR_FLAGS(KBD_POWERED_UP_FAILURE)
  114. #define MOUSE_POWERED_UP_FAILED() SET_PWR_FLAGS(MOU_POWERED_UP_FAILURE)
  115. //
  116. // Define the i8042 controller input/output ports.
  117. //
  118. typedef enum _I8042_IO_PORT_TYPE {
  119. DataPort = 0,
  120. CommandPort,
  121. MaximumPortCount
  122. } I8042_IO_PORT_TYPE;
  123. //
  124. // Intel i8042 configuration information.
  125. //
  126. typedef struct _I8042_CONFIGURATION_INFORMATION {
  127. //
  128. // The port/register resources used by this device.
  129. //
  130. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[MaximumPortCount];
  131. ULONG PortListCount;
  132. } I8042_CONFIGURATION_INFORMATION, *PI8042_CONFIGURATION_INFORMATION;
  133. //
  134. // Define the common portion of the keyboard/mouse device extension.
  135. //
  136. typedef struct COMMON_DATA {
  137. //
  138. // Device type field
  139. //
  140. ULONG deviceType;
  141. //
  142. // Pointer back to the this extension's device object.
  143. //
  144. PDEVICE_OBJECT Self;
  145. //
  146. // The top of the stack before this filter was added. AKA the location
  147. // to which all IRPS should be directed.
  148. //
  149. PDEVICE_OBJECT TopOfStack;
  150. //
  151. // "THE PDO" (ejected by root)
  152. //
  153. PDEVICE_OBJECT PDO;
  154. //
  155. // Current power state that the device is in
  156. //
  157. DEVICE_POWER_STATE PowerState;
  158. POWER_ACTION ShutdownType;
  159. //
  160. // Reference count for number of keyboard enables.
  161. //
  162. LONG EnableCount;
  163. //
  164. // Class connection data.
  165. //
  166. CONNECT_DATA ConnectData;
  167. //
  168. // WMI Information
  169. //
  170. WMILIB_CONTEXT WmiLibInfo;
  171. BOOLEAN Initialized;
  172. BOOLEAN IsKeyboard;
  173. UNICODE_STRING DeviceName;
  174. //
  175. // Has it been started?
  176. // Has the device been manually removed?
  177. //
  178. BOOLEAN Started;
  179. BOOLEAN ManuallyRemoved;
  180. } *PCOMMON_DATA;
  181. #define GET_COMMON_DATA(ext) ((PCOMMON_DATA) ext)
  182. //
  183. // Define the keyboard portion of the port device extension.
  184. //
  185. typedef struct _PORT_KEYBOARD_EXTENSION {
  186. //
  187. // Data in common with the mouse extension;
  188. //
  189. struct COMMON_DATA;
  190. } PORT_KEYBOARD_EXTENSION, *PPORT_KEYBOARD_EXTENSION;
  191. //
  192. // Define the mouse portion of the port device extension.
  193. //
  194. typedef struct _PORT_MOUSE_EXTENSION {
  195. //
  196. // Data in common with the keyboard extension;
  197. //
  198. struct COMMON_DATA;
  199. } PORT_MOUSE_EXTENSION, *PPORT_MOUSE_EXTENSION;
  200. //
  201. // controller specific data used by both devices
  202. //
  203. typedef struct _CONTROLLER_DATA {
  204. //
  205. // Indicate which hardware is actually present (keyboard and/or mouse).
  206. //
  207. ULONG HardwarePresent;
  208. //
  209. // IOCTL synchronization object
  210. //
  211. PCONTROLLER_OBJECT ControllerObject;
  212. //
  213. // Port configuration information.
  214. //
  215. I8042_CONFIGURATION_INFORMATION Configuration;
  216. //
  217. // Spin lock to guard powering the devices back up
  218. //
  219. KSPIN_LOCK PowerUpSpinLock;
  220. } CONTROLLER_DATA, *PCONTROLLER_DATA;
  221. typedef struct _GLOBALS {
  222. #if PTDRV_VERBOSE
  223. //
  224. // Flags: Bit field for enabling debugging print statements
  225. // Level: Legacy way of controllign debugging statements
  226. //
  227. ULONG DebugFlags;
  228. #endif
  229. //
  230. // Pointer to controller specific data that both extensions may access it
  231. //
  232. PCONTROLLER_DATA ControllerData;
  233. //
  234. // The two possible extensions that can be created
  235. //
  236. PPORT_MOUSE_EXTENSION MouseExtension;
  237. PPORT_KEYBOARD_EXTENSION KeyboardExtension;
  238. //
  239. // Path to the driver's entry in the registry
  240. //
  241. UNICODE_STRING RegistryPath;
  242. //
  243. // Keep track of the number of AddDevice and StartDevice calls. Want to
  244. // postpone h/w initialization until the last StartDevice is received
  245. // (due to some h/w which freezes if initialized more than once)
  246. //
  247. LONG AddedKeyboards;
  248. LONG AddedMice;
  249. ULONG ulDeviceNumber;
  250. USHORT PowerUpFlags;
  251. //
  252. // Provide mutual exclusion during dispatch functions
  253. //
  254. FAST_MUTEX DispatchMutex;
  255. } GLOBALS;
  256. extern GLOBALS Globals;
  257. //
  258. // Statically allocate the (known) scancode-to-indicator-light mapping.
  259. // This information is returned by the
  260. // IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION device control request.
  261. //
  262. #define KEYBOARD_NUMBER_OF_INDICATORS 3
  263. static const INDICATOR_LIST IndicatorList[KEYBOARD_NUMBER_OF_INDICATORS] = {
  264. {0x3A, KEYBOARD_CAPS_LOCK_ON},
  265. {0x45, KEYBOARD_NUM_LOCK_ON},
  266. {0x46, KEYBOARD_SCROLL_LOCK_ON}};
  267. //
  268. // Function prototypes.
  269. //
  270. NTSTATUS
  271. PtEntry(
  272. IN PDRIVER_OBJECT DriverObject,
  273. IN PUNICODE_STRING RegistryPath
  274. );
  275. #if PTDRV_VERBOSE
  276. VOID
  277. PtServiceParameters(
  278. IN PUNICODE_STRING RegistryPath
  279. );
  280. #endif
  281. VOID
  282. PtSendCurrentKeyboardInput(
  283. IN PDEVICE_OBJECT DeviceObject,
  284. IN PKEYBOARD_INPUT_DATA pInput,
  285. IN ULONG ulEntries
  286. );
  287. VOID
  288. PtSendCurrentMouseInput(
  289. IN PDEVICE_OBJECT DeviceObject,
  290. IN PMOUSE_INPUT_DATA pInput,
  291. IN ULONG ulEntries
  292. );
  293. NTSTATUS
  294. PtClose (
  295. IN PDEVICE_OBJECT DeviceObject,
  296. IN PIRP Irp
  297. );
  298. NTSTATUS
  299. PtCreate (
  300. IN PDEVICE_OBJECT DeviceObject,
  301. IN PIRP Irp
  302. );
  303. NTSTATUS
  304. PtDeviceControl(
  305. IN PDEVICE_OBJECT DeviceObject,
  306. IN PIRP Irp
  307. );
  308. NTSTATUS
  309. PtInternalDeviceControl(
  310. IN PDEVICE_OBJECT DeviceObject,
  311. IN PIRP Irp
  312. );
  313. VOID
  314. PtStartIo(
  315. IN PDEVICE_OBJECT DeviceObject,
  316. IN PIRP Irp
  317. );
  318. NTSTATUS
  319. PtKeyboardConfiguration(
  320. IN PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  321. IN PCM_RESOURCE_LIST ResourceList
  322. );
  323. VOID
  324. PtKeyboardRemoveDevice(
  325. PDEVICE_OBJECT DeviceObject
  326. );
  327. NTSTATUS
  328. PtKeyboardStartDevice(
  329. IN OUT PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  330. IN PCM_RESOURCE_LIST ResourceList
  331. );
  332. NTSTATUS
  333. PtMouseConfiguration(
  334. IN PPORT_MOUSE_EXTENSION MouseExtension,
  335. IN PCM_RESOURCE_LIST ResourceList
  336. );
  337. NTSTATUS
  338. PtMouseStartDevice(
  339. PPORT_MOUSE_EXTENSION MouseExtension,
  340. IN PCM_RESOURCE_LIST ResourceList
  341. );
  342. NTSTATUS
  343. PtAddDevice (
  344. IN PDRIVER_OBJECT Driver,
  345. IN PDEVICE_OBJECT PDO
  346. );
  347. VOID
  348. PtFilterResourceRequirements(
  349. IN PDEVICE_OBJECT DeviceObject,
  350. IN PIRP Irp
  351. );
  352. NTSTATUS
  353. PtFindPortCallout(
  354. IN PVOID Context,
  355. IN PUNICODE_STRING PathName,
  356. IN INTERFACE_TYPE BusType,
  357. IN ULONG BusNumber,
  358. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  359. IN CONFIGURATION_TYPE ControllerType,
  360. IN ULONG ControllerNumber,
  361. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  362. IN CONFIGURATION_TYPE PeripheralType,
  363. IN ULONG PeripheralNumber,
  364. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  365. );
  366. LONG
  367. PtManuallyRemoveDevice(
  368. PCOMMON_DATA CommonData
  369. );
  370. NTSTATUS
  371. PtPnP (
  372. IN PDEVICE_OBJECT DeviceObject,
  373. IN PIRP Irp
  374. );
  375. NTSTATUS
  376. PtPnPComplete (
  377. IN PDEVICE_OBJECT DeviceObject,
  378. IN PIRP Irp,
  379. IN PKEVENT Event
  380. );
  381. NTSTATUS
  382. PtPower (
  383. IN PDEVICE_OBJECT DeviceObject,
  384. IN PIRP Irp
  385. );
  386. NTSTATUS
  387. PtPowerUpToD0Complete (
  388. IN PDEVICE_OBJECT DeviceObject,
  389. IN PIRP Irp,
  390. IN PVOID Context
  391. );
  392. BOOLEAN
  393. PtRemovePort(
  394. IN PIO_RESOURCE_DESCRIPTOR ResDesc
  395. );
  396. NTSTATUS
  397. PtSendIrpSynchronously (
  398. IN PDEVICE_OBJECT DeviceObject,
  399. IN PIRP Irp
  400. );
  401. VOID
  402. PtUnload(
  403. IN PDRIVER_OBJECT DriverObject
  404. );
  405. NTSTATUS
  406. PtSystemControl (
  407. IN PDEVICE_OBJECT DeviceObject,
  408. IN PIRP Irp
  409. );
  410. NTSTATUS
  411. PtInitWmi(
  412. PCOMMON_DATA CommonData
  413. );
  414. NTSTATUS
  415. PtSetWmiDataBlock(
  416. IN PDEVICE_OBJECT DeviceObject,
  417. IN PIRP Irp,
  418. IN ULONG GuidIndex,
  419. IN ULONG InstanceIndex,
  420. IN ULONG BufferSize,
  421. IN PUCHAR Buffer
  422. );
  423. NTSTATUS
  424. PtSetWmiDataItem(
  425. IN PDEVICE_OBJECT DeviceObject,
  426. IN PIRP Irp,
  427. IN ULONG GuidIndex,
  428. IN ULONG InstanceIndex,
  429. IN ULONG DataItemId,
  430. IN ULONG BufferSize,
  431. IN PUCHAR Buffer
  432. );
  433. NTSTATUS
  434. PtKeyboardQueryWmiDataBlock(
  435. IN PDEVICE_OBJECT DeviceObject,
  436. IN PIRP Irp,
  437. IN ULONG GuidIndex,
  438. IN ULONG InstanceIndex,
  439. IN ULONG InstanceCount,
  440. IN OUT PULONG InstanceLengthArray,
  441. IN ULONG BufferAvail,
  442. OUT PUCHAR Buffer
  443. );
  444. NTSTATUS
  445. PtMouseQueryWmiDataBlock(
  446. IN PDEVICE_OBJECT DeviceObject,
  447. IN PIRP Irp,
  448. IN ULONG GuidIndex,
  449. IN ULONG InstanceIndex,
  450. IN ULONG InstanceCount,
  451. IN OUT PULONG InstanceLengthArray,
  452. IN ULONG BufferAvail,
  453. OUT PUCHAR Buffer
  454. );
  455. NTSTATUS
  456. PtQueryWmiRegInfo(
  457. IN PDEVICE_OBJECT DeviceObject,
  458. OUT PULONG RegFlags,
  459. OUT PUNICODE_STRING InstanceName,
  460. OUT PUNICODE_STRING *RegistryPath,
  461. OUT PUNICODE_STRING MofResourceName,
  462. OUT PDEVICE_OBJECT *Pdo
  463. );
  464. extern WMIGUIDREGINFO KbWmiGuidList[1];
  465. extern WMIGUIDREGINFO MouWmiGuidList[1];
  466. #if DBG
  467. #define DEFAULT_DEBUG_FLAGS 0x8cc88888
  468. #else
  469. #define DEFAULT_DEBUG_FLAGS 0x0
  470. #endif
  471. #if PTDRV_VERBOSE
  472. //
  473. //Debug messaging and breakpoint macros
  474. //
  475. #define DBG_ALWAYS 0x00000000
  476. #define DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  477. #define DBG_SS_NOISE 0x00000001
  478. #define DBG_SS_TRACE 0x00000002
  479. #define DBG_SS_INFO 0x00000004
  480. #define DBG_SS_ERROR 0x00000008
  481. #define DBG_IOCTL_MASK 0x00000F00
  482. #define DBG_IOCTL_NOISE 0x00000100
  483. #define DBG_IOCTL_TRACE 0x00000200
  484. #define DBG_IOCTL_INFO 0x00000400
  485. #define DBG_IOCTL_ERROR 0x00000800
  486. #define DBG_DPC_MASK 0x0000F000
  487. #define DBG_DPC_NOISE 0x00001000
  488. #define DBG_DPC_TRACE 0x00002000
  489. #define DBG_DPC_INFO 0x00004000
  490. #define DBG_DPC_ERROR 0x00008000
  491. #define DBG_POWER_MASK 0x00F00000
  492. #define DBG_POWER_NOISE 0x00100000
  493. #define DBG_POWER_TRACE 0x00200000
  494. #define DBG_POWER_INFO 0x00400000
  495. #define DBG_POWER_ERROR 0x00800000
  496. #define DBG_PNP_MASK 0x0F000000
  497. #define DBG_PNP_NOISE 0x01000000
  498. #define DBG_PNP_TRACE 0x02000000
  499. #define DBG_PNP_INFO 0x04000000
  500. #define DBG_PNP_ERROR 0x08000000
  501. #define Print(_flags_, _x_) \
  502. if (Globals.DebugFlags & (_flags_) || !(_flags_)) { \
  503. DbgPrint (pDriverName); \
  504. DbgPrint _x_; \
  505. }
  506. #define TRAP() DbgBreakPoint()
  507. #else
  508. #define Print(_l_,_x_)
  509. #define TRAP()
  510. #endif // PTDRV_VERBOSE
  511. #endif // _PTDRVCOM_