# Audio on bluetooth with virtual_oss



## TLoe (Dec 20, 2019)

I had some driver issues, but got past that.. now I am able to connect to my speaker and it makes the connection sound and then I get a DISCOVER FAILED message and it makes the disconnection sound and it runs in a loop until I force quit it..  its the same for both my BT speaker (UE boom3) and my BT headset (RHA ma650)


```
➜  ~ sudo virtual_oss -C 2 -c 2 -r 22050 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/boom3 -d dsp
hw.snd.basename_clone: 0 -> 0
backend_bt: PSM=0x19
backend_bt: DISCOVER FAILED
backend_bt: PSM=0x19
backend_bt: DISCOVER FAILED
^C
➜  ~ sudo virtual_oss -C 2 -c 2 -r 22050 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/rha -d dsp
hw.snd.basename_clone: 0 -> 0
backend_bt: PSM=0x19
backend_bt: DISCOVER FAILED
backend_bt: PSM=0x19
backend_bt: DISCOVER FAILED
```

I can connect to both of them with hccontrol. Here I'm connecting to the headset:


```
➜  ~ hccontrol -n ubt0hci inquiry
Inquiry result, num_responses=1
Inquiry result #0
    BD_ADDR: RHA
    Page Scan Rep. Mode: 0x1
    Page Scan Period Mode: 00
    Page Scan Mode: 00
    Class: 24:04:04
    Clock offset: 0x4b86
Inquiry complete. Status: No error [00]
➜  ~ sudo hccontrol -n ubt0hci create_connection RHA  
Password:
Status: Page timeout [0x4]
➜  ~ sudo hccontrol -n ubt0hci create_connection RHA
BD_ADDR: RHA
Connection handle: 256
Encryption mode: Disabled [0]
➜  ~ hccontrol -n ubt0hci read_connection_list
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
RHA                  256  ACL    0 MAST    NONE       0     0 OPEN
➜  ~
```


----------



## hselasky@ (Dec 27, 2019)

Hi,

I think you need to enable the encryption mode before it will work.

write_encryption_mode mode(0|1|2)

--HPS


----------



## TLoe (Dec 28, 2019)

Tried with 0 (default) and 1 with the same result. When I tried to set 2 I got "Status: Unsupported feature or parameter value [0x11]"


----------



## hselasky@ (Dec 28, 2019)

Did you follow the advice at:





						203745 – A2DP Support for Bluetooth Headphone Audio
					






					bugs.freebsd.org
				




You need SDPD and HCSECD daemons running.

You also need to pair your device(s) using the bluetooth-config script in base.

--HPS


----------



## TLoe (Jan 2, 2020)

Busy days so slow reply

Yes I followed the advice there.

I have both SDPD and HCSECD running.. I've tried configuring both manualy and with the bluetooth-config scrip and end up with the same result.


----------



## hselasky@ (Jan 2, 2020)

Did you try to build and start the virtual_bt_speaker utility . See separate port option for virtual_oss. Some BT audio devices connect back before they work. Else you might start to look at hcidump in ports, which can trace all BT traffic, and the resulting trace file can be opened by wireshark.


----------



## TLoe (Jan 2, 2020)

No I didn't try that actually.

How do I know what /dev/dspXXX to use?


----------



## TLoe (Jan 2, 2020)

Tried with all of them, but getting:
`Starting to listen
Registering service via SDP
SDP failed to register: Input/output error
Failed to register in SDP`


----------



## hselasky@ (Jan 2, 2020)

Is your sdpd running and up-to-date with the latest available in your -stable branch?


----------



## TLoe (Jan 2, 2020)

Yes sdpd is running.

There is no available updates with freebsd-update fetch and I just ran a pkg upgrade.


----------



## TLoe (Jan 2, 2020)

`Jan  2 14:17:45 T sdpd[1475]: Could not process SDP request from control socket, pdu->pid=129, pdu->tid=1, pdu->len=14, len=19, error=3`


----------



## hselasky@ (Jan 2, 2020)

What version of FreeBSD is this? Maybe you need to compile SDPD from stable-source.


----------



## TLoe (Jan 2, 2020)

`➜  ~ uname -a
FreeBSD T 12.1-RELEASE-p1 FreeBSD 12.1-RELEASE-p1 GENERIC  amd64`


----------



## hselasky@ (Jan 2, 2020)

It looks like you have all the right patches. You should have the following definitions:


```
grep -r audio_sink /usr/include/
/usr/include/sdp.h:struct sdp_audio_sink_profile
/usr/include/sdp.h:typedef struct sdp_audio_sink_profile    sdp_audio_sink_profile_t;
/usr/include/sdp.h:typedef struct sdp_audio_sink_profile    *sdp_audio_sink_profile_p;
```

Have you tried another USB bluetooth dongle?


----------



## TLoe (Jan 2, 2020)

Hmm.. that returns nothing here..

I don't build the system myself though..

Don't have another usb dongle.. This is the internal in a dell XPS 13


----------



## hselasky@ (Jan 2, 2020)

If the grep returns nothing, you need a newer system.


----------



## TLoe (Jan 2, 2020)

Hum.. Think I have the latest? freebsd-update fetch and install says there is nothing to update?

And I am on 12.1 as the uname -a shows above?

Isn't this in 12.1-RELEASE-p1?


----------



## hselasky@ (Jan 2, 2020)

There were some recent changes made to SDPD and sdp.h which you need.
Among the patches you need is this one r344144 (Feb 15 2019) and 12.1 was branched in September. Maybe you didn't opt for updating the header files and sources?


----------



## hselasky@ (Jan 2, 2020)

If it doesn't work and you are sure you have the latest binary and sources, then you need to analyze the hcidump in wireshark to figure out where the protocol goes wrong.


----------



## TLoe (Jan 8, 2020)

Sorry.. realized wireshark would take some time to get into and didn't have the time..

Got the hcidump loaded in wireshark now.. not sure, but it seems like the speaker is trying to send a connection request for AVCTP-control and that the system does not support it?


----------



## TLoe (Jan 8, 2020)

hum.. trying to attach a file, but getting a linethrough on the filename after I upload it..

uploaded it here: https://www.justbeamit.com/9bkaw


----------



## hselasky@ (Jan 8, 2020)

TLoe said:


> Sorry.. realized wireshark would take some time to get into and didn't have the time..
> 
> Got the hcidump loaded in wireshark now.. not sure, but it seems like the speaker is trying to send a connection request for AVCTP-control and that the system does not support it?



AVCTP-control is not supported, but you could implement it if you know how.

--HPS


----------



## TLoe (Jan 8, 2020)

Hmm.. right, but is that  what makes it fail? Should it be able to playback without it?

Realized the link I posted to expired after 10 minutes. Zip seems to work though 

The first file is for virtual_oss dump and the second is for when I run virtual_bt_speaker.. that seems to get a connection, but the audio isn't comming from the speaker..


----------



## hselasky@ (Jan 8, 2020)

I don't know. Maybe the firmware of your audio devices has certain expectations about the BT host it connects to. Maybe all you need is to ACK a few AVCTP-control commands and it will work ... The specifications you'll find on the internet and also in the Linux kernel.


----------



## TLoe (Jan 9, 2020)

Hmm right.. might look into it later if I get time. Where can I find the code for this?


----------



## hselasky@ (Jan 9, 2020)

http://www.bluez.org/ and https://www.bluetooth.com/specifications/protocol-specifications/

--HPS


----------



## TLoe (Jan 9, 2020)

Ah nice thanks.. I meant in the freebsd code base though


----------



## hselasky@ (Jan 9, 2020)

You should look at "usr.sbin/bluetooth/sdpd" and https://github.com/hselasky/virtual_oss/tree/master/backend_bt

SDPD usually is used to announce the service via parameters provided by virtual_oss via a special socket. Then virtual_oss somehow need to implement the service.

--HPS


----------



## TLoe (Jan 9, 2020)

Okay cool thanks.. I'll have a look when I get more time


----------

