summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2015-12-29 13:21:30 -0800
committerAndre Eisenbach <eisenbach@google.com>2016-01-15 00:01:12 +0000
commit914484bd8562ae75b062a669c89020773c8529b5 (patch)
tree10fe44ac1d6f536c7478ec8d4afec67f601c433b /jni
parentde00ed882cf20e5c136e349ae5e40ad35c5a74ee (diff)
downloadandroid_packages_apps_Bluetooth-914484bd8562ae75b062a669c89020773c8529b5.tar.gz
android_packages_apps_Bluetooth-914484bd8562ae75b062a669c89020773c8529b5.tar.bz2
android_packages_apps_Bluetooth-914484bd8562ae75b062a669c89020773c8529b5.zip
Implement createBondOutOfBand
This patch implements out of band pairing that uses optional data. Currently it works only for LE transport, using Temporary Key value. In future fields might be added to OOBData to support other options for optional data. Change-Id: I1b4942e656be7b5d1ae5a4bf9d867ffd74753798
Diffstat (limited to 'jni')
-rwxr-xr-xjni/com_android_bluetooth_btservice_AdapterService.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp
index 9223157de..6462e0bb4 100755
--- a/jni/com_android_bluetooth_btservice_AdapterService.cpp
+++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp
@@ -31,6 +31,8 @@
namespace android {
+#define OOB_TK_SIZE 16
+
#define ADDITIONAL_NREFS 50
static jmethodID method_stateChangeCallback;
static jmethodID method_adapterPropertyChangedCallback;
@@ -771,6 +773,54 @@ static jboolean createBondNative(JNIEnv* env, jobject obj, jbyteArray address, j
return result;
}
+static jbyteArray callByteArrayGetter(JNIEnv* env, jobject object, char* className, char* methodName) {
+ jclass myClass = env->FindClass(className);
+ jmethodID myMethod = env->GetMethodID(myClass, methodName, "()[B");
+ return (jbyteArray) env->CallObjectMethod(object, myMethod);
+}
+
+static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj, jbyteArray address,
+ jint transport, jobject oobData) {
+ jbyte *addr;
+ jboolean result = JNI_FALSE;
+ bt_out_of_band_data_t oob_data;
+
+ memset(&oob_data, 0, sizeof(oob_data));
+
+ if (!sBluetoothInterface) return result;
+
+ addr = env->GetByteArrayElements(address, NULL);
+ if (addr == NULL) {
+ jniThrowIOException(env, EINVAL);
+ return result;
+ }
+
+ jbyte* smTKBytes = 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);
+ jniThrowIOException(env, EINVAL);
+ goto done;
+ }
+ memcpy(oob_data.sm_tk, smTKBytes, len);
+ }
+
+ if (sBluetoothInterface->create_bond_out_of_band((bt_bdaddr_t *)addr, transport, &oob_data)
+ == BT_STATUS_SUCCESS)
+ result = JNI_TRUE;
+
+done:
+ env->ReleaseByteArrayElements(address, addr, 0);
+
+ if (smTK != NULL)
+ env->ReleaseByteArrayElements(smTK, smTKBytes, 0);
+
+ return result;
+}
+
static jboolean removeBondNative(JNIEnv* env, jobject obj, jbyteArray address) {
ALOGV("%s:",__FUNCTION__);
@@ -1145,6 +1195,7 @@ static JNINativeMethod sMethods[] = {
{"startDiscoveryNative", "()Z", (void*) startDiscoveryNative},
{"cancelDiscoveryNative", "()Z", (void*) cancelDiscoveryNative},
{"createBondNative", "([BI)Z", (void*) createBondNative},
+ {"createBondOutOfBandNative", "([BILandroid/bluetooth/OobData;)Z", (void*) createBondOutOfBandNative},
{"removeBondNative", "([B)Z", (void*) removeBondNative},
{"cancelBondNative", "([B)Z", (void*) cancelBondNative},
{"getConnectionStateNative", "([B)I", (void*) getConnectionStateNative},