DO NOT COMMIT - Use Handles for Characteristic and Descriptor IDs

Change GetCharacteristic, GetDescriptor, and CharacteristicToFidl to use ID as handle

Change-Id: If9110b89f30c190337502b7bb83e5707d94b799e
diff --git a/src/connectivity/bluetooth/core/bt-host/fidl/gatt_remote_service_server.cc b/src/connectivity/bluetooth/core/bt-host/fidl/gatt_remote_service_server.cc
index 2aa4606..b4db860 100644
--- a/src/connectivity/bluetooth/core/bt-host/fidl/gatt_remote_service_server.cc
+++ b/src/connectivity/bluetooth/core/bt-host/fidl/gatt_remote_service_server.cc
@@ -26,7 +26,8 @@
 
 Characteristic CharacteristicToFidl(const RemoteCharacteristic& chrc) {
   Characteristic fidl_char;
-  fidl_char.id = chrc.id();
+  //fidl_char.id = chrc.id();
+  fidl_char.id = static_cast<uint64_t>(chrc.info().handle);
   fidl_char.type = chrc.info().type.ToString();
   fidl_char.properties =
       static_cast<uint16_t>(chrc.info().properties & kPropertyMask);
@@ -35,7 +36,8 @@
 
   for (const auto& descr : chrc.descriptors()) {
     Descriptor fidl_descr;
-    fidl_descr.id = descr.id();
+    //fidl_descr.id = descr.id();
+    fidl_descr.id = static_cast<uint64_t>(descr.info().handle);
     fidl_descr.type = descr.info().type.ToString();
     fidl_char.descriptors.push_back(std::move(fidl_descr));
   }
diff --git a/src/connectivity/bluetooth/core/bt-host/gatt/remote_service.cc b/src/connectivity/bluetooth/core/bt-host/gatt/remote_service.cc
index 005dc50..1dadf7b 100644
--- a/src/connectivity/bluetooth/core/bt-host/gatt/remote_service.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gatt/remote_service.cc
@@ -464,10 +464,23 @@
   if (!HasCharacteristics())
     return HostError::kNotReady;
 
+  /*
   if (id >= characteristics_.size())
     return HostError::kNotFound;
 
   *out_char = &characteristics_[id];
+  */
+
+  auto c = std::find_if(
+      characteristics_.begin(),
+      characteristics_.end(),
+      [id](auto& c) { return c.info().handle == static_cast<uint16_t>(id); }
+      );
+
+  if (c == characteristics_.end())
+    return HostError::kNotFound;
+
+  *out_char = &*c;
   return HostError::kNoError;
 }
 
@@ -482,6 +495,7 @@
   if (!HasCharacteristics())
     return HostError::kNotReady;
 
+  /*
   // The second set of 16-bits of |id| represent the characteristic ID and the
   // lower bits are the descriptor index. (See the section titled "ID SCHEME" in
   // remote_characteristic.h)
@@ -497,6 +511,26 @@
 
   *out_desc = &chrc->descriptors()[desc_idx];
   ZX_DEBUG_ASSERT((*out_desc)->id() == id);
+  */
+
+  const RemoteCharacteristic::Descriptor* descriptor = nullptr;
+
+  for (const auto& c: characteristics_) {
+    auto d = std::find_if(
+        c.descriptors().begin(),
+        c.descriptors().end(),
+        [id](auto& d) { return d.info().handle == static_cast<uint16_t>(id); }
+        );
+    if (d != c.descriptors().end()) {
+      descriptor = &*d;
+      break;
+    }
+  }
+
+  if (!descriptor)
+    return HostError::kNotFound;
+
+  *out_desc = descriptor;
 
   return HostError::kNoError;
 }