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

Commit 45fcbee3 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

BLE OOB Pairing - parse address type (3/5)

When address type is not parsed, creating bond to devices not using
random address is impossible.

Bug: 32780409
Test: try pairing with nRF52DK using random address
Change-Id: Ifae63995e5ffb3a5071d0c993a0e15c0b6e8a7eb
(cherry picked from commit ad08afbe)
parent d248cd29
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@
#include <fcntl.h>

namespace android {

// OOB_LE_BD_ADDR_SIZE is 6 bytes addres + 1 byte address type
#define OOB_LE_BD_ADDR_SIZE 7
#define OOB_TK_SIZE 16
#define OOB_LE_SC_C_SIZE 16
#define OOB_LE_SC_R_SIZE 16
@@ -838,13 +839,28 @@ static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj, jbyteArray a
        return result;
    }

    jbyte* leBtDeviceAddressBytes = NULL;
    jbyte* smTKBytes = NULL;
    jbyte* leScCBytes = NULL;
    jbyte* leScRBytes = NULL;
    jbyteArray leBtDeviceAddress = NULL;
    jbyteArray smTK = NULL;
    jbyteArray leScC = NULL;
    jbyteArray leScR = NULL;

    jbyteArray smTK = callByteArrayGetter(env, oobData, "android/bluetooth/OobData", "getSecurityManagerTk");
    leBtDeviceAddress = callByteArrayGetter(env, oobData, "android/bluetooth/OobData", "getLeBluetoothDeviceAddress");
    if (leBtDeviceAddress != NULL) {
        leBtDeviceAddressBytes = env->GetByteArrayElements(leBtDeviceAddress, NULL);
        int len = env->GetArrayLength(leBtDeviceAddress);
        if (len != OOB_LE_BD_ADDR_SIZE) {
            ALOGI("%s: wrong length of leBtDeviceAddress, should be empty or %d bytes.", __func__, OOB_LE_BD_ADDR_SIZE);
            jniThrowIOException(env, EINVAL);
            goto done;
        }
        memcpy(oob_data.le_bt_dev_addr, leBtDeviceAddressBytes, len);
    }

    smTK = callByteArrayGetter(env, oobData, "android/bluetooth/OobData", "getSecurityManagerTk");
    if (smTK != NULL) {
        smTKBytes = env->GetByteArrayElements(smTK, NULL);
        int len = env->GetArrayLength(smTK);
@@ -891,6 +907,9 @@ static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj, jbyteArray a
done:
    env->ReleaseByteArrayElements(address, addr, 0);

    if (leBtDeviceAddress != NULL)
        env->ReleaseByteArrayElements(leBtDeviceAddress, leBtDeviceAddressBytes, 0);

    if (smTK != NULL)
        env->ReleaseByteArrayElements(smTK, smTKBytes, 0);