Add DCT advertising UUID

PiperOrigin-RevId: 730673334
This commit is contained in:
Guogang Li
2025-02-24 18:17:37 -08:00
committed by Copybara-Service
parent eb914ecc59
commit 202915c310
4 changed files with 25 additions and 14 deletions
+3 -2
View File
@@ -17,6 +17,7 @@
#include <algorithm>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -707,7 +708,7 @@ bool BleV2::GenerateAdvertisementCharacteristic(
GattCharacteristic::Property property = GattCharacteristic::Property::kRead;
// NOLINTNEXTLINE(google3-legacy-absl-backports)
absl::optional<Uuid> advertiement_uuid =
std::optional<Uuid> advertiement_uuid =
mediums::bleutils::GenerateAdvertisementUuid(slot);
if (!advertiement_uuid.has_value()) {
LOG(INFO) << "Unable to generate advertisement uuid.";
@@ -779,7 +780,7 @@ void BleV2::ProcessFetchGattAdvertisementsRequest(
// failure because there's nothing we could've done about a
// non-existed characteristic.
// NOLINTNEXTLINE(google3-legacy-absl-backports)
absl::optional<Uuid> advertiement_uuid =
std::optional<Uuid> advertiement_uuid =
mediums::bleutils::GenerateAdvertisementUuid(slot);
if (!advertiement_uuid.has_value()) {
continue;
@@ -16,12 +16,12 @@
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include "absl/base/attributes.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/types/optional.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_packet.h"
@@ -52,6 +52,11 @@ constexpr std::int64_t kAdvertisementUuidLsb = 0x8000000000000000;
const std::uint64_t kCopresenceServiceUuidMsb = 0x0000FEF300001000;
const std::uint64_t kCopresenceServiceUuidLsb = 0x800000805F9B34FB;
// The most significant bits and the least significant bits for the DCT
// UUID.
const std::uint64_t kDctServiceUuidMsb = 0x0000FC7300001000;
const std::uint64_t kDctServiceUuidLsb = 0x800000805F9B34FB;
// Creates a string as a space separated listing of hex bytes with [] at the
// beginning and the end.
//
@@ -69,7 +74,10 @@ std::string StringToPrintableHexString(const std::string& source) {
} // namespace
ABSL_CONST_INIT const Uuid kCopresenceServiceUuid(kCopresenceServiceUuidMsb,
kCopresenceServiceUuidLsb);
kCopresenceServiceUuidLsb);
ABSL_CONST_INIT const Uuid kDctServiceUuid(kDctServiceUuidMsb,
kDctServiceUuidLsb);
ByteArray GenerateHash(const std::string& source, size_t size) {
return Utils::Sha256Hash(source, size);
@@ -104,9 +112,9 @@ ByteArray GenerateAdvertisementHash(const ByteArray& advertisement_bytes) {
}
// NOLINTNEXTLINE(google3-legacy-absl-backports)
absl::optional<Uuid> GenerateAdvertisementUuid(int slot) {
std::optional<Uuid> GenerateAdvertisementUuid(int slot) {
if (slot < 0) {
return absl::nullopt; // NOLINT
return std::nullopt;
}
return Uuid(kAdvertisementUuidMsb, kAdvertisementUuidLsb | slot);
}
@@ -15,15 +15,13 @@
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_UTILS_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_UTILS_H_
#include <cstddef>
#include <optional>
#include <string>
#include "absl/strings/str_format.h"
#include "absl/types/optional.h"
#include "absl/base/attributes.h"
#include "connections/implementation/mediums/ble_v2//ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_packet.h"
#include "connections/implementation/mediums/utils.h"
#include "internal/platform/prng.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/uuid.h"
namespace nearby {
@@ -32,6 +30,7 @@ namespace mediums {
namespace bleutils {
ABSL_CONST_INIT extern const Uuid kCopresenceServiceUuid;
ABSL_CONST_INIT extern const Uuid kDctServiceUuid;
// Return SHA256 hash.
//
@@ -62,7 +61,7 @@ ByteArray GenerateAdvertisementHash(const ByteArray& advertisement_bytes);
//
// slot - the advertisement slot to generate a UUID for.
// NOLINTNEXTLINE(google3-legacy-absl-backports)
absl::optional<Uuid> GenerateAdvertisementUuid(int slot);
std::optional<Uuid> GenerateAdvertisementUuid(int slot);
} // namespace bleutils
} // namespace mediums
@@ -14,11 +14,14 @@
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include <optional>
#include <string>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/uuid.h"
namespace nearby {
namespace connections {
@@ -75,7 +78,7 @@ TEST(BleUtilsTest, CanGenerateAdvertisementHash) {
TEST(BleUtilsTest, CanGenerateAdvertisementUuid) {
// NOLINTNEXTLINE(google3-legacy-absl-backports)
absl::optional<Uuid> generated_uuid = GenerateAdvertisementUuid(0);
std::optional<Uuid> generated_uuid = GenerateAdvertisementUuid(0);
ASSERT_TRUE(generated_uuid.has_value());
EXPECT_THAT(std::string(*generated_uuid),
StrCaseEq("00000000-0000-3000-8000-000000000000"));