Returned to my lower KMDF Filter saga after break. I’m trying to get the descriptor of the USB device.
The code below (I removed some DgPrint) runs but fails to return the descriptor of the device that was just added. This method is thus called from the XXXDeviceAdd().
No status is ever wrong. But the descriptor returned is not valid.
Also when I look at “IoGetCurrentIrpStackLocation(WdfRequestWdmGetIrp(request))->Parameters.Others.Argument1” which, I believe, should be my URB, it is NULL !
Surely, I must be doing something very wrong. I don’t seem to be able to see it.
Any help greatly appreciated (feeling despondent and like writing a WDM driver ;-))
NTSTATUS get_descriptor(IN WDFDEVICE device, LONGLONG timeout)
{
NTSTATUS status;
PURB pUrb;
WDFMEMORY urbMemory;
USB_DEVICE_DESCRIPTOR deviceDescriptor;
WDF_REQUEST_SEND_OPTIONS syncReqOptions;
WDFREQUEST request;
PURB pUrb2; // for debugging
PIRP pirp; // ditto
status = WdfMemoryCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NonPagedPool,
0,
sizeof(URB),
&urbMemory,
NULL
);
if (!NT_SUCCESS(status)) {
return status;
}
pUrb = WdfMemoryGetBuffer(
urbMemory,
NULL
);
UsbBuildGetDescriptorRequest(
pUrb,
sizeof(URB),
USB_DEVICE_DESCRIPTOR_TYPE,
0, // this parameter not used for device descriptors
0, // this parameter not used for device descriptors
&deviceDescriptor,
NULL,
sizeof(USB_DEVICE_DESCRIPTOR),
NULL);
status = WdfRequestCreate(
WDF_NO_OBJECT_ATTRIBUTES, WdfDeviceGetIoTarget(device), &request);
if (!NT_SUCCESS(status)) {
return status;
}
WDF_REQUEST_SEND_OPTIONS_INIT(
&syncReqOptions,
0
);
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(
&syncReqOptions,
WDF_REL_TIMEOUT_IN_SEC(timeout)
);
status = WdfIoTargetFormatRequestForInternalIoctlOthers(
WdfDeviceGetIoTarget(device),
request,
IOCTL_INTERNAL_USB_SUBMIT_URB,
urbMemory,
0,
NULL,
0,
NULL,
0
);
if (!NT_SUCCESS(status)) {
return status;
}
pirp = WdfRequestWdmGetIrp(request);
if (pirp == NULL)
{
MyPrint(" IRP NULL \n");
}
else
{
MyDogPrint(" IRP %x \n",pirp);
MyDogPrint( " IRP STACK %x \n",IoGetCurrentIrpStackLocation(pirp));
if (IoGetCurrentIrpStackLocation(pirp) == NULL)
{
MyDogPrint( " IRP STACK NULL \n");
}
else
{
pUrb2 = (PURB) IoGetCurrentIrpStackLocation(WdfRequestWdmGetIrp(request))->Parameters.Others.Argument1;
MyDogPrint( " purB2 %x \n", pUrb2);
}
}
syncReqOptions.Flags |= WDF_REQUEST_SEND_OPTION_SYNCHRONOUS;
if (WdfRequestSend(
request,
WdfDeviceGetIoTarget(device),
&syncReqOptions
) == FALSE) {
status = WdfRequestGetStatus(request);
}
else {
status = STATUS_SUCCESS;
}
// code removed
// descriptor "returned " (?) is wrong
return status;
}