Hi all
I don’t know that you ever forced to use an another HID device in your own device(your device need to work with another device in HID structure),but i forced to do so.
At first I show you a small part of driver code for this situation:
WCHAR pPattern[23] = {0,};
UNICODE_STRING uniShortLink;
if (!NT_SUCCESS(RtlStringCbPrintfW(pPattern, sizeof(pPattern), L"hid#vid_%4x&pid_%4x#", HID_VENDORID, HID_PRODUCTID)))
{
status = STATUS_INTERNAL_ERROR;
CompleteIrp(pIrp, status, 0);
return status;
}
status = IoGetDeviceInterfaces(&pDeviceExt-\>HidGuid, NULL, 0, &pInterfaceList);
if (!NT_SUCCESS(status))
{
CompleteIrp(pIrp, status, 0);
return status;
}
pInterface = pInterfaceList;
while (pInterface[0])
{
if (!wcsstr(_wcslwr(pInterface), pPattern))
break;
pInterface += (wcslen(pInterface) + 1);
}
if (!pInterface[0])
{
status = STATUS_DEVICE_NOT_CONNECTED;
CompleteIrp(pIrp, status, 0);
return status;
}
RtlInitUnicodeString(&uniShortLink, pInterface);
status = IoGetDeviceObjectPointer(&uniShortLink, FILE_READ_DATA | FILE_WRITE_DATA,
&pDeviceExt-\>pDeviceFileObj, &pDeviceExt-\>pDeviceObj);
ExFreePool(pInterfaceList);
if (!NT_SUCCESS(status))
{
CompleteIrp(pIrp, status, 0);
return status;
}
-------
IoBuildDeviceIoControlRequest(for flushing device synchronously)
IoBuildSynchronousFsdRequest(write to device synchronously)
IoBuildSynchronousFsdRequest(read from device synchronously)
-------
if (pDeviceExt-\>pDeviceFileObj)
{
ObDereferenceObject(pDeviceExt-\>pDeviceFileObj);
pDeviceExt-\>pDeviceFileObj = NULL;
}
pDeviceExt-\>pDeviceObj = NULL;
As you see,the first part of code,finds proper HID device and gets its DEVICE_OBJECT and FILE_OBJECT by IoGetDeviceObjectPointer.
After that I use IoBuildDeviceIoControlRequest to create a request for flushing HID device buffers and two IoBuildSynchronousFsdRequest calls in order to create write and read requests to/from HID device.
Finnaly i use ObDereferenceObject for releasing objects acquired.
Now this is my problem:
Assume an application that using this code.If that application creates a service of my driver and runs codes that I have shown you,and then stops driver close service handle,there is no problem. I can run program several times without any problem.
But if after running program, I restart computer, After boot up HID device will be corrupted!!!It means in codes that I had shown you, all operations for opening device,sending device IO control and write to HID is OK,But operation hangs on reading from HID device(or in order hand, synchronous read event never signals and if you use port sniffers,read request never reachs usb device but all other has been reached).It seems read request has been disappeared after eraching system HID device… if you check system’s ‘Device Manger’ in a computer(not VMWare) you will see a warning sign on your HID device that means device is not working properly.
What do you think about this problem?What has been caused it?
Regards