Blame SOURCES/btattach-bcm-service.sh

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