Pass the interrupt urb as the context to the completion routine. In the completion routine, the current stack location is the location of the PIRP as when it arrived to your driver or an invalid stack location if you allocated the irp on your own. You set the URB in the next stack location. If you are using the context for your device context, either store the URB in the context (As long as there is only one) or allocate a piece of memory that holds the extension and the urb and use that for the context.
d
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of SUJA JAMES
Sent: Tuesday, February 24, 2004 11:42 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] USB Interrupt
Hi All,
I modified the Bluetooth command sending interface as suggested by this list. Now I have to check the reply of that command. For that I am using the interrupt pipe. I used the same sample code provided by Oney’s book. (The same CreateInterruptUrb() and StartInterruptUrb().
Now my real problem comes. The OnInterrupt() competion routine is calling with status SUCCESS. But the return URB is null. So how I can watch the value returned by the interrupt pipe. I am pasting my code here. In OnInterrupt(), the URB is null.
Pleae help…
Regards
Suja.
void SendBluetoothCommand(? IN PDEVICE_OBJECT DeviceObject,
? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?IN PIRP Irp)
{
? ? ?? PDEVICE_EXTENSION deviceExtension;
? ? ?? PIO_STACK_LOCATION irpStack;
? ? ?? NTSTATUS? ntStatus;
? ? ? ULONG uSize;
? ? ? PURB? urb = NULL;
? ? ? ?? PUCHAR localBuffer;
? ? ?? ULONG BuffLength =8;
? ? ?? UCHAR Index;
? ? ?
? ? ? deviceExtension = DeviceObject->DeviceExtension;
? ? ?? BULKUSB_KdPrint ( DBGLVL_DEFAULT, (“enter SendBluetoothCommand()\n”));
? ? ? irpStack = IoGetCurrentIrpStackLocation (Irp);
? ? ? uSize = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST? );
? ? ?? urb = BULKUSB_ExAllocatePool(NonPagedPool, uSize);
? ? ? // get pointers and lengths of the caller’s (user’s) IO buffer
? ? ?? localBuffer = Irp->AssociatedIrp.SystemBuffer;
? ? ?? BuffLength? = irpStack->Parameters.DeviceIoControl.InputBufferLength;
? ? ?? Irp->IoStatus.Information = 0;
? ? ?
? ? ? if (urb)
? ? ?? {
? ? ?? ? ?RtlZeroMemory(urb, uSize);/*/Fill Memory with null*/
? ? ?? ? ?UsbBuildVendorRequest(urb,
? ? ? ? ? ? ? ? ? ? ? ? URB_FUNCTION_CLASS_DEVICE,
? ? ? ? ? ? ? ? ? ? ? ? sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? 0,
? ? ? ? ? ? ? ? ? ? ? ? localBuffer,
? ? ? ? ? ? ? ? ? ? ? ? NULL,
? ? ? ? ? ? ? ? ? ? ? ? BuffLength,
? ? ? ? ? ? ? ? ? ? ? ? NULL);
? ? ?? ? ?BulkUsb_CallUSBD ( DeviceObject,urb);
? ? ?? ? ?StartInterruptUrb(deviceExtension); //Start the interrupt polling
? ? ?? ? ?BULKUSB_ExFreePool(urb);
? ? ?? }//End of if
? ? ?? else
? ? ? ? {
? ? ? ? ? return STATUS_INSUFFICIENT_RESOURCES;
? ? ? ? }
? ? ?BULKUSB_KdPrint ( DBGLVL_DEFAULT, (" Exit SendBluetoothCommand()\n"));
? ? return ntStatus;
}
NTSTATUS OnInterrupt(PDEVICE_OBJECT junk, PIRP Irp, PDEVICE_EXTENSION pdx)
{? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?? ? ?// OnInterrupt
? ? ?PIO_STACK_LOCATION stack;
? ? ?PURB pUrb;
? ? ?struct _URB_BULK_OR_INTERRUPT_TRANSFER *pBulkOrInterruptTransfer;
? ? ?stack = IoGetCurrentIrpStackLocation(Irp);
? ? ?if (NT_SUCCESS(Irp->IoStatus.Status))
? ? ?{? ? ?? ? ?? ? ?? ? ?? ? ?
? ? ?? ? ?BULKUSB_KdPrint ( DBGLVL_DEFAULT, (“Interrupt\n”));
? ? ?? ? ?pUrb = (PURB)stack->Parameters.Others.Argument1;
? ? ?? ? ?if (pUrb)
? ? ?? ? ?{
? ? ?? ? ?? ? ?DUMPURB( pUrb);
? ? ?? ? ?}
? ? ?? ? ?else
? ? ?? ? ?{
? ? ?? ? ?? ? ?BULKUSB_KdPrint ( DBGLVL_DEFAULT, (“Interrupt URB is null\n”)); ? ? ?
? ? ?? ? ?}
? ? ?}
? ? ?else
? ? ?{
? ? ?? ? ?BULKUSB_KdPrint ( DBGLVL_DEFAULT, (“Interrupt polling IRP failed\n”));
? ? ?? ? ?KdPrint((DBGSTR_PREFIX " - Interrupt polling IRP %X failed - %X (USBD status %X)\n",
? ? ?? ? ?? ? ?Irp, Irp->IoStatus.Status, URB_STATUS(pdx->PollingUrb)));
? ? ?? ? ?
? ? ?}
? ? ?return STATUS_MORE_PROCESSING_REQUIRED;
}
— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com