Bluetooth Filter Driver for DS3-compatibility - research notes

Biggest struggle in this project so far 😆


Couldn't fall asleep last night, implemented bus enumerator instead:

Youtube Video

What's going on in the video: once the connection of both HID Control and Interrupt channels has been established, the wonderful KMDF bus driver API kicks in and spawns a new PNP device:


pdoDesc.RemoteAddress = ClientConnection->RemoteAddress;
pdoDesc.DeviceType = ClientConnection->DeviceType;

// Invoke new child creation
status = WdfChildListAddOrUpdateChildDescriptionAsPresent(

In order to de-clutter the profile/bus driver I decided to outsource the device-specific logic into one or more additional function drivers, introducing IOCTLs to fetch data from and send to the PDOs without having to deal with Bluetooth-specific paradigms at all. I've introduced artificial GUID-based hardware IDs for every distinct device:

  • DS_DEVICE_TYPE_SIXAXIS - SIXAXIS or DualShock 3 compatible (including 3rd party controllers)
  • DS_DEVICE_TYPE_NAVIGATION - PlayStation Move Navigation Controller
  • DS_DEVICE_TYPE_MOTION - PlayStation Move Motion Controller
  • DS_DEVICE_TYPE_WIRELESS - DualShock 4 Revision 1 or 2 Wireless Controller

On a personal note; I'm quite pleased about the pacing here, implementing the bus logic was done almost entirely from memory and implemented once again without crashing the test host 👏

A lot of progress was made today. Nothing much to present yet but I've basically started to design and implement the interface that will be used to talk to the exposed PDOs via own function driver. This causes the code base for the profile driver remain encapsulated for Bluetooth related stuff only. Higher level functions (HID mini-driver, LED, Rumble, ...) will then be implemented by one or more individual function drivers latching onto the PDOs.


Wrapped all necessary driver (un-)installation tasks in a small self-contained tool and finished proper error handling:


This tool can then assist a setup in automating the installation and also making test installations more bearable 😉

What happens in the picture for each line:

  • BluetoothSetLocalServiceInfo is invoked which causes bthenum to spawn a PDO for the profile driver to latch onto
  • Bluetooth profile driver gets installed in driver store and device driver installation for newly spawned PDO gets kicked off
  • bthusb lower filter driver service (BthPS3PSM) gets created
  • BthPS3PSM gets added as lower filter driver for GUID_DEVCLASS_BLUETOOTH device class
  • Same action is invoked again, leading to a different response
  • Service creation is invoked again, failing because it's already registered

That'll be all for today, folks! 🤠

It's communicating! 😄

I've managed to quickly hack together an ugly demo function driver for the SIXAXIS PDO in under an hour and test it with only two crashes 😇

    WDFTIMER  Timer
    WDFDEVICE device = WdfTimerGetParentObject(Timer);
    WDFIOTARGET ioTarget = WdfDeviceGetIoTarget(device);
    PDEVICE_CONTEXT devCtx = DeviceGetContext(device);


    static UCHAR G_Ds3HidOutputReport[] = {
    0x52, 0x01, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x1E, 0xFF, 0x27, 0x10, 0x00,
    0x32, 0xFF, 0x27, 0x10, 0x00, 0x32, 0xFF, 0x27,
    0x10, 0x00, 0x32, 0xFF, 0x27, 0x10, 0x00, 0x32,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00

    static BOOLEAN toggle = FALSE;

    toggle = !toggle;
    G_Ds3HidOutputReport[11] = (toggle) ? 0x02 : 0x04;

    NTSTATUS status;

    WDF_MEMORY_DESCRIPTOR  MemoryDescriptor;
    WDFMEMORY  MemoryHandle = NULL;
    status = WdfMemoryCreate(NULL,


    controlWrite->BufferLength = 0x32;
    controlWrite->Buffer = ExAllocatePoolWithTag(
    RtlCopyMemory(controlWrite->Buffer, G_Ds3HidOutputReport, 0x32);


    status = WdfIoTargetSendInternalIoctlSynchronously(

    ExFreePoolWithTag(controlWrite->Buffer, 'aylB');

    if (!NT_SUCCESS(status)) {
            "WdfIoTargetSendInternalIoctlSynchronously failed with status %!STATUS!",

    WdfTimerStart(devCtx->OutputReportTimer, WDF_REL_TIMEOUT_IN_MS(0x01F4));


This is a timer callback function getting called around every 500 ms and cycling through LED 1 and 2 by submitting an output report to the HID Control endpoint via IOCTL_BTHPS3_HID_CONTROL_WRITE. The driver is very minimal, inefficient with memory handling and horribly named but for a demonstration just perfect 😆


Next I'm gonna try to read from it 💥

Turns out reading from the HID interrupt channel the right way is a bit more challenging than I expected. Unfortunately there's no Bluetooth equivalent of the continuous reader for USB pipes in WDF so you've to implement that thing yourself. There are reference implementations available but they're so "ripped apart" and all over the place I'll instead try to write it from scratch to better understand what's happening. Maybe I get somewhere today, we'll see 🎖

There we go 😎

2019/02/10-17:52:51.880	TRACE_LEVEL_VERBOSE	BthPS3_PDO_EvtWdfIoQueueIoInternalDeviceControl Entry
2019/02/10-17:52:51.880	TRACE_LEVEL_VERBOSE	BthPS3_EvtWdfIoQueueIoInternalDeviceControl Entry
2019/02/10-17:52:51.880	TRACE_LEVEL_VERBOSE	bufferLength: 50
2019/02/10-17:52:51.885	TRACE_LEVEL_VERBOSE	brb->BufferSize: 50, brb->RemainingBufferSize: 0
2019/02/10-17:52:51.885	TRACE_LEVEL_INFORMATION	A1 01 00 00 00 00 00 7A 81 80 7D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 05 16 FF CD 00 01 33 00 77 00 40 01 FA 01 ED 01 91 00 05 
2019/02/10-17:52:51.885	TRACE_LEVEL_VERBOSE	BthPS3_PDO_EvtWdfIoQueueIoInternalDeviceControl Exit

What threw me off for quite a few hours was the weird behavior of the RemainingBufferSize member of the _BRB_L2CA_ACL_TRANSFER structure, which was increasing fast to values way higher than the buffer I supplied could hold. Turns out this field is not talking about the Buffer member the caller supplies but the internal buffer of the Bluetooth host which tells you how many bytes have already come in from the remote device and are available to be read by further calls with that same BRB. I don't think the reference code I had a peek at did take that into account as this value was subtracted from BufferSize which could lead to a negative value resulting in 💥

Now that that's sorted out off to cleaning up this mess and looking for leaking memory 😇

Going the extra mile today: testing the PS Move Navigation controller 😈 Connection established:

2019/02/10-18:32:19.445	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Entry
2019/02/10-18:32:19.445	TRACE_LEVEL_INFORMATION	New connection for PSM 0x5053 from 70401E341 arrived
2019/02/10-18:32:19.445	TRACE_LEVEL_VERBOSE	L2CAP_PS3_HandleRemoteConnect Entry
2019/02/10-18:32:19.446	TRACE_LEVEL_ERROR	BTHPS3_GET_DEVICE_NAME failed with status STATUS_INVALID_PARAMETER (0xC000000D), dropping connection
2019/02/10-18:32:19.446	TRACE_LEVEL_VERBOSE	L2CAP_PS3_DenyRemoteConnect Entry
2019/02/10-18:32:19.446	TRACE_LEVEL_VERBOSE	L2CAP_PS3_DenyRemoteConnectCompleted Entry (STATUS_SUCCESS (0x00000000))
2019/02/10-18:32:19.446	TRACE_LEVEL_VERBOSE	L2CAP_PS3_DenyRemoteConnectCompleted Exit
2019/02/10-18:32:19.446	TRACE_LEVEL_VERBOSE	L2CAP_PS3_DenyRemoteConnect Exit
2019/02/10-18:32:19.446	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Exit
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Entry
2019/02/10-18:32:20.247	TRACE_LEVEL_INFORMATION	New connection for PSM 0x5053 from 70401E341 arrived
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	L2CAP_PS3_HandleRemoteConnect Entry
2019/02/10-18:32:20.247	TRACE_LEVEL_INFORMATION	++ Device 70401E341 name: Navigation Controller
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	L2CAP_PS3_HandleRemoteConnect Exit (STATUS_SUCCESS (0x00000000))
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Exit
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Entry (Indication: 0x0, Context: 0xFFFFFA80074DE0C0)
2019/02/10-18:32:20.247	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Exit
2019/02/10-18:32:20.497	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ControlConnectResponseCompleted Entry
2019/02/10-18:32:20.497	TRACE_LEVEL_INFORMATION	Connection completion, status: STATUS_SUCCESS (0x00000000)
2019/02/10-18:32:20.497	TRACE_LEVEL_INFORMATION	HID Control Channel connection established
2019/02/10-18:32:20.497	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ControlConnectResponseCompleted Exit
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Entry
2019/02/10-18:32:20.689	TRACE_LEVEL_INFORMATION	New connection for PSM 0x5055 from 70401E341 arrived
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	L2CAP_PS3_HandleRemoteConnect Entry
2019/02/10-18:32:20.689	TRACE_LEVEL_INFORMATION	++ Device 70401E341 name: Navigation Controller
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	++ Found desired connection item in connection list
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	L2CAP_PS3_HandleRemoteConnect Exit (STATUS_SUCCESS (0x00000000))
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	BthPS3IndicationCallback Exit
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Entry (Indication: 0x0, Context: 0xFFFFFA80074DE0C0)
2019/02/10-18:32:20.689	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Exit
2019/02/10-18:32:20.783	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Entry (Indication: 0x4, Context: 0xFFFFFA80074DE0C0)
2019/02/10-18:32:20.783	TRACE_LEVEL_INFORMATION	L2CAP_PS3_ConnectionIndicationCallback ++ IndicationRemoteConfigRequest
2019/02/10-18:32:20.783	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionIndicationCallback Exit
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	L2CAP_PS3_InterruptConnectResponseCompleted Entry
2019/02/10-18:32:20.824	TRACE_LEVEL_INFORMATION	Connection completion, status: STATUS_SUCCESS (0x00000000)
2019/02/10-18:32:20.824	TRACE_LEVEL_INFORMATION	HID Interrupt Channel connection established
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionStateConnected Entry
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	L2CAP_PS3_ConnectionStateConnected Exit
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	L2CAP_PS3_InterruptConnectResponseCompleted Exit
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	BthPS3_EvtWdfChildListCreateDevice Entry
2019/02/10-18:32:20.824	TRACE_LEVEL_VERBOSE	BthPS3_EvtWdfChildListCreateDevice Exit

And there we have the HID Input Report in the function driver 🎉

2019/02/10-18:34:23.749	TRACE_LEVEL_INFORMATION	InputReport_EvtTimerFunc Entry
2019/02/10-18:34:23.757	TRACE_LEVEL_INFORMATION	A1 01 00 00 00 00 00 80 80 7D 85 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 03 14 FF C2 00 00 23 D6 77 00 40 02 00 02 04 01 A3 01 FF 
2019/02/10-18:34:23.757	TRACE_LEVEL_INFORMATION	InputReport_EvtTimerFunc Exit

Alright, time to properly polish and fix power management.

I've implemented dropping all connections in case of bthenum surprise removal (unplugging the USB Bluetooth dongle without warning), freeing memory and instructing child device (PDO) removal. This works well and allows unloading the driver, so no dangling objects here. But as soon as the function driver attaches, everything stalls on surprise removal. I haven't yet had the time to debug/implement it but I can document a few assumptions to help me later when I pick it up again.

  • EvtWdfIoQueueIoInternalDeviceControl sends BRBs synchronously out of convenience, this probably isn't the brightest idea, will adjust that to asynchronous
  • PDO might be missing PNP/Power capabilities
  • Queue I/O stop callback isn't invoked
  • Maybe implement self-managed I/O flush callback?

I bet it's an easy fix and I'm just overthinking the issue. Will pick up development again in a few days 👋

Surprise removal power-down sequence fixed!

Two things had to be done (properly):

Another step closer to finishing and hardening the profile/bus driver 🎉

Goddammit, I managed to make bthport.sys leak memory ☠


Time for code review! 🤦



Aha! It only happens when I send data to the HID Control Channel, how interesting 🤔 We'll see about that... :male-detective:

Seriously, how did I do that 😦


Pool tag details:

BTHP - bthport.sys  - Bluetooth port driver (generic)
HCIT - bthport.sys  - Bluetooth port driver (HCI)

Now if the symbols could download faster than over 56k I could actually see more 💤

Better graph, still no clue 🙄


Ha, found it! 🎉 Now that's more like it:


Purple is non-paged memory from HCI-specific pool now only slightly jittering up and down as expected. Green is the BTHP pool which is now steady as well. The uneven bumps are probably owed to timing in the driver and probably latency on the radio link.

So what was the issue? Well, previously I was only writing to the HID Control Channel (periodically) because that's how the HID Output Report travels to the remote device. Now since I couldn't find any issues with my memory handling in my own drivers I was starting to experiment and implemented reading from the control channel (where there shouldn't be any data coming back because the DS3 sends data over the HID Interrupt Channel) as well and look at that: with every packet I send out there's one byte of "response" available to read as well! The content is always a solid 0x00 but still, this was allocating and holding memory in the lower sections of bthport.sys and the reason for the rise in non-paged memory usage. I'm now also periodically reading and therefore "emptying" the control channel and now it's not growing anymore. Nice!

Time for a break ☀

Guess some sort of Writer's Block got me, but for coding. No worries though, will do something else then until the spirits are up for it again 😄

Cheers 🥂

I've currently "interrupted" further coding with building my WHQL lab. The progress on it gets its own thread here but since my Windows 7 test boxes are ready I'll throw the current revision of the profile driver into it and see what happens 😈


Can't wait to connect my Ps3 controller via bluetooth to pc without installing malicious software 😄 (it's this project all about this right?, if yes, when it will be released? 😇 )

@epikvigem pretty much sums it up, yeah 😛 This set of drivers will allow you to use the popular PS3 peripherals (DualShock 3, Navigation & Move Controllers) transparently with little overhead on Windows 7 up to 10.

As for the estimated release schedule... If the current pace stays where it is I aim for early or mid May?


HCK had its run over night on the profile driver and look how happy it is 😅


Next I have to polish and test the filter driver and extend it with a few management features (like turning it on or off from user-land).