Doron Holan said :
Is the slot driver synchronously waiting for the irp to complete? If so, you can process it asynchronously by setting a completion routine and processing the results in the completion routine instead of waiting for it to complete.
You can look how process my function, the problem if I catch the IRP in my Bus driver and I don’t complete the IRP my slot are blocked until the IRP was completed “IoCompleteRequest”
NTSTATUS
ccid_SendDeviceInterrupt2(PDEVICE_OBJECT deviceObject)
{
NTSTATUS status;
IO_STATUS_BLOCK ioStatus;
KEVENT event;
PIRP irp;
PIO_STACK_LOCATION irpNextStack;
PDEVICE_EXTENSION deviceExtension = (PDEVICE_EXTENSION)deviceObject->DeviceExtension;
PSMARTCARD_EXTENSION SmartcardExtension = &deviceExtension->SmartcardExtension;
ULONG sizeSlotNumber=(ULONG)SmartcardExtension->ReaderExtension->bSlot;
do {
KeInitializeEvent(
&event,
NotificationEvent,
FALSE
);
SmartcardExtension->ReaderExtension->SlotIoControlCode = IOCTL_SEND_DEVICE_INT;
// Build irp to be sent to serial driver
irp = IoBuildDeviceIoControlRequest(
IOCTL_SEND_DEVICE_INT,
SmartcardExtension->ReaderExtension->SlotConnected,
BufferLocalInterrupt,
LengthLocal,
BufferLocalInterrupt,
LengthLocal,
FALSE,
&event,
&ioStatus
);
if (irp == NULL) {
return STATUS_INSUFFICIENT_RESOURCES;
}
irpNextStack = IoGetNextIrpStackLocation(irp);
status = IoCallDriver(
SmartcardExtension->ReaderExtension->SlotConnected,
irp
);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL
);
status = ioStatus.Status;
SmartcardExtension->ReaderExtension->ReplyBufferLength = 0;
}
if (SmartcardExtension->ReaderExtension->SlotIoControlCode ==
SMARTCARD_WRITE)
{
status = STATUS_MORE_PROCESSING_REQUIRED;
}
} while (status == STATUS_MORE_PROCESSING_REQUIRED);
return status;
}
And if I understand you, I must just add a completionRoutine before keWaitforSingleObject ?
like that :
NTSTATUS
ccid_SendDeviceInterrupt2(PDEVICE_OBJECT deviceObject)
{
NTSTATUS status;
IO_STATUS_BLOCK ioStatus;
KEVENT event;
PIRP irp;
do {
// Build irp to be sent to serial driver
irp = IoBuildDeviceIoControlRequest()
IoSetCompletionRoutine(irp, (PIO_COMPLETION_ROUTINE) ccid_OnInterrupt, deviceExtension, TRUE, TRUE, TRUE);
irpNextStack = IoGetNextIrpStackLocation(irp);
status = IoCallDriver(
SmartcardExtension->ReaderExtension->SlotConnected,
irp
);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL
);
status = ioStatus.Status;
SmartcardExtension->ReaderExtension->ReplyBufferLength = 0;
}
} while (status == STATUS_MORE_PROCESSING_REQUIRED);
return status;
}
If it’s ok how proceed for continue to use my slot normaly and send other IRP even if this IRP is not completed.
Thank you
Best regards,
Kamel