Bluetooth headset HSP/HFP profile issue


#1

Hello everyone,

I’m currently trying to get Bluetooth Headset audio working on my Dragonboard 410c. The Dragonboard crashes in a very unexpected way when starting a bluetooth audio stream that is HSP (headset) or HFP (handfree), in the way that the system halts for about half a second then reboots (after complaining about some HCI frame sending issues).

In the example below I’m using bluez-alsa (https://github.com/Arkq/bluez-alsa) but the same is happening when I’m trying with pulseaudio instead.

To build/install bluezalsa on a linaro dev image:

apt-get install libasound-dev libbluetooth3-dev libglib2.0-dev libsbc-dev
git clone https://github.com/Arkq/bluez-alsa.git
cd bluez-alsa && autoreconf --install
mkdir build && cd build
../configure --enable-debug
make && sudo make install

Now run bluez-alsa:

# make sure that pulseaudio is not running 
pulseaudio -k

# start blueaudio with the HSP audio gateway profile only
sudo bluealsa -p hsp-ag

In another terminal, connect with a bluetooth headset:

bluetoothctl
[bluetooth] pair XX:XX:XX:XX:XX
[bluetooth] connect XX:XX:XX:XX:XX
[bluetooth] exit

Now aplay / arecord something:

aplay -D bluealsa:HCI=hci0,DEV=XX:XX:XX:XX:XX:XX,PROFILE=sco piano2.wav      

Basically this is what I’m doing after a fresh boot (log from below on the Linaro 18.01 developper build, but it’s the same on a 19.01 and a self build OE-RPB with the 4.14.96 Kernel):

................. LOTS OF LOGS........
linaro-developer login: root (automatic login)

Last login: Mon Mar  4 13:31:50 UTC 2019 on ttyMSM0
Linux linaro-developer 4.14.0-qcomlt-arm64 #1 SMP PREEMPT Thu Jan 3 21:50:32 UTC 2019 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@linaro-developer:~# tail -f /var/log/messages
Mar  4 13:36:12 linaro-developer NetworkManager[1720]: <info>  [1551706572.7016] dhcp6 (enx00e04d370e3d):   nameserver 'fd00::464e:6dff:fe1b:94d4'
Mar  4 13:36:12 linaro-developer NetworkManager[1720]: <info>  [1551706572.7017] dhcp6 (enx00e04d370e3d): state changed unknown -> bound
Mar  4 13:36:12 linaro-developer NetworkManager[1720]: <info>  [1551706572.7101] dhcp6 (enx00e04d370e3d): client pid 1893 exited with status 0
Mar  4 13:36:12 linaro-developer NetworkManager[1720]: <info>  [1551706572.7102] dhcp6 (enx00e04d370e3d): state changed bound -> done
Mar  4 13:36:13 linaro-developer kernel: [   14.944502] Bluetooth: RFCOMM TTY layer initialized
Mar  4 13:36:13 linaro-developer kernel: [   14.944559] Bluetooth: RFCOMM socket layer initialized
Mar  4 13:36:13 linaro-developer kernel: [   14.948267] Bluetooth: RFCOMM ver 1.11
Mar  4 13:36:13 linaro-developer NetworkManager[1720]: <info>  [1551706573.5388] bluez5: NAP: added interface 02:00:14:E9:15:93
Mar  4 13:36:37 linaro-developer NetworkManager[1720]: <info>  [1551706597.0915] device (wlan0): supplicant interface state: starting -> down
Mar  4 13:40:56 linaro-developer NetworkManager[1720]: <warn>  [1551706856.8643] device (wlan0): re-acquiring supplicant interface (#1).
[   64.309584] random: crng init done
[   64.309668] random: 7 urandom warning(s) missed due to ratelimiting
Mar  4 13:41:12 linaro-developer kernel: [   64.309584] random: crng init done
Mar  4 13:41:12 linaro-developer kernel: [   64.309668] random: 7 urandom warning(s) missed due to ratelimiting
[   64.348488] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Mar  4 13:41:12 linaro-developer NetworkManager[1720]: <info>  [1551706872.1956] sup-iface[0xaaaaf0f64b90,wlan0]: supports 5 scan SSIDs
Mar  4 13:41:12 linaro-developer NetworkManager[1720]: <info>  [1551706872.2004] device (wlan0): supplicant interface state: starting -> ready
Mar  4 13:41:12 linaro-developer NetworkManager[1720]: <info>  [1551706872.2007] device (wlan0): state change: unavailable -> disconnected (reason 'supplicant-available', sys-iface-state: 'managed')
Mar  4 13:41:12 linaro-developer kernel: [   64.348488] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
#### NOTE FROM syteng:
#### this is the moment when the aplay/arecord command is executed
#### NOTE END
[  116.960324] Bluetooth: hci0 sending frame failed (-84)
[  116.963042] Bluetooth: hci0 sending frame failed (-84)

Format: Log Type - Time(microsec) - Message - Optional Info
Log Type: B - Since Boot(Power On Reset),  D - Delta,  S - Statistic
S - QC_IMAGE_VERSION_STRING=BOOT.BF.3.0-00288
S - IMAGE_VARIANT_STRING=HAAAANAZA
S - OEM_IMAGE_VERSION_STRING=CRM
S - Boot Config, 0x000002e1
S - Core 0 Frequency, 0 MHz
B -      1544 - PBL, Start
B -      3489 - bootable_media_detect_entry, Start
B -     69702 - bootable_media_detect_success, Start
B -     69706 - elf_loader_entry, Start
B -     71222 - auth_hash_seg_entry, Start
B -     71431 - auth_hash_seg_exit, Start
B -     86744 - elf_segs_hash_verify_entry, Start
B -    146973 - PBL, End
B -    153567 - SBL1, Start
B -    216214 - pm_device_init, Start
D -     14731 - pm_device_init, Delta
B -    231373 - boot_flash_init, Start
D -         0 - boot_flash_init, Delt
......... stop here

I tried quite a lot of things in the last few days. For example streaming music via A2DP works flawlessly. Both PA and Bluezalsa work fine when I’m relying on a USB BT dongle instead of using the Dragonboards chipset.

Any clue?


#2

Like many embedded SoC, Bluetooth SCO audio encoding is offloaded to hardware, meaning the controller does not support (well it’s maybe configurable via a Bluetooh HCI vendor command) SCO over the standard HCI interface. Audio needs to be routed instead directly to the bluetooth controller PCM/I2S interface [1]. I know it’s mostly straightforward on android: Android bluetooth HFP client on DragonBoard 410c, but I never tested this with Linux.

[1] https://bluekitchen-gmbh.com/btstack/chipsets/


#3

Thank you for the clarification Loic,

do you have any direction for me regarding the audio routing on Linux?
Eventually any clue regarding that weird crash? Could that be that the I2S signals actually get to the SoC but the pins are not configured for it?


#4

Well, you need two things:

  • having the HSP client (bluealsa, pulseaudio…) routing packet to a defined interface instead of routing to SCO/HCI. Maybe ask directly on mailing list for support (e.g. https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss)
  • Add the bt input/output audio interface which does not seem to appear in alsamixer, maybe qcom team can help here, since it request modifying msm8916 audio driver.

Not sure, It could be caused by writing to non-allowed memory area.