diff --git a/board/common/overlay/etc/bluetooth/main.conf b/board/common/overlay/etc/bluetooth/main.conf index 42da82ff6d..cfea82441f 120000 --- a/board/common/overlay/etc/bluetooth/main.conf +++ b/board/common/overlay/etc/bluetooth/main.conf @@ -1 +1 @@ -/data/etc/bluetooth.conf \ No newline at end of file +/var/lib/bluetooth.conf \ No newline at end of file diff --git a/board/common/overlay/etc/init.d/S37bluetooth b/board/common/overlay/etc/init.d/S37bluetooth index 0266cc1a5f..22299d8cd6 100755 --- a/board/common/overlay/etc/init.d/S37bluetooth +++ b/board/common/overlay/etc/init.d/S37bluetooth @@ -18,9 +18,27 @@ test -n "$os_version" || source /etc/init.d/base hci=hci0 bluetoothd=/usr/libexec/bluetooth/bluetoothd +run_conf="/var/lib/bluetooth.conf" + +configure() { + cp $conf $run_conf + + # if no specific name configured, use hostname + if ! grep -E 'Name\s*=' $run_conf &>/dev/null; then + sed -ri "s/(\[General\])/\1\nName = $(hostname)/" /etc/bluetooth/main.conf + fi + + # bring adapter up + hciconfig $hci up + + # if DiscoverableTimeout is set to 0, make adapter is discoverable from boot time + if ! grep -E '^DiscoverableTimeout\s*=\s*0$' $run_conf &>/dev/null; then + hciconfig $hci piscan + fi +} start() { - msg_begin "Starting bluetooth" + msg_begin "Configuring bluetooth" # wait up to 10 seconds for device count=0 @@ -34,13 +52,21 @@ start() { return 1 fi done - + + if configure; then + msg_done + else + msg_fail + return 1 + fi + + msg_begin "Starting bluetoothd" /usr/libexec/bluetooth/bluetoothd &>/dev/null & msg_done } stop() { - msg_begin "Stopping bluetooth" + msg_begin "Stopping bluetoothd" killall bluetoothd &>/dev/null test $? == 0 && msg_done || msg_fail }