Skip to content
Snippets Groups Projects
Verified Commit dd7dd584 authored by Clayton Craft's avatar Clayton Craft :speech_balloon:
Browse files

Add retry mechnism for setting BT MAC addr

This replaces 3bfb183f with a retry mechanism, where the BT mac is
(re)tried every 1 second for up to 5 seconds (configurable).

If this doesn't play nicely with udev rules when using RUN, BT_TIMEOUT
can be set in the env.
parent 3ff0f370
No related branches found
No related tags found
No related merge requests found
Pipeline #214046 passed
......@@ -16,6 +16,7 @@ WLAN_INTERFACE="wlan0"
BT_INTERFACE="hci0"
# Default MAC prefix
MAC_PREFIX="0200"
BT_TIMEOUT=${BT_TIMEOUT:-5} # seconds
log() {
echo "$@" | logger -t "bootmac"
......@@ -141,9 +142,6 @@ mac_generate() {
}
mac_bluetooth() {
# Some Bluetooth adapters take time before they can be configured
sleep 1
log "setting Bluetooth MAC to $BT_MAC"
# Check if the Bluetooth interface is up
......@@ -162,7 +160,24 @@ mac_bluetooth() {
# The 'yes | btmgmt xxx' workaround is needed for proper working of btmgmt
# as noted in https://gitlab.com/postmarketOS/bootmac/-/issues/3
yes | btmgmt -i "$BT_INTERFACE" power off
yes | btmgmt -i "$BT_INTERFACE" public-addr "$BT_MAC"
# Setting the mac addr might fail if the device/driver hasn't finished
# initializing, so retry
timeout=0
while [ $timeout -lt "$BT_TIMEOUT" ]; do
if yes | btmgmt -i "$BT_INTERFACE" public-addr "$BT_MAC"; then
break
fi
echo "Unable to set Bluetooth MAC, retrying after 1 second..."
sleep 1
timeout=$((timeout + 1))
done
if [ $timeout -ge "$BT_TIMEOUT" ]; then
echo "Failed to set Bluetooth MAC address, command timed out after $BT_TIMEOUT seconds"
return 1
fi
if [ -n "$BT_RFKILL_UNBLOCKED" ]; then
log "restoring Bluetooth rfkill state to unblocked"
rfkill unblock bluetooth
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment