Hi,
I need to query Vendor Id of a usb storage device from a upper class
filter driver. I used IOCTL_STORAGE_QUERY_PROPERTY for the same. But
it is not working. I am getting zero as VendorIdOffset. Please help me
to solve this problem.
ulInputSize = sizeof(STORAGE_PROPERTY_QUERY);
ulTotOutputSize = sizeof(STORAGE_DEVICE_DESCRIPTOR);
pProperty = (STORAGE_PROPERTY_QUERY*)ExAllocatePool(NonPagedPo ol,ulInputSize);
pOutBuff = ExAllocatePool(NonPagedPool,ulTotOutputSize);
RtlZeroMemory(pProperty,ulInputSize);
RtlZeroMemory(pOutBuff,ulTotOutputSize);
pProperty->PropertyId = StorageDeviceProperty ;
pProperty->QueryType = PropertyStandardQuery ;
NtStatus = SendIoctl(deviceExtension->NextLowerDriver,
IOCTL_STORAGE_QUERY_PROPERTY,
(void*)pProperty,ulInputSize,pOutBuff,
ulTotOutputSize);
if(!NT_SUCCESS(NtStatus))
{
DbgPrint(" SendIoctl failed. Error code = %x\n", NtStatus);
} else {
DbgPrint(" SendIoctl success. Error code = %x\n", NtStatus);
pDevDes = (STORAGE_DEVICE_DESCRIPTOR*)pOutBuff;
DbgPrint("pDevDes->Version = %x\n",pDevDes->Version);
DbgPrint("pDevDes->Size = %x\n",pDevDes->Size);
DbgPrint("pDevDes->DeviceType = %x\n",pDevDes->DeviceType );
DbgPrint("pDevDes->CommandQueueing =
%x\n",pDevDes->CommandQueueing );
DbgPrint("pDevDes->VendorIdOffset = %x\n",pDevDes->VendorIdOffset
);
DbgPrint("pDevDes->ProductIdOffset =
%x\n",pDevDes->ProductIdOffset );
}
ExFreePool(pProperty);
ExFreePool(pOutBuff);
}
NTSTATUS
SendIoctl(IN DEVICE_OBJECT *pDevObj,
IN ULONG IoControlCode,
IN PVOID InputBuffer,
IN ULONG InputBufferLength,
OUT PVOID OutputBuffer,
IN ULONG OutputBufferLength)
{
NTSTATUS NtStatus = STATUS_SUCCESS;
KEVENT hkQueryEvent;
IO_STATUS_BLOCK IoStatus;
PIRP pIrp = NULL;
do
{
KeInitializeEvent(&hkQueryEvent,SynchronizationEve nt,FALSE);
pIrp = IoBuildDeviceIoControlRequest(IoControlCode,pDevOb j,InputBuffer,
InputBufferLength,OutputBuffer,
OutputBufferLength,FALSE,&hkQueryEvent,&IoStatus);
if(!pIrp)
{
DbgPrint("SendIoctl:IoBuildDeviceIoControlRequest failed");
NtStatus = STATUS_INSUFFICIENT_RESOURCES;
break;
}
else
{
DbgPrint("SendIoctl:IoBuildDeviceIoControlRequest success");
NtStatus = IoCallDriver(pDevObj,pIrp);
if(STATUS_PENDING ==NtStatus)
{
NtStatus = KeWaitForSingleObject(&hkQueryEvent,
Executive,
KernelMode,
FALSE,NULL);
if(STATUS_SUCCESS == NtStatus)
NtStatus = IoStatus.Status;
else
NtStatus = STATUS_UNSUCCESSFUL;
}
break;
}
}while(0);
return NtStatus;
}