Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


WdfUsbTargetDeviceCreateWithParameters fails in usb bus filter

Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226
Hello !
I am writing usb bus filter.
I am upper filter for

USB Bus Devices (hubs and host controllers)
Class = USB
ClassGuid = {36fc9e60-c465-11cf-8056-444553540000}

I call WdfUsbTargetDeviceCreateWithParameters from prepare hardware callback like this:

WDF_USB_DEVICE_CREATE_CONFIG usbCreateConfig;
WDF_USB_DEVICE_CREATE_CONFIG_INIT(&usbCreateConfig, USBD_CLIENT_CONTRACT_VERSION_602);

WDFUSBDEVICE usbDevice;
NTSTATUS stat = WdfUsbTargetDeviceCreateWithParameters(device, &usbCreateConfig, WDF_NO_OBJECT_ATTRIBUTES, &usbDevice);

Testing on virtualbox win10x64 with one usb hdd attached.
Here are some the results for different devices enumerated during windows load

Device 1:
device class name is USB
device description is USB xHCI Compliant Host Controller
device manufacturer is Generic USB xHCI Host Controller
device friendly name is Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
device bus GUID name is GUID_BUS_TYPE_PCI
device bus is PCIBus
device location is PCI bus 0, device 12, function 0

Wdflogdump excerpt:
FxUsbDevice::InitDevice - Could not retrieve device descriptor, 0xc0000010(STATUS_INVALID_DEVICE_REQUEST)

Device 2:
device description is USB Root Hub (USB 3.0)
device class name is USB
device manufacturer is (Standard USB HUBs)
device bus GUID name is GUID_BUS_TYPE_USB
device bus is PNPBus

Wdflogdump excerpt:
FxUsbDevice::InitDevice - Could not retrieve device descriptor, 0xc0000001(STATUS_UNSUCCESSFUL)


Device 3:
device description is USB Mass Storage Device
device class name is USB
device manufacturer is Compatible USB storage device
device location is Port_#0009.Hub_#0001
device bus GUID name is GUID_BUS_TYPE_USB
device bus is PNPBus

Wdflogdump excerpt:
FxUsbDevice::InitDevice - Could not retrieve device descriptor, 0xc00000bb(STATUS_NOT_SUPPORTED)


I also tried to call this routine from adddevice and d0entry callbacks with the same result.

Am I doing something wrong ? Maybe I can’t call this routine for filter device object ?

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,490

    What are you trying to implement in this filter? You select configs are failing because an upper filter cannot send select configs through the FDO. Most FDOs are expecting to send the select config themselves, do not expect a select config IRP to be sent to the FDO so they fail the incoming select config IRPs.

    d
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226

    Thank you very much Doran !!
    I had such suspicion.
    I don’t know much about usb right now. This is why I writing this filter, to learn things.

    I try to query information about usb device, such as vid, pid, device class, serial number.
    For one device( usb hdd) I can get this information if I send request directly to PDO, bypassing fdo.

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,490

    if you are trying to learn, a class filter is not the right choice IMHO. Write a device lower filter for one specific device. Your usb mass storage device is a great example. Your device lower filter can see all of the USB URB traffice flowing from the FDO down the stack. From there you can query the config (i would not recommend setting the config as you are changing the state of the device behind the FDO's back). as well

    d
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226

    Thank you again Doran !

    I don’t want to dive deep in usb internals. My goal is to identify devices so that my filter can decide if device will be available to user or not.
    It would be great to construct some globally unique identifier for device, so that policy could be enforced for all machines in organization.

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226

    Also could you please confirm that I can change device state just by sending query urbs to device and device can misbehave as a result ?

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,490

    querying state/config will not change the state. Can you expand on what you mean by "available to the user"? are you interested only in mass storage? any usb device?

    A USB device will have have a globally unique identifier (it's serial number) or not. In the absence of a serial number, there is no way to identify the device outside of the port it is plugged into. IOW, if it is plugged into a different port on the same machine, or a different machine entirely, it will be appear as an entirely new device.

    d
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226

    @Doron_Holan said:
    querying state/config will not change the state.

    Thank you !

    Can you expand on what you mean by "available to the user"?

    I mean that I fail adddevice or start device if device is not whitelisted, not that device will be available for one user and not present for another

    are you interested only in mass storage? any usb device?

    Any usb device, so that employee was unable to use his personal usb storage/webcam/ anything usb on employer’s machine

    A USB device will have have a globally unique identifier (it's serial number) or not. In the absence of a serial number, there is no way to identify the device outside of the port it is plugged into. IOW, if it is plugged into a different port on the same machine, or a different machine entirely, it will be appear as an entirely new device.

    Thank you, I thought so :(

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,403

    My goal is to identify devices so that my filter can decide if device will be available to user or not.

    And what do you think YOU can do that the Windows Group Policy system and the roughly 300 existing products on the market that offer this exact same service cannot do?

    I don’t want to dive deep in usb internals.

    That's a trigger phrase. How can you possibly hope to understand what effect your interference will have without understanding how USB works?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 226
    > @Tim_Roberts said:
    > (Quote)
    > And what do you think YOU can do that the Windows Group Policy system and the roughly 300 existing products on the market that offer this exact same service cannot do?

    I think that this is my task assigned to me by my higher ups

    > (Quote)
    > That's a trigger phrase. How can you possibly hope to understand what effect your interference will have without understanding how USB works?

    For me it is enough to be able to query usb device characteristics. For example device class from device descriptor. If I fail device start device won’t appear on the system. I think that this is true for device of any class and not usb specific.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA