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