Bug 203745

Summary: A2DP Support for Bluetooth Headphone Audio
Product: Base System Reporter: Tony Narlock <tony>
Component: wirelessAssignee: freebsd-wireless mailing list <wireless>
Status: Open ---    
Severity: Affects Only Me CC: Scoobi_doo, adrian, alex, avidal, che, danfe, dumbbell, henry.hu.sh, honey, hselasky, jakob, js, lme, olivierw1+bugzilla-freebsd, vermaden, xbs
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Tony Narlock 2015-10-13 17:49:50 UTC
Hi fellow FreeBSD users and developers,

I have a Sennheiser bluetooth headset. After some digging I haven't seen a topic mentioning A2DP on bugzilla.

Here are some related links on the issue:

- https://forums.pcbsd.org/thread-19754.html (PC-BSD - support for bluetooth headsets)
- https://lists.freebsd.org/pipermail/freebsd-bluetooth/2013-June/001834.html (What is it going to take to get basic A2DP support into -HEAD?)

From the above thread, NetBSD seems to be a candidate to port A2DP support from.

As of very recently (September 15, 2015), they are experimenting with a new A2DP at https://mail-index.netbsd.org/netbsd-users/2015/09/14/msg016883.html.

What is standing in our way if we want to port NetBSD's A2DP?

Would A2DP handle the microphone portion also?
Comment 1 Hans Petter Selasky freebsd_committer 2015-10-14 12:42:49 UTC
I recommend using libcuse for this making a daemon in userspace 
which handle everything emulating a DSP device. See:

svn --username anonsvn --password anonsvn \
       checkout svn://svn.turbocat.net/i4b

Search for "virtual_oss*"
Comment 2 Maxim Filimonov 2015-10-14 13:18:17 UTC
Shouldn't this issue be assigned to freebsd-bluetooth@?
Comment 3 Hans Petter Selasky freebsd_committer 2015-10-19 08:44:28 UTC
Hi,

Over the weekend I've imported Nathanial Sloss's A2DP code into my virtual OSS backend for FreeBSD. If someone wants to do recording support, would be great. How to connect:

0) Add your device to /etc/bluetooth/hcsecd.conf

device {
        bdaddr  xx:xx:xx:xx:xx:xx;
        name    "BT audio device";
        key     nokey;
        pin     "0000";
}

1) /etc/rc.d/hcsecd onestart
2) hccontrol -n ubt0hci write_authentication_enable 1
3) Now switch on pairing
4) hccontrol -n ubt0hci create_connection xx:xx:xx:xx:xx:xx

5) Install cuse4bsd-kmod from ports or set HAVE_CUSE=YES for 11-current.
6) kldload cuse4bsd or cuse

7) svn --username anonsvn --password anonsvn \
       checkout svn://svn.turbocat.net/i4b/trunk/virtual_oss

cd virtual_oss
make HAVE_BLUETOOTH=YES all

# Disable kernel's /dev/dsp
sysctl hw.snd.basename_clone=0

# Create new /dev/dsp
./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/xx:xx:xx:xx:xx:xx -d dsp

Assuming you have sox installed:

play test.wav

Or use VLC and select OSS audio backend.
Comment 4 Hans Petter Selasky freebsd_committer 2015-10-19 08:56:20 UTC
What's missing from recording support is simply the SBC audio decoder.
Comment 5 Lars Engels freebsd_committer 2015-10-19 19:12:56 UTC
I tried your instructions with a Teufel Bamster bluetooth speaker.

It all went fine until I start virtual_oss:

# ./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/a0:e9:db:00:32:0d -d dsp
virtual_oss: AUTOCONFIG FAILED: No error: 0
virtual_oss: AUTOCONFIG FAILED: No error: 0
virtual_oss: AUTOCONFIG FAILED: No error: 0
virtual_oss: AUTOCONFIG FAILED: No error: 0
virtual_oss: AUTOCONFIG FAILED: No error: 0

The message is emitted every second and the speaker shortly beeps at the same time.
Comment 6 Tony Narlock 2015-10-19 20:38:50 UTC
Fantastic news to brighten a tough day. Thank you Hans.

Here is what I get.  Is there anything I can do to give you better information?  Same sennheiser Urbanite bluetooth headset.

# freebsd-version; uname -a
11.0-CURRENT
FreeBSD z600 11.0-CURRENT FreeBSD 11.0-CURRENT #5: Mon Oct 19 13:26:50 CDT 2015     root@z600:/usr/obj/usr/src/sys/GENERIC  amd64


➜  virtual_oss  sudo hccontrol -n ubt0hci read_connection_list
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
00:16:94:14:13:ae     12  ACL    0 MAST    NONE       0     0 OPEN
➜  virtual_oss  ./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/00:16:94:xx:xx:xx  -d dsp
virtual_oss: Could not connect to cuse module

➜  virtual_oss  sudo ./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/00:16:94:XX:XX:XX  -d dsp 
Password:
virtual_oss: Could not connect to HC: Input/output error
virtual_oss: Could not connect to HC: Input/output error
virtual_oss: Could not connect to HC: Input/output error
virtual_oss: Could not connect to HC: Input/output error
virtual_oss: Could not connect to HC: Input/output error
^C%                                                                                                                                                          ➜  virtual_oss  sudo hccontrol -n ubt0hci read_connection_list                                                              
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
00:16:94:xx:xx:xx     12  ACL    0 MAST    NONE       0     0 OPEN
➜  virtual_oss  sudo ./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/00:16:94:XX:XX:XX  -d dsp
virtual_oss: Could not open SDP: Host is down
virtual_oss: PSM not found: Host is down
virtual_oss: Could not open SDP: Permission denied
virtual_oss: PSM not found: Permission denied
virtual_oss: Could not open SDP: Permission denied
virtual_oss: PSM not found: Permission denied
virtual_oss: Could not open SDP: Permission denied
virtual_oss: PSM not found: Permission denied
Comment 7 Hans Petter Selasky freebsd_committer 2015-10-20 08:00:47 UTC
(In reply to Lars Engels from comment #5)
Hi,

Possibly 48000 is not supported. Try 44100. Or add debug prints in the "avdtpAutoConfig" function.

--HPS
Comment 8 Hans Petter Selasky freebsd_committer 2015-10-20 08:02:42 UTC
(In reply to Tony Narlock from comment #6)

Hi,

This error code, simply means the speaker and BT dongle are not properly paired.

Try experimenting with /etc/bluetooth/hcsecd.conf and ensure the hcsecd daemon is started.

virtual_oss: Could not connect to HC: Input/output error

--HPS
Comment 9 Lars Engels freebsd_committer 2015-10-20 08:40:45 UTC
BTW I used erdgeist's bluetooth-config script from https://reviews.freebsd.org/D3778 to pair with the speaker. Works pretty well!
Comment 10 Tony Narlock 2015-10-20 18:26:08 UTC
(In reply to Lars Engels from comment #9)

Lars, that script was excellent.  Is there a bugzilla tracker ticket for that?
Comment 11 Tony Narlock 2015-10-20 19:22:10 UTC
(In reply to Hans Petter Selasky from comment #7)

Thank you. I'm getting the "AUTOCONFIG FAILED" error now.

Trying with 44100 doesn't help. I am new to gdb, but tried giving that a go too.

It seems that AutoConfig never gets passed avdtpGetCapabilities.

avdtpCheckResponse ends up skipping `else if ((len % AVDTP_LEN_SUCCESS) 2, len - 2)` and returning response_invalid.

(gdb) info args
recvfd = <value optimized out>
trans = <value optimized out>
signalId = 1
pkt_type = (int *) 0xac2060d861b6f7f9
data = (uint8_t *) 0x7fffffffe0e0 " áÿÿ\005"
datasize = (size_t *) 0x7fffffffe0d8
(gdb) info locals
buffer = 0x7fffffffe040 "2\001\024\b\004\b"
len = 6

data: 140737488347312
datasize: 140737488347296
Comment 12 Hans Petter Selasky freebsd_committer 2015-10-20 19:31:54 UTC
(In reply to Tony Narlock from comment #11)
Could you try to just fake a "return (0);" instead of "return (EINVAL);" for now and see if you get further?
Comment 13 Lars Engels freebsd_committer 2015-10-20 20:18:13 UTC
(In reply to Hans Petter Selasky from comment #12)
At least for me s/EINVAL/0/ doesn't change anything.
Comment 14 Hans Petter Selasky freebsd_committer 2015-10-20 20:20:57 UTC
(In reply to Lars Engels from comment #13)
Right. I'm not an SDP expert. What you could do is to dump that buffer in GDB like this:

print /x buffer

So that it shows in HEX instead of a string. Maybe someone here knows what's wrong. The SDP code was copied from the one provided by NetBSD.
Comment 15 Tony Narlock 2015-10-21 22:29:46 UTC
(In reply to Hans Petter Selasky from comment #14)

Like this?

(lldb) frame v  buffer -f hex
(uint8_t [64]) buffer = {
  [0] = 0x40
  [1] = 0x02
  [2] = 0x14
  [3] = 0x08
  [4] = 0x04
  [5] = 0x08
  [6] = 0x00
  [7] = 0x00
  [8] = 0x2f
  [9] = 0x69
  [10] = 0x6b
  [11] = 0x01
  [12] = 0x08
  [13] = 0x00
  [14] = 0x00
  [15] = 0x00
  [16] = 0x1b
  [17] = 0x60
  [18] = 0xdc
  [19] = 0x01
  [20] = 0x08
  [21] = 0x00
  [22] = 0x00
  [23] = 0x00
  [24] = 0x07
  [25] = 0x00
  [26] = 0x00
  [27] = 0x1e
  [28] = 0x00
  [29] = 0x1b
  [30] = 0x00
  [31] = 0x00
  [32] = 0x48
  [33] = 0xe1
  [34] = 0xff
  [35] = 0xff
  [36] = 0xff
  [37] = 0x7f
  [38] = 0x00
  [39] = 0x00
  [40] = 0x07
  [41] = 0x00
  [42] = 0x00
  [43] = 0x00
  [44] = 0x00
  [45] = 0x00
  [46] = 0x00
  [47] = 0x00
  [48] = 0xa0
  [49] = 0xe1
  [50] = 0xff
  [51] = 0xff
  [52] = 0xff
  [53] = 0x7f
  [54] = 0x00
  [55] = 0x00
  [56] = 0xe9
  [57] = 0x9a
  [58] = 0xe4
  [59] = 0x00
  [60] = 0x08
  [61] = 0x00
  [62] = 0x00
  [63] = 0x00
}
Comment 16 Tony Narlock 2015-10-21 22:30:53 UTC
Are either of you two on IRC?

Lars to confirm, you're getting the same issue still?

    AUTOCONFIG FAILED: No error: 0
Comment 17 Lars Engels freebsd_committer 2015-10-22 10:31:20 UTC
(In reply to Tony Narlock from comment #16)
Yes, no news unfortunately.
Comment 18 Hans Petter Selasky freebsd_committer 2015-10-26 07:59:42 UTC
(In reply to Tony Narlock from comment #15)
Could you SVN up and recompile and try again?

I've received a small patch from Nathanial Sloss.
Comment 19 Tony Narlock 2015-10-26 10:50:30 UTC
(In reply to Hans Petter Selasky from comment #18)

Interesting, with the new revision:

I got the same results as before for a few attempts. I forgot to do the 'sysctl hw.snd.basename_clone=1'

Then after switching it to 0, I now get this:

./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -R /dev/null -P /dev/bluetooth/00:16:94:14:13:ae -d dsp

virtual_oss: DSP: Could not create '/dev/dsp'

Could I be forgetting something? 

# freebsd-version; uname -a
11.0-CURRENT
FreeBSD z600 11.0-CURRENT FreeBSD 11.0-CURRENT #4: Sun Oct 25 08:00:14 CDT 2015     root@z600:/usr/obj/usr/src/sys/MYKERNEL  amd64

Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
urbanite              12  ACL    0 MAST    NONE       0     0 OPEN
Comment 20 Hans Petter Selasky freebsd_committer 2015-10-26 11:06:06 UTC
(In reply to Tony Narlock from comment #19)
Hi,

Ensure "sysctl hw.snd.basename_clone=0", or use another device name -d dsp.bt

Also check that other instances of virtual_oss are killed.

--HPS
Comment 21 Tony Narlock 2015-11-03 13:41:06 UTC
(In reply to Hans Petter Selasky from comment #20)
I tried again on revision 3644.

Continue to get the AUTOCONFIG FAILED.

I'm still pretty interested in getting this working.  I'm going to dig a bit more into cuse and OSS myself.

Does anyone know any good overviews on that part of the codebase?
Comment 22 Hans Petter Selasky freebsd_committer 2015-11-03 13:52:14 UTC
Everything Bluetooth related is in backend_bt/*.[ch]
Comment 23 Hans Petter Selasky freebsd_committer 2015-11-16 08:38:49 UTC
Forwarding message from Nathanial Sloss:

> AFAICT the only reason as to why auto config would fail would be if the max
> bitpool value that is calculated is smaller than the minimum bit pool value.
> 
> This is possibile on some headphones/speakers bta2dpd has the -B switch so the
> user can set the max bitpool value.  Is there hci dump on freebsd as seeing
> the output of getConfiguration will confirm this.  Otherwize increasing
> DEFAULT_MAXBITPOOL from 80 to say 160 in sbc_encode.h might work for his
> headphones but I am at a loss as to whether this will effect others.  The
> problem stems from the fact that different manufacturers specify different
> encoding ranges and I've made it use the highest possible value as this will
> give the best quality but in some cases the headphones will report a bitpool
> range of 2-253 but if you encode the audio at 253 you wont get any playback
> and most android/linux will just use 36 and this wont work with some
> headphones or sound bad.

Tony: Could you try to change the definition of DEFAULT_MAXBITPOOL?

--HPS
Comment 24 Tony Narlock 2015-11-24 02:39:00 UTC
(In reply to Hans Petter Selasky from comment #23)

Sorry for the late response.


I tried 40, 160, 253 and 500.

Unfortunately, same results.
Comment 25 Hans Petter Selasky freebsd_committer 2015-12-22 22:57:48 UTC
Hi Tone,

Can you SVN up and try the latest version of virtual_oss? I've tried to add support for MPEG-2 AAC-LC which some audio headsets use. Some RTP framing bits are missing, so at least mine doesn't produce sound, but does transfer the payload data.

Maybe someone wants to help out?

--HPS
Comment 26 Hans Petter Selasky freebsd_committer 2015-12-22 23:13:44 UTC
Forgot to say: You'll need to install libsamplerate and libfaac .

--HPS
Comment 27 Hans Petter Selasky freebsd_committer 2015-12-23 14:24:10 UTC
A closer look reveals that the codec is called aac_latm and is supported by ffmpeg. Looks like lib faac won't produce the correct data. Will look more at this after x-mas. Feel free to send me patches.
Comment 28 Adrian Chadd freebsd_committer 2016-06-04 08:06:46 UTC
Two problems:

* it's choppy on atheros bluetooth with -s 1024, I need -s 4096 for it to not sound choppy. it sonuds like wifi beacons are interfering but it happens when I disable beacons/wifi!

* I can't talk to a pair of B&W P5 headphones:

root@gertrude:/home/adrian/svn/virtual_oss # ./run ubt0hci ec:66:d1:83:e5:22
hw.snd.basename_clone: 0 -> 1
hw.snd.basename_clone: 1 -> 0
backend_bt: 0x1 0x0 0x7 0x9 0x0 0xff
backend_bt: 0x7 0x9 0x0 0xff 0x4f 0x0
backend_bt: 0x4 0x2 0x2 0x0 0x0 0x0
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x12, freq=3, chmode=2
backend_bt: 0x1 0x0 0x7 0x9 0x0 0xff
backend_bt: 0x7 0x9 0x0 0xff 0x4f 0x0
backend_bt: 0x4 0x2 0x2 0x0 0x0 0x0
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x18, freq=3, chmode=0
backend_bt: AUTOCONFIG FAILED
backend_bt: 0x1 0x0 0x7 0x9 0x0 0xff
backend_bt: 0x7 0x9 0x0 0xff 0x4f 0x0
backend_bt: 0x4 0x2 0x2 0x0 0x0 0x0
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x12, freq=3, chmode=2
backend_bt: 0x1 0x0 0x7 0x9 0x0 0xff
backend_bt: 0x7 0x9 0x0 0xff 0x4f 0x0
backend_bt: 0x4 0x2 0x2 0x0 0x0 0x0
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x18, freq=3, chmode=0
backend_bt: AUTOCONFIG FAILED

..
Comment 29 Adrian Chadd freebsd_committer 2016-06-04 08:20:38 UTC
It's odd; it's decoding it as "codecType 0xff" and then "contentprotection", with no SBC codec. What's the story? I thought SBC was mandated.
Comment 30 Adrian Chadd freebsd_committer 2016-06-04 08:41:20 UTC
I hacked on the negotiation bits after reading the spec.

The spec mandates SBC, but the initial config fetch doesn't return SBC. It's returning some non-mandatory codec. I'm not sure if we have to ask it another way or not.

I overrode some things, and it fails the set_configuration call, but the headset makes the "i'm ready!" noise. So something's happening.

backend_bt: media: 0x4
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x12, freq=3, chmode=2
backend_bt: sending config: freq=12, blk=15, supmin=23, supmax=23
backend_bt: OPEN FAILED
backend_bt: info: len=19
backend_bt: i=2: 0x1 0x0 0x7 0x9 0x0 0xff
backend_bt: media: 0x1
backend_bt: i=4: 0x7 0x9 0x0 0xff 0x4f 0x0
backend_bt: media: 0x7
backend_bt: codec : 0xff
backend_bt: i=15: 0x4 0x2 0x2 0x0 0x0 0x0
backend_bt: media: 0x4
backend_bt: No frequency and mode match (avail=0x00 freqmode=0x12, freq=3, chmode=2
backend_bt: sending config: freq=12, blk=15, supmin=23, supmax=23
backend_bt: OPEN FAILED
^C

I'll read the error values back from the call soon and see what's going on.
Comment 31 Hans Petter Selasky freebsd_committer 2016-06-04 11:20:53 UTC
Some headsets use mpeg4. I need some help to support that.

--HPS
Comment 32 Alexey Dokuchaev freebsd_committer 2016-07-16 18:28:00 UTC
(In reply to Hans Petter Selasky from comment #3)

These instructions worked perfectly for my combination of FreeBSD 8.4 and Leme EB30A headphones.  However, music playback has occasional hiccups despite unloaded CPU and that distance between devices was minimal and unobstructed; any ideas what might be causing them?  (They do not occur when feeding sound from a smartphone AFAICT.)

Another issue I had was with volume control.  By default it is set to 128 (returned correctly by issuing SNDCTL_DSP_GETPLAYVOL ioctl() call), and looking at virtual-oss code it should support SNDCTL_DSP_SETPLAYVOL as well, but it didn't for me (volume always remains 128).

Apart of that, great work Hans, thanks!
Comment 33 Hans Petter Selasky freebsd_committer 2016-09-16 17:17:59 UTC
Hi,

I've just updated virtual OSS and figured out why SBC was not selected for my MP4 headset. Patches are in my I4B SVN. Can you refresh the sources and try again. Also the volume control has not a maximum of 100 instead of 128.

--HPS
Comment 34 Hans Petter Selasky freebsd_committer 2016-11-06 19:29:45 UTC
Hi,

virtual_oss is now in ports, see audio/virtual_oss .

--HPS
Comment 35 Henry Hu 2016-12-28 03:49:37 UTC
I tried this on a Logitech UE Mobile Boombox and it works well. To make it coexist with other devices, I use dsp3 as the device name.
The new device is not automatically detected by pulseaudio. To make it available for use in firefox, I run

> pacmd load-module /usr/local/lib/pulse-9.0/modules/module-oss.so device=/dev/dsp3

The log message says:

Dec 27 22:45:25 pepsi pulseaudio[62731]: [(null)] oss-util.c: device doesn't support 44100 Hz, changed to 48000 Hz.
Dec 27 22:45:25 pepsi pulseaudio[62731]: [(null)] source.c: Default and alternate sample rates are the same.
Dec 27 22:45:25 pepsi pulseaudio[62731]: [(null)] sink.c: Default and alternate sample rates are the same.
Dec 27 22:45:25 pepsi pulseaudio[62731]: [(null)] oss-util.c: Failed to open mixer '/dev/dsp3': -^VM-^G件-^HM-^V-^[-^U-^M-^X-^\

Then I can use pavucontrol to switch firefox's output to /dev/dsp3, and now firefox uses it as sound output.

Thank you for the great work!
Comment 36 js 2017-01-06 04:28:56 UTC
This is great!  With 11.0, A2DP is working perfectly with iwn wireless device and OontZ XL speaker.  Thank you!
Comment 37 vermaden 2018-04-01 00:46:22 UTC
Hi,

I tried to pair with Dell AD211 Bluetooth Speaker but I am not able to get the /dev/bluetooth/xx:xx:xx:xx:xx:xx device ...

This is this speaker:
https://downloads.dell.com/manuals/all-products/esuprt_electronics/esuprt_speakers/dell-ad211_user%27s%20guide_en-us.pdf

This is 11.1-RELEASE with GENERIC kernel and userland.

The Bluetooth device is on the ThinkPad T420s:

# kldstat -v | grep ng_ubt
38    1 0xffffffff8296f000 4f08     ng_ubt.ko (/boot/kernel/ng_ubt.ko)
                545 uhub/ng_ubt

# grep ubt /var/run/dmesg.boot
ubt0 on uhub3
ubt0: <Broadcom Corp Broadcom Bluetooth Device, class 224/1, rev 2.00/7.48, addr 4> on usbus0



Searching for device (finds the speaker):

# hccontrol -n ubt0hci inquiry
Inquiry result, num_responses=1
Inquiry result #0
        BD_ADDR: 04:fe:a1:43:7b:9b
        Page Scan Rep. Mode: 0x1
        Page Scan Period Mode: 00
        Page Scan Mode: 00
        Class: 24:04:04
        Clock offset: 0x7b8b
Inquiry complete. Status: No error [00]

# hccontrol -n ubt0hci remote_name_request 04:fe:a1:43:7b:9b
BD_ADDR: 04:fe:a1:43:7b:9b
Name: Dell Portable

# hccontrol -n ubt0hci read_connection_list
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State

# hccontrol -n ubt0hci create_connection 04:fe:a1:43:7b:9b
BD_ADDR: 04:fe:a1:43:7b:9b
Connection handle: 12
Encryption mode: Disabled [0]

# hccontrol -n ubt0hci read_connection_list                                     
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
04:fe:a1:43:7b:9b     12  ACL    0 MAST    NONE       0     0 OPEN

Connected?



I can switch role from MASTER to SLAVE.

# hccontrol -n ubt0hci Switch_Role 04:fe:a1:43:7b:9b 1
BD_ADDR: Dell_Portable
Role: Slave [0x1]

# hccontrol -n ubt0hci read_connection_list                            
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
Dell_Portable         12  ACL    0 SLAV    NONE       0     0 OPEN


I also tried this script but the effect is the same:
https://reviews.freebsd.org/file/data/zaaxr2kboxot76hf5dk4/PHID-FILE-twx4z2ngvki4pm7m6y4l/bluetooth-config


This is the config:

# cat /etc/bluetooth/hcsecd.conf
device {
        bdaddr  04:fe:a1:43:7b:9b;
        name    "Dell Portable";
        key     nokey;
        pin     "0000";
}

I also tried with "1234" an 'nopin' but no success.


Am I doing something wrong?
Comment 38 Lars Engels freebsd_committer 2019-01-11 15:58:16 UTC
FYI: The bluetooth-config script from https://reviews.freebsd.org/D3778 was now committed to HEAD and should land in 12.1.
Comment 39 Jakob Alvermark 2019-01-31 15:14:33 UTC
Hi,

I have been testing this but it can't get it to work.
Tried the version in ports:
# virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -f /dev/bluetooth/78:44:05:9b:51:aa -d dsp -T /dev/sndstat -t vdsp.ctl
hw.snd.basename_clone: 0 -> 0
backend_bt: PSM not found
backend_bt: PSM not found
backend_bt: PSM not found

And it repeats PSM not found forever.

Also tried the current version from svn://svn.turbocat.net/i4b
hw.snd.basename_clone: 0 -> 0
backend_bt: PSM=0xffffffff
backend_bt: PSM not found
backend_bt: PSM=0xffffffff
backend_bt: PSM not found


I have both a bluetooth speaker and a headset, same thing happens with both.
Comment 40 Hans Petter Selasky freebsd_committer 2019-01-31 15:40:58 UTC
Try:

virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -P /dev/bluetooth/78:44:05:9b:51:aa -R /dev/null -d dsp -T /dev/sndstat -t vdsp.ctl

If your device doesn't support SBC recording it won't work with -f.

--HPS
Comment 41 Jakob Alvermark 2019-01-31 19:11:44 UTC
(In reply to Hans Petter Selasky from comment #40)
> Try:
> 
> virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -P
> /dev/bluetooth/78:44:05:9b:51:aa -R /dev/null -d dsp -T /dev/sndstat -t
> vdsp.ctl
> 
> If your device doesn't support SBC recording it won't work with -f.
> 
> --HPS

Yes, thanks. That works for the speaker. The headset still refuses to work.

I expected /dev/sndstat to change but it doesn't:
# cat /dev/sndstat 
Installed devices:
pcm0: <Realtek ALC283 (Analog 2.0+HP/2.0)> (play/rec) default
pcm1: <Intel (0x2882) (HDMI/DP 8ch)> (play)
No devices installed from userspace.

Also it might be a good idea to restore hw.snd.basename_clone upon exit?
Comment 42 Hans Petter Selasky freebsd_committer 2019-01-31 19:26:24 UTC
Yes, I might want to add an atexit() rule for that. Feel free to make a patch and submit it at github.com/hselasky .

Some headsets use Bluetooth SCO for transport and need a bunch of AT commands before they work. This is currently not supported.

--HPS
Comment 43 Hans Petter Selasky freebsd_committer 2019-02-09 10:37:35 UTC
Hi,

There has been some updates to sdpd in -current and virtual_oss has a new utility called virtual_bt_speaker, which can sink sound.

https://github.com/hselasky/virtual_oss

--HPS
Comment 44 Hans Petter Selasky freebsd_committer 2019-02-09 10:43:20 UTC
Before trying the latest virtual_oss you need to rebuild:

1) libsdp
2) sdpd

Does not work with iOS yet. If someone wants to work on that you can send me patches.
Comment 45 Joshua Rogers 2019-04-02 14:00:27 UTC
Hi all,

I've been following bt support for FreeBSD for quite some time now, but only just found this bug report. Good job to those that got it all working!

I've followed the instructions throughout this bug report, and in conjunction with ath3k-firmware (I've got an AR9565), finally got bluetooth at least activating, and pairing with my headphones.

However, getting any audio playing through them hasn't been successful so far:
http://paste.pr0.tips/A3

It seems as if the headphones are paired correctly, before and after attempting to use virtual_oss.

Any tips would be helpful!

Cheers
Comment 46 Hans Petter Selasky freebsd_committer 2019-04-02 14:24:13 UTC
Hi,

Did you try:

hccontrol -n ubt0hci write_authentication_enable 1

Before connecting?

BTW: Virtual OSS in ports now has all the latest BT support. If you want BT server you need to build from source.

--HPS
Comment 47 Joshua Rogers 2019-04-02 14:30:55 UTC
(In reply to Hans Petter Selasky from comment #46)

>hccontrol -n ubt0hci write_authentication_enable 1

Trying that and then trying to connect, I get the error message:

$ sudo hccontrol -n ubt0hci create_connection  50:1a:xx:xx:xx:xx
Status: Pairing not allowed [0x18]
Comment 48 Hans Petter Selasky freebsd_committer 2019-04-02 14:39:13 UTC
What pin-code did you set? Try 1234 or 0000 explicitly.

--HPS
Comment 49 Joshua Rogers 2019-04-02 15:06:25 UTC
Getting a bit further now.

$ sudo ./virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -P /dev/bluetooth/50:1a:xx:xx:xx:xx -R /dev/null -d dsp
hw.snd.basename_clone: 0 -> 0
backend_bt: PSM=0x19
Alarm clock

But no audio.

Thanks for all the help!
Comment 50 Hans Petter Selasky freebsd_committer 2019-04-02 15:11:18 UTC
Can you compile virtual_oss with debug support and try again?

My guess is the device doesn't respond to one of the A2DP commands.

--HPS
Comment 51 Joshua Rogers 2019-04-02 15:21:53 UTC
Minor success: my speaker works completely!

However, my headphones are the issue at the moment.

Using /usr/ports/audio/virtual_oss, compiling in debug mode gives no different result. Using virtual_oss.debug from your github doesn't work at all: bash: ./virtual_oss.debug: cannot execute binary file: Exec format error
Comment 52 Hans Petter Selasky freebsd_committer 2019-04-02 15:53:23 UTC
HI,

You might want to single step and backtrace from GDB the following line of code:

backend_bt/avdtp.c:	alarm(8);			/* set timeout */

To figure out which command fails.

You can also try to install and run:

virtual_bt_speaker -d /dev/dspXXX

Some A2DP devices try to connect back.

There is also hcidump in ports, which gives you a .pcap file suitable for opening with wireshark. This will reveal where the protocol stops.

--HPS
Comment 53 Joshua Rogers 2019-04-02 17:05:43 UTC
From wireshark:

It seems that it's an issue with PSM ( https://i.imgur.com/5uL2eq7.png ):

42	0.870566	localhost ()	GnNetcom_96:9d:39 ()	L2CAP	21	Sent Connection Response - Refused - PSM not supported (SCID: 0x0980)

A full pcap file can be downloaded here: https://pcap.honeynet.org.my/v1/submission/view.php?id=1602.php

I can't install gdb at the moment, and virtual_bt_speaker errors while compiling: http://paste.pr0.tips/Io

Given that it talks about PSM, I would guess that indeed it is trying to connect back. I guess it makes sense, since this pair of headphones integrates with Google Assistant.
Comment 54 xbs 2019-09-02 07:09:05 UTC
Same PSM issues here. 

I'm on FreeBSD xxxx 12.0-RELEASE-p4 FreeBSD 12.0-RELEASE-p4 GENERIC  amd64. 

My Headset is a YAMAY BH-M20. The user manual says it was capable of A2DP and AVRCP. 

Aug 31 17:12:33 xxxx kernel: ubt0: <Broadcom Corp BCM20702A0, rev 2.00/1.12, addr 5> on usbus0

I can't connect hccontrol-wise but also get the PSM errors mentioned above when trying 
virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -f /dev/bluetooth/00:6a:8e:17:3d:d4 -d dsp.bt

regards
Tom
Comment 55 xbs 2019-09-02 07:11:14 UTC
(In reply to xbs from comment #54)

Sorry, type mismatch:

I CAN connect hccontrol-wise but also get the PSM errors mentioned above when trying 
virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 1024 -f /dev/bluetooth/00:6a:8e:17:3d:d4 -d dsp.bt