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

Commit 36756b11 authored by Ian Coolidge's avatar Ian Coolidge Committed by Android Git Automerger
Browse files

am a4d4a468: service: Allow manufacturer data to be set.

* commit 'a4d4a468':
  service: Allow manufacturer data to be set.
parents ae44f6f8 a4d4a468
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -569,8 +569,10 @@ bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) {

bool Server::SetAdvertisement(const std::vector<Uuid>& ids,
                              const std::vector<uint8_t>& service_data,
                              const std::vector<uint8_t>& manufacturer_data,
                              bool transmit_name) {
  std::vector<uint8_t> id_data;
  auto mutable_manufacturer_data = manufacturer_data;
  auto mutable_service_data = service_data;

  for (const Uuid &id : ids) {
@@ -587,7 +589,8 @@ bool Server::SetAdvertisement(const std::vector<Uuid> &ids,
      false,                       /* no txpower */
      2, 2,                        /* interval */
      0,                           /* appearance */
      0, nullptr,                  /* no mfg data */
      mutable_manufacturer_data.size(),
      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
      mutable_service_data.size(),
      reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
      reinterpret_cast<char *>(id_data.data()));
@@ -600,8 +603,10 @@ bool Server::SetAdvertisement(const std::vector<Uuid> &ids,

bool Server::SetScanResponse(const std::vector<Uuid>& ids,
                             const std::vector<uint8_t>& service_data,
                             const std::vector<uint8_t>& manufacturer_data,
                             bool transmit_name) {
  std::vector<uint8_t> id_data;
  auto mutable_manufacturer_data = manufacturer_data;
  auto mutable_service_data = service_data;

  for (const Uuid &id : ids) {
@@ -618,7 +623,8 @@ bool Server::SetScanResponse(const std::vector<Uuid> &ids,
      false,                      /* no txpower */
      2, 2,                       /* interval */
      0,                          /* appearance */
      0, nullptr,                 /* no mfg data */
      mutable_manufacturer_data.size(),
      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
      mutable_service_data.size(),
      reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
      reinterpret_cast<char *>(id_data.data()));
+6 −4
Original line number Diff line number Diff line
@@ -73,11 +73,13 @@ class Server {
  // Control the content of service advertisement.
  bool SetAdvertisement(const std::vector<Uuid>& ids,
                        const std::vector<uint8_t>& service_data,
                        const std::vector<uint8_t>& manufacturer_data,
                        bool transmit_name);

  // Control the content of service scan response.
  bool SetScanResponse(const std::vector<Uuid>& ids,
                       const std::vector<uint8_t>& service_data,
                       const std::vector<uint8_t>& manufacturer_data,
                       bool transmit_name);

  // Add an ordinary characteristic for reading and/or writing.
+26 −8
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ bool UnixIPCHost::OnSetCharacteristicValue(const std::string& service_uuid,
bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
                              const std::string& advertise_uuids,
                              const std::string& advertise_data,
                              const std::string& manufacturer_data,
                              const std::string& transmit_name) {
  LOG_INFO(LOG_TAG, "%s: service:%s uuids:%s data:%s", __func__, service_uuid.c_str(),
           advertise_uuids.c_str(), advertise_data.c_str());
@@ -198,8 +199,15 @@ bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,

  std::string decoded_data;
  base::Base64Decode(advertise_data, &decoded_data);
  std::vector<uint8_t> blob_data(decoded_data.begin(), decoded_data.end());
  gatt_servers_[service_uuid]->SetAdvertisement(ids, blob_data,
  std::vector<uint8_t> decoded_advertise_data(decoded_data.begin(),
                                              decoded_data.end());

  base::Base64Decode(manufacturer_data, &decoded_data);
  std::vector<uint8_t> decoded_manufacturer_data(decoded_data.begin(),
                                                 decoded_data.end());

  gatt_servers_[service_uuid]->SetAdvertisement(ids, decoded_advertise_data,
                                                decoded_manufacturer_data,
                                                TokenBool(transmit_name));
  return true;
}
@@ -207,6 +215,7 @@ bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
bool UnixIPCHost::OnSetScanResponse(const std::string& service_uuid,
                             const std::string& scan_response_uuids,
                             const std::string& scan_response_data,
                             const std::string& manufacturer_data,
                             const std::string& transmit_name) {
  std::vector<std::string> scan_response_uuid_tokens;
  base::SplitString(scan_response_uuids, '.', &scan_response_uuid_tokens);
@@ -218,8 +227,15 @@ bool UnixIPCHost::OnSetScanResponse(const std::string& service_uuid,

  std::string decoded_data;
  base::Base64Decode(scan_response_data, &decoded_data);
  std::vector<uint8_t> blob_data(decoded_data.begin(), decoded_data.end());
  gatt_servers_[service_uuid]->SetScanResponse(ids, blob_data,
  std::vector<uint8_t> decoded_advertise_data(decoded_data.begin(),
                                              decoded_data.end());

  base::Base64Decode(manufacturer_data, &decoded_data);
  std::vector<uint8_t> decoded_manufacturer_data(decoded_data.begin(),
                                                 decoded_data.end());

  gatt_servers_[service_uuid]->SetScanResponse(ids, decoded_advertise_data,
                                               decoded_manufacturer_data,
                                               TokenBool(transmit_name));
  return true;
}
@@ -273,13 +289,15 @@ bool UnixIPCHost::OnMessage() {
        return OnSetCharacteristicValue(tokens[1], tokens[2], tokens[3]);
      break;
    case 5:
      if (tokens[0] == kSetAdvertisementCommand)
        return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4]);
      if (tokens[0] == kSetScanResponseCommand)
        return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4]);
      if (tokens[0] == kAddCharacteristicCommand)
        return OnAddCharacteristic(tokens[1], tokens[2], tokens[3], tokens[4]);
      break;
    case 6:
      if (tokens[0] == kSetAdvertisementCommand)
        return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
      if (tokens[0] == kSetScanResponseCommand)
        return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
      break;
    default:
      break;
  }
+2 −0
Original line number Diff line number Diff line
@@ -76,12 +76,14 @@ class UnixIPCHost {
  bool OnSetAdvertisement(const std::string& service_uuid,
                          const std::string& advertise_uuids,
                          const std::string& advertise_data,
                          const std::string& manufacturer_data,
                          const std::string& transmit_name);

  // Applies settings to scan response.
  bool OnSetScanResponse(const std::string& service_uuid,
                         const std::string& advertise_uuids,
                         const std::string& advertise_data,
                         const std::string& manufacturer_data,
                         const std::string& transmit_name);

  // Starts service (advertisement and connections)