Developing an HID input device driver for a BLE GATT device on Windows 10

时间秒杀一切 提交于 2020-12-04 17:21:18

问题


(This is a crosspost from the MSDN forums since there hasn't been any response there for quite some time and I thought I would get better answers here.)

I have a BLE device containing a custom GATT service, of which I cannot modify the firmware. I want to listen for the GATT characteristic events from that service, and make Windows consume them as HID reports to make Windows recognize it as another device. How would I go about doing this?

I conducted some research, and found the information below:

  • There were BLE GATT Profile driver samples in WDK 8.0, but they are outdated and do not compile with VS2017 / WDK10
  • In order to inject HID reports from a non-HID device, you need to use the virtual HID framework for which there are a more detailed page and a sample.
  • There is also a sample for Windows IoT Core
  • It seems to be not allowed to create filter drivers for BthLeEnum
  • The available BLE GATT functions for C++ are on MSDN
  • There is a sample on using them for a client app (not a driver)

My question is, what approach is needed here to create this driver?

  • Do I need to create two drivers (a virtual HID driver and a GATT Profile driver), and then somehow connect them to each other?
  • Do I need to make the Bluetooth LE API calls from the virtual HID driver?
  • Do I need to create a GATT Profile driver that makes HID calls?
  • Or something else entirely?

Are GATT Profile drivers even still allowed on Windows 10, since it seems it is not allowed to create filter drivers for BthLeEnum?

Update

I really appreciate that Alain took the time to answer the question and therefore I marked his answer as answer to the question; however for me the question is not completely answered yet. Seeing that the question already got more than 10 votes, I think it deserves a more extensive answer. Points that could be improved / added are:

  • the argumentation behind the advice (e.g. why UMDF minidriver instead of VHF driver, why to use UWP bluetooth APIs requiring to use cppwinrt instead of simply using the C++ Bluetooth functions that I found in my research, what about writing a GATT Profile driver, etc.). Without that argumentation I won't learn much from the advice.
  • answers to my subquestions
  • examples of using cppwinrt code from a driver and whether it is possible to access those APIs there. Are there any limitations to that (since the code will not be running from an appx)? Cppwinrt is pitched here as something new, but I can't find any documentation of using cppwinrt in the context of a driver.
  • some reflection on my own research - the current answer doesn't touch upon what points I found are good or not. This reflection would help me to understand the topic better.

Update 2

I suppose that Alain recommended a UMDF HID minidriver over VHF because VHF requires writing a KMDF driver. UMDF has the benefits of easier debugging (can be debugged on local pc), less security (and signing) restrictions and no risk of bugchecking a machine when there is a bug in the driver.

Update 3

In order to make it possible to create a client application that injects RadialController events (rather than having to write a driver which is a very high barrier for private developers), I posted a request for it on Feedback Hub. Please consider voting for it if you think that is worth supporting.


回答1:


The best approach to this would be to create a UMDF HID driver (https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/creating-umdf-hid-minidrivers) that installs on the bthleenum device node that is created for the device's custom service and use the new Bluetooth LE UWP apis (https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.genericattributeprofile).

There is some ambiguity about the use of UWP Apis from non store application, but this is incorrect. These Apis are usable in pretty much every conditions. In case you need help setting up your project, here is a C++/UWP sample that can help you get started.

I hope this helps! Alain




回答2:


In regards to the BLE GATT Profile driver samples in WDK 8.0, you can compile with VS2017 / WDK10 by following the steps here

I was able to compile the WpdHealthHeartRateService.




回答3:


I got this working as a Proof of Concept, but not reliably. Developing Windows drivers turned out to be too steep of a learning curve for the time I have available to invest in this.

Besides, as a private person I would never be able to distribute this to other people since drivers need to go through a signing and publishing process.

For the sake of knowledge exchange:

  • For the driver I used https://github.com/Microsoft/DMF combined with C++/WinRT. I used https://github.com/microsoft/DMF/blob/master/Dmf/Modules.Library/Dmf_VirtualHidMini.md and the https://github.com/microsoft/DMF/tree/master/DmfSamples/VHidMini2Dmf sample as a basis for which Sam Tertzakian gets a lot of 👍s
  • I built an UWP app to
    • discover my BLE device and send its unique ID to the driver, via a HID command
    • turn the driver functionality on / off, also via a HID command
  • the C++/WinRT part in the driver could connect to the BLE device using the WinRT BLE APIs (using the supplied unique ID) and stream the incoming events to the HID part of the driver.
  • the HID part of the driver injects the events as HID input into Windows


来源:https://stackoverflow.com/questions/45773666/developing-an-hid-input-device-driver-for-a-ble-gatt-device-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!