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