ReactOS  0.4.15-dev-1070-ge1a01de
kbdhid.c File Reference
#include "kbdhid.h"
Include dependency graph for kbdhid.c:

Go to the source code of this file.

Functions

VOID KbdHid_DispatchInputData (IN PKBDHID_DEVICE_EXTENSION DeviceExtension, IN PKEYBOARD_INPUT_DATA InputData)
 
BOOLEAN NTAPI KbdHid_InsertScanCodes (IN PVOID Context, IN PCHAR NewScanCodes, IN ULONG Length)
 
NTSTATUS NTAPI KbdHid_ReadCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS KbdHid_InitiateRead (IN PKBDHID_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI KbdHid_CreateCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI KbdHid_Create (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_Close (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_InternalDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_DeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_Power (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_SystemControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS KbdHid_SubmitRequest (PDEVICE_OBJECT DeviceObject, ULONG IoControlCode, ULONG InputBufferSize, PVOID InputBuffer, ULONG OutputBufferSize, PVOID OutputBuffer)
 
NTSTATUS NTAPI KbdHid_StartDevice (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI KbdHid_StartDeviceCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI KbdHid_FreeResources (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI KbdHid_Flush (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_Pnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI KbdHid_AddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
VOID NTAPI KbdHid_Unload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
 

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegPath 
)

Definition at line 1036 of file kbdhid.c.

1039 {
1040  /* initialize driver object */
1051 
1052  /* done */
1053  return STATUS_SUCCESS;
1054 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_FLUSH_BUFFERS
NTSTATUS NTAPI KbdHid_Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:238
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID NTAPI KbdHid_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: kbdhid.c:1027
NTSTATUS NTAPI KbdHid_InternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:351
NTSTATUS NTAPI KbdHid_Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:845
NTSTATUS NTAPI KbdHid_Flush(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:819
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
NTSTATUS NTAPI KbdHid_DeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:542
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
#define IRP_MJ_SYSTEM_CONTROL
NTSTATUS NTAPI KbdHid_SystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:574
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
NTSTATUS NTAPI KbdHid_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: kbdhid.c:953
NTSTATUS NTAPI KbdHid_Close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:314
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
NTSTATUS NTAPI KbdHid_Power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: kbdhid.c:560
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ KbdHid_AddDevice()

NTSTATUS NTAPI KbdHid_AddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 953 of file kbdhid.c.

956 {
959  PKBDHID_DEVICE_EXTENSION DeviceExtension;
961 
962  /* create device object */
964  sizeof(KBDHID_DEVICE_EXTENSION),
965  NULL,
967  0,
968  FALSE,
969  &DeviceObject);
970  if (!NT_SUCCESS(Status))
971  {
972  /* failed to create device object */
973  return Status;
974  }
975 
976  /* now attach it */
978  if (!NextDeviceObject)
979  {
980  /* failed to attach */
983  }
984 
985  /* get device extension */
986  DeviceExtension = DeviceObject->DeviceExtension;
987 
988  /* zero extension */
989  RtlZeroMemory(DeviceExtension, sizeof(KBDHID_DEVICE_EXTENSION));
990 
991  /* init device extension */
992  DeviceExtension->NextDeviceObject = NextDeviceObject;
994 
995  /* init keyboard attributes */
999  DeviceExtension->Attributes.NumberOfIndicators = 3; // caps, num lock, scroll lock
1000  DeviceExtension->Attributes.NumberOfKeysTotal = 101;
1001  DeviceExtension->Attributes.InputDataQueueLength = 1;
1006 
1007  /* allocate irp */
1008  DeviceExtension->Irp = IoAllocateIrp(NextDeviceObject->StackSize, FALSE);
1009 
1010  /* FIXME handle allocation error */
1011  ASSERT(DeviceExtension->Irp);
1012 
1013  /* set power state to D0 */
1014  State.DeviceState = PowerDeviceD0;
1016 
1017  /* init device object */
1020 
1021  /* completed successfully */
1022  return STATUS_SUCCESS;
1023 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
KEYBOARD_TYPEMATIC_PARAMETERS KeyRepeatMaximum
Definition: ntddkbd.h:131
#define DO_POWER_PAGABLE
UCHAR Type
Definition: ntddkbd.h:101
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
USHORT NumberOfKeysTotal
Definition: ntddkbd.h:128
#define KEYBOARD_TYPEMATIC_RATE_MINIMUM
Definition: kbdhid.h:131
#define FALSE
Definition: types.h:117
#define KEYBOARD_TYPEMATIC_DELAY_MAXIMUM
Definition: kbdhid.h:135
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
smooth NULL
Definition: ftsmooth.c:416
#define KEYBOARD_TYPE_UNKNOWN
Definition: kbdhid.h:140
#define MICROSOFT_KBD_FUNC
Definition: kbdhid.h:139
KEVENT ReadCompletionEvent
Definition: kbdhid.h:31
#define MICROSOFT_KBD_101_TYPE
Definition: kbdhid.h:141
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
KEYBOARD_TYPEMATIC_PARAMETERS KeyRepeatMinimum
Definition: ntddkbd.h:130
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
USHORT NumberOfIndicators
Definition: ntddkbd.h:127
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * NextDeviceObject
Definition: ndis.h:4640
Status
Definition: gdiplustypes.h:24
KEYBOARD_ID KeyboardIdentifier
Definition: ntddkbd.h:124
UCHAR Subtype
Definition: ntddkbd.h:102
#define KEYBOARD_TYPEMATIC_RATE_DEFAULT
Definition: kbdhid.h:133
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
USHORT NumberOfFunctionKeys
Definition: ntddkbd.h:126
ULONG InputDataQueueLength
Definition: ntddkbd.h:129
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:708
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
KEYBOARD_ATTRIBUTES Attributes
Definition: kbdhid.h:111
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define KEYBOARD_TYPEMATIC_DELAY_MINIMUM
Definition: kbdhid.h:134
#define FILE_DEVICE_KEYBOARD
Definition: winioctl.h:116

Referenced by DriverEntry().

◆ KbdHid_Close()

NTSTATUS NTAPI KbdHid_Close ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 314 of file kbdhid.c.

317 {
318  PKBDHID_DEVICE_EXTENSION DeviceExtension;
319 
320  /* get device extension */
321  DeviceExtension = DeviceObject->DeviceExtension;
322 
323  DPRINT("[KBDHID] IRP_MJ_CLOSE ReadReportActive %x\n", DeviceExtension->ReadReportActive);
324 
325  if (DeviceExtension->ReadReportActive)
326  {
327  /* request stopping of the report cycle */
328  DeviceExtension->StopReadReport = TRUE;
329 
330  /* wait until the reports have been read */
332 
333  /* cancel irp */
334  IoCancelIrp(DeviceExtension->Irp);
335  }
336 
337  DPRINT("[KBDHID] IRP_MJ_CLOSE ReadReportActive %x\n", DeviceExtension->ReadReportActive);
338 
339  /* remove file object */
340  DeviceExtension->FileObject = NULL;
341 
342  /* skip location */
344 
345  /* pass irp to down the stack */
346  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
347 }
PFILE_OBJECT FileObject
Definition: kbdhid.h:96
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
KEVENT ReadCompletionEvent
Definition: kbdhid.h:31
void DPRINT(...)
Definition: polytest.cpp:61
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101

Referenced by DriverEntry().

◆ KbdHid_Create()

NTSTATUS NTAPI KbdHid_Create ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 238 of file kbdhid.c.

241 {
242  PIO_STACK_LOCATION IoStack;
244  KEVENT Event;
245  PKBDHID_DEVICE_EXTENSION DeviceExtension;
246 
247  DPRINT("[KBDHID]: IRP_MJ_CREATE\n");
248 
249  /* get device extension */
250  DeviceExtension = DeviceObject->DeviceExtension;
251 
252  /* get stack location */
254 
255  /* copy stack location to next */
257 
258  /* init event */
260 
261  /* prepare irp */
263 
264  /* call lower driver */
265  Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
266  if (Status == STATUS_PENDING)
267  {
268  /* request pending */
270  }
271 
272  /* check for success */
273  if (!NT_SUCCESS(Status))
274  {
275  /* failed */
276  Irp->IoStatus.Status = Status;
278  return Status;
279  }
280 
281  /* is the driver already in use */
282  if (DeviceExtension->FileObject == NULL)
283  {
284  /* did the caller specify correct attributes */
285  ASSERT(IoStack->Parameters.Create.SecurityContext);
286  if (IoStack->Parameters.Create.SecurityContext->DesiredAccess)
287  {
288  /* store file object */
289  DeviceExtension->FileObject = IoStack->FileObject;
290 
291  /* reset event */
292  KeClearEvent(&DeviceExtension->ReadCompletionEvent);
293 
294  /* initiating read */
295  Status = KbdHid_InitiateRead(DeviceExtension);
296  DPRINT("[KBDHID] KbdHid_InitiateRead: status %x\n", Status);
297  if (Status == STATUS_PENDING)
298  {
299  /* report irp is pending */
301  }
302  }
303  }
304 
305  /* complete request */
306  Irp->IoStatus.Status = Status;
308  return Status;
309 }
NTSTATUS KbdHid_InitiateRead(IN PKBDHID_DEVICE_EXTENSION DeviceExtension)
Definition: kbdhid.c:189
PFILE_OBJECT FileObject
Definition: kbdhid.h:96
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2864
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
KEVENT ReadCompletionEvent
Definition: kbdhid.h:31
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI KbdHid_CreateCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: kbdhid.c:226
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:3014
HRESULT Create([out]ITransactionReceiver **ppReceiver)

Referenced by DriverEntry().

◆ KbdHid_CreateCompletion()

NTSTATUS NTAPI KbdHid_CreateCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 226 of file kbdhid.c.

230 {
233 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117

Referenced by KbdHid_Create().

◆ KbdHid_DeviceControl()

NTSTATUS NTAPI KbdHid_DeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 542 of file kbdhid.c.

545 {
546  PKBDHID_DEVICE_EXTENSION DeviceExtension;
547 
548  /* get device extension */
549  DeviceExtension = DeviceObject->DeviceExtension;
550 
551  /* skip stack location */
553 
554  /* pass and forget */
555  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
556 }
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by DriverEntry().

◆ KbdHid_DispatchInputData()

VOID KbdHid_DispatchInputData ( IN PKBDHID_DEVICE_EXTENSION  DeviceExtension,
IN PKEYBOARD_INPUT_DATA  InputData 
)

Definition at line 14 of file kbdhid.c.

17 {
18  KIRQL OldIrql;
19  ULONG InputDataConsumed;
20 
21  if (!DeviceExtension->ClassService)
22  return;
23 
24  /* sanity check */
25  ASSERT(DeviceExtension->ClassService);
26  ASSERT(DeviceExtension->ClassDeviceObject);
27 
28  /* raise irql */
30 
31  /* dispatch input data */
32  (*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->ClassService)(DeviceExtension->ClassDeviceObject, InputData, InputData + 1, &InputDataConsumed);
33 
34  /* lower irql to previous level */
36 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
UCHAR KIRQL
Definition: env_spec_w32.h:591
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID(STDAPICALLTYPE * PSERVICE_CALLBACK_ROUTINE)(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2, IN OUT PVOID SystemArgument3)
Definition: kbdmou.h:86
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
unsigned int ULONG
Definition: retypes.h:1

Referenced by KbdHid_InsertScanCodes().

◆ KbdHid_Flush()

NTSTATUS NTAPI KbdHid_Flush ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 819 of file kbdhid.c.

822 {
823  PIO_STACK_LOCATION IoStack;
824  PKBDHID_DEVICE_EXTENSION DeviceExtension;
825 
826  /* get device extension */
827  DeviceExtension = DeviceObject->DeviceExtension;
828 
829  /* skip current stack location */
831 
832  /* get next stack location */
833  IoStack = IoGetNextIrpStackLocation(Irp);
834 
835  /* change request to hid flush queue request */
837  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_HID_FLUSH_QUEUE;
838 
839  /* call device */
840  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
841 }
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define IOCTL_HID_FLUSH_QUEUE
Definition: hidclass.h:57
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by DriverEntry().

◆ KbdHid_FreeResources()

NTSTATUS NTAPI KbdHid_FreeResources ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 777 of file kbdhid.c.

779 {
780  PKBDHID_DEVICE_EXTENSION DeviceExtension;
781 
782  /* get device extension */
783  DeviceExtension = DeviceObject->DeviceExtension;
784 
785  /* free resources */
786  if (DeviceExtension->PreparsedData)
787  {
788  ExFreePoolWithTag(DeviceExtension->PreparsedData, KBDHID_TAG);
789  DeviceExtension->PreparsedData = NULL;
790  }
791 
792  if (DeviceExtension->UsageListBuffer)
793  {
794  ExFreePoolWithTag(DeviceExtension->UsageListBuffer, KBDHID_TAG);
795  DeviceExtension->UsageListBuffer = NULL;
796  DeviceExtension->CurrentUsageList = NULL;
797  DeviceExtension->PreviousUsageList = NULL;
798  DeviceExtension->MakeUsageList = NULL;
799  DeviceExtension->BreakUsageList = NULL;
800  }
801 
802  if (DeviceExtension->ReportMDL)
803  {
804  IoFreeMdl(DeviceExtension->ReportMDL);
805  DeviceExtension->ReportMDL = NULL;
806  }
807 
808  if (DeviceExtension->Report)
809  {
810  ExFreePoolWithTag(DeviceExtension->Report, KBDHID_TAG);
811  DeviceExtension->Report = NULL;
812  }
813 
814  return STATUS_SUCCESS;
815 }
#define KBDHID_TAG
Definition: kbdhid.h:148
PUSAGE_AND_PAGE MakeUsageList
Definition: kbdhid.h:71
PUSAGE_AND_PAGE BreakUsageList
Definition: kbdhid.h:66
PUSAGE_AND_PAGE PreviousUsageList
Definition: kbdhid.h:61
PUSAGE_AND_PAGE CurrentUsageList
Definition: kbdhid.h:56
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
PHIDP_PREPARSED_DATA PreparsedData
Definition: kbdhid.h:76
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by KbdHid_Pnp().

◆ KbdHid_InitiateRead()

NTSTATUS KbdHid_InitiateRead ( IN PKBDHID_DEVICE_EXTENSION  DeviceExtension)

Definition at line 189 of file kbdhid.c.

191 {
192  PIO_STACK_LOCATION IoStack;
194 
195  /* re-use irp */
196  IoReuseIrp(DeviceExtension->Irp, STATUS_SUCCESS);
197 
198  /* init irp */
199  DeviceExtension->Irp->MdlAddress = DeviceExtension->ReportMDL;
200 
201  /* get next stack location */
202  IoStack = IoGetNextIrpStackLocation(DeviceExtension->Irp);
203 
204  /* init stack location */
205  IoStack->Parameters.Read.Length = DeviceExtension->ReportLength;
206  IoStack->Parameters.Read.Key = 0;
207  IoStack->Parameters.Read.ByteOffset.QuadPart = 0LL;
208  IoStack->MajorFunction = IRP_MJ_READ;
209  IoStack->FileObject = DeviceExtension->FileObject;
210 
211  /* set completion routine */
212  IoSetCompletionRoutine(DeviceExtension->Irp, KbdHid_ReadCompletion, DeviceExtension, TRUE, TRUE, TRUE);
213 
214  /* read is active */
215  DeviceExtension->ReadReportActive = TRUE;
216 
217  /* start the read */
218  Status = IoCallDriver(DeviceExtension->NextDeviceObject, DeviceExtension->Irp);
219 
220  /* done */
221  return Status;
222 }
#define LL
Definition: tui.h:84
VOID NTAPI IoReuseIrp(IN OUT PIRP Irp, IN NTSTATUS Status)
Definition: irp.c:1971
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
NTSTATUS NTAPI KbdHid_ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: kbdhid.c:97
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by KbdHid_Create(), and KbdHid_ReadCompletion().

◆ KbdHid_InsertScanCodes()

BOOLEAN NTAPI KbdHid_InsertScanCodes ( IN PVOID  Context,
IN PCHAR  NewScanCodes,
IN ULONG  Length 
)

Definition at line 40 of file kbdhid.c.

44 {
45  KEYBOARD_INPUT_DATA InputData;
46  ULONG Index;
47  PKBDHID_DEVICE_EXTENSION DeviceExtension;
48  CHAR Prefix = 0;
49 
50  /* get device extension */
51  DeviceExtension = Context;
52 
53  for(Index = 0; Index < Length; Index++)
54  {
55  DPRINT("[KBDHID] ScanCode Index %lu ScanCode %x\n", Index, NewScanCodes[Index] & 0xFF);
56 
57  /* check if this is E0 or E1 prefix */
58  if (NewScanCodes[Index] == (CHAR)0xE0 || NewScanCodes[Index] == (CHAR)0xE1)
59  {
60  Prefix = NewScanCodes[Index];
61  continue;
62  }
63 
64  /* init input data */
65  RtlZeroMemory(&InputData, sizeof(KEYBOARD_INPUT_DATA));
66 
67  /* use keyboard unit id */
68  InputData.UnitId = DeviceExtension->KeyboardTypematic.UnitId;
69 
70  if (NewScanCodes[Index] & 0x80)
71  {
72  /* scan codes with 0x80 flag are a key break */
73  InputData.Flags |= KEY_BREAK;
74  }
75 
76  /* set a prefix if needed */
77  if (Prefix)
78  {
79  InputData.Flags |= (Prefix == (CHAR)0xE0 ? KEY_E0 : KEY_E1);
80  Prefix = 0;
81  }
82 
83  /* store key code */
84  InputData.MakeCode = NewScanCodes[Index] & 0x7F;
85 
86  /* dispatch scan codes */
87  KbdHid_DispatchInputData(Context, &InputData);
88  }
89 
90  /* done */
91  return TRUE;
92 }
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
KEYBOARD_TYPEMATIC_PARAMETERS KeyboardTypematic
Definition: kbdhid.h:126
#define KEY_BREAK
Definition: ntddkbd.h:71
void DPRINT(...)
Definition: polytest.cpp:61
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define KEY_E1
Definition: ntddkbd.h:73
#define KEY_E0
Definition: ntddkbd.h:72
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CHAR(Char)
VOID KbdHid_DispatchInputData(IN PKBDHID_DEVICE_EXTENSION DeviceExtension, IN PKEYBOARD_INPUT_DATA InputData)
Definition: kbdhid.c:14

Referenced by KbdHid_ReadCompletion().

◆ KbdHid_InternalDeviceControl()

NTSTATUS NTAPI KbdHid_InternalDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 351 of file kbdhid.c.

354 {
355  PIO_STACK_LOCATION IoStack;
356  PKBDHID_DEVICE_EXTENSION DeviceExtension;
359 
360  /* get current stack location */
362 
363  DPRINT("[KBDHID] InternalDeviceControl %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
364 
365  /* get device extension */
366  DeviceExtension = DeviceObject->DeviceExtension;
367 
368  switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
369  {
371  /* verify output buffer length */
372  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(MOUSE_ATTRIBUTES))
373  {
374  /* invalid request */
375  DPRINT1("[KBDHID] IOCTL_KEYBOARD_QUERY_ATTRIBUTES Buffer too small\n");
376  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
379  }
380 
381  /* get output buffer */
382  Attributes = Irp->AssociatedIrp.SystemBuffer;
383 
384  /* copy attributes */
386  &DeviceExtension->Attributes,
387  sizeof(KEYBOARD_ATTRIBUTES));
388 
389  /* complete request */
390  Irp->IoStatus.Information = sizeof(MOUSE_ATTRIBUTES);
391  Irp->IoStatus.Status = STATUS_SUCCESS;
393  return STATUS_SUCCESS;
394 
396  /* verify input buffer length */
397  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONNECT_DATA))
398  {
399  /* invalid request */
400  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
403  }
404 
405  /* is it already connected */
406  if (DeviceExtension->ClassService)
407  {
408  /* already connected */
409  Irp->IoStatus.Status = STATUS_SHARING_VIOLATION;
412  }
413 
414  /* get connect data */
415  Data = IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
416 
417  /* store connect details */
418  DeviceExtension->ClassDeviceObject = Data->ClassDeviceObject;
419  DeviceExtension->ClassService = Data->ClassService;
420 
421  /* completed successfully */
422  Irp->IoStatus.Status = STATUS_SUCCESS;
424  return STATUS_SUCCESS;
425 
427  /* not implemented */
428  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
430  return STATUS_NOT_IMPLEMENTED;
431 
433  /* not supported */
434  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
436  return STATUS_NOT_SUPPORTED;
437 
439  /* not supported */
440  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
442  return STATUS_NOT_SUPPORTED;
443 
445  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS))
446  {
447  /* invalid parameter */
448  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
451  }
452 
453  /* copy indicators */
454  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
455  &DeviceExtension->KeyboardIndicator,
457 
458  /* complete request */
459  Irp->IoStatus.Status = STATUS_SUCCESS;
460  Irp->IoStatus.Information = sizeof(KEYBOARD_INDICATOR_PARAMETERS);
462  return STATUS_NOT_IMPLEMENTED;
463 
465  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KEYBOARD_TYPEMATIC_PARAMETERS))
466  {
467  /* invalid parameter */
468  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
471  }
472 
473  /* copy indicators */
474  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
475  &DeviceExtension->KeyboardTypematic,
477 
478  /* done */
479  Irp->IoStatus.Status = STATUS_SUCCESS;
480  Irp->IoStatus.Information = sizeof(KEYBOARD_TYPEMATIC_PARAMETERS);
482  return STATUS_SUCCESS;
483 
485  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS))
486  {
487  /* invalid parameter */
488  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
491  }
492 
493  /* copy indicators */
494  RtlCopyMemory(&DeviceExtension->KeyboardIndicator,
495  Irp->AssociatedIrp.SystemBuffer,
497 
498  /* done */
499  Irp->IoStatus.Status = STATUS_SUCCESS;
500  Irp->IoStatus.Information = 0;
502  return STATUS_SUCCESS;
503 
505  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_TYPEMATIC_PARAMETERS))
506  {
507  /* invalid parameter */
508  Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
511  }
512 
513  /* copy indicators */
514  RtlCopyMemory(&DeviceExtension->KeyboardTypematic,
515  Irp->AssociatedIrp.SystemBuffer,
517 
518  /* done */
519  Irp->IoStatus.Status = STATUS_SUCCESS;
520  Irp->IoStatus.Information = 0;
522  return STATUS_SUCCESS;
523 
525  /* not implemented */
526  DPRINT1("IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION not implemented\n");
527  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
529  return STATUS_NOT_IMPLEMENTED;
530  }
531 
532  /* unknown control code */
533  DPRINT1("[KBDHID] Unknown DeviceControl %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
534  /* unknown request not supported */
535  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
537  return STATUS_NOT_SUPPORTED;
538 }
#define IOCTL_KEYBOARD_QUERY_TYPEMATIC
Definition: ntddkbd.h:41
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION
Definition: ntddkbd.h:38
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT ClassDeviceObject
Definition: kbdhid.h:36
KEYBOARD_TYPEMATIC_PARAMETERS KeyboardTypematic
Definition: kbdhid.h:126
struct _KEYBOARD_TYPEMATIC_PARAMETERS KEYBOARD_TYPEMATIC_PARAMETERS
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _KEYBOARD_INDICATOR_PARAMETERS KEYBOARD_INDICATOR_PARAMETERS
#define STATUS_SHARING_VIOLATION
Definition: udferr_usr.h:154
#define IOCTL_KEYBOARD_SET_TYPEMATIC
Definition: ntddkbd.h:44
KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicator
Definition: kbdhid.h:121
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:971
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IOCTL_INTERNAL_KEYBOARD_DISABLE
Definition: kbdmou.h:65
#define IOCTL_KEYBOARD_QUERY_INDICATORS
Definition: ntddkbd.h:35
#define IOCTL_INTERNAL_KEYBOARD_DISCONNECT
Definition: kbdmou.h:59
#define IOCTL_INTERNAL_KEYBOARD_CONNECT
Definition: kbdmou.h:56
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IOCTL_INTERNAL_KEYBOARD_ENABLE
Definition: kbdmou.h:62
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_KEYBOARD_QUERY_ATTRIBUTES
Definition: ntddkbd.h:32
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define IO_NO_INCREMENT
Definition: iotypes.h:581
KEYBOARD_ATTRIBUTES Attributes
Definition: kbdhid.h:111
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define IOCTL_KEYBOARD_SET_INDICATORS
Definition: ntddkbd.h:47
return STATUS_SUCCESS
Definition: btrfs.c:3014
struct _MOUSE_ATTRIBUTES MOUSE_ATTRIBUTES

Referenced by DriverEntry().

◆ KbdHid_Pnp()

NTSTATUS NTAPI KbdHid_Pnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 845 of file kbdhid.c.

848 {
849  PIO_STACK_LOCATION IoStack;
850  KEVENT Event;
852  PKBDHID_DEVICE_EXTENSION DeviceExtension;
853 
854  /* get device extension */
855  DeviceExtension = DeviceObject->DeviceExtension;
856 
857  /* get current irp stack */
859  DPRINT("[KBDHID] IRP_MJ_PNP Request: %x\n", IoStack->MinorFunction);
860 
861  switch (IoStack->MinorFunction)
862  {
863  case IRP_MN_STOP_DEVICE:
865  /* free resources */
867  /* fall through */
872  /* indicate success */
873  Irp->IoStatus.Status = STATUS_SUCCESS;
874 
875  /* skip irp stack location */
877 
878  /* dispatch to lower device */
879  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
880 
882  /* FIXME synchronization */
883 
884  /* cancel irp */
885  IoCancelIrp(DeviceExtension->Irp);
886 
887  /* free resources */
889 
890  /* indicate success */
891  Irp->IoStatus.Status = STATUS_SUCCESS;
892 
893  /* skip irp stack location */
895 
896  /* dispatch to lower device */
897  Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
898 
899  IoFreeIrp(DeviceExtension->Irp);
900  IoDetachDevice(DeviceExtension->NextDeviceObject);
902  return Status;
903 
904  case IRP_MN_START_DEVICE:
905  /* init event */
907 
908  /* copy stack location */
910 
911  /* set completion routine */
913  Irp->IoStatus.Status = 0;
914 
915  /* pass request */
916  Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
917  if (Status == STATUS_PENDING)
918  {
920  Status = Irp->IoStatus.Status;
921  }
922 
923  if (!NT_SUCCESS(Status))
924  {
925  /* failed */
926  Irp->IoStatus.Status = Status;
928  return Status;
929  }
930 
931  /* lets start the device */
933  DPRINT("KbdHid_StartDevice %x\n", Status);
934 
935  /* complete request */
936  Irp->IoStatus.Status = Status;
938 
939  /* done */
940  return Status;
941 
942  default:
943  /* skip irp stack location */
945 
946  /* dispatch to lower device */
947  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
948  }
949 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI KbdHid_FreeResources(IN PDEVICE_OBJECT DeviceObject)
Definition: kbdhid.c:777
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2864
#define FALSE
Definition: types.h:117
#define IRP_MN_QUERY_REMOVE_DEVICE
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
NTSTATUS NTAPI KbdHid_StartDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: kbdhid.c:637
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI KbdHid_StartDeviceCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: kbdhid.c:766
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define IRP_MN_CANCEL_STOP_DEVICE
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by DriverEntry().

◆ KbdHid_Power()

NTSTATUS NTAPI KbdHid_Power ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 560 of file kbdhid.c.

563 {
564  PKBDHID_DEVICE_EXTENSION DeviceExtension;
565 
566  DeviceExtension = DeviceObject->DeviceExtension;
569  return PoCallDriver(DeviceExtension->NextDeviceObject, Irp);
570 }
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by DriverEntry().

◆ KbdHid_ReadCompletion()

NTSTATUS NTAPI KbdHid_ReadCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 97 of file kbdhid.c.

101 {
102  PKBDHID_DEVICE_EXTENSION DeviceExtension;
104  ULONG ButtonLength;
105 
106  /* get device extension */
107  DeviceExtension = Context;
108 
109  if (Irp->IoStatus.Status == STATUS_PRIVILEGE_NOT_HELD ||
110  Irp->IoStatus.Status == STATUS_DEVICE_NOT_CONNECTED ||
111  Irp->IoStatus.Status == STATUS_CANCELLED ||
112  DeviceExtension->StopReadReport)
113  {
114  /* failed to read or should be stopped*/
115  DPRINT1("[KBDHID] ReadCompletion terminating read Status %x\n", Irp->IoStatus.Status);
116 
117  /* report no longer active */
118  DeviceExtension->ReadReportActive = FALSE;
119 
120  /* request stopping of the report cycle */
121  DeviceExtension->StopReadReport = FALSE;
122 
123  /* signal completion event */
124  KeSetEvent(&DeviceExtension->ReadCompletionEvent, 0, 0);
126  }
127 
128  //
129  // print out raw report
130  //
131  ASSERT(DeviceExtension->ReportLength >= 9);
132  DPRINT("[KBDHID] ReadCompletion %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", DeviceExtension->Report[0], DeviceExtension->Report[1], DeviceExtension->Report[2],
133  DeviceExtension->Report[3], DeviceExtension->Report[4], DeviceExtension->Report[5],
134  DeviceExtension->Report[6], DeviceExtension->Report[7], DeviceExtension->Report[8]);
135 
136 
137  /* get current usages */
138  ButtonLength = DeviceExtension->UsageListLength;
141  DeviceExtension->CurrentUsageList,
142  &ButtonLength,
143  DeviceExtension->PreparsedData,
144  DeviceExtension->Report,
145  DeviceExtension->ReportLength);
147 
148  /* FIXME check if needs mapping */
149 
150  /* get usage difference */
152  DeviceExtension->CurrentUsageList,
153  DeviceExtension->BreakUsageList,
154  DeviceExtension->MakeUsageList,
155  DeviceExtension->UsageListLength);
157 
158  /* replace previous usage list with current list */
159  RtlMoveMemory(DeviceExtension->PreviousUsageList,
160  DeviceExtension->CurrentUsageList,
161  sizeof(USAGE_AND_PAGE) * DeviceExtension->UsageListLength);
162 
163  /* translate break usage list */
165  DeviceExtension->UsageListLength,
167  &DeviceExtension->ModifierState,
169  DeviceExtension);
171 
172  /* translate new usage list */
174  DeviceExtension->UsageListLength,
176  &DeviceExtension->ModifierState,
178  DeviceExtension);
180 
181  /* re-init read */
182  KbdHid_InitiateRead(DeviceExtension);
183 
184  /* stop completion */
186 }
NTSTATUS KbdHid_InitiateRead(IN PKBDHID_DEVICE_EXTENSION DeviceExtension)
Definition: kbdhid.c:189
PUSAGE_AND_PAGE MakeUsageList
Definition: kbdhid.h:71
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
PUSAGE_AND_PAGE BreakUsageList
Definition: kbdhid.h:66
PUSAGE_AND_PAGE PreviousUsageList
Definition: kbdhid.h:61
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
PUSAGE_AND_PAGE CurrentUsageList
Definition: kbdhid.h:56
#define FALSE
Definition: types.h:117
KEVENT ReadCompletionEvent
Definition: kbdhid.h:31
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN NTAPI KbdHid_InsertScanCodes(IN PVOID Context, IN PCHAR NewScanCodes, IN ULONG Length)
Definition: kbdhid.c:40
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_Must_inspect_result_ HIDAPI NTSTATUS NTAPI HidP_TranslateUsageAndPagesToI8042ScanCodes(_In_reads_(UsageListLength) PUSAGE_AND_PAGE ChangedUsageList, _In_ ULONG UsageListLength, _In_ HIDP_KEYBOARD_DIRECTION KeyAction, _Inout_ PHIDP_KEYBOARD_MODIFIER_STATE ModifierState, _In_ PHIDP_INSERT_SCANCODES InsertCodesProcedure, _In_opt_ PVOID InsertCodesContext)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define HIDP_LINK_COLLECTION_UNSPECIFIED
Definition: hidpi.h:185
#define DPRINT1
Definition: precomp.h:8
PHIDP_PREPARSED_DATA PreparsedData
Definition: kbdhid.h:76
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
USHORT UsageListLength
Definition: kbdhid.h:51
HIDAPI NTSTATUS NTAPI HidP_GetUsagesEx(IN HIDP_REPORT_TYPE ReportType, IN USHORT LinkCollection, OUT PUSAGE_AND_PAGE ButtonList, IN OUT ULONG *UsageLength, IN PHIDP_PREPARSED_DATA PreparsedData, IN PCHAR Report, IN ULONG ReportLength)
Definition: hidp.c:161
HIDAPI NTSTATUS NTAPI HidP_UsageAndPageListDifference(IN PUSAGE_AND_PAGE PreviousUsageList, IN PUSAGE_AND_PAGE CurrentUsageList, OUT PUSAGE_AND_PAGE BreakUsageList, OUT PUSAGE_AND_PAGE MakeUsageList, IN ULONG UsageListLength)
Definition: hidp.c:176
HIDP_KEYBOARD_MODIFIER_STATE ModifierState
Definition: kbdhid.h:116

Referenced by KbdHid_InitiateRead().

◆ KbdHid_StartDevice()

NTSTATUS NTAPI KbdHid_StartDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 637 of file kbdhid.c.

639 {
641  ULONG Buttons;
645  PKBDHID_DEVICE_EXTENSION DeviceExtension;
647 
648  /* get device extension */
649  DeviceExtension = DeviceObject->DeviceExtension;
650 
651  /* query collection information */
654  0,
655  NULL,
657  &Information);
658  if (!NT_SUCCESS(Status))
659  {
660  /* failed to query collection information */
661  DPRINT1("[KBDHID] failed to obtain collection information with %x\n", Status);
662  return Status;
663  }
664 
665  /* lets allocate space for preparsed data */
667  if (!PreparsedData)
668  {
669  /* no memory */
670  DPRINT1("[KBDHID] no memory size %u\n", Information.DescriptorSize);
672  }
673 
674  /* now obtain the preparsed data */
677  0,
678  NULL,
679  Information.DescriptorSize,
680  PreparsedData);
681  if (!NT_SUCCESS(Status))
682  {
683  /* failed to get preparsed data */
684  DPRINT1("[KBDHID] failed to obtain collection information with %x\n", Status);
686  return Status;
687  }
688 
689  /* lets get the caps */
692  {
693  /* failed to get capabilities */
694  DPRINT1("[KBDHID] failed to obtain caps with %x\n", Status);
696  return Status;
697  }
698 
699  DPRINT("[KBDHID] Usage %x UsagePage %x InputReportLength %lu\n", Capabilities.Usage, Capabilities.UsagePage, Capabilities.InputReportByteLength);
700 
701  /* init input report */
703  ASSERT(DeviceExtension->ReportLength);
704  DeviceExtension->Report = ExAllocatePoolWithTag(NonPagedPool, DeviceExtension->ReportLength, KBDHID_TAG);
705  ASSERT(DeviceExtension->Report);
706  RtlZeroMemory(DeviceExtension->Report, DeviceExtension->ReportLength);
707 
708  /* build mdl */
709  DeviceExtension->ReportMDL = IoAllocateMdl(DeviceExtension->Report,
710  DeviceExtension->ReportLength,
711  FALSE,
712  FALSE,
713  NULL);
714  ASSERT(DeviceExtension->ReportMDL);
715 
716  /* init mdl */
717  MmBuildMdlForNonPagedPool(DeviceExtension->ReportMDL);
718 
719  /* get max number of buttons */
721  DPRINT("[KBDHID] Buttons %lu\n", Buttons);
722  ASSERT(Buttons > 0);
723 
724  /* now allocate an array for those buttons */
726  if (!Buffer)
727  {
728  /* no memory */
731  }
732  DeviceExtension->UsageListBuffer = Buffer;
733 
734  /* init usage lists */
735  RtlZeroMemory(Buffer, sizeof(USAGE_AND_PAGE) * 4 * Buttons);
736  DeviceExtension->CurrentUsageList = Buffer;
737  Buffer += Buttons;
738  DeviceExtension->PreviousUsageList = Buffer;
739  Buffer += Buttons;
740  DeviceExtension->MakeUsageList = Buffer;
741  Buffer += Buttons;
742  DeviceExtension->BreakUsageList = Buffer;
743 
744  //
745  // FIMXE: implement device hacks
746  //
747  // UsageMappings
748  // KeyboardTypeOverride
749  // KeyboardSubTypeOverride
750  // KeyboardNumberTotalKeysOverride
751  // KeyboardNumberFunctionKeysOverride
752  // KeyboardNumberIndicatorsOverride
753 
754  /* store number of buttons */
755  DeviceExtension->UsageListLength = (USHORT)Buttons;
756 
757  /* store preparsed data */
758  DeviceExtension->PreparsedData = PreparsedData;
759 
760  /* completed successfully */
761  return STATUS_SUCCESS;
762 }
#define KBDHID_TAG
Definition: kbdhid.h:148
PUSAGE_AND_PAGE MakeUsageList
Definition: kbdhid.h:71
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG _In_ PHIDP_PREPARSED_DATA PreparsedData
Definition: hidpi.h:333
PUSAGE_AND_PAGE BreakUsageList
Definition: kbdhid.h:66
PUSAGE_AND_PAGE PreviousUsageList
Definition: kbdhid.h:61
HIDAPI ULONG NTAPI HidP_MaxUsageListLength(IN HIDP_REPORT_TYPE ReportType, IN USAGE UsagePage OPTIONAL, IN PHIDP_PREPARSED_DATA PreparsedData)
Definition: hidp.c:79
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
LONG NTSTATUS
Definition: precomp.h:26
Iosb Information
Definition: create.c:4353
#define IOCTL_HID_GET_COLLECTION_DESCRIPTOR
Definition: hidclass.h:58
PUSAGE_AND_PAGE CurrentUsageList
Definition: kbdhid.h:56
#define FALSE
Definition: types.h:117
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
NTSTATUS KbdHid_SubmitRequest(PDEVICE_OBJECT DeviceObject, ULONG IoControlCode, ULONG InputBufferSize, PVOID InputBuffer, ULONG OutputBufferSize, PVOID OutputBuffer)
Definition: kbdhid.c:586
#define HID_USAGE_PAGE_KEYBOARD
Definition: hidusage.h:181
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
HIDAPI NTSTATUS NTAPI HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData, OUT PHIDP_CAPS Capabilities)
Definition: hidp.c:26
static const TBBUTTON Buttons[]
Definition: mplay32.c:41
USAGE UsagePage
Definition: hidpi.h:151
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _HIDP_PREPARSED_DATA * PHIDP_PREPARSED_DATA
Definition: hidpi.h:39
#define IOCTL_HID_GET_COLLECTION_INFORMATION
Definition: hidclass.h:59
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
USAGE Usage
Definition: hidpi.h:150
unsigned short USHORT
Definition: pedump.c:61
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define DPRINT1
Definition: precomp.h:8
PHIDP_PREPARSED_DATA PreparsedData
Definition: kbdhid.h:76
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
USHORT UsageListLength
Definition: kbdhid.h:51
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
USHORT InputReportByteLength
Definition: hidpi.h:152

Referenced by KbdHid_Pnp().

◆ KbdHid_StartDeviceCompletion()

NTSTATUS NTAPI KbdHid_StartDeviceCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 766 of file kbdhid.c.

770 {
773 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117

Referenced by KbdHid_Pnp().

◆ KbdHid_SubmitRequest()

NTSTATUS KbdHid_SubmitRequest ( PDEVICE_OBJECT  DeviceObject,
ULONG  IoControlCode,
ULONG  InputBufferSize,
PVOID  InputBuffer,
ULONG  OutputBufferSize,
PVOID  OutputBuffer 
)

Definition at line 586 of file kbdhid.c.

593 {
594  KEVENT Event;
595  PKBDHID_DEVICE_EXTENSION DeviceExtension;
596  PIRP Irp;
599 
600  /* get device extension */
601  DeviceExtension = DeviceObject->DeviceExtension;
602 
603  /* init event */
605 
606  /* build request */
608  DeviceExtension->NextDeviceObject,
609  InputBuffer,
610  InputBufferSize,
611  OutputBuffer,
612  OutputBufferSize,
613  FALSE,
614  &Event,
615  &IoStatus);
616  if (!Irp)
617  {
618  /* no memory */
620  }
621 
622  /* send request */
623  Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
624  if (Status == STATUS_PENDING)
625  {
626  /* wait for request to complete */
628  Status = IoStatus.Status;
629  }
630 
631  /* done */
632  return Status;
633 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881

Referenced by KbdHid_StartDevice().

◆ KbdHid_SystemControl()

NTSTATUS NTAPI KbdHid_SystemControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 574 of file kbdhid.c.

577 {
578  PKBDHID_DEVICE_EXTENSION DeviceExtension;
579 
580  DeviceExtension = DeviceObject->DeviceExtension;
582  return IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
583 }
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT NextDeviceObject
Definition: kbdhid.h:21
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by DriverEntry().

◆ KbdHid_Unload()

VOID NTAPI KbdHid_Unload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 1027 of file kbdhid.c.

1029 {
1030  UNIMPLEMENTED;
1031 }
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by DriverEntry().