NTSTATUS KMUnHandleIrp(DEVICE_OBJECT *DeviceObject, IRP *Irp)
{
KdPrint(("Irp: %d\n", IoGetCurrentIrpStackLocation(Irp)->MajorFunction));
IoSkipCurrentIrpStackLocation(Irp);
return IoCallDriver(((PMY_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedTo, Irp);
}
NTSTATUS KMOpenClose(DEVICE_OBJECT *DeviceObject, IRP *Irp)
{
KdPrint(("KMOpenClose.\n"));
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS KMPnp(DEVICE_OBJECT *DeviceObject, IRP *Irp)
{
PIO_STACK_LOCATION pIo = IoGetCurrentIrpStackLocation(Irp);
KdPrint(("KMPnp.\n"));
switch (pIo->MinorFunction) {
default:
IoSkipCurrentIrpStackLocation(Irp);
IoCallDriver(((PMY_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedTo, Irp);
break;
}
return STATUS_SUCCESS;
}
NTSTATUS KMPower(DEVICE_OBJECT *DeviceObject, IRP *Irp)
{
KdPrint(("KMPower.\n"));
IoSkipCurrentIrpStackLocation(Irp);
PoStartNextPowerIrp(Irp);
return PoCallDriver(((PMY_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedTo, Irp);
}
NTSTATUS KMAddDevice(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING puServiceRegPath)
{
UNICODE_STRING usObjectName;
PDRIVER_OBJECT KbdDriver;
NTSTATUS status;
PDEVICE_OBJECT tmpDevice, myDevice;
UNICODE_STRING usDeviceName;
WCHAR buff[64];
int index = 0;
PMY_DEVICE_EXTENSION DeviceExtension;
RtlInitUnicodeString(&usObjectName, L"\\Driver\\KbdClass");
status = ObReferenceObjectByName(&usObjectName,
OBJ_CASE_INSENSITIVE,
NULL,
0,
IoDriverObjectType,
KernelMode,
NULL,
(PVOID)&KbdDriver);
if (!NT_SUCCESS(status)) {
KdPrint(("Find the kbd class failed!\n"));
return status;
}
tmpDevice = KbdDriver->DeviceObject;
while (tmpDevice) {
swprintf(buff, L"\\Device\\MyDevice%d", index++);
RtlInitUnicodeString(&usDeviceName, buff);
status = IoCreateDevice(pDriverObject,
sizeof(MY_DEVICE_EXTENSION),
&usDeviceName,
tmpDevice->DeviceType,
tmpDevice->Characteristics,
FALSE,
&myDevice);
if (!NT_SUCCESS(status)) {
ObDereferenceObject(KbdDriver);
return status;
}
KdPrint(("devobj: 0x%p.\n",myDevice));