mac-address-set: Make the bt mac inverted on demand

Detecting if the mac address must be inverted means doing two resets of
the chip in a short period when the mac must be inverted.
These two resets is sometimes letting the BT chip in a state where it
does not answer for more than a minute.

Also fixes getopts string: options -w and -b don't have arguments.

BugzID: 77171
This commit is contained in:
Alexandre Bard 2022-02-03 14:52:48 +01:00
parent 7c3befb14c
commit b1540a4555
2 changed files with 13 additions and 9 deletions

View File

@ -37,6 +37,7 @@ log_level="$level_info"
eth_mac=0
set_wlan=0
set_bt=0
invert_bt_mac=0
log () {
msg_level="$1"
@ -191,8 +192,7 @@ prepare_and_set_wlan_mac_address() {
set_and_check_bt_mac_address() {
address="$1"
addr_to_set="$address" # Because of some bug the address to set may be inverted
invert="$2"
if [[ "$invert" -eq "1" ]]; then
if [[ "$invert_bt_mac" -eq "1" ]]; then
addr_to_set=$(echo "$address" | sed -r "s/^(.{2}):(.{2}):(.{2}):(.{2}):(.{2}):(.{2})/\\6:\\5:\\4:\\3:\\2:\\1/")
fi
@ -228,13 +228,8 @@ prepare_and_set_bt_mac_address() {
hciconfig hci0 up
log_info "Setting bluetooth mac address to $address"
set_and_check_bt_mac_address "$address" 0
set_and_check_bt_mac_address "$address"
ret=$?
if [ $ret -ne 0 ]; then
log_info "Trying with reversed address" # This is a bug in some systems
set_and_check_bt_mac_address "$address" 1
ret=$?
fi
return $ret
}
@ -292,17 +287,19 @@ main() {
echo " $0 -l <loglevel> # loglevel being between 0 (errors) and 2 (info)"
echo " $0 -w # set wifi address"
echo " $0 -b # set bluetooth address"
echo " $0 -i # invert bluetooth address"
echo " $0 -e <eth0 addr> # mac address input, e.g. 00:11:22:33:44:10"
exit 0
fi
while getopts l:w:b:e: option
while getopts l:wbie: option
do
case "${option}"
in
l)log_level=${OPTARG};;
w)set_wlan=1;;
b)set_bt=1;;
i)invert_bt_mac=1;;
e)eth_mac=${OPTARG};;
esac
done

View File

@ -26,11 +26,18 @@ FILES_${PN}_append = " \
/usr \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
do_install () {
install -d ${D}${systemd_unitdir}/system/
install -m 0644 wlan-address-set.service ${D}${systemd_unitdir}/system/
install -m 0644 bt-address-set.service ${D}${systemd_unitdir}/system/
# Invert BT mac for TI chips
if ${@bb.utils.contains('MACHINE_FEATURES', 'tibluetooth', 'true', 'false',d)}; then
sed -i 's/^ExecStart=.*/& -i/g' ${D}${systemd_unitdir}/system/bt-address-set.service
fi
install -d ${D}/usr/bin
install -m 0755 mac-address-set.sh ${D}/usr/bin/mac-address-set
}