Question about reader USB multislot

Hello everybody,
It’s my first post and i hope you help me for my problems.

I try to develop driver PCSC for a smartcardreader multislot USB.

i would like to know the best solution for using the reader.
For the moment i have 2 .sys.
_ the first is for USB driver (the parent)
_ the second is for slots (child)

My problem is the communication Bus to SLOT.

with the function “IoGetDeviceObjectPointer” in the slot driver i arrive to point to the bus driver.
But the bus driver work with the endpoint interrupt, so it’s the bus that start the communication to slot.

for the moment I found a solution, Slots send an IRP to the bus for poll the endpointInterruptIN, and if there are a cardInserted I update a buffer with the response of the interrupt and I copy this response in the IRP before the completion.

The problem is this polling.

I would like to know if it’s possible to communicate directly when I have an InterruptIN to the concerned Slots.

And the last question.
when I create my Bus driver I use this function “IoRegisterDeviceInterface” for create a symbolicLink.
How to proceed for catch this name when I create my SLots ???
It’s possible to use the registry for write this name with the bus and read this value by the slots ?

Thank you,

Best regards,

ps : sorry for my level in english.

You should pend the IRPs from the slot drivers in your bus driver, and only complete them when there is a change from the interrupt endpoint. If there was a slot notification while there wasn’t an IRP pending, you will probably want to save this data until the IRP arrives.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, June 24, 2008 2:41 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Question about reader USB multislot

Hello everybody,
It’s my first post and i hope you help me for my problems.

I try to develop driver PCSC for a smartcardreader multislot USB.

i would like to know the best solution for using the reader.
For the moment i have 2 .sys.
_ the first is for USB driver (the parent)
_ the second is for slots (child)

My problem is the communication Bus to SLOT.

with the function “IoGetDeviceObjectPointer” in the slot driver i arrive to point to the bus driver.
But the bus driver work with the endpoint interrupt, so it’s the bus that start the communication to slot.

for the moment I found a solution, Slots send an IRP to the bus for poll the endpointInterruptIN, and if there are a cardInserted I update a buffer with the response of the interrupt and I copy this response in the IRP before the completion.

The problem is this polling.

I would like to know if it’s possible to communicate directly when I have an InterruptIN to the concerned Slots.

And the last question.
when I create my Bus driver I use this function “IoRegisterDeviceInterface” for create a symbolicLink.
How to proceed for catch this name when I create my SLots ???
It’s possible to use the registry for write this name with the bus and read this value by the slots ?

Thank you,

Best regards,

ps : sorry for my level in english.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thank you Randy for your response.
I already try to pend my IRP.
But the problem is the Slot is blocked and it’s impossible to communicate with the slot during this pending.
For exemple if I launch a PCSC Tools (Smartdiag) this tools doesn’t work until the IRP has been completed.
I have try to create a thread but I have the same result.

Could you explain me a method for use a thread not blocked that send an IRP .
And even if the IRP is not completed the slot continue to work.

Thank you for your futur response.

Best regards,
Kamel

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.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, June 24, 2008 9:05 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Question about reader USB multislot

Thank you Randy for your response.
I already try to pend my IRP.
But the problem is the Slot is blocked and it’s impossible to communicate with the slot during this pending.
For exemple if I launch a PCSC Tools (Smartdiag) this tools doesn’t work until the IRP has been completed.
I have try to create a thread but I have the same result.

Could you explain me a method for use a thread not blocked that send an IRP .
And even if the IRP is not completed the slot continue to work.

Thank you for your futur response.

Best regards,
Kamel


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

thank you Doron,
I don’t understand what you asked me, sorry.
Instead of wait the “IoCompleteRequest (Irp, IO_NO_INCREMENT);” for the completion.
I can continue to use my slot without complete the IRP request ?
But how to proceed for complete asynchronously the request and complete it just when there is an interruptIN.

My problem is I always my thread for send this IRP.
The best solution for me is to execute this thread only when I have an Interrupt.
But I don’t know how to proceed for catch the result directly in the completion and not wait the “IoCompleteRequest”

Please could you help me for know if it’s possible or not

Thanks,

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