Add scripts to automatically btattach serial-port / uart connected

Broadcom HCIs found on some Atom based x86 hardware
This commit is contained in:
Hans de Goede 2017-09-07 20:51:51 +02:00
parent 4730eabcd1
commit 9089a629a1
4 changed files with 88 additions and 1 deletions

33
69-btattach-bcm.rules Normal file
View File

@ -0,0 +1,33 @@
# Some devices have a bluetooth HCI connected to an uart, these needs to be
# setup by calling btattach. The systemd btattach-bcm.service takes care of
# this. These udev rules hardware-activate that service when necessary.
#
# For now this only suports ACPI enumerated Broadcom BT HCIs.
# This has been tested on Bay and Cherry Trail devices with both ACPI and
# PCI enumerated UARTs.
# Note we check for the platform device not for the acpi device, because
# some DSDTs list multiple bluetooth adapters, but only some (or none)
# are enabled. Only enabled adapters get a platform device created.
ACTION!="add", GOTO="btattach_bcm_rules_end"
SUBSYSTEM!="platform", GOTO="btattach_bcm_rules_end"
KERNEL=="BCM2E1A:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E39:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E3A:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E3D:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E3F:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E40:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E54:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E55:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E64:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E65:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E67:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E71:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E7B:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E7C:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E7E:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E95:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
KERNEL=="BCM2E96:00", TAG+="systemd", ENV{SYSTEMD_WANTS}="btattach-bcm@%k.service"
LABEL="btattach_bcm_rules_end"

View File

@ -1,13 +1,19 @@
Name: bluez Name: bluez
Summary: Bluetooth utilities Summary: Bluetooth utilities
Version: 5.46 Version: 5.46
Release: 4%{?dist} Release: 5%{?dist}
License: GPLv2+ License: GPLv2+
URL: http://www.bluez.org/ URL: http://www.bluez.org/
Source0: http://www.kernel.org/pub/linux/bluetooth/bluez-%{version}.tar.xz Source0: http://www.kernel.org/pub/linux/bluetooth/bluez-%{version}.tar.xz
Source1: bluez.gitignore Source1: bluez.gitignore
# Scripts for automatically btattach-ing serial ports connected to Broadcom HCIs
# as found on some Atom based x86 hardware
Source2: 69-btattach-bcm.rules
Source3: btattach-bcm@.service
Source4: btattach-bcm-service.sh
# https://github.com/hadess/bluez/commits/build-fixes-5.46 # https://github.com/hadess/bluez/commits/build-fixes-5.46
Patch0: 0001-build-Enable-BIND_NOW.patch Patch0: 0001-build-Enable-BIND_NOW.patch
Patch1: 0002-obexd-Fix-compilation-error-on-F27.patch Patch1: 0002-obexd-Fix-compilation-error-on-F27.patch
@ -162,6 +168,11 @@ mkdir -p $RPM_BUILD_ROOT/%{_libdir}/bluetooth/
install -D -p -m0644 src/main.conf ${RPM_BUILD_ROOT}/etc/bluetooth/main.conf install -D -p -m0644 src/main.conf ${RPM_BUILD_ROOT}/etc/bluetooth/main.conf
sed -i 's/#\[Policy\]$/\[Policy\]/; s/#AutoEnable=false/AutoEnable=true/' ${RPM_BUILD_ROOT}/%{_sysconfdir}/bluetooth/main.conf sed -i 's/#\[Policy\]$/\[Policy\]/; s/#AutoEnable=false/AutoEnable=true/' ${RPM_BUILD_ROOT}/%{_sysconfdir}/bluetooth/main.conf
#serial port connected Broadcom HCIs scripts
install -D -p -m0644 %{SOURCE2} ${RPM_BUILD_ROOT}/%{_udevrulesdir}/
install -D -p -m0644 %{SOURCE3} ${RPM_BUILD_ROOT}/%{_unitdir}/
install -D -p -m0755 %{SOURCE4} ${RPM_BUILD_ROOT}/%{_libexecdir}/bluetooth/
%post libs -p /sbin/ldconfig %post libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig %postun libs -p /sbin/ldconfig
@ -221,10 +232,13 @@ sed -i 's/#\[Policy\]$/\[Policy\]/; s/#AutoEnable=false/AutoEnable=true/' ${RPM_
%{_mandir}/man1/rctest.1.* %{_mandir}/man1/rctest.1.*
%{_mandir}/man8/* %{_mandir}/man8/*
%{_libexecdir}/bluetooth/bluetoothd %{_libexecdir}/bluetooth/bluetoothd
%{_libexecdir}/bluetooth/btattach-bcm-service.sh
%{_libdir}/bluetooth/ %{_libdir}/bluetooth/
%{_localstatedir}/lib/bluetooth %{_localstatedir}/lib/bluetooth
%{_datadir}/dbus-1/system-services/org.bluez.service %{_datadir}/dbus-1/system-services/org.bluez.service
%{_unitdir}/bluetooth.service %{_unitdir}/bluetooth.service
%{_unitdir}/btattach-bcm@.service
%{_udevrulesdir}/69-btattach-bcm.rules
%files libs %files libs
%{!?_licensedir:%global license %%doc} %{!?_licensedir:%global license %%doc}
@ -251,6 +265,10 @@ sed -i 's/#\[Policy\]$/\[Policy\]/; s/#AutoEnable=false/AutoEnable=true/' ${RPM_
%{_userunitdir}/obex.service %{_userunitdir}/obex.service
%changelog %changelog
* Thu Sep 07 2017 Hans de Goede <hdegoede@redhat.com> - 5.46-5
- Add scripts to automatically btattach serial-port / uart connected
Broadcom HCIs found on some Atom based x86 hardware
* Mon Sep 04 2017 Bastien Nocera <bnocera@redhat.com> - 5.46-4 * Mon Sep 04 2017 Bastien Nocera <bnocera@redhat.com> - 5.46-4
+ bluez-5.46-4 + bluez-5.46-4
- Patches cleanup - Patches cleanup

30
btattach-bcm-service.sh Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# Simple shell script to wait for the tty for an uart using BT HCI to show up
# and then invoke btattach with the right parameters, this is intended to be
# invoked from a hardware-activated systemd service
#
# For now this only suports ACPI enumerated Broadcom BT HCIs.
# This has been tested on Bay and Cherry Trail devices with both ACPI and
# PCI enumerated UARTs.
#
# Note the kernel bt developers are working on solving this entirely in the
# kernel, so it is not worth the trouble to write something better then this.
BT_DEV="/sys/bus/platform/devices/$1"
BT_DEV="$(readlink -f $BT_DEV)"
UART_DEV="$(dirname $BT_DEV)"
# Stupid GPD-pocket has USB BT with id 0000:0000, but still claims to have
# an uart attached bt
if [ "$1" = "BCM2E7E:00" ] && lsusb | grep -q "ID 0000:0000"; then
exit 0
fi
while [ ! -d "$UART_DEV/tty" ]; do
sleep .2
done
TTY="$(ls $UART_DEV/tty)"
exec btattach --bredr "/dev/$TTY" -P bcm

6
btattach-bcm@.service Normal file
View File

@ -0,0 +1,6 @@
[Unit]
Description=btattach for Broadcom devices
[Service]
Type=simple
ExecStart=/usr/libexec/bluetooth/btattach-bcm-service.sh %I