mac-address-set: BT: do a hard reset when soft reset fails

It happens that a soft reset is failing and blocking the chip in a state
where it always times out. The only wait to get out of this is to hard
reset the bluetooth chip.

BugzID: 77171
This commit is contained in:
Alexandre Bard 2022-02-07 19:06:41 +01:00
parent b1540a4555
commit e284973988
1 changed files with 27 additions and 2 deletions

View File

@ -189,6 +189,8 @@ prepare_and_set_wlan_mac_address() {
}
# Returns 1 in case reset failed
# Returns 2 when the address is not correct after reset
set_and_check_bt_mac_address() {
address="$1"
addr_to_set="$address" # Because of some bug the address to set may be inverted
@ -202,8 +204,12 @@ set_and_check_bt_mac_address() {
log_warning "Setting bluetooth address failed: $ret"
fi
sleep 2
log_info "Restarting bluetooth service"
hciconfig hci0 reset
if ! hciconfig hci0 reset; then
return 1
fi
systemctl restart bluetooth
sleep 1
wait_on_hci0
@ -215,7 +221,7 @@ set_and_check_bt_mac_address() {
ret=0
else
log_warning "Setting bluetooth address failed without error"
ret=1
ret=2
fi
return $ret
}
@ -234,6 +240,17 @@ prepare_and_set_bt_mac_address() {
return $ret
}
do_bt_hard_reset() {
if systemctl is-active --quiet jody-w1-bt-init; then
systemctl restart jody-w1-bt-init
elif systemctl is-active --quiet tibluetooth; then
systemctl restart tibluetooth
else
log_error "No hard reset possible"
return 1
fi
}
# VCU1 scheme, starts with 7C:97:63:
# eth0: 50:XX:YY
# wlan0: 70:XX:YY
@ -336,6 +353,14 @@ main() {
if [ $set_bt = 1 ]; then
prepare_and_set_bt_mac_address "$bt_addr"
ret_bt=$?
while [ $ret_bt -eq 1 ]; do
log_warning "Soft reset failed, doing hard reset and retrying"
do_bt_hard_reset
prepare_and_set_bt_mac_address "$bt_addr"
ret_bt=$?
done
if [ $ret_bt -ne 0 ]; then
log_error "Failed to set bluetooth mac address"
ret="$ret_bt"