Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions recipes-connectivity/bluez5/bluez5/qca_set_bdaddr.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=start set BDA script for bluetooth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve the description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, noted.

ConditionPathExists=/sys/devices/soc0/serial_number
Requires=bluetooth.service
After=bluetooth.service

[Service]
Type=simple
ExecStart=+/etc/initscripts/qca_set_bdaddr.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nack, script should be an executable available in /usr/bin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or ${sbindir}.


[Install]
WantedBy=bluetooth.target
67 changes: 67 additions & 0 deletions recipes-connectivity/bluez5/bluez5/qca_set_bdaddr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
# Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Function to format BD-Address and Set it
set_bda() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's zero error checking and handling in this method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will will error checking for each command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the entire script actually

# Read the serial number
serial_number=$(cat /sys/devices/soc0/serial_number)

# Convert to hexadecimal
hex_serial_number=$(printf '%x\n' $serial_number)

# Format the serial number
formatted_serial_number=$(echo "${hex_serial_number}" | sed 's/../&:/g;s/:$//')

# Append qualcomm general prefix BDA value 22:22
BDA=22:22:${formatted_serial_number:0:14}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bashism, will not work with posix shells

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, where does 22:22 come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we took android HAL code as reference for this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't take random unreliable sources. There are standards, owners, etc.


#After FW download completed wait for some time
sleep 1

# Pass the formatted serial number to btmgmt tool
# Start btmgmt and send commands
{
echo "public-addr $BDA"
sleep 1
} | btmgmt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it so complex? btmgmt --index 0 public-addr ${addr}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since btmgmt is interactive it is actually stuck If we directly use the command during boot in script . With above approach everytime it is working and it is not getting stuck.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read carefully what I wrote.

}


# Function to check BD Address and wait until it becomes configured or unconfigured
validate_and_set_bda() {
while true; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a fixed set of runs here, probably trying the loop for up to 5 times with a sleep 1 or similar between runs, no need for while true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure , will consider and update the iteration based on the results

# Get the BD Address
hciconfig_output=$(hciconfig)

bd_address=$(echo "$hciconfig_output" | grep 'BD Address' | awk '{print $3}')
unconfigured=$(echo "$hciconfig_output" | grep -o 'DOWN RAW')
configured=$(echo "$hciconfig_output" | grep -o 'DOWN')

# Check if the BD Address is 00:00:00:00:00:00
if [[ "$bd_address" == "00:00:00:00:00:00" ]]; then
sleep 1
elif [[ "$unconfigured" == "DOWN RAW" ]]; then
break
elif [[ "$configured" == "DOWN" ]]; then
echo "BD-Address already configured!!"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to say anything if it works as expected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noisy success messages Understood. will remove success prints

return 0
else
break
fi
done

# Call the set_bda function
set_bda
}



# Run bluetoothctl show and capture the output
bluetoothctl_output=$(bluetoothctl show)

# Check if the BD Address is valid
if echo "$bluetoothctl_output" | grep -q "No default controller available"; then
# Call the validate_and_set_bda function
validate_and_set_bda
fi
52 changes: 52 additions & 0 deletions recipes-connectivity/bluez5/bluez5_%.bbappend
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
inherit systemd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a different recipe for this, it needs bluez but there is no need to be part of it.


FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"

RRECOMMENDS:${PN} += " \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep variables sorted by usage, so R* goes below do_install, SRC* goes above do_unpack, configure vars go right above do_configure and installation vars go right above do_install.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the guidance. will reorder variables accordingly

glibc-gconv-utf-16 \
glibc-gconv-utf-32 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment, why do you need these

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will handle in different recipe and PR with updated the comment

"

SRC_URI:append = " file://qca_set_bdaddr.service \
file://qca_set_bdaddr.sh \
"

#Include obex to support obex related profiles like OPP, FTP, MAP, PBAP
RDEPENDS:${PN} += "${PN}-obex"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated. In general, such things should be split into separate commits. In this particular case it should be solved by the distro layer instead by pulling the right set of packages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will pull the commit changes related to obex tools to separate commit and PR


#Include only desired tools that are conditional on READLINE in bluez
INST_TOOLS_READLINE = " \
tools/bluetooth-player \
tools/obexctl \
tools/btmgmt \
"

#Remove desired tools from noinst-tools
NOINST_TOOLS:remove = " \
${@bb.utils.contains('PACKAGECONFIG', 'readline', '${INST_TOOLS_READLINE}', '', d)} \
"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate commit with a proper explanation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will handle in different PR


do_install:append:qcom() {

#Install desired tools that upstream leaves in build area
for f in ${INST_TOOLS_READLINE} ; do
install -m 755 ${B}/$f ${D}/${bindir}
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be patched in the upstream or in OE-Core


#Create below directory which is used by obex service
install -d ${D}${localstatedir}/bluetooth

# Install script to set unique BDA
install -d ${D}${sysconfdir}/initscripts
install -m 755 ${UNPACKDIR}/qca_set_bdaddr.sh ${D}${sysconfdir}/initscripts/

# Install service that will run qca_set_bdaddr.sh script on boot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemd.bbclass should be enabling this by default already:

# Whether to enable or disable the services on installation.
SYSTEMD_AUTO_ENABLE ??= "enable"
[...]
        if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
                for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}; do
                        systemctl ${OPTS} enable "$service"
                done

                for service in ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", True, d)}; do
                        systemctl --global ${OPTS} enable "$service"
                done
        fi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will reuse these SYSTEMD_AUTO_ENABLE.

install -m 0644 ${UNPACKDIR}/qca_set_bdaddr.service -D ${D}${systemd_system_unitdir}/qca_set_bdaddr.service
install -d ${D}${systemd_system_unitdir}/bluetooth.target.wants/
ln -sf ${systemd_system_unitdir}/qca_set_bdaddr.service ${D}${systemd_system_unitdir}/bluetooth.target.wants/qca_set_bdaddr.service
}

SYSTEMD_SERVICE:${PN} += "qca_set_bdaddr.service"
FILES:${PN}:append = "${systemd_system_unitdir}/qca_set_bdaddr.service \
${sysconfdir}/initscripts/qca_set_bdaddr.sh \
"