SOS: usb device, driver ok, but can't be opened by user program!

SOS: usb device, driver ok, but can't be opened by user program!

Post by QW1hbmRhIE » Fri, 26 May 2006 18:26:01


My problem is that: a user program can on longer access the device after a
surprise removal and re-plug-in


I'm writing a usb device driver of vendor type for windows 2000 and debug it
with windbg.
The problem is:
When I first plug-in the usb device after PC power up, everything is OK and
a test user program can access the device via "CeateFile()"

But after the program close the device handle, I did a surprise remove to
the device.
The driver handles IRP_MN_SURPRISE_REMOVE and then IRP_MN_REMOVE_DEVICE
successfully (interface disabled ,device object deleted).
Then when I plug-in the device again, the OS finds the device and call my
AddDevice routine and sends IRP to start the device.
Driver creates the device object, start and configure the device again. The
descriptors got seem OK , symbolic link is created, interfaces are register
and enabled.

However, I find the user program can no longer open the device!
Although it can get interface data and set proper device path, CreateFile()
returns INVALID_HANDLE_VALUE.
The error code from getLasterror() is 2, means "ERROR_FILE_NOT_FOUND".
And from windbg, I found the driver routine to handle "IRP_MJ_CREATE" is not
called.

The information in the registry seems OK. All driver routine succeeds during
the process.

I'm confused. Who can give me some idea? Thanks a lot!
Does the symbolic link not work?
 
 
 

SOS: usb device, driver ok, but can't be opened by user program!

Post by QW1hbmRhIE » Thu, 01 Jun 2006 12:24:02

Thank all of you for your kindly help.
The bug is resolved.

I made a mistake about UNICODE_STRING and its buffer of characters.
So the device symbolic name that I back in the device extenstion is wrong.

When I disable the device interface when device is removed, I give the bad
symbolic link name I backed. IoSetDeviceInterfaceState(*, FALSE) returns
STATUS_SUCCESS at that time. But an internal mistake seems to have happened.

So when I enable the device interface next time with a correct symlink name
(in ADD_DEVICE). Althougth OS still shows success, the interface can not work
in fact.

That results in the "ERROR_FILE_NOT_FOUND" when a application try to access
the device via CreateFile().Although
SetupDiGetClassDevs()
SetupDiEnumDeviceInterfaces()
SetupDiGetDeviceInterfaceDetail() all suceed.


Now I use the correct symlic name to disable the device interface and
everything is OK.

Best Regards

Amanda Lin