none
Statically loaded driver for a pnp device(USB) RRS feed

  • Question

  • Hi All,

    I am trying to develop a statically loaded driver on PnP Device(USB):

    • Driver should not be unloaded even after PnP device plugged out.
    • Driver should aware of ejection of device.
    • Driver should not create one more instance of the same device on re plugging the device. Instead driver has to re initialize all data structures.

    Is this possible with KMDF driver?

    Thanks & Regards,

    Vidyasagar


    vidyasagar196

    Sunday, October 30, 2016 5:22 AM

All replies

  • What problem are you trying to solve?   Your approach is not the way windows works, ejection implies the device has gone away, insertion can be the first time, or reinsertion.

    There are ways to store data for a device instance, but what are you really trying to do?


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Sunday, October 30, 2016 11:50 AM
  • Hi Don,

    I am trying to create a serial COM over USB device, COM port instance is created on first arrival of device and COM port should not disappear when USB Device is unplugged. 



    vidyasagar196

    Sunday, October 30, 2016 12:08 PM
  • So what happens to the output when the USB device is disabled?  You could create a virtual COM port, that talks to the USB device, and treats the removal like removing the cable on a real serial device.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Sunday, October 30, 2016 1:45 PM
  • USB Device is a Class7 Device, Inbox driver is loaded on the Deivce. How can I talk to USB Device from a virtual COM.

    vidyasagar196

    Sunday, October 30, 2016 1:50 PM
  • It is going to show up when a DeviceInterface is registered for the device, you are going to have register to receive notifications of that class of device interface, then determine it is the one you care about (this will be specific to your model, so can't help), and then talk to the device, again specific to your work.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Sunday, October 30, 2016 2:22 PM
  • if it isn't clear from don's response, there are two drivers. I described this to you in a previous thread

    1) the pnp usb driver. could be usbser or your own

    2) a root enumerated virtual driver that opens up the pnp usb driver when it arrives, registers for notifications for when it leaves

    the root driver will have to handle the coming and going of the pnp device in the middle of a session


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Sunday, October 30, 2016 4:16 PM
  • Thanks Don & Doron,

    Thanks for suggesting me, I am using my custom driver for USB communication.

    Let me try to forward IRP from Virtual COM driver to Custom USB Driver using IOTargets.


    vidyasagar196

    Sunday, October 30, 2016 4:28 PM
  • Let me try to forward IRP from Virtual COM driver to Custom USB Driver using IOTargets.

    Can you do a little mental experiment? predict the outcome of this without writing code?

    --pa

    Sunday, October 30, 2016 10:07 PM
  • Hi Pavel,

    Create and opening target:

    As we registered for device interface notifications, we get symbolic link of the device and create a target using symbolic link.

    Forwarding IRP:

    As Target is created and opened, We format request according to the request type and forward to the IOTarget.

    Request Handling in Target:

    Target driver handles the request for Write/Read by writing/reading to USB pipes.


    vidyasagar196

    Sunday, October 30, 2016 11:16 PM
  • Yes, it is certainly possible, whether it solves your problem or is a good idea isn't clear. I've done this a few times. In your INF file, add an entry in your devices section that puts your device on the root bus, e.g. name it something like: ROOT\mycompany_mydevice. Your driver will get loaded and your DeviceAdd routine will be called for both the root bus enumeration and when your hardware device is enumerated. In your DeviceAdd routine, you will need to call WdfFdoInitAllocAndQueryProperty for the DevicePropertyLocationInformation. This will give you the hardware ID that is being enumerated, so you can decide what to do.

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Monday, October 31, 2016 3:46 AM
    Moderator
  • Thanks Brian,

    Actual requirement is to create static COM ports on top of USB.

    Here static meant for COM Port once mapped should always talk to same usb device, even after multiple plug and ejection sequences.

    Also COM Port should forward IO (read/write) requests to mapped USB device.

    I hope its clear about my requirement.


    vidyasagar196

    Monday, October 31, 2016 7:45 AM

  • Forwarding IRP:

    As Target is created and opened, We format request according to the request type and forward to the IOTarget.

    Request Handling in Target:

    Target driver handles the request for Write/Read by writing/reading to USB pipes.


    Your device is a COM port (because of the application requirement) so forwarding will work only if the target device itself understands IRPs (ioctls) for COM port. Otherwise your driver needs to translate its requests to what the USB driver understands.

    - pa

    Monday, October 31, 2016 10:46 AM
  • Yeah Pavel, 

    I am formating the request for read/write in custom USB driver request handling callbacks using WdfUsbTargetPipeFormatRequestForWrite.


    vidyasagar196

    Monday, October 31, 2016 10:55 AM
  • How are you going to map your static COM port to a USB device? Unless the USB device has a serial number, giving it a unique name regardless of which USB port it is plugged into, you'll either need some sort of administrative utility to configure the mapping, or ensure that only one target device is attached to the system at any time

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Monday, October 31, 2016 6:53 PM
    Moderator
  • USB Device has a unique serial number, which can be retrieved by sending a command to device(writing to USB) and reading from USB.

    we have 4 devices connected to system and 4 virtual COM ports are mapped respectively.


    vidyasagar196

    Tuesday, November 1, 2016 3:25 AM
  • Hi,

    I have a one more problem here, Now I need to get Pnp Notification for USB Device(Class 7 Printer) which works with usbprint.sys.

    How can I get INTERFACE GUID for these kind of devices.?


    vidyasagar196

    Wednesday, November 2, 2016 5:26 PM
  • You stated the inbox driver is loaded, is this a printer driver, or what?   Worst case you register for the device class, then check with IoGetDevice Property to see if the bus is USB.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Wednesday, November 2, 2016 5:33 PM
  • Yes Don,

    Device is USB Class 7 Printer

    I have tried with these class guids, I did not see any thing from pnp notifications

    //{4658ee7e-f050-11d1-b6bd-00c04fa372a7}
    DEFINE_GUID(GUID_PRINT_CLASS,
    0x4658ee7e, 0xf050, 0x11d1, 0xb6, 0xbd, 0x0, 0xc0, 0x4f, 0xa3, 0x72, 0xa7);

    //{88BAE032-5A81-49f0-BC3D-A4FF138216D6}
    DEFINE_GUID(GUID_USBD_CLASS,
    0x88BAE032, 0x5A81, 0x49f0, 0xbc, 0x3d, 0xa4, 0xff, 0x13, 0x82, 0x16, 0xd6);


    vidyasagar196

    Wednesday, November 2, 2016 5:44 PM
  • the GUIDs associated with drivers are confusing. there are two categories

    1) class GUIDs. these are used in the INF and provide the icon and broad settings for all devices in the in class. an inf can only have one class guid. a device is installed in a class.

    2) device interface GUIDs. these are per device (and can be many for a single device) and represent the IO contract for the device.

    you want to use guids from #2, but the two guids you listed are from #1. you want to use guids that start with GUID_DEVINTERFACE_ , not GUID_Xxxx_CLASS.


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, November 2, 2016 6:51 PM
  • Thank you Doron,

    I am able to get notification on USB Device arrival and removal, now I have a question.

    I need to distinguish between different USB printers( multiple printers connected) in PnP Notification callback, How Can I do this ?


    The hardware we have is a class 7 printer, I can retrieve a printer unique serial # by sending vendor specific command

    How can I get make use of this specific command to retrieve printer serial# in PnP Notification callback?

    Thursday, November 3, 2016 1:26 AM
  • which specific devinterface are you registering for arrival notifications? the typical pattern is that you open a handle (remote io target in kmdf) and send IO to query the device to see if it is interesting. if you are opening a printer interface, you will not be able to query anything USB as that is a lower level detail that usbprint does not report back to the caller. so it is important to know what type of interface guid you are opening.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, November 3, 2016 7:07 AM
  • I am using GUID_DEVINTERFACE_USB_DEVICE for registering Pnp Notifications. I am able to open an IO Target to USB device.

    From USBPRINT.sys documentation, it says that it supports set of IOCTLs and IO.

    https://msdn.microsoft.com/en-us/windows/hardware/drivers/print/programming-considerations-for-usbprint


    vidyasagar196

    Thursday, November 3, 2016 7:16 AM
  • GUID_DEVINTERFACE_USB_DEVICE is way to generic. you will be notified of EVERY USB device and hub plugged into the system. you don't want your code interfering with every random USB device's start up path. GUID_DEVINTERFACE_USBPRINT in usbprint is much more specific and correct

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, November 3, 2016 4:29 PM
  • Thanks Doron, Now I am only receiving notification for printers only.

    Once application is sending a write request to my custom driver which receives pnp notification, I need to forward it to USBPRINT.sys (IOTarget is opened in pnp notification handler using symbolic link).  How This can be achieved in kmdf?


    vidyasagar196

    Thursday, November 3, 2016 5:38 PM
  • at some point you need to learn how to do this yourself. yes. you can send IO from KM to another driver

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, November 4, 2016 2:40 AM