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

Commit d248cd29 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Add LE Secure Connection data parsing (2/4)

Bug: 30460956
Change-Id: Ie5c3ad96e7a834c9dc0a6791cf2cd24ecaeb927e
(cherry picked from commit 97e7410c)
parent 39dda655
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@
namespace android {

#define OOB_TK_SIZE 16
#define OOB_LE_SC_C_SIZE 16
#define OOB_LE_SC_R_SIZE 16

#define ADDITIONAL_NREFS 50
static jmethodID method_stateChangeCallback;
@@ -837,18 +839,51 @@ static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj, jbyteArray a
    }

    jbyte* smTKBytes = NULL;
    jbyte* leScCBytes = NULL;
    jbyte* leScRBytes = NULL;
    jbyteArray leScC = NULL;
    jbyteArray leScR = NULL;

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

    leScC = callByteArrayGetter(env, oobData, "android/bluetooth/OobData",
                                           "getLeSecureConnectionsConfirmation");
    if (leScC != NULL) {
        leScCBytes = env->GetByteArrayElements(leScC, NULL);
        int len = env->GetArrayLength(leScC);
        if (len != OOB_LE_SC_C_SIZE) {
            ALOGI("%s: wrong length of LE SC Confirmation, should be empty or %d bytes.",
                    __func__, OOB_LE_SC_C_SIZE);
            jniThrowIOException(env, EINVAL);
            goto done;
        }
        memcpy(oob_data.le_sc_c, leScCBytes, len);
    }

    leScR = callByteArrayGetter(env, oobData, "android/bluetooth/OobData",
                                           "getLeSecureConnectionsRandom");
    if (leScR != NULL) {
        leScRBytes = env->GetByteArrayElements(leScR, NULL);
        int len = env->GetArrayLength(leScR);
        if (len != OOB_LE_SC_R_SIZE) {
            ALOGI("%s: wrong length of LE SC Random, should be empty or %d bytes.",
                  __func__, OOB_LE_SC_R_SIZE);
            jniThrowIOException(env, EINVAL);
            goto done;
        }
        memcpy(oob_data.le_sc_r, leScRBytes, len);
    }

    if (sBluetoothInterface->create_bond_out_of_band((bt_bdaddr_t *)addr, transport, &oob_data)
        == BT_STATUS_SUCCESS)
        result = JNI_TRUE;
@@ -859,6 +894,12 @@ done:
    if (smTK != NULL)
        env->ReleaseByteArrayElements(smTK, smTKBytes, 0);

    if (leScC != NULL)
        env->ReleaseByteArrayElements(leScC, leScCBytes, 0);

    if (leScR != NULL)
        env->ReleaseByteArrayElements(leScR, leScRBytes, 0);

    return result;
}