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/


KMDF Mouse driver

ezhxezhx Member Posts: 3

Hello,

I am a beginner in kmdf driver development.
I would like to just try creating a simple driver to read data from my mouse ( I don't want the mouse to work, just get the data sent on the USB ).

I used the "kmdf_enumswitches" kmdf template as it is supposed to read continous data on the USB (?) but the function "WdfUsbTargetDeviceCreateWithParameters" returns "STATUS_INVALID_DEVICE_REQUEST"

My guess is that the system knows it is a HID mouse and don't let me open an USB handle to it.

Maybe what I am trying to do is not doable.

In this case, I thought about using an Arduino Due to send data to the driver, would that be an easier approach?

Thanks in advance

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,735
    Do you want to see the raw usb data or the cooked mouse data? For cooked mouse data you can start with the moufiltr example. For the raw usb data you need to filter a lower part of the stack. Probably the easiest choice is to start with the toaster filter example and install it as a device lower filter below hidusb.sys. You will not send any requests on your own, rather you should filter the URBs sent by hidusb and in the completion routine you can see the data read from the device.


    BUT… what are you trying to learn? There may be easier paths to follow if you can state your goals.
    d
  • ezhxezhx Member Posts: 3

    Thanks for you answer,

    I just want to demonstrate for a studies project how to retrieve data from a hardware using a windows driver.
    I had in mind not to build a filter driver (as it would mean I just get the data from an already working windows driver that I didn't code myself?), and rather be the first part of the stack: just the hardware and my driver, but maybe it is not possible?

    I would like just the raw usb data (without even taking into account that it is a hid device).

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,735
    Force install your driver and replace hidusb. You will have complete control over the io to the device.
    d
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,445

    I think you're unclear about the architecture of USB. The only component that talks directly to the hardware is the Host Controller Driver. All other drivers in the USB stack pass around URBs (USB Request Blocks) as normal IRPs. Because of that, you might as well use a filter driver examine the URBs that get passed around during normal mouse operation.

    It is possible for you to replace the HID driver with your own custom driver, or even with WinUSB to allow you to drive it from user mode. However, you will need to read and understand the USB Specification and the USB HID Specification in order to understand the protocols you need to follow.

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

  • ezhxezhx Member Posts: 3

    Replacing the microsoft usb drivers with my own custom driver would definitely work, but I think it's a tough task for a beginner.

    I read some more microsoft docs and things are starting to get clearer.

    So let's say I have a hardware HID device, that has extra features that I need to handle. If I am right, what I should do is build a function driver that binds to the HID class Windows driver?

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,735
    Outside of keyboard and mouse, you can directly access HID devices from user mode without an additional driver. You can write a function driver for the hid function, but it is not the simplest path.
    d
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,445

    So let's say I have a hardware HID device, that has extra features that I need to handle. If I am right, what I should do is build a function driver that binds to the HID class Windows driver?

    HID is not a particularly good example, because the operating system already has full driver support. No kernel code is required. Keyboards and mice don't have "extra functions"; they follow the spec, and the system can handle the spec. For devices other than keyboards and mice, the user mode HID library can do anything you need to do.

    Non-HID USB devices are fun to play with. There are dozens and dozens of "USB experimenter kits" that you can play with.

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

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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 January 2023 Live, Online
Developing Minifilters 20 March 2023 Live, Online
Internals & Software Drivers 17 April 2023 Live, Online
Writing WDF Drivers 22 May 2023 Live, Online