DualShock 4 Bluetooth pairing

FrostKiwi

New Member

Reaction score: 7
Messages: 19

I would like to connect a DualShock 4 (and PS5 controller later on) with FreeBSD and my integrated (USB) Bluetooth 4.0 chip.
With the DualShock 4 connected via USB, controllermap successfully detects both the controller and every single controller button / analog stick.
Now I used bluetooth_config scan to pair the controller. When asked for a pin, I simply left it at the default nopin.

Now there is an alias in /etc/bluetooth/hosts, an entry in hcsecd.conf with nokey and nopin and bthidd.conf lists the device with the bdaddr, some more info and the hid_descriptor{ ... }.

However, nothing really happens from here on out.
Every 10 seconds, the bluetooth lamp blinks and hccontrol read_connection_list reports:
Code:
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
DualShock4          3902  ACL    0 MAST    NONE       0     0 W4_CONN_COMPLETE
This lasts roughly 3 seconds, before the entry disappears and the cycle starts anew. The DualShock4 never lights up, putting it into connection mode changes nothing, just the blue connection light flashing on the controller. controllermap never detects a joystick.

What can I do to get a connection? Is my pairing maybe incomplete, because I set nopin and nokey? With Linux and DualShock 3 there appears to be the need to connect it via USB first to exchange pairing data. Maybe that's when the key is transfered? But this does not appear to be the case for DualShock 4.
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

I compared to Linux and here are the results:
Connection on Linux works automatically. The DualShock4 turns instantly blue and the controller inputs are read successfully.
I checked /var/lib/bluetooth for pairing information.
My Smartphone leaves behind a pairing key, the DualShock4 does not. The DualShock4's bluetooth info file shows no special information being left behind:
Code:
[General]
Name=Wireless Controller
Class=0x002508
SupportedTechnologies=BR/EDR;
Trusted=false
Blocked=false
WakeAllowed=true
Services=00001124-0000-1000-8000-00805f9b34fb;00001200-0000-1000-8000-00805f9b34fb;

[DeviceID]
Source=2
Vendor=1356
Product=2508
Version=256
For comparison the SmartPhone Info file:
Code:
[LinkKey]
Key=4A210DB2D0D1CC87459184DFB6A7F601
Type=5
PINLength=0

[General]
Name=OnePlus One
Class=0x5a020c
SupportedTechnologies=BR/EDR;
Trusted=true
Blocked=false
Services=00001105-0000-1000-8000-00805f9b34fb;0000110a-0000-1000-8000-00805f9b34fb;0000110c-0000-1000-8000-00805f9b34fb;0000110d-0000-1000-8000-00805f9b34fb;0000110e-0000-1000-8000-00805f9b34fb;00001112-0000-1000-8000-00805f9b34fb;00001115-0000-1000-8000-00805f9b34fb;00001116-0000-1000-8000-00805f9b34fb;0000111f-0000-1000-8000-00805f9b34fb;0000112f-0000-1000-8000-00805f9b34fb;00001132-0000-1000-8000-00805f9b34fb;00001200-0000-1000-8000-00805f9b34fb;00001800-0000-1000-8000-00805f9b34fb;00001801-0000-1000-8000-00805f9b34fb;

[DeviceID]
Source=1
Vendor=224
Product=4608
Version=5174
Thus I conclude, that both nopin and nokey properties in FreeBSD are indeed correct. So something about the handling of the Controller is wrong. I don't even know whether the pairing succesds or not, and I have no idea how to understand what hccontrol means by "W4_CONN_COMPLETE". skimming the kernel code, ng_hci_ulpi.c states "NG_HCI_CON_W4_CONN_COMPLETE means that upper layer already requested connection or we just accepted it. In any case all we need to do here is set appropriate notification bit and wait."
I guess FreeBSD is waiting for the DualShock4 to answer, but I'm way over my head here. I have no idea how to proceed or where to look for answers.
halp 🥺
 

sidetone

Daemon

Reaction score: 720
Messages: 1,579

According to the Handbook, Bluetooth version 1.1 and some models of v2 work. Some have claimed up to Bluetooth 3.0, or Bluetooth LE works, while the documentation is years behind, but this is difficult to validate or confirm. They say Bluetooth audio works no matter the version, this is documented.
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

According to the Handbook, Bluetooth version 1 and some manufacturers of 2.1 work. Some have said up to Bluetooth 3.0 or Bluetooth LE works, while the documentation is years behind, but this is difficult to validate or confirm. They say Bluetooth audio works no matter the version.
Ohh... So I misunderstood what FBSD supports.
There is just no support for Bluetooth v4, no need to try and investigate anything. I specifically replaced the USB daughterboard in my Thinkpads to Bluetooth v4 ones. I can downgrade to Bluetooth 2.1 again. Since the DualShock 4 is BlueTooth v2.1 and the PS5's Dual Sense controller propably supports BlueTooth 2.0 via backwards compatibility, because you can use a PS5 controller on a PS3 (A BlueTooth 2.0 only device), I should get everything to work by downgrading to the BlueTooth 2.1 daughter board.

That seems like a good theory to try :] Will test that tomorrow and report back.
 

sidetone

Daemon

Reaction score: 720
Messages: 1,579

After reading the section on the handbook, the supported versions were easy to miss. I actually missed it, and went and bought a higher version Bluetooth dongle.

Some Bluetooth peripherals have shown up, but not as a Bluetooth device. They didn't work.

In a thread, there was a claim of Bluetooth v4 working. Bluetooth LE may possibly include higher versions. These claims of higher versions working is difficult to validate.

There's the possibility that some Bluetooth code was temporarily in Stable or Current. It's also possible that there's some code in FreeBSD base that isn't complete or officially functional.
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

Progress!
After changing from the BCM920702MD BlueTooth 4.0 board to the BCM92046MD BlueTooth 2.1 EDR2 Board, pairing can be successfully completed.
The Bluetooth driver responds when the DualShock4 is turned on and opens a connection. After a successful pairing, the bluetooth lamp starts blinking non-stop and the controller shines light-blue all the time.
Code:
bthidd[892]: Accepted control connection from a0:ab:51:43:ba:27
bthidd[892]: Accepted interrupt connection from a0:ab:51:43:ba:27
hccontrol read_connection_list now reports constantly:
Code:
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
a0:ab:51:43:ba:27     11  ACL    0 MAST     P2P       0     0 OPEN
Setting everything up, this article really helped. "bluetooth_config scan" behaves a bid weird, throwing error after writing the hid descriptor even though it succeeds. Manully setting it up, no errors were encountered. Also, I do not understand when or how it is setup, but sometimes I got to a state, where the BlueTooth chip would scan every 10 seconds actively with the lamp blinking. This is not the case anymore. Now it simply remains neutral, until the DS4 requests a connection.
Now the DualShock4 constantly shines light-blue. The same light blue that blinks when it searches for a connection. However, it is not the DarkBlue I encountered in Linux, when it is working as a controller.
No joystick is detected by controllermap. How can I procced? Where can I look? I don't even know whether there was a device created in /dev/ or not...
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

Highly annoyingly I cannot get it to pair again to research further >.<
Nothing changed, but now the DS4 just blinks, the Bluetooth lamp blinks for a single time but nothing happens, no "Accepted control connection" in /var/messages
Doing manually
sudo hccontrol -n ubt0hci create_connection a0:ab:51:43:ba:27
results in
Status: ACL connection already exists [0xb]
And hccontrol read_connection_list lists the following for a single second:
Code:
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
a0:ab:51:43:ba:27     3848  ACL    0 MAST     P2P       0     0 W4_CONN_COMPLETE
Like with the non-working BlueTooth 4.0. So frustrating, I don't know how to coerce it into connecting again. Since these are the symptoms as with BlueTooth 4, maybe BlueTooth 4 did work after all?
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

There exists this user space driver for the DualShock4 on Linux: https://github.com/chrippa/ds4drv
Let's say, that through sheer power of will I actually get FreeBSD's bluetooth to stick to "Accepted control connection" again, like on that miracle of a day...
... where would that bluetooth device be created? Is there a corresponding /dev/.... entry?
 

sidetone

Daemon

Reaction score: 720
Messages: 1,579

I believe so, that a device will be created in /dev/. A module may also be created in /boot/modules/. Use dmesg to see terminal output of a new connection.

* edit, a Bluetooth driver, if there is one. As for the gamepad driver, FreeBSD may already have it. Iichid is base of FreeBSD 13.0.
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

I believe so, that a device will be created in /dev/. A module may also be created in /boot/modules/. Use dmesg to see terminal output of a new connection.

* edit, a Bluetooth driver, if there is one. As for the gamepad driver, FreeBSD may already have it. Iichid is base of FreeBSD 13.0.
A Bluetooth driver what for? What is it's purpose, for what device? To interface with the DualShock 4? To manage the BlueTooth Chip?

Also any idea how to solve
"sudo hccontrol -n ubt0hci create_connection a0:ab:51:43:ba:27" returning "Status: ACL connection already exists [0xb]"?
 

sidetone

Daemon

Reaction score: 720
Messages: 1,579

A Bluetooth driver simply for being of Bluetooth, if the version needed still doesn't work.
sysutils/btsixad, iichid(4) is in base of FreeBSD 13.0, and they say SDL takes care of gamepad/joystick drivers too. Try one of those. If it has both Bluetooth and a USB cable, test it over USB connection first.

Is there a command to list connected Bluetooth devices? There's dmesg, but there may be one more specific to Bluetooth. What about kldstat? I would say, ask on the mailing list (https://lists.freebsd.org/mailman/listinfo/freebsd-bluetooth) too, but it hardly has anything. It wouldn't hurt to try, perhaps there can be a response.
 
OP
FrostKiwi

FrostKiwi

New Member

Reaction score: 7
Messages: 19

A Bluetooth driver simply for being of Bluetooth, if the version needed still doesn't work.
sysutils/btsixad, iichid(4) is in base of FreeBSD 13.0, and they say SDL takes care of gamepad/joystick drivers too. Try one of those. If it has both Bluetooth and a USB cable, test it over USB connection first.

Is there a command to list connected Bluetooth devices? There's dmesg, but there may be one more specific to Bluetooth. What about kldstat? I would say, ask on the mailing list (https://lists.freebsd.org/mailman/listinfo/freebsd-bluetooth) too, but it hardly has anything. It wouldn't hurt to try, perhaps there can be a response.
DualShock4 via USB works flawlessly and spawns /dev/uhid0, as described in the OP.
As for BlueTooth, I think this is once more progress...
...bthidd can interpret the HID descriptor and accept the DualShock4, as described in this post. However, this does not get us far no device is spawned in /dev.
Now on to btsixad - Many thanks for the reference! bthidd and btsixad listen on the same socket, so one thing or the other.
With bthidd gone, btsixad also detects the DS4, though not in name and disconnects:
Code:
btsixad 23379 - - connection from a0:ab:51:43:ba:27 on control channel
btsixad 23379 - - connection from a0:ab:51:43:ba:27 on interrupt channel
btsixad 23379 - - connection is from unknown device: vendor 0x054c (by 0x0002), product 0x09cc, release 0x0100
btsixad 23379 - - connection from a0:ab:51:43:ba:27 closed
The kernel module ng_l2cap_l2ca_receive also complains:
Code:
Jun 16 01:30:01 stripes kernel: ng_l2cap_l2ca_receive: ubt0l2cap - unexpected L2CAP data packet. Invalid channel state, cid=108, state=5
Jun 16 01:30:01 stripes syslogd: last message repeated 2 times
I presume the kernel complains, because btsixad killed the connection ungracefully, and not vice-versa (bluetooth kernel module creates an issue, that makes btsixad fail)

This is as far as I get. The btsixad package homepage mentions, that btsixad is aimed at the DualShock3. Maybe involve that package author to explain to us what would have to be done to revamp support for the PS4's DualShock 4 and the PS5's DualSense...
 
Top