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"
DATA_DIR="/var/lib/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
@ -40,14 +41,16 @@ start() {
# wait up to 10 seconds for device
count=0
while ! ${PROG_HC} ${ADAPTER} &>/dev/null; do
sleep 1
count=$((${count} + 1))
if [[ ${count} -ge 10 ]]; then
# on RPi boards, the absence of an on-board BT can be detected earlier, preventing 10s timeout
count=$((count + 1))
if [[ ${count} -ge 10 ]] || [[ -f "${NO_ON_BOARD_BT}" ]]; then
msg_fail "no device"
logger -t bluetooth "bluetooth device not available, calling panic action"
panic_action bluetooth
return 1
logger -t bluetooth "bluetooth device not available"
return 0
fi
sleep 1
done
if configure; then

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/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 -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
function start() {
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
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
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
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
}
case "$1" in
start)
msg_begin "Attaching UART bluetooth modem"
# for some reason, sometimes the hciattach command needs to be run twice
(start || start) &>/dev/null &
msg_begin "Attaching UART bluetooth device"
start &>/dev/null &
msg_background
;;
stop)
msg_begin "Detaching UART bluetooth modem"
msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail
;;
*)
echo $"Usage: $0 {start}"
echo $"Usage: $0 {start|stop}"
exit 1
esac
exit $?

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/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 -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
function start() {
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
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
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
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
}
case "$1" in
start)
msg_begin "Attaching UART bluetooth modem"
# for some reason, sometimes the hciattach command needs to be run twice
(start || start) &>/dev/null &
msg_begin "Attaching UART bluetooth device"
start &>/dev/null &
msg_background
;;
stop)
msg_begin "Detaching UART bluetooth modem"
msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail
;;
*)
echo $"Usage: $0 {start}"
echo $"Usage: $0 {start|stop}"
exit 1
esac
exit $?

View File

@ -3,44 +3,46 @@
SYS_CONF="/etc/bluetooth.conf"
BOOT_CONF="/boot/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 -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
function start() {
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
/usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = "16" ]]; then
/usr/bin/hciattach -t 10 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null
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
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
}
case "$1" in
start)
msg_begin "Attaching UART bluetooth modem"
# for some reason, sometimes the hciattach command needs to be run twice
(start || start) &>/dev/null &
msg_begin "Attaching UART bluetooth device"
start &>/dev/null &
msg_background
;;
stop)
msg_begin "Detaching UART bluetooth modem"
msg_begin "Detaching UART bluetooth device"
killall hciattach &>/dev/null
test $? == 0 && msg_done || msg_fail
;;
*)
echo $"Usage: $0 {start}"
echo $"Usage: $0 {start|stop}"
exit 1
esac
exit $?