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

Commit a7e3825f authored by Martin Brabham's avatar Martin Brabham Committed by Myles Watson
Browse files

IRK: Pipe IRK through to host stack

The IRK is stored in a ScanFilter.  During ScanFilterAdd, check the IRK and add it to the
controller resolving list.

Bug: 178234318
Test: Manual
Tag: #feature
Change-Id: I70cb07d02200470faa25acbc88e9dabdce2a1eb5
parent 3492fd1a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1496,6 +1496,7 @@ static void gattClientScanFilterAddNative(JNIEnv* env, jobject object,
  jfieldID addressFid =
      env->GetFieldID(entryClazz, "address", "Ljava/lang/String;");
  jfieldID addrTypeFid = env->GetFieldID(entryClazz, "addr_type", "B");
  jfieldID irkTypeFid = env->GetFieldID(entryClazz, "irk", "[B");
  jfieldID uuidFid = env->GetFieldID(entryClazz, "uuid", "Ljava/util/UUID;");
  jfieldID uuidMaskFid =
      env->GetFieldID(entryClazz, "uuid_mask", "Ljava/util/UUID;");
@@ -1521,6 +1522,30 @@ static void gattClientScanFilterAddNative(JNIEnv* env, jobject object,

    curr.addr_type = env->GetByteField(current.get(), addrTypeFid);

    // Zero out Apcf IRK, maybe set later if one was passed
    int j;
    for (j = 0; j < 16; j++) {
      curr.irk[j] = 0;
    }

    ScopedLocalRef<jbyteArray> irkByteArray(
        env, (jbyteArray)env->GetObjectField(current.get(), irkTypeFid));

    if (irkByteArray.get() != nullptr) {
      int len = env->GetArrayLength(irkByteArray.get());
      // IRK is 128 bits or 16 octets, set the bytes or zero it out
      if (len != 16) {
        ALOGE("%s: Invalid IRK length '%d'; expected 16", __func__, len);
        jniThrowIOException(env, EINVAL);
      }
      jbyte* irkBytes = env->GetByteArrayElements(irkByteArray.get(), NULL);
      if (irkBytes != NULL) {
        for (int j = 0; j < len; j++) {
          curr.irk[i] = irkBytes[i];
        }
      }
    }

    ScopedLocalRef<jobject> uuid(env,
                                 env->GetObjectField(current.get(), uuidFid));
    if (uuid.get() != NULL) {
+10 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import java.util.UUID;
        public byte type;
        public String address;
        public byte addr_type;
        public byte[] irk;
        public UUID uuid;
        public UUID uuid_mask;
        public String name;
@@ -61,11 +62,12 @@ import java.util.UUID;

    private Set<Entry> mEntries = new HashSet<Entry>();

    void addDeviceAddress(String address, byte type) {
    void addDeviceAddress(String address, byte type, byte[] irk) {
        Entry entry = new Entry();
        entry.type = TYPE_DEVICE_ADDRESS;
        entry.address = address;
        entry.addr_type = type;
        entry.irk = irk;
        mEntries.add(entry);
    }

@@ -179,7 +181,13 @@ import java.util.UUID;
            addName(filter.getDeviceName());
        }
        if (filter.getDeviceAddress() != null) {
            addDeviceAddress(filter.getDeviceAddress(), DEVICE_TYPE_ALL);
            byte addressType = (byte) filter.getAddressType();
            // If addressType == iADDRESS_TYPE_PUBLIC (0) then this is the original
            // setDeviceAddress(address) API path which provided DEVICE_TYPE_ALL (2) which might map
            // to the stack value for address type of BTM_BLE_STATIC (2)
            // Additionally, we shouldn't confuse device type with address type.
            addDeviceAddress(filter.getDeviceAddress(),
                    ((addressType == 0) ? DEVICE_TYPE_ALL : addressType), filter.getIrk());
        }
        if (filter.getServiceUuid() != null) {
            if (filter.getServiceUuidMask() == null) {