Re4son / re4son-kernel-builder

48 stars 20 forks source link

Bluetooth on RPi0w not working with `hciattach` #7

Open mame82 opened 6 years ago

mame82 commented 6 years ago

The package https://github.com/Re4son/re4son-kernel-builder/blob/build-4.14.n/repo/pi-bluetooth_0.1.4%2Bre4son_all.deb provides the btuart bash script.

This script relies on hciattach

#!/bin/bash

if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then
    if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ] ; then
        /usr/bin/hciattach /dev/serial1 bcm43xx 3000000 flow -
    else
        /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
    fi
else
    /usr/bin/hciattach /dev/serial1 bcm43xx 460800 noflow -
fi

Starting btuart or hciattach:

/usr/bin/btuart: line 3: warning: command substitution: ignored null byte in input
/usr/bin/btuart: line 3: warning: command substitution: ignored null byte in input
bcm43xx_init
Cannot open directory '/etc/firmware': No such file or directory
Patch not found, continue anyway
Set Controller UART speed to 3000000 bit/s
Device setup complete

(seems to search firmware in /etc/firmware)

The dmesg output after starting btuart

[  120.348455] Bluetooth: HCI UART driver ver 2.3
[  120.350275] Bluetooth: HCI UART protocol H4 registered
[  120.352063] Bluetooth: HCI UART protocol Three-wire (H5) registered
[  120.363333] Bluetooth: HCI UART protocol Broadcom registered
[  128.837286] uart-pl011 20201000.serial: no DMA platform data
[  129.433063] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[  129.434732] Bluetooth: BNEP filters: protocol multicast
[  129.436473] Bluetooth: BNEP socket layer initialized

And hcitool:

root@kali:~# hcitool dev
Devices:
    hci0    AA:AA:AA:AA:AA:AA

fix:

The Bluez version used by Kali with your kernel relies on btattach

root@kali:~# uname -a
Linux kali 4.14.62-Re4son+ #1 Wed Oct 10 13:37:15 CEST 2018 armv6l GNU/Linux
root@kali:~# bluetoothd --version
5.50

After disabling the hciuart service (and reboot), this call allows to create a working hci device:

btattach -B /dev/ttyAMA0 -P bcm -S 3000000

Respective dmesg output

[   46.435928] Bluetooth: HCI UART driver ver 2.3
[   46.437786] Bluetooth: HCI UART protocol H4 registered
[   46.439580] Bluetooth: HCI UART protocol Three-wire (H5) registered
[   46.453300] Bluetooth: HCI UART protocol Broadcom registered
[   46.597159] Bluetooth: hci0: BCM: chip id 94
[   46.601147] Bluetooth: hci0: BCM: features 0x2e
[   46.629722] Bluetooth: hci0: BCM43430A1
[   46.632006] Bluetooth: hci0: BCM43430A1 (001.002.009) build 0000
[   50.415292] Bluetooth: hci0: BCM (001.002.009) build 0360
[   51.009860] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   51.011654] Bluetooth: BNEP filters: protocol multicast
[   51.016651] Bluetooth: BNEP socket layer initialized

... and hcitool output

root@kali:~# hcitool dev
Devices:
    hci0    B8:27:EB:EA:03:83

Additionally btattach deploys the hci_uart module if needed, this didn't work for me wit hciattach.

mame82 commented 6 years ago

A fixed version of btuart, which works for me on Pi0w:

#!/bin/bash

if [ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ] ; then
    if [ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ] ; then
#       /usr/bin/hciattach /dev/serial1 bcm43xx 3000000 flow -
        /usr/bin/btattach -B /dev/ttyAMA0 -P bcm -S 3000000
    else
        /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
    fi
else
    /usr/bin/hciattach /dev/serial1 bcm43xx 460800 noflow -
fi