Am I on the right track here? I’m now getting IRQL_NOT_LESS_OR_EQUAL: http://i.imgur.com/AHPOx.png
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
…
UINT i = 0;
CHAR packetBuffer[100];
ULONG IoctlControlCode = BIOCSENDPACKETSNOSYNC;
PDEVICE_OBJECT TopOfDeviceStack = NULL;
PVOID OutputBuffer = NULL;
ULONG OutputBufferLength = 0;
…
for(i=0;i<100;i++) {
packetBuffer[i]= (u_char)i;
}
…
TopOfDeviceStack = IoGetAttachedDeviceReference(DriverObject->DeviceObject);
/*
NTSTATUS
MakeSynchronousIoctl (
IN PDEVICE_OBJECT TopOfDeviceStack,
IN ULONG IoctlControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength
);
*/
MakeSynchronousIoctl (
TopOfDeviceStack,
IoctlControlCode,
&packetBuffer,
100,
OutputBuffer,
OutputBufferLength
);
ObDereferenceObject(TopOfDeviceStack);
…
}
NTSTATUS
MakeSynchronousIoctl (
IN PDEVICE_OBJECT TopOfDeviceStack,
IN ULONG IoctlControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength
)
/*++
Arguments:
TopOfDeviceStack - ??
IoctlControlCode - Value of the IOCTL request
InputBuffer - Buffer to be sent to the TopOfDeviceStack
InputBufferLength - Size of buffer to be sent to the TopOfDeviceStack
OutputBuffer - Buffer for received data from the TopOfDeviceStack
OutputBufferLength - Size of receive buffer from the TopOfDeviceStack
Return Value:
NT status code
–*/
{
KEVENT event;
PIRP irp;
IO_STATUS_BLOCK ioStatus;
NTSTATUS status;
//
// Creating Device control IRP and send it to the another
// driver without setting a completion routine.
//
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest (
IoctlControlCode,
TopOfDeviceStack,
InputBuffer,
InputBufferLength,
OutputBuffer,
OutputBufferLength,
FALSE, // External
&event,
&ioStatus);
if (NULL == irp) {
return STATUS_INSUFFICIENT_RESOURCES;
}
status = IoCallDriver(TopOfDeviceStack, irp);
if (status == STATUS_PENDING) {
//
// You must wait here for the IRP to be completed because:
// 1) The IoBuildDeviceIoControlRequest associates the IRP with the
// thread and if the thread exits for any reason, it would cause the IRP
// to be canceled.
// 2) The Event and IoStatus block memory is from the stack and we
// cannot go out of scope.
// This event will be signaled by the I/O manager when the
// IRP is completed.
//
status = KeWaitForSingleObject(
&event,
Executive, // wait reason
KernelMode, // To prevent stack from being paged out.
FALSE, // You are not alertable
NULL); // No time out !!!
status = ioStatus.Status;
}
return status;
}
Very much appreciated.