-
Notifications
You must be signed in to change notification settings - Fork 153
Bluetooth: Add Bluetooth BD address setup service and script #1212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [Unit] | ||
| Description=start set BDA script for bluetooth | ||
| ConditionPathExists=/sys/devices/soc0/serial_number | ||
| Requires=bluetooth.service | ||
| After=bluetooth.service | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| ExecStart=+/etc/initscripts/qca_set_bdaddr.sh | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nack, script should be an executable available in /usr/bin
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or ${sbindir}. |
||
|
|
||
| [Install] | ||
| WantedBy=bluetooth.target | ||
| 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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's zero error checking and handling in this method
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure will will error checking for each command.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bashism, will not work with posix shells
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, where does 22:22 come from?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we took android HAL code as reference for this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it so complex?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!!" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to say anything if it works as expected.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| inherit systemd | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} += " \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment, why do you need these
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)} \ | ||
| " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate commit with a proper explanation
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. systemd.bbclass should be enabling this by default already:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
| " | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please improve the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, noted.