Bluetooth absence no longer generates panic action

This commit is contained in:
Calin Crisan 2019-09-11 22:51:51 +03:00
parent c1de43870b
commit 949bc964b8
4 changed files with 48 additions and 39 deletions

View File

@ -10,6 +10,7 @@ PROG="/usr/libexec/bluetooth/bluetoothd"
PROG_HC="/usr/bin/hciconfig" PROG_HC="/usr/bin/hciconfig"
DATA_DIR="/var/lib/bluetooth" DATA_DIR="/var/lib/bluetooth"
RUN_DATA_DIR="/data/bluetooth" RUN_DATA_DIR="/data/bluetooth"
NO_ON_BOARD_BT="/tmp/.no_on_board_bt" # used by RPi to explicitly indicate that no on-board BT was detected
test -x ${PROG} || exit 0 test -x ${PROG} || exit 0
@ -40,14 +41,16 @@ start() {
# wait up to 10 seconds for device # wait up to 10 seconds for device
count=0 count=0
while ! ${PROG_HC} ${ADAPTER} &>/dev/null; do while ! ${PROG_HC} ${ADAPTER} &>/dev/null; do
sleep 1 # on RPi boards, the absence of an on-board BT can be detected earlier, preventing 10s timeout
count=$((${count} + 1))
if [[ ${count} -ge 10 ]]; then count=$((count + 1))
if [[ ${count} -ge 10 ]] || [[ -f "${NO_ON_BOARD_BT}" ]]; then
msg_fail "no device" msg_fail "no device"
logger -t bluetooth "bluetooth device not available, calling panic action" logger -t bluetooth "bluetooth device not available"
panic_action bluetooth return 0
return 1
fi fi
sleep 1
done done
if configure; then if configure; then

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
CONF="/data/etc/bluetooth.conf" CONF="/data/etc/bluetooth.conf"
NO_ON_BOARD_BT="/tmp/.no_on_board_bt" # used by RPi to explicitly indicate that no on-board BT was detected
test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0 test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0
test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected if ! [ -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" ]; then
touch ${NO_ON_BOARD_BT}
exit 0 # no rpi bluetooth detected
fi
test -n "${OS_VERSION}" || source /etc/init.d/base test -n "${OS_VERSION}" || source /etc/init.d/base
function start() { function start() {
if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null
fi fi
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null
fi fi
} }
case "$1" in case "$1" in
start) start)
msg_begin "Attaching UART bluetooth modem" msg_begin "Attaching UART bluetooth device"
# for some reason, sometimes the hciattach command needs to be run twice start &>/dev/null &
(start || start) &>/dev/null &
msg_background msg_background
;; ;;
stop) stop)
msg_begin "Detaching UART bluetooth modem" msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
;; ;;
*) *)
echo $"Usage: $0 {start}" echo $"Usage: $0 {start|stop}"
exit 1 exit 1
esac esac
exit $? exit $?

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
CONF="/data/etc/bluetooth.conf" CONF="/data/etc/bluetooth.conf"
NO_ON_BOARD_BT="/tmp/.no_on_board_bt" # used by RPi to explicitly indicate that no on-board BT was detected
test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0 test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0
test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected if ! [ -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" ]; then
touch ${NO_ON_BOARD_BT}
exit 0 # no rpi bluetooth detected
fi
test -n "${OS_VERSION}" || source /etc/init.d/base test -n "${OS_VERSION}" || source /etc/init.d/base
function start() { function start() {
if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null
fi fi
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null
fi fi
} }
case "$1" in case "$1" in
start) start)
msg_begin "Attaching UART bluetooth modem" msg_begin "Attaching UART bluetooth device"
# for some reason, sometimes the hciattach command needs to be run twice start &>/dev/null &
(start || start) &>/dev/null &
msg_background msg_background
;; ;;
stop) stop)
msg_begin "Detaching UART bluetooth modem" msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
;; ;;
*) *)
echo $"Usage: $0 {start}" echo $"Usage: $0 {start|stop}"
exit 1 exit 1
esac esac
exit $? exit $?

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf" SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/bluetooth.conf" BOOT_CONF="/boot/bluetooth.conf"
CONF="/data/etc/bluetooth.conf" CONF="/data/etc/bluetooth.conf"
NO_ON_BOARD_BT="/tmp/.no_on_board_bt" # used by RPi to explicitly indicate that no on-board BT was detected
test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0 test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0
test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected if ! [ -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" ]; then
touch ${NO_ON_BOARD_BT}
exit 0 # no rpi bluetooth detected
fi
test -n "${OS_VERSION}" || source /etc/init.d/base test -n "${OS_VERSION}" || source /etc/init.d/base
function start() { function start() {
if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null
fi fi
else else
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null /usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null
fi fi
} }
case "$1" in case "$1" in
start) start)
msg_begin "Attaching UART bluetooth modem" msg_begin "Attaching UART bluetooth device"
# for some reason, sometimes the hciattach command needs to be run twice start &>/dev/null &
(start || start) &>/dev/null &
msg_background msg_background
;; ;;
stop) stop)
msg_begin "Detaching UART bluetooth modem" msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail test $? == 0 && msg_done || msg_fail
;; ;;
*) *)
echo $"Usage: $0 {start}" echo $"Usage: $0 {start|stop}"
exit 1 exit 1
esac esac
exit $? exit $?