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.

864 lines
24 KiB

  1. /*--
  2. Copyright (c) 1998. 1999 Microsoft Corporation
  3. Module Name:
  4. kbfiltr.c
  5. Abstract:
  6. Environment:
  7. Kernel mode only.
  8. Notes:
  9. --*/
  10. #include "kbfiltr.h"
  11. NTSTATUS DriverEntry (PDRIVER_OBJECT, PUNICODE_STRING);
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text (INIT, DriverEntry)
  14. #pragma alloc_text (PAGE, KbFilter_AddDevice)
  15. #pragma alloc_text (PAGE, KbFilter_CreateClose)
  16. #pragma alloc_text (PAGE, KbFilter_IoCtl)
  17. #pragma alloc_text (PAGE, KbFilter_InternIoCtl)
  18. #pragma alloc_text (PAGE, KbFilter_Unload)
  19. #pragma alloc_text (PAGE, KbFilter_DispatchPassThrough)
  20. #pragma alloc_text (PAGE, KbFilter_PnP)
  21. #pragma alloc_text (PAGE, KbFilter_Power)
  22. #endif
  23. NTSTATUS
  24. DriverEntry (
  25. IN PDRIVER_OBJECT DriverObject,
  26. IN PUNICODE_STRING RegistryPath
  27. )
  28. /*++
  29. Routine Description:
  30. Initialize the entry points of the driver.
  31. --*/
  32. {
  33. ULONG i;
  34. UNREFERENCED_PARAMETER (RegistryPath);
  35. //
  36. // Fill in all the dispatch entry points with the pass through function
  37. // and the explicitly fill in the functions we are going to intercept
  38. //
  39. for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  40. DriverObject->MajorFunction[i] = KbFilter_DispatchPassThrough;
  41. }
  42. DriverObject->MajorFunction [IRP_MJ_CREATE] =
  43. DriverObject->MajorFunction [IRP_MJ_CLOSE] = KbFilter_CreateClose;
  44. DriverObject->MajorFunction [IRP_MJ_PNP] = KbFilter_PnP;
  45. DriverObject->MajorFunction [IRP_MJ_POWER] = KbFilter_Power;
  46. DriverObject->MajorFunction [IRP_MJ_INTERNAL_DEVICE_CONTROL] =
  47. KbFilter_InternIoCtl;
  48. //
  49. // If you are planning on using this function, you must create another
  50. // device object to send the requests to. Please see the considerations
  51. // comments for KbFilter_DispatchPassThrough for implementation details.
  52. //
  53. // DriverObject->MajorFunction [IRP_MJ_DEVICE_CONTROL] = KbFilter_IoCtl;
  54. DriverObject->DriverUnload = KbFilter_Unload;
  55. DriverObject->DriverExtension->AddDevice = KbFilter_AddDevice;
  56. return STATUS_SUCCESS;
  57. }
  58. NTSTATUS
  59. KbFilter_AddDevice(
  60. IN PDRIVER_OBJECT Driver,
  61. IN PDEVICE_OBJECT PDO
  62. )
  63. {
  64. PDEVICE_EXTENSION devExt;
  65. IO_ERROR_LOG_PACKET errorLogEntry;
  66. PDEVICE_OBJECT device;
  67. NTSTATUS status = STATUS_SUCCESS;
  68. PAGED_CODE();
  69. status = IoCreateDevice(Driver,
  70. sizeof(DEVICE_EXTENSION),
  71. NULL,
  72. FILE_DEVICE_KEYBOARD,
  73. 0,
  74. FALSE,
  75. &device
  76. );
  77. if (!NT_SUCCESS(status)) {
  78. return (status);
  79. }
  80. RtlZeroMemory(device->DeviceExtension, sizeof(DEVICE_EXTENSION));
  81. devExt = (PDEVICE_EXTENSION) device->DeviceExtension;
  82. devExt->TopOfStack = IoAttachDeviceToDeviceStack(device, PDO);
  83. if (devExt->TopOfStack == NULL) {
  84. IoDeleteDevice(device);
  85. return STATUS_DEVICE_NOT_CONNECTED;
  86. }
  87. ASSERT(devExt->TopOfStack);
  88. devExt->Self = device;
  89. devExt->PDO = PDO;
  90. devExt->DeviceState = PowerDeviceD0;
  91. devExt->SurpriseRemoved = FALSE;
  92. devExt->Removed = FALSE;
  93. devExt->Started = FALSE;
  94. device->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE);
  95. device->Flags &= ~DO_DEVICE_INITIALIZING;
  96. return status;
  97. }
  98. NTSTATUS
  99. KbFilter_Complete(
  100. IN PDEVICE_OBJECT DeviceObject,
  101. IN PIRP Irp,
  102. IN PVOID Context
  103. )
  104. /*++
  105. Routine Description:
  106. Generic completion routine that allows the driver to send the irp down the
  107. stack, catch it on the way up, and do more processing at the original IRQL.
  108. --*/
  109. {
  110. PKEVENT event;
  111. event = (PKEVENT) Context;
  112. UNREFERENCED_PARAMETER(DeviceObject);
  113. UNREFERENCED_PARAMETER(Irp);
  114. //
  115. // We could switch on the major and minor functions of the IRP to perform
  116. // different functions, but we know that Context is an event that needs
  117. // to be set.
  118. //
  119. KeSetEvent(event, 0, FALSE);
  120. //
  121. // Allows the caller to use the IRP after it is completed
  122. //
  123. return STATUS_MORE_PROCESSING_REQUIRED;
  124. }
  125. NTSTATUS
  126. KbFilter_CreateClose (
  127. IN PDEVICE_OBJECT DeviceObject,
  128. IN PIRP Irp
  129. )
  130. /*++
  131. Routine Description:
  132. Maintain a simple count of the creates and closes sent against this device
  133. --*/
  134. {
  135. PIO_STACK_LOCATION irpStack;
  136. NTSTATUS status;
  137. PDEVICE_EXTENSION devExt;
  138. PAGED_CODE();
  139. irpStack = IoGetCurrentIrpStackLocation(Irp);
  140. devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  141. status = Irp->IoStatus.Status;
  142. switch (irpStack->MajorFunction) {
  143. case IRP_MJ_CREATE:
  144. if (NULL == devExt->UpperConnectData.ClassService) {
  145. //
  146. // No Connection yet. How can we be enabled?
  147. //
  148. status = STATUS_INVALID_DEVICE_STATE;
  149. }
  150. else if ( 1 == InterlockedIncrement(&devExt->EnableCount)) {
  151. //
  152. // first time enable here
  153. //
  154. }
  155. else {
  156. //
  157. // More than one create was sent down
  158. //
  159. }
  160. break;
  161. case IRP_MJ_CLOSE:
  162. if (0 == InterlockedDecrement(&devExt->EnableCount)) {
  163. //
  164. // successfully closed the device, do any appropriate work here
  165. //
  166. }
  167. break;
  168. }
  169. Irp->IoStatus.Status = status;
  170. //
  171. // Pass on the create and the close
  172. //
  173. return KbFilter_DispatchPassThrough(DeviceObject, Irp);
  174. }
  175. NTSTATUS
  176. KbFilter_DispatchPassThrough(
  177. IN PDEVICE_OBJECT DeviceObject,
  178. IN PIRP Irp
  179. )
  180. /*++
  181. Routine Description:
  182. Passes a request on to the lower driver.
  183. Considerations:
  184. If you are creating another device object (to communicate with user mode
  185. via IOCTLs), then this function must act differently based on the intended
  186. device object. If the IRP is being sent to the solitary device object, then
  187. this function should just complete the IRP (becuase there is no more stack
  188. locations below it). If the IRP is being sent to the PnP built stack, then
  189. the IRP should be passed down the stack.
  190. These changes must also be propagated to all the other IRP_MJ dispatch
  191. functions (create, close, cleanup, etc) as well!
  192. --*/
  193. {
  194. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  195. //
  196. // Pass the IRP to the target
  197. //
  198. IoSkipCurrentIrpStackLocation(Irp);
  199. return IoCallDriver(((PDEVICE_EXTENSION) DeviceObject->DeviceExtension)->TopOfStack, Irp);
  200. }
  201. NTSTATUS
  202. KbFilter_InternIoCtl(
  203. IN PDEVICE_OBJECT DeviceObject,
  204. IN PIRP Irp
  205. )
  206. /*++
  207. Routine Description:
  208. This routine is the dispatch routine for internal device control requests.
  209. There are two specific control codes that are of interest:
  210. IOCTL_INTERNAL_KEYBOARD_CONNECT:
  211. Store the old context and function pointer and replace it with our own.
  212. This makes life much simpler than intercepting IRPs sent by the RIT and
  213. modifying them on the way back up.
  214. IOCTL_INTERNAL_I8042_HOOK_KEYBOARD:
  215. Add in the necessary function pointers and context values so that we can
  216. alter how the ps/2 keyboard is initialized.
  217. NOTE: Handling IOCTL_INTERNAL_I8042_HOOK_KEYBOARD is *NOT* necessary if
  218. all you want to do is filter KEYBOARD_INPUT_DATAs. You can remove
  219. the handling code and all related device extension fields and
  220. functions to conserve space.
  221. Arguments:
  222. DeviceObject - Pointer to the device object.
  223. Irp - Pointer to the request packet.
  224. Return Value:
  225. Status is returned.
  226. --*/
  227. {
  228. PIO_STACK_LOCATION irpStack;
  229. PDEVICE_EXTENSION devExt;
  230. PINTERNAL_I8042_HOOK_KEYBOARD hookKeyboard;
  231. KEVENT event;
  232. PCONNECT_DATA connectData;
  233. NTSTATUS status = STATUS_SUCCESS;
  234. devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  235. Irp->IoStatus.Information = 0;
  236. irpStack = IoGetCurrentIrpStackLocation(Irp);
  237. switch (irpStack->Parameters.DeviceIoControl.IoControlCode) {
  238. //
  239. // Connect a keyboard class device driver to the port driver.
  240. //
  241. case IOCTL_INTERNAL_KEYBOARD_CONNECT:
  242. //
  243. // Only allow one connection.
  244. //
  245. if (devExt->UpperConnectData.ClassService != NULL) {
  246. status = STATUS_SHARING_VIOLATION;
  247. break;
  248. }
  249. else if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
  250. sizeof(CONNECT_DATA)) {
  251. //
  252. // invalid buffer
  253. //
  254. status = STATUS_INVALID_PARAMETER;
  255. break;
  256. }
  257. //
  258. // Copy the connection parameters to the device extension.
  259. //
  260. connectData = ((PCONNECT_DATA)
  261. (irpStack->Parameters.DeviceIoControl.Type3InputBuffer));
  262. devExt->UpperConnectData = *connectData;
  263. //
  264. // Hook into the report chain. Everytime a keyboard packet is reported
  265. // to the system, KbFilter_ServiceCallback will be called
  266. //
  267. connectData->ClassDeviceObject = devExt->Self;
  268. connectData->ClassService = KbFilter_ServiceCallback;
  269. break;
  270. //
  271. // Disconnect a keyboard class device driver from the port driver.
  272. //
  273. case IOCTL_INTERNAL_KEYBOARD_DISCONNECT:
  274. //
  275. // Clear the connection parameters in the device extension.
  276. //
  277. // devExt->UpperConnectData.ClassDeviceObject = NULL;
  278. // devExt->UpperConnectData.ClassService = NULL;
  279. status = STATUS_NOT_IMPLEMENTED;
  280. break;
  281. //
  282. // Attach this driver to the initialization and byte processing of the
  283. // i8042 (ie PS/2) keyboard. This is only necessary if you want to do PS/2
  284. // specific functions, otherwise hooking the CONNECT_DATA is sufficient
  285. //
  286. case IOCTL_INTERNAL_I8042_HOOK_KEYBOARD:
  287. DebugPrint(("hook keyboard received!\n"));
  288. if (irpStack->Parameters.DeviceIoControl.InputBufferLength <
  289. sizeof(INTERNAL_I8042_HOOK_KEYBOARD)) {
  290. DebugPrint(("InternalIoctl error - invalid buffer length\n"));
  291. status = STATUS_INVALID_PARAMETER;
  292. break;
  293. }
  294. hookKeyboard = (PINTERNAL_I8042_HOOK_KEYBOARD)
  295. irpStack->Parameters.DeviceIoControl.Type3InputBuffer;
  296. //
  297. // Enter our own initialization routine and record any Init routine
  298. // that may be above us. Repeat for the isr hook
  299. //
  300. devExt->UpperContext = hookKeyboard->Context;
  301. //
  302. // replace old Context with our own
  303. //
  304. hookKeyboard->Context = (PVOID) DeviceObject;
  305. if (hookKeyboard->InitializationRoutine) {
  306. devExt->UpperInitializationRoutine =
  307. hookKeyboard->InitializationRoutine;
  308. }
  309. hookKeyboard->InitializationRoutine =
  310. (PI8042_KEYBOARD_INITIALIZATION_ROUTINE)
  311. KbFilter_InitializationRoutine;
  312. if (hookKeyboard->IsrRoutine) {
  313. devExt->UpperIsrHook = hookKeyboard->IsrRoutine;
  314. }
  315. hookKeyboard->IsrRoutine = (PI8042_KEYBOARD_ISR) KbFilter_IsrHook;
  316. //
  317. // Store all of the other important stuff
  318. //
  319. devExt->IsrWritePort = hookKeyboard->IsrWritePort;
  320. devExt->QueueKeyboardPacket = hookKeyboard->QueueKeyboardPacket;
  321. devExt->CallContext = hookKeyboard->CallContext;
  322. status = STATUS_SUCCESS;
  323. break;
  324. //
  325. // These internal ioctls are not supported by the new PnP model.
  326. //
  327. #if 0 // obsolete
  328. case IOCTL_INTERNAL_KEYBOARD_ENABLE:
  329. case IOCTL_INTERNAL_KEYBOARD_DISABLE:
  330. status = STATUS_NOT_SUPPORTED;
  331. break;
  332. #endif // obsolete
  333. //
  334. // Might want to capture these in the future. For now, then pass them down
  335. // the stack. These queries must be successful for the RIT to communicate
  336. // with the keyboard.
  337. //
  338. case IOCTL_KEYBOARD_QUERY_ATTRIBUTES:
  339. case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:
  340. case IOCTL_KEYBOARD_QUERY_INDICATORS:
  341. case IOCTL_KEYBOARD_SET_INDICATORS:
  342. case IOCTL_KEYBOARD_QUERY_TYPEMATIC:
  343. case IOCTL_KEYBOARD_SET_TYPEMATIC:
  344. break;
  345. }
  346. if (!NT_SUCCESS(status)) {
  347. Irp->IoStatus.Status = status;
  348. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  349. return status;
  350. }
  351. return KbFilter_DispatchPassThrough(DeviceObject, Irp);
  352. }
  353. NTSTATUS
  354. KbFilter_PnP(
  355. IN PDEVICE_OBJECT DeviceObject,
  356. IN PIRP Irp
  357. )
  358. /*++
  359. Routine Description:
  360. This routine is the dispatch routine for plug and play irps
  361. Arguments:
  362. DeviceObject - Pointer to the device object.
  363. Irp - Pointer to the request packet.
  364. Return Value:
  365. Status is returned.
  366. --*/
  367. {
  368. PDEVICE_EXTENSION devExt;
  369. PIO_STACK_LOCATION irpStack;
  370. NTSTATUS status = STATUS_SUCCESS;
  371. KIRQL oldIrql;
  372. KEVENT event;
  373. PAGED_CODE();
  374. devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  375. irpStack = IoGetCurrentIrpStackLocation(Irp);
  376. switch (irpStack->MinorFunction) {
  377. case IRP_MN_START_DEVICE: {
  378. //
  379. // The device is starting.
  380. //
  381. // We cannot touch the device (send it any non pnp irps) until a
  382. // start device has been passed down to the lower drivers.
  383. //
  384. IoCopyCurrentIrpStackLocationToNext(Irp);
  385. KeInitializeEvent(&event,
  386. NotificationEvent,
  387. FALSE
  388. );
  389. IoSetCompletionRoutine(Irp,
  390. (PIO_COMPLETION_ROUTINE) KbFilter_Complete,
  391. &event,
  392. TRUE,
  393. TRUE,
  394. TRUE); // No need for Cancel
  395. status = IoCallDriver(devExt->TopOfStack, Irp);
  396. if (STATUS_PENDING == status) {
  397. KeWaitForSingleObject(
  398. &event,
  399. Executive, // Waiting for reason of a driver
  400. KernelMode, // Waiting in kernel mode
  401. FALSE, // No allert
  402. NULL); // No timeout
  403. }
  404. if (NT_SUCCESS(status) && NT_SUCCESS(Irp->IoStatus.Status)) {
  405. //
  406. // As we are successfully now back from our start device
  407. // we can do work.
  408. //
  409. devExt->Started = TRUE;
  410. devExt->Removed = FALSE;
  411. devExt->SurpriseRemoved = FALSE;
  412. }
  413. //
  414. // We must now complete the IRP, since we stopped it in the
  415. // completetion routine with MORE_PROCESSING_REQUIRED.
  416. //
  417. Irp->IoStatus.Status = status;
  418. Irp->IoStatus.Information = 0;
  419. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  420. break;
  421. }
  422. case IRP_MN_SURPRISE_REMOVAL:
  423. //
  424. // Same as a remove device, but don't call IoDetach or IoDeleteDevice
  425. //
  426. devExt->SurpriseRemoved = TRUE;
  427. // Remove code here
  428. IoSkipCurrentIrpStackLocation(Irp);
  429. status = IoCallDriver(devExt->TopOfStack, Irp);
  430. break;
  431. case IRP_MN_REMOVE_DEVICE:
  432. devExt->Removed = TRUE;
  433. // remove code here
  434. Irp->IoStatus.Status = STATUS_SUCCESS;
  435. IoSkipCurrentIrpStackLocation(Irp);
  436. status = IoCallDriver(devExt->TopOfStack, Irp);
  437. IoDetachDevice(devExt->TopOfStack);
  438. IoDeleteDevice(DeviceObject);
  439. break;
  440. case IRP_MN_QUERY_REMOVE_DEVICE:
  441. case IRP_MN_QUERY_STOP_DEVICE:
  442. case IRP_MN_CANCEL_REMOVE_DEVICE:
  443. case IRP_MN_CANCEL_STOP_DEVICE:
  444. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  445. case IRP_MN_STOP_DEVICE:
  446. case IRP_MN_QUERY_DEVICE_RELATIONS:
  447. case IRP_MN_QUERY_INTERFACE:
  448. case IRP_MN_QUERY_CAPABILITIES:
  449. case IRP_MN_QUERY_DEVICE_TEXT:
  450. case IRP_MN_QUERY_RESOURCES:
  451. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  452. case IRP_MN_READ_CONFIG:
  453. case IRP_MN_WRITE_CONFIG:
  454. case IRP_MN_EJECT:
  455. case IRP_MN_SET_LOCK:
  456. case IRP_MN_QUERY_ID:
  457. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  458. default:
  459. //
  460. // Here the filter driver might modify the behavior of these IRPS
  461. // Please see PlugPlay documentation for use of these IRPs.
  462. //
  463. IoSkipCurrentIrpStackLocation(Irp);
  464. status = IoCallDriver(devExt->TopOfStack, Irp);
  465. break;
  466. }
  467. return status;
  468. }
  469. NTSTATUS
  470. KbFilter_Power(
  471. IN PDEVICE_OBJECT DeviceObject,
  472. IN PIRP Irp
  473. )
  474. /*++
  475. Routine Description:
  476. This routine is the dispatch routine for power irps Does nothing except
  477. record the state of the device.
  478. Arguments:
  479. DeviceObject - Pointer to the device object.
  480. Irp - Pointer to the request packet.
  481. Return Value:
  482. Status is returned.
  483. --*/
  484. {
  485. PIO_STACK_LOCATION irpStack;
  486. PDEVICE_EXTENSION devExt;
  487. POWER_STATE powerState;
  488. POWER_STATE_TYPE powerType;
  489. PAGED_CODE();
  490. devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  491. irpStack = IoGetCurrentIrpStackLocation(Irp);
  492. powerType = irpStack->Parameters.Power.Type;
  493. powerState = irpStack->Parameters.Power.State;
  494. switch (irpStack->MinorFunction) {
  495. case IRP_MN_SET_POWER:
  496. if (powerType == DevicePowerState) {
  497. devExt->DeviceState = powerState.DeviceState;
  498. }
  499. case IRP_MN_POWER_SEQUENCE:
  500. case IRP_MN_WAIT_WAKE:
  501. case IRP_MN_QUERY_POWER:
  502. default:
  503. break;
  504. }
  505. PoStartNextPowerIrp(Irp);
  506. IoSkipCurrentIrpStackLocation(Irp);
  507. return PoCallDriver(devExt->TopOfStack, Irp);
  508. }
  509. NTSTATUS
  510. KbFilter_InitializationRoutine(
  511. IN PDEVICE_OBJECT DeviceObject,
  512. IN PVOID SynchFuncContext,
  513. IN PI8042_SYNCH_READ_PORT ReadPort,
  514. IN PI8042_SYNCH_WRITE_PORT WritePort,
  515. OUT PBOOLEAN TurnTranslationOn
  516. )
  517. /*++
  518. Routine Description:
  519. This routine gets called after the following has been performed on the kb
  520. 1) a reset
  521. 2) set the typematic
  522. 3) set the LEDs
  523. i8042prt specific code, if you are writing a packet only filter driver, you
  524. can remove this function
  525. Arguments:
  526. DeviceObject - Context passed during IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
  527. SynchFuncContext - Context to pass when calling Read/WritePort
  528. Read/WritePort - Functions to synchronoulsy read and write to the kb
  529. TurnTranslationOn - If TRUE when this function returns, i8042prt will not
  530. turn on translation on the keyboard
  531. Return Value:
  532. Status is returned.
  533. --*/
  534. {
  535. PDEVICE_EXTENSION devExt;
  536. NTSTATUS status = STATUS_SUCCESS;
  537. devExt = DeviceObject->DeviceExtension;
  538. //
  539. // Do any interesting processing here. We just call any other drivers
  540. // in the chain if they exist. Make Translation is turned on as well
  541. //
  542. if (devExt->UpperInitializationRoutine) {
  543. status = (*devExt->UpperInitializationRoutine) (
  544. devExt->UpperContext,
  545. SynchFuncContext,
  546. ReadPort,
  547. WritePort,
  548. TurnTranslationOn
  549. );
  550. if (!NT_SUCCESS(status)) {
  551. return status;
  552. }
  553. }
  554. *TurnTranslationOn = TRUE;
  555. return status;
  556. }
  557. BOOLEAN
  558. KbFilter_IsrHook(
  559. PDEVICE_OBJECT DeviceObject,
  560. PKEYBOARD_INPUT_DATA CurrentInput,
  561. POUTPUT_PACKET CurrentOutput,
  562. UCHAR StatusByte,
  563. PUCHAR DataByte,
  564. PBOOLEAN ContinueProcessing,
  565. PKEYBOARD_SCAN_STATE ScanState
  566. )
  567. /*++
  568. Routine Description:
  569. This routine gets called at the beginning of processing of the kb interrupt.
  570. i8042prt specific code, if you are writing a packet only filter driver, you
  571. can remove this function
  572. Arguments:
  573. DeviceObject - Our context passed during IOCTL_INTERNAL_I8042_HOOK_KEYBOARD
  574. CurrentInput - Current input packet being formulated by processing all the
  575. interrupts
  576. CurrentOutput - Current list of bytes being written to the keyboard or the
  577. i8042 port.
  578. StatusByte - Byte read from I/O port 60 when the interrupt occurred
  579. DataByte - Byte read from I/O port 64 when the interrupt occurred.
  580. This value can be modified and i8042prt will use this value
  581. if ContinueProcessing is TRUE
  582. ContinueProcessing - If TRUE, i8042prt will proceed with normal processing of
  583. the interrupt. If FALSE, i8042prt will return from the
  584. interrupt after this function returns. Also, if FALSE,
  585. it is this functions responsibilityt to report the input
  586. packet via the function provided in the hook IOCTL or via
  587. queueing a DPC within this driver and calling the
  588. service callback function acquired from the connect IOCTL
  589. Return Value:
  590. Status is returned.
  591. --*/
  592. {
  593. PDEVICE_EXTENSION devExt;
  594. BOOLEAN retVal = TRUE;
  595. devExt = DeviceObject->DeviceExtension;
  596. if (devExt->UpperIsrHook) {
  597. retVal = (*devExt->UpperIsrHook) (
  598. devExt->UpperContext,
  599. CurrentInput,
  600. CurrentOutput,
  601. StatusByte,
  602. DataByte,
  603. ContinueProcessing,
  604. ScanState
  605. );
  606. if (!retVal || !(*ContinueProcessing)) {
  607. return retVal;
  608. }
  609. }
  610. *ContinueProcessing = TRUE;
  611. return retVal;
  612. }
  613. VOID
  614. KbFilter_ServiceCallback(
  615. IN PDEVICE_OBJECT DeviceObject,
  616. IN PKEYBOARD_INPUT_DATA InputDataStart,
  617. IN PKEYBOARD_INPUT_DATA InputDataEnd,
  618. IN OUT PULONG InputDataConsumed
  619. )
  620. /*++
  621. Routine Description:
  622. Called when there are keyboard packets to report to the RIT. You can do
  623. anything you like to the packets. For instance:
  624. o Drop a packet altogether
  625. o Mutate the contents of a packet
  626. o Insert packets into the stream
  627. Arguments:
  628. DeviceObject - Context passed during the connect IOCTL
  629. InputDataStart - First packet to be reported
  630. InputDataEnd - One past the last packet to be reported. Total number of
  631. packets is equal to InputDataEnd - InputDataStart
  632. InputDataConsumed - Set to the total number of packets consumed by the RIT
  633. (via the function pointer we replaced in the connect
  634. IOCTL)
  635. Return Value:
  636. Status is returned.
  637. --*/
  638. {
  639. PDEVICE_EXTENSION devExt;
  640. devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  641. (*(PSERVICE_CALLBACK_ROUTINE) devExt->UpperConnectData.ClassService)(
  642. devExt->UpperConnectData.ClassDeviceObject,
  643. InputDataStart,
  644. InputDataEnd,
  645. InputDataConsumed);
  646. }
  647. VOID
  648. KbFilter_Unload(
  649. IN PDRIVER_OBJECT Driver
  650. )
  651. /*++
  652. Routine Description:
  653. Free all the allocated resources associated with this driver.
  654. Arguments:
  655. DriverObject - Pointer to the driver object.
  656. Return Value:
  657. None.
  658. --*/
  659. {
  660. PAGED_CODE();
  661. UNREFERENCED_PARAMETER(Driver);
  662. ASSERT(NULL == Driver->DeviceObject);
  663. }