From 5308fad8bcbc6455b0a5034dc4e6fc0b250806a8 Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Thu, 16 Jun 2016 10:29:45 +0200 Subject: [PATCH] bluez5-init: add support to set qca6564 mac address The steps to set the bluetooth MAC address is send an specific hci command and an hci reset, so the bluetooth interface need to be up in order to configure it. Additionally we have generalized the way to read the MAC address from the device tree and removed some old code for getting the MAC address in kernel version 2. https://jira.digi.com/browse/DUB-595 Signed-off-by: Isaac Hermida --- .../bluez/bluez5-5.33/bluez-init | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-5.33/bluez-init b/meta-digi-dey/recipes-connectivity/bluez/bluez5-5.33/bluez-init index 5dfe8a764..9637792e5 100755 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-5.33/bluez-init +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-5.33/bluez-init @@ -45,11 +45,35 @@ bt_init_qca6564() { exit fi - if hciconfig hci0 up; then - echo "${SCRIPTNAME}: OK" - else - echo "${SCRIPTNAME}: FAILED" + # Convert the BT address to the hcitool command format. + # Example: "00:04:F3:11:22:33" coverted to "33 22 11 F3 04 00" + HCI_BTADDR="$(echo ${BTADDR} | tr ':' '\n' | tac | tr '\n' ' ' | sed -e 's/ $//g')" + + # Up the interface to be able to send hci commands + if ! hciconfig hci0 up; then + echo "${SCRIPTNAME}: FAILED (hci0 up)" + exit fi + + # Set the MAC address + if ! hcitool -i hci0 cmd 3F 000B 01 02 06 ${HCI_BTADDR} > /dev/null; then + echo "${SCRIPTNAME}: FAILED (hci set MAC)" + exit + fi + + # HCI Reset + if ! hcitool -i hci0 cmd 03 0003 00 > /dev/null; then + echo "${SCRIPTNAME}: FAILED (hci reset)" + exit + fi + + # Down and up the interface to load the new MAC address + if ! hciconfig hci0 down; then + echo "${SCRIPTNAME}: FAILED (hci0 down)" + exit + fi + + hciconfig hci0 up && echo "${SCRIPTNAME}: OK" || echo "${SCRIPTNAME}: FAILED" } bt_init_ar3k() { @@ -63,16 +87,6 @@ bt_init_ar3k() { ( cd /lib/firmware/ar3k/1020200 - # Get MAC address from device tree or NVRAM. Use a default value it it has not been set. - if [ -f "/proc/device-tree/bluetooth/mac-address" ]; then - BTADDR="$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/bluetooth/mac-address | sed 's/:$//g')" - else - BTADDR="$(sed -ne 's,^.*btaddr1=\([^[:blank:]]\+\)[:blank:]*.*,\1,g;T;p' /proc/cmdline)" - fi - if [ -z "${BTADDR}" ] || [ "${BTADDR}" = "00:00:00:00:00:00" ]; then - BTADDR="00:04:F3:FF:FF:BB" - fi - # Update the MAC address file only if it has changed. FW_MAC="ar3kbdaddr.pst" [ -f "${FW_MAC}" ] && [ "$(cat ${FW_MAC})" = "${BTADDR}" ] || echo ${BTADDR} > ${FW_MAC} @@ -128,6 +142,14 @@ bt_init_ar3k() { # Check if this hardware does support Bluetooth if [ -d "/proc/device-tree/bluetooth" ]; then + # Get MAC address from device tree. Use a default value if it has not been set. + if [ -f "/proc/device-tree/bluetooth/mac-address" ]; then + BTADDR="$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/bluetooth/mac-address | sed 's/:$//g')" + fi + if [ -z "${BTADDR}" ] || [ "${BTADDR}" = "00:00:00:00:00:00" ]; then + BTADDR="00:04:F3:FF:FF:BB" + fi + # Initialize for the specific bluetooth chip if grep -qs '\' /proc/device-tree/compatible; then bt_init_qca6564