Blame SOURCES/btattach-bcm-service.sh

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