Current State of Windows HIDAPI and Wiimotes

Introduction

This is a small follow up on my testings. Long time it was believed that the PlusInside Wiimotes (“-TR”) are not working with the default Bluetooth Windows Stack. Every program and library recommends the common Toshiba Bluetooth “hack” to get “-TR” Wiimotes and Wii U Pro controllers working on Windows. I did some research with the HIDAPI on Windows and came to the result, that on Windows 8 and above using the proper API Calls, “-TR” Wiimotes, as well as the Wii U Pro Controller is working perfectly fine.

I implemented and fixed the Wiimote Code in the Dolphin Project, which also lead to improved Wiimote Audio for “-TR” Wiimotes.

TLDR;

Using the proper API Calls the Toshiba Bluetooth Stack is not needed anymore on Windows 8 and above. Both Wiimotes types (TR & non-TR) and the Wii U Pro are working fine. Here is the code repository of my test program.

The following post is basically just a copy & paste of the Readme, as it got quite extensive.

Windows 7

The API Calls would also work fine on Windows 7, but there is a bug in the Microsoft HID Class Driver. This renders the “WriteFile”-Method unusable on Windows 7, therefore it is not possible to use the HIDAPI to send data to “-TR” Wiimotes.

HIDAPI

Sending & Receiving

Sending HID Reports:

Recieving HID Reports:

The MSDN Design Guides Sending HID Reports and Obtaining HID Reports are stating, that WriteFile and ReadFile are the preferred methods to send and recieve data from the device. Additionally sending data to a “-TR” Wiimote via WriteFile is working fine, whereas using HidD_SetOutputReport will result in the Wiimote turning off.

Issues with WriteFile

As the MSDN Desgin Guide Sending HID Reports by Kernel-Mode Drivers (WriteFile will send out an IRP_MJ_WRITE request to the driver interface) suggests, the output report buffers shall have the size of the largest output report supported by the device. In case of the Wiimote this is 22 Byte.

This seems to be currently enforced by the Microsoft HID Class Driver on Windows 7 and the Toshiba Bluetooth Stack, as they will fail WriteFile attempts with the error ERROR_INVALID_USER_BUFFER, when the buffer size is less.

On Windows 7 however more bytes than the acutal report are sent to the device, which produces an error on the Wiimote. It is unknown whether this is a bug or intented behaviour. The Toshiba Bluetooth Stack in contrast only sends the appropiate amount of bytes according to the used report to the device.

On Windows 8 and higher, the output report buffer can be arbitrary in size, as the given amount of byte are submitted to the device.

This results in the following table of compability.

Table of compability

x Toshiba Stack Win 7 Win 8.1 Win 10
WriteFile Largest Report Size +
WriteFile Acutal Report Size + +
SetOutputReport +* +* +*

* does not support “-TR” when connected via Bluetooth

Method Priority Order

This leads us to the following order of prioritized methods:

  1. Detect whether the Microsoft Stack or the Toshiba Stack is used for the Wii Remote.
  2. In case of Toshiba Stack, use WriteFile with the largest report size for the buffer
  3. In case of Microsoft Stack, try WriteFile with the actual report size
  4. If WriteFile fails, fall back to HidD_SetOutputReport

Detecting Stack

To detect the used stack for the Wiimote, the provider property of the used HID Class Driver is evaluated. As the enumerated Wiimote Devices are just raw PDO’s, that are acting as interfaces for the HID Class Driver and don’t have a driver directly associated with, it is neccessary to move one node up in the device tree to get to the device node that is associated with the HID Class Driver. To do so the PnP Configuration Manager API is used.

Why WriteFile supports “-TR”

It is believed, that the usage of HidD_SetOutputReport will result in sending the output report via the Control Channel. This is not supported by “-TR” Wiimotes, as they will immediately shut down. In contrast WriteFile seems to send the data to device via the Interrput/Data Channel.

DolphinBar

The Mayflash DolphinBar enumerates Wiimotes as USB Devices, resulting in using the Microsoft HID Class Driver. Therefore WriteFile won’t work on Windows 7 for Wiimotes connected through the DolphinBar either. However as the DolphinBar takes care of the Bluetooth communication and the outgoing data is send via USB to the DolphinBar, HidD_SetOutputReport does support “-TR” Wiimotes as long as they are connected through a DolphinBar.

HID Wiimote Windows 10 Builds

Nyhet!

HID Wiimote Windows 10 Builds

Some more information

From now on there will be a unified build for Windows Desktop systems. The new WDK 10 makes it possible and in return it means less mess with different packages.

This build has nothing new except that is has been rebuild with the newest Visual Studio 2015 and Windows Driver Kit 10. So for non Windows 10 users there is no urgent need to download/update it. But you can if you like to, just make sure to uninstall the previous/old driver.

This new build was tested on a Windows 10 system with a build-in Bluetooth adapter and a separate Bluetooth Dongle, as well as on a Windows 8.1 system with a Bluetooth Dongle. I wasn’t able to test it on Windows 7, because i have currently no Windows 7 system here around, so please report back if there is any issue.

Windows 10 Universal Driver: Coming Soon™

So this is a multi-system Desktop build and not an Universal Driver. I am going to provide an Universal Driver as well soon, but there is some work to be done. The driver compiles fine and without any error. The only issue is that i have to make an universal .inf file, which simply requires me to read through the MSDN documentation.  However, i am currently not able to test the Universal Driver on a Windows Phone nor on an IoT-System, so the build is going to be purely experimental and for people that just want to give it a try.

I am also not quite certain about the driver signing regarding the Universal Driver. I have no clue whether it is possible to deactivate the driver verification on Mobile and IoT-Systems and get an unsigned driver loaded. I would assume there is some way, because devs need the ability to test drivers on the device, but that might require additional test modes, which in turn may have side effects.

Changes

  • Windows 10 Desktop Build