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