Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 208ce8a2 authored by Patty Huang's avatar Patty Huang
Browse files

Bass: Fix incorrect broadcast source address in add source command

* Reverse the source address in add source command to correct the address order
* Correct the address order while parsing BroadcastReceiverState

Bug: 240501535
Tag: #refactor
Test: atest BluetoothInstrumentationTests
Test: Make sure the remote headset can receive correct broadcast source
address and join the encrypted broadcast

Change-Id: I2f6421e0e8c98d9bd807e219098ea6c2848caf3a
parent 272c4647
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -734,6 +734,7 @@ public class BassClientStateMachine extends StateMachine {
                    BassConstants.BCAST_RCVR_STATE_SRC_ADDR_SIZE);
            byte sourceAddressType = receiverState[BassConstants
                    .BCAST_RCVR_STATE_SRC_ADDR_TYPE_IDX];
            BassUtils.reverse(sourceAddress);
            String address = Utils.getAddressStringFromByte(sourceAddress);
            BluetoothDevice device = btAdapter.getRemoteLeDevice(
                    address, sourceAddressType);
@@ -1243,7 +1244,9 @@ public class BassClientStateMachine extends StateMachine {
        stream.write(metaData.getSourceAddressType());

        // Advertiser_Address
        stream.write(Utils.getBytesFromAddress(advSource.getAddress()), 0, 6);
        byte[] bcastSourceAddr = Utils.getBytesFromAddress(advSource.getAddress());
        BassUtils.reverse(bcastSourceAddr);
        stream.write(bcastSourceAddr, 0, 6);
        log("Address bytes: " + advSource.getAddress());

        // Advertising_SID
+9 −0
Original line number Diff line number Diff line
@@ -141,4 +141,13 @@ class BassUtils {
            log("array[" + i + "] :" + Byte.toUnsignedInt(array[i]));
        }
    }

    static void reverse(byte[] address) {
        int len = address.length;
        for (int i = 0; i < len / 2; ++i) {
            byte b = address[i];
            address[i] = address[len - 1 - i];
            address[len - 1 - i] = b;
        }
    }
}