Hello all,
I’m a complete newbie with windows driver development and I’ve been attempting to make a simple driver to attach onto the keyboard stack (final goal is to make the lights flash) but I seem to have gotten stuck. My driver attaches to the stack which I can see in devicetree and my status is always 0. After creating the device and obtaining the target device the pointers are non null so I’m assuming that those are correct.
The problem I encounter is that when I press a button it works the first time, and then the keyboard stops working.I would have assumed that since I’ve set all of my major functions to pass that it should have been called when the button was pressed but its not printing anything like it should be if it were being called.
Since this is an assignment I’m hoping people here could give me some tips rather than stating what the problem is? Heres the code with a few pieces removed (sorry for all the debugging).
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“Hello from driver1!\n”);
UNICODE_STRING filteredDeviceName;
RtlInitUnicodeString(&filteredDeviceName, L"\Device\KeyboardClass0");
PDEVICE_OBJECT target_device = NULL;
PDEVICE_OBJECT my_device = NULL;
DbgPrint(“%d\n”, status);
DbgPrint(“running 1\n”);
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &my_device);
DbgPrint(“%d\n”, status);
P_DEVICE_EXTENSION ext = (P_DEVICE_EXTENSION) (my_device -> DeviceExtension);
status = IoAttachDevice(my_device, &filteredDeviceName, &(ext -> TargetDeviceObject));
DbgPrint(“%d\n”, status);
unsigned i;
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
DbgPrint(“adding handler for %d\n”, i);
DriverObject->MajorFunction[i] = pass;
DriverObject->DriverUnload = unload;
DriverObject->DriverStartIo = NULL;
DriverObject->DriverExtension->AddDevice = addDevice;
DriverObject->DeviceObject = my_device;
ext -> DeviceObject = my_device;
DbgPrint(“%p\n”, my_device);
DbgPrint(“%p\n”, ext -> TargetDeviceObject);
DbgPrint(“%d\n”, status);
DbgPrint(“%d\n”, STATUS_SUCCESS);
return status;
}
void unload(IN PDRIVER_OBJECT DriverObject)
{
IoDeleteDevice(DriverObject->DeviceObject);
DbgPrint(“Goodbye from driver1!\n”);
}
NTSTATUS pass(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
DbgPrint(“passing\n”);
P_DEVICE_EXTENSION deviceExtension = NULL;
IoSkipCurrentIrpStackLocation(Irp);
deviceExtension = (P_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
return IoCallDriver(deviceExtension->TargetDeviceObject, Irp);
}
Thanks in advance.