Make StringToUUID constexpr (#33649)
* Implement StringToUUID as constexpr
* Change local variable to use one global constexpr
* restyle
* Typo
* Remove strings from tizen and linux platform
* refactor
* Fix review issue
diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp
index 0e69e59..78e74bd 100644
--- a/src/ble/BLEEndPoint.cpp
+++ b/src/ble/BLEEndPoint.cpp
@@ -389,7 +389,7 @@
// Indicate close of chipConnection to peripheral via GATT unsubscribe. Keep end point allocated until
// unsubscribe completes or times out, so platform doesn't close underlying BLE connection before
// we're really sure the unsubscribe request has been sent.
- if (!mBle->mPlatformDelegate->UnsubscribeCharacteristic(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_2_ID))
+ if (!mBle->mPlatformDelegate->UnsubscribeCharacteristic(mConnObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID))
{
ChipLogError(Ble, "BtpEngine unsub failed");
@@ -750,7 +750,7 @@
{
// Subscribe to characteristic which peripheral will use to send indications. Prompts peripheral to send
// BLE transport capabilities indication.
- VerifyOrExit(mBle->mPlatformDelegate->SubscribeCharacteristic(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_2_ID),
+ VerifyOrExit(mBle->mPlatformDelegate->SubscribeCharacteristic(mConnObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID),
err = BLE_ERROR_GATT_SUBSCRIBE_FAILED);
// We just sent a GATT subscribe request, so make sure to attempt unsubscribe on close.
@@ -1313,14 +1313,14 @@
{
mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
- return mBle->mPlatformDelegate->SendWriteRequest(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_1_ID, std::move(buf));
+ return mBle->mPlatformDelegate->SendWriteRequest(mConnObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move(buf));
}
bool BLEEndPoint::SendIndication(PacketBufferHandle && buf)
{
mConnStateFlags.Set(ConnectionStateFlag::kGattOperationInFlight);
- return mBle->mPlatformDelegate->SendIndication(mConnObj, &CHIP_BLE_SVC_ID, &mBle->CHIP_BLE_CHAR_2_ID, std::move(buf));
+ return mBle->mPlatformDelegate->SendIndication(mConnObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID, std::move(buf));
}
CHIP_ERROR BLEEndPoint::StartConnectTimer()
diff --git a/src/ble/BleLayer.cpp b/src/ble/BleLayer.cpp
index de1f845..3e1473a 100644
--- a/src/ble/BleLayer.cpp
+++ b/src/ble/BleLayer.cpp
@@ -138,20 +138,6 @@
//
static BleEndPointPool sBLEEndPointPool;
-// UUIDs used internally by BleLayer:
-
-const ChipBleUUID BleLayer::CHIP_BLE_CHAR_1_ID = { { // 18EE2EF5-263D-4559-959F-4F9C429F9D11
- 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42,
- 0x9F, 0x9D, 0x11 } };
-
-const ChipBleUUID BleLayer::CHIP_BLE_CHAR_2_ID = { { // 18EE2EF5-263D-4559-959F-4F9C429F9D12
- 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42,
- 0x9F, 0x9D, 0x12 } };
-
-const ChipBleUUID BleLayer::CHIP_BLE_CHAR_3_ID = { { // 64630238-8772-45F2-B87D-748A83218F04
- 0x64, 0x63, 0x02, 0x38, 0x87, 0x72, 0x45, 0xF2, 0xB8, 0x7D, 0x74, 0x8A, 0x83,
- 0x21, 0x8F, 0x04 } };
-
// BleTransportCapabilitiesRequestMessage implementation:
void BleTransportCapabilitiesRequestMessage::SetSupportedProtocolVersion(uint8_t index, uint8_t version)
@@ -486,7 +472,7 @@
PacketBufferHandle && pBuf)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Write received on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_1_ID, charId), false, ChipLogError(Ble, "Write received on unknown char"));
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_1_UUID, charId), false, ChipLogError(Ble, "Write received on unknown char"));
VerifyOrReturnError(!pBuf.IsNull(), false, ChipLogError(Ble, "Write received null buffer"));
// Find matching connection end point.
@@ -512,7 +498,7 @@
PacketBufferHandle && pBuf)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Indication received on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId), false, ChipLogError(Ble, "Indication received on unknown char"));
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId), false, ChipLogError(Ble, "Indication received on unknown char"));
VerifyOrReturnError(!pBuf.IsNull(), false, ChipLogError(Ble, "Indication received null buffer"));
// Find matching connection end point.
@@ -528,7 +514,7 @@
bool BleLayer::HandleWriteConfirmation(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Write confirmation on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_1_ID, charId), false, ChipLogError(Ble, "Write confirmation on unknown char"));
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_1_UUID, charId), false, ChipLogError(Ble, "Write confirmation on unknown char"));
HandleAckReceived(connObj);
return true;
@@ -537,7 +523,7 @@
bool BleLayer::HandleIndicationConfirmation(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Indication confirmation on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId), false,
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId), false,
ChipLogError(Ble, "Indication confirmation on unknown char"));
HandleAckReceived(connObj);
@@ -558,7 +544,7 @@
bool BleLayer::HandleSubscribeReceived(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Subscribe received on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId), false,
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_UUID, charId), false,
ChipLogError(Ble, "Subscribe received on unknown char"));
// Find end point already associated with BLE connection, if any.
@@ -572,7 +558,7 @@
bool BleLayer::HandleSubscribeComplete(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Subscribe complete on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId), false,
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_UUID, charId), false,
ChipLogError(Ble, "Subscribe complete on unknown char"));
BLEEndPoint * endPoint = sBLEEndPointPool.Find(connObj);
@@ -585,7 +571,7 @@
bool BleLayer::HandleUnsubscribeReceived(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Unsubscribe received on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId), false,
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_UUID, charId), false,
ChipLogError(Ble, "Unsubscribe received on unknown char"));
// Find end point already associated with BLE connection, if any.
@@ -599,7 +585,7 @@
bool BleLayer::HandleUnsubscribeComplete(BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId)
{
VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_SVC_ID, svcId), false, ChipLogError(Ble, "Unsubscribe complete on unknown svc"));
- VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_ID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_ID, charId), false,
+ VerifyOrReturnError(UUIDsMatch(&CHIP_BLE_CHAR_2_UUID, charId) || UUIDsMatch(&CHIP_BLE_CHAR_3_UUID, charId), false,
ChipLogError(Ble, "Unsubscribe complete on unknown char"));
// Find end point already associated with BLE connection, if any.
diff --git a/src/ble/BleLayer.h b/src/ble/BleLayer.h
index e7d619f..7056a09 100644
--- a/src/ble/BleLayer.h
+++ b/src/ble/BleLayer.h
@@ -313,13 +313,6 @@
private:
// Private data members:
- // UUID of CHIP service characteristic used for central writes.
- static const ChipBleUUID CHIP_BLE_CHAR_1_ID;
- // UUID of CHIP service characteristic used for peripheral indications.
- static const ChipBleUUID CHIP_BLE_CHAR_2_ID;
- // UUID of CHIP service characteristic used for additional data
- static const ChipBleUUID CHIP_BLE_CHAR_3_ID;
-
BleConnectionDelegate * mConnectionDelegate;
BlePlatformDelegate * mPlatformDelegate;
BleApplicationDelegate * mApplicationDelegate;
diff --git a/src/ble/BleUUID.cpp b/src/ble/BleUUID.cpp
index 098595f..f42fc98 100644
--- a/src/ble/BleUUID.cpp
+++ b/src/ble/BleUUID.cpp
@@ -26,15 +26,6 @@
namespace chip {
namespace Ble {
-const ChipBleUUID CHIP_BLE_SVC_ID = { { // 0000FFF6-0000-1000-8000-00805F9B34FB
- 0x00, 0x00, 0xFF, 0xF6, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34,
- 0xFB } };
-
-inline static uint8_t HexDigitToInt(const char c)
-{
- return static_cast<uint8_t>(c >= '0' && c <= '9' ? c - '0' : tolower(c) - 'a' + 10);
-}
-
bool UUIDsMatch(const ChipBleUUID * idOne, const ChipBleUUID * idTwo)
{
if ((idOne == nullptr) || (idTwo == nullptr))
@@ -44,35 +35,5 @@
return (memcmp(idOne->bytes, idTwo->bytes, 16) == 0);
}
-// Convert a string like "0000FFF6-0000-1000-8000-00805F9B34FB" to binary UUID
-bool StringToUUID(const char * str, ChipBleUUID & uuid)
-{
- constexpr size_t NUM_UUID_NIBBLES = sizeof(uuid.bytes) * 2;
- size_t nibbleId = 0;
-
- for (; *str; ++str)
- {
- if (*str == '-') // skip separators
- continue;
-
- if (!isxdigit(*str)) // invalid character!
- return false;
-
- if (nibbleId >= NUM_UUID_NIBBLES) // too long string!
- return false;
-
- uint8_t & byte = uuid.bytes[nibbleId / 2];
- if (nibbleId % 2 == 0)
- byte = static_cast<uint8_t>(HexDigitToInt(*str) << 4);
- else
- byte = static_cast<uint8_t>(byte | HexDigitToInt(*str));
-
- ++nibbleId;
- }
-
- // All bytes were initialized?
- return nibbleId == NUM_UUID_NIBBLES;
-}
-
} /* namespace Ble */
} /* namespace chip */
diff --git a/src/ble/BleUUID.h b/src/ble/BleUUID.h
index 315af9e..6470cfe 100644
--- a/src/ble/BleUUID.h
+++ b/src/ble/BleUUID.h
@@ -22,7 +22,9 @@
#error "Please include <ble/Ble.h> instead!"
#endif
+#include <cstddef>
#include <cstdint>
+#include <utility>
namespace chip {
namespace Ble {
@@ -36,11 +38,73 @@
uint8_t bytes[16];
};
-// UUID of CHIP BLE service. Exposed for use in scan filter.
-extern const ChipBleUUID CHIP_BLE_SVC_ID;
+constexpr bool isValidHexChar(char c)
+{
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+constexpr uint8_t HexDigitToInt(const char c)
+{
+ if (c >= '0' && c <= '9')
+ return static_cast<uint8_t>(c - '0');
+ else
+ return static_cast<uint8_t>((c >= 'a' ? c - 'a' : c - 'A') + 10);
+}
bool UUIDsMatch(const ChipBleUUID * idOne, const ChipBleUUID * idTwo);
-bool StringToUUID(const char * str, ChipBleUUID & uuid);
+
+/*
+ * StringToUUID converts a string representation of a UUID to a binary UUID.
+ * The string representation must be in the format "0000FFF6-0000-1000-8000-00805F9B34FB".
+ * The function returns a pair of a boolean indicating whether the conversion was successful
+ * and the binary UUID.
+ *
+ */
+template <size_t N>
+constexpr std::pair<bool, ChipBleUUID> StringToUUID(const char (&str)[N])
+{
+ constexpr size_t UUID_LEN = 16;
+ constexpr size_t NUM_UUID_NIBBLES = UUID_LEN * 2;
+ static_assert(N >= NUM_UUID_NIBBLES);
+ ChipBleUUID uuid{};
+
+ size_t nibbleId = 0;
+ for (size_t i = 0; i < N - 1; ++i)
+ {
+ if (str[i] == '-')
+ continue;
+ if (!isValidHexChar(str[i]))
+ return { false, {} };
+ if (nibbleId >= NUM_UUID_NIBBLES)
+ return { false, {} };
+ uint8_t & byte = uuid.bytes[nibbleId / 2];
+ if (nibbleId % 2 == 0)
+ byte = static_cast<uint8_t>(HexDigitToInt(str[i]) << 4);
+ else
+ byte = static_cast<uint8_t>(byte | HexDigitToInt(str[i]));
+ ++nibbleId;
+ }
+ return { nibbleId == NUM_UUID_NIBBLES, uuid };
+}
+
+#define StringToUUIDConstexpr(str) \
+ []() { \
+ constexpr std::pair<bool, ::chip::Ble::ChipBleUUID> res = ::chip::Ble::StringToUUID(str); \
+ static_assert(res.first, "Argument: \"" #str "\" is not valid hex string"); \
+ return res.second; \
+ }();
+
+// UUID of CHIP BLE service.
+inline constexpr char CHIP_BLE_DESC_SHORT_UUID_STR[] = "2902";
+inline constexpr char CHIP_BLE_SERVICE_SHORT_UUID_STR[] = "FFF6";
+inline constexpr char CHIP_BLE_SERVICE_LONG_UUID_STR[] = "0000FFF6-0000-1000-8000-00805F9B34FB";
+inline constexpr char CHIP_BLE_CHAR_1_UUID_STR[] = "18EE2EF5-263D-4559-959F-4F9C429F9D11";
+inline constexpr char CHIP_BLE_CHAR_2_UUID_STR[] = "18EE2EF5-263D-4559-959F-4F9C429F9D12";
+inline constexpr char CHIP_BLE_CHAR_3_UUID_STR[] = "64630238-8772-45F2-B87D-748A83218F04";
+inline constexpr ChipBleUUID CHIP_BLE_SVC_ID = StringToUUIDConstexpr("0000FFF6-0000-1000-8000-00805F9B34FB");
+inline constexpr ChipBleUUID CHIP_BLE_CHAR_1_UUID = StringToUUIDConstexpr("18EE2EF5-263D-4559-959F-4F9C429F9D11");
+inline constexpr ChipBleUUID CHIP_BLE_CHAR_2_UUID = StringToUUIDConstexpr("18EE2EF5-263D-4559-959F-4F9C429F9D12");
+inline constexpr ChipBleUUID CHIP_BLE_CHAR_3_UUID = StringToUUIDConstexpr("64630238-8772-45F2-B87D-748A83218F04");
} /* namespace Ble */
} /* namespace chip */
diff --git a/src/ble/tests/TestBleLayer.cpp b/src/ble/tests/TestBleLayer.cpp
index 9b79037..968293d 100644
--- a/src/ble/tests/TestBleLayer.cpp
+++ b/src/ble/tests/TestBleLayer.cpp
@@ -44,14 +44,6 @@
namespace {
constexpr ChipBleUUID uuidZero{};
-constexpr ChipBleUUID uuidSvc = { { 0x00, 0x00, 0xFF, 0xF6, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34,
- 0xFB } };
-constexpr ChipBleUUID uuidChar1 = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D,
- 0x11 } };
-constexpr ChipBleUUID uuidChar2 = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F, 0x9D,
- 0x12 } };
-constexpr ChipBleUUID uuidChar3 = { { 0x64, 0x63, 0x02, 0x38, 0x87, 0x72, 0x45, 0xF2, 0xB8, 0x7D, 0x74, 0x8A, 0x83, 0x21, 0x8F,
- 0x04 } };
}; // namespace
@@ -111,14 +103,14 @@
{
constexpr uint8_t capReq[] = { 0x65, 0x6c, 0x54, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x06 };
auto buf = System::PacketBufferHandle::NewWithData(capReq, sizeof(capReq));
- return HandleWriteReceived(connObj, &uuidSvc, &uuidChar1, std::move(buf));
+ return HandleWriteReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move(buf));
}
// Processing subscription request after capabilities request should finalize
// connection establishment.
bool HandleSubscribeReceivedOnChar2(BLE_CONNECTION_OBJECT connObj)
{
- return HandleSubscribeReceived(connObj, &uuidSvc, &uuidChar2);
+ return HandleSubscribeReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID);
}
///
@@ -220,7 +212,7 @@
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleSubscribeReceived(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleSubscribeReceived(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_FALSE(HandleSubscribeReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleSubscribeReceived)
@@ -234,7 +226,7 @@
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleSubscribeComplete(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleSubscribeComplete(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_FALSE(HandleSubscribeComplete(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleSubscribeComplete)
@@ -243,14 +235,14 @@
ASSERT_TRUE(HandleWriteReceivedCapabilitiesRequest(connObj));
ASSERT_TRUE(HandleSubscribeReceivedOnChar2(connObj));
- EXPECT_TRUE(HandleSubscribeComplete(connObj, &uuidSvc, &uuidChar2));
+ EXPECT_TRUE(HandleSubscribeComplete(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID));
}
TEST_F(TestBleLayer, HandleUnsubscribeReceivedInvalidUUID)
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleUnsubscribeReceived(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleUnsubscribeReceived(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_FALSE(HandleUnsubscribeReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleUnsubscribeReceived)
@@ -259,14 +251,14 @@
ASSERT_TRUE(HandleWriteReceivedCapabilitiesRequest(connObj));
ASSERT_TRUE(HandleSubscribeReceivedOnChar2(connObj));
- EXPECT_TRUE(HandleUnsubscribeReceived(connObj, &uuidSvc, &uuidChar2));
+ EXPECT_TRUE(HandleUnsubscribeReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID));
}
TEST_F(TestBleLayer, HandleUnsubscribeCompleteInvalidUUID)
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleUnsubscribeComplete(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleUnsubscribeComplete(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_FALSE(HandleUnsubscribeComplete(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleUnsubscribeComplete)
@@ -275,7 +267,7 @@
ASSERT_TRUE(HandleWriteReceivedCapabilitiesRequest(connObj));
ASSERT_TRUE(HandleSubscribeReceivedOnChar2(connObj));
- EXPECT_TRUE(HandleUnsubscribeComplete(connObj, &uuidSvc, &uuidChar2));
+ EXPECT_TRUE(HandleUnsubscribeComplete(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID));
}
TEST_F(TestBleLayer, HandleWriteReceivedInvalidUUID)
@@ -285,7 +277,7 @@
ASSERT_FALSE(buf.IsNull());
EXPECT_FALSE(HandleWriteReceived(connObj, &uuidZero, &uuidZero, buf.Retain()));
- EXPECT_FALSE(HandleWriteReceived(connObj, &uuidSvc, &uuidChar3, std::move(buf)));
+ EXPECT_FALSE(HandleWriteReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_3_UUID, std::move(buf)));
}
TEST_F(TestBleLayer, HandleWriteReceived)
@@ -300,14 +292,14 @@
auto buf = System::PacketBufferHandle::NewWithData(data, sizeof(data));
ASSERT_FALSE(buf.IsNull());
- EXPECT_TRUE(HandleWriteReceived(connObj, &uuidSvc, &uuidChar1, std::move(buf)));
+ EXPECT_TRUE(HandleWriteReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move(buf)));
}
TEST_F(TestBleLayer, HandleWriteConfirmationInvalidUUID)
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleWriteConfirmation(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleWriteConfirmation(connObj, &uuidSvc, &uuidChar2));
+ EXPECT_FALSE(HandleWriteConfirmation(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID));
}
TEST_F(TestBleLayer, HandleWriteConfirmationUninitialized)
@@ -320,7 +312,7 @@
auto connObj = GetConnectionObject();
ASSERT_TRUE(HandleWriteReceivedCapabilitiesRequest(connObj));
- EXPECT_TRUE(HandleWriteConfirmation(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_TRUE(HandleWriteConfirmation(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleIndicationReceivedInvalidUUID)
@@ -330,7 +322,7 @@
ASSERT_FALSE(buf.IsNull());
EXPECT_FALSE(HandleIndicationReceived(connObj, &uuidZero, &uuidZero, buf.Retain()));
- EXPECT_FALSE(HandleIndicationReceived(connObj, &uuidSvc, &uuidChar1, std::move(buf)));
+ EXPECT_FALSE(HandleIndicationReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID, std::move(buf)));
}
TEST_F(TestBleLayer, HandleIndicationReceived)
@@ -345,14 +337,14 @@
auto buf = System::PacketBufferHandle::NewWithData(data, sizeof(data));
ASSERT_FALSE(buf.IsNull());
- EXPECT_TRUE(HandleIndicationReceived(connObj, &uuidSvc, &uuidChar2, std::move(buf)));
+ EXPECT_TRUE(HandleIndicationReceived(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID, std::move(buf)));
}
TEST_F(TestBleLayer, HandleIndicationConfirmationInvalidUUID)
{
auto connObj = GetConnectionObject();
EXPECT_FALSE(HandleIndicationConfirmation(connObj, &uuidZero, &uuidZero));
- EXPECT_FALSE(HandleIndicationConfirmation(connObj, &uuidSvc, &uuidChar1));
+ EXPECT_FALSE(HandleIndicationConfirmation(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_1_UUID));
}
TEST_F(TestBleLayer, HandleIndicationConfirmation)
@@ -360,7 +352,7 @@
auto connObj = GetConnectionObject();
ASSERT_TRUE(HandleWriteReceivedCapabilitiesRequest(connObj));
- EXPECT_TRUE(HandleIndicationConfirmation(connObj, &uuidSvc, &uuidChar2));
+ EXPECT_TRUE(HandleIndicationConfirmation(connObj, &CHIP_BLE_SVC_ID, &CHIP_BLE_CHAR_2_UUID));
}
TEST_F(TestBleLayer, HandleConnectionError)
diff --git a/src/ble/tests/TestBleUUID.cpp b/src/ble/tests/TestBleUUID.cpp
index 4dbc6dd..4455355 100644
--- a/src/ble/tests/TestBleUUID.cpp
+++ b/src/ble/tests/TestBleUUID.cpp
@@ -34,6 +34,9 @@
namespace {
+constexpr ChipBleUUID expectedUUID = { { 0x00, 0x00, 0xFF, 0xF6, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34,
+ 0xFB } };
+
TEST(TestBleUUID, CheckUUIDsMatch_NULL)
{
// Test that NULL pointer UUIDs are not equal
@@ -43,46 +46,36 @@
TEST(TestBleUUID, CheckStringToUUID_ChipUUID)
{
// Test positive scenario - CHIP Service UUID
- ChipBleUUID uuid;
- EXPECT_TRUE(StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
- EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
+ ChipBleUUID uuid = StringToUUIDConstexpr("0000FFF6-0000-1000-8000-00805F9B34FB");
+ EXPECT_TRUE(UUIDsMatch(&uuid, &expectedUUID));
}
TEST(TestBleUUID, CheckStringToUUID_ChipUUID_RandomCase)
{
// Test that letter case doesn't matter
- ChipBleUUID uuid;
- EXPECT_TRUE(StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
- EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
+ ChipBleUUID uuid = StringToUUIDConstexpr("0000FfF6-0000-1000-8000-00805f9B34Fb");
+ EXPECT_TRUE(UUIDsMatch(&uuid, &expectedUUID));
}
TEST(TestBleUUID, CheckStringToUUID_ChipUUID_NoSeparators)
{
// Test that separators don't matter
- ChipBleUUID uuid;
- EXPECT_TRUE(StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
- EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
+ ChipBleUUID uuid = StringToUUIDConstexpr("0000FFF600001000800000805F9B34FB");
+ EXPECT_TRUE(UUIDsMatch(&uuid, &expectedUUID));
}
TEST(TestBleUUID, CheckStringToUUID_TooLong)
{
// Test that even one more digit is too much
- ChipBleUUID uuid;
- EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
-}
-
-TEST(TestBleUUID, CheckStringToUUID_TooShort)
-{
- // Test that even one less digit is too little
- ChipBleUUID uuid;
- EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34F", uuid));
+ auto result = StringToUUID("0000FFF600001000800000805F9B34FB0");
+ EXPECT_FALSE(result.first);
}
TEST(TestBleUUID, CheckStringToUUID_InvalidChar)
{
// Test that non-hex digits don't pass
- ChipBleUUID uuid;
- EXPECT_FALSE(StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
+ auto result = StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB");
+ EXPECT_FALSE(result.first);
}
} // namespace
diff --git a/src/platform/Linux/bluez/BluezConnection.cpp b/src/platform/Linux/bluez/BluezConnection.cpp
index eeb1e7f..6ed15b5 100644
--- a/src/platform/Linux/bluez/BluezConnection.cpp
+++ b/src/platform/Linux/bluez/BluezConnection.cpp
@@ -94,7 +94,7 @@
if (service != nullptr)
{
if ((BluezIsServiceOnDevice(service, mDevice.get())) == TRUE &&
- (strcmp(bluez_gatt_service1_get_uuid(service), CHIP_BLE_UUID_SERVICE_STRING) == 0))
+ (strcmp(bluez_gatt_service1_get_uuid(service), Ble::CHIP_BLE_SERVICE_LONG_UUID_STR) == 0))
{
mService.reset(service);
break;
@@ -111,18 +111,18 @@
if (char1 != nullptr)
{
if ((BluezIsCharOnService(char1, mService.get()) == TRUE) &&
- (strcmp(bluez_gatt_characteristic1_get_uuid(char1), CHIP_PLAT_BLE_UUID_C1_STRING) == 0))
+ (strcmp(bluez_gatt_characteristic1_get_uuid(char1), Ble::CHIP_BLE_CHAR_1_UUID_STR) == 0))
{
mC1.reset(char1);
}
else if ((BluezIsCharOnService(char1, mService.get()) == TRUE) &&
- (strcmp(bluez_gatt_characteristic1_get_uuid(char1), CHIP_PLAT_BLE_UUID_C2_STRING) == 0))
+ (strcmp(bluez_gatt_characteristic1_get_uuid(char1), Ble::CHIP_BLE_CHAR_2_UUID_STR) == 0))
{
mC2.reset(char1);
}
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
else if ((BluezIsCharOnService(char1, mService.get()) == TRUE) &&
- (strcmp(bluez_gatt_characteristic1_get_uuid(char1), CHIP_PLAT_BLE_UUID_C3_STRING) == 0))
+ (strcmp(bluez_gatt_characteristic1_get_uuid(char1), Ble::CHIP_BLE_CHAR_3_UUID_STR) == 0))
{
mC3.reset(char1);
}
diff --git a/src/platform/Linux/bluez/BluezEndpoint.cpp b/src/platform/Linux/bluez/BluezEndpoint.cpp
index 151c09e..55b127e 100644
--- a/src/platform/Linux/bluez/BluezEndpoint.cpp
+++ b/src/platform/Linux/bluez/BluezEndpoint.cpp
@@ -438,10 +438,10 @@
static const char * const c3_flags[] = { "read", nullptr };
#endif
- mService.reset(CreateGattService(CHIP_BLE_UUID_SERVICE_SHORT_STRING));
+ mService.reset(CreateGattService(Ble::CHIP_BLE_SERVICE_SHORT_UUID_STR));
// C1 characteristic
- mC1.reset(CreateGattCharacteristic(mService.get(), "c1", CHIP_PLAT_BLE_UUID_C1_STRING, c1_flags));
+ mC1.reset(CreateGattCharacteristic(mService.get(), "c1", Ble::CHIP_BLE_CHAR_1_UUID_STR, c1_flags));
g_signal_connect(mC1.get(), "handle-read-value",
G_CALLBACK(+[](BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInv, GVariant * aOpt,
BluezEndpoint * self) { return self->BluezCharacteristicReadValue(aChar, aInv, aOpt); }),
@@ -455,7 +455,7 @@
g_signal_connect(mC1.get(), "handle-confirm", G_CALLBACK(BluezCharacteristicConfirmError), nullptr);
// C2 characteristic
- mC2.reset(CreateGattCharacteristic(mService.get(), "c2", CHIP_PLAT_BLE_UUID_C2_STRING, c2_flags));
+ mC2.reset(CreateGattCharacteristic(mService.get(), "c2", Ble::CHIP_BLE_CHAR_2_UUID_STR, c2_flags));
g_signal_connect(mC2.get(), "handle-read-value",
G_CALLBACK(+[](BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInv, GVariant * aOpt,
BluezEndpoint * self) { return self->BluezCharacteristicReadValue(aChar, aInv, aOpt); }),
@@ -478,7 +478,7 @@
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
ChipLogDetail(DeviceLayer, "CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING is TRUE");
// Additional data characteristics
- mC3.reset(CreateGattCharacteristic(mService.get(), "c3", CHIP_PLAT_BLE_UUID_C3_STRING, c3_flags));
+ mC3.reset(CreateGattCharacteristic(mService.get(), "c3", Ble::CHIP_BLE_CHAR_3_UUID_STR, c3_flags));
g_signal_connect(mC3.get(), "handle-read-value",
G_CALLBACK(+[](BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInv, GVariant * aOpt,
BluezEndpoint * self) { return self->BluezCharacteristicReadValue(aChar, aInv, aOpt); }),
diff --git a/src/platform/Linux/bluez/ChipDeviceScanner.cpp b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
index dcb113b..3323f1e 100644
--- a/src/platform/Linux/bluez/ChipDeviceScanner.cpp
+++ b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
@@ -42,7 +42,7 @@
GVariant * serviceData = bluez_device1_get_service_data(&aDevice);
VerifyOrReturnError(serviceData != nullptr, false);
- GAutoPtr<GVariant> dataValue(g_variant_lookup_value(serviceData, CHIP_BLE_UUID_SERVICE_STRING, nullptr));
+ GAutoPtr<GVariant> dataValue(g_variant_lookup_value(serviceData, Ble::CHIP_BLE_SERVICE_LONG_UUID_STR, nullptr));
VerifyOrReturnError(dataValue != nullptr, false);
size_t dataLen = 0;
diff --git a/src/platform/Linux/bluez/Types.h b/src/platform/Linux/bluez/Types.h
index 95fd669..4bd2c89 100644
--- a/src/platform/Linux/bluez/Types.h
+++ b/src/platform/Linux/bluez/Types.h
@@ -110,18 +110,6 @@
#define ADVERTISING_INTERFACE BLUEZ_INTERFACE ".LEAdvertisement1"
#define DEVICE_INTERFACE BLUEZ_INTERFACE ".Device1"
-#define CHIP_PLAT_BLE_UUID_C1_STRING "18ee2ef5-263d-4559-959f-4f9c429f9d11"
-#define CHIP_PLAT_BLE_UUID_C2_STRING "18ee2ef5-263d-4559-959f-4f9c429f9d12"
-#define CHIP_PLAT_BLE_UUID_C3_STRING "64630238-8772-45F2-B87D-748A83218F04"
-
-#define CHIP_BLE_BASE_SERVICE_UUID_STRING "-0000-1000-8000-00805f9b34fb"
-#define CHIP_BLE_SERVICE_PREFIX_LENGTH 8
-#define CHIP_BLE_BASE_SERVICE_PREFIX "0000"
-#define CHIP_BLE_UUID_SERVICE_SHORT_STRING "fff6"
-
-#define CHIP_BLE_UUID_SERVICE_STRING \
- CHIP_BLE_BASE_SERVICE_PREFIX CHIP_BLE_UUID_SERVICE_SHORT_STRING CHIP_BLE_BASE_SERVICE_UUID_STRING
-
#define BLUEZ_ADV_TYPE_FLAGS 0x01
#define BLUEZ_ADV_TYPE_SERVICE_DATA 0x16
diff --git a/src/platform/Tizen/BLEManagerImpl.cpp b/src/platform/Tizen/BLEManagerImpl.cpp
index a78efd9..944447d 100644
--- a/src/platform/Tizen/BLEManagerImpl.cpp
+++ b/src/platform/Tizen/BLEManagerImpl.cpp
@@ -74,14 +74,6 @@
namespace {
-/* CHIPoBLE UUID strings */
-constexpr char chip_ble_service_uuid[] = "0000FFF6-0000-1000-8000-00805F9B34FB";
-constexpr char chip_ble_char_c1_tx_uuid[] = "18EE2EF5-263D-4559-959F-4F9C429F9D11";
-constexpr char chip_ble_char_c2_rx_uuid[] = "18EE2EF5-263D-4559-959F-4F9C429F9D12";
-
-constexpr char chip_ble_desc_uuid_short[] = "2902";
-constexpr char chip_ble_service_uuid_short[] = "FFF6";
-
constexpr System::Clock::Timeout kNewConnectionScanTimeout = System::Clock::Seconds16(20);
constexpr System::Clock::Timeout kConnectTimeout = System::Clock::Seconds16(20);
constexpr System::Clock::Timeout kFastAdvertiseTimeout =
@@ -582,12 +574,12 @@
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_server_create() failed: %s", get_error_message(ret)));
// Create Service (BTP Service)
- ret = bt_gatt_service_create(chip_ble_service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service);
+ ret = bt_gatt_service_create(Ble::CHIP_BLE_SERVICE_LONG_UUID_STR, BT_GATT_SERVICE_TYPE_PRIMARY, &service);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_service_create() failed: %s", get_error_message(ret)));
// Create 1st Characteristic (Client TX Buffer)
ret = bt_gatt_characteristic_create(
- chip_ble_char_c1_tx_uuid, BT_GATT_PERMISSION_WRITE,
+ Ble::CHIP_BLE_CHAR_1_UUID_STR, BT_GATT_PERMISSION_WRITE,
BT_GATT_PROPERTY_WRITE, // Write Request is not coming if we use WITHOUT_RESPONSE property. Let's use WRITE property and
// consider to use WITHOUT_RESPONSE property in the future according to the CHIP Spec 4.16.3.2. BTP
// GATT Service
@@ -611,7 +603,7 @@
ChipLogError(DeviceLayer, "bt_gatt_service_add_characteristic() failed: %s", get_error_message(ret)));
// Create 2nd Characteristic (Client RX Buffer)
- ret = bt_gatt_characteristic_create(chip_ble_char_c2_rx_uuid, BT_GATT_PERMISSION_READ,
+ ret = bt_gatt_characteristic_create(Ble::CHIP_BLE_CHAR_2_UUID_STR, BT_GATT_PERMISSION_READ,
BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_INDICATE, "CHIPoBLE_C2", strlen("CHIPoBLE_C2"),
&char2);
VerifyOrExit(ret == BT_ERROR_NONE,
@@ -637,8 +629,8 @@
get_error_message(ret)));
// Create CCC Descriptor
- ret = bt_gatt_descriptor_create(chip_ble_desc_uuid_short, BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE, desc_value,
- sizeof(desc_value), &desc);
+ ret = bt_gatt_descriptor_create(Ble::CHIP_BLE_DESC_SHORT_UUID_STR, BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE,
+ desc_value, sizeof(desc_value), &desc);
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_descriptor_create() failed: %s", get_error_message(ret)));
ret = bt_gatt_characteristic_add_descriptor(char2, desc);
VerifyOrExit(ret == BT_ERROR_NONE,
@@ -711,7 +703,8 @@
VerifyOrExit(err == CHIP_NO_ERROR,
ChipLogError(DeviceLayer, "GetBLEDeviceIdentificationInfo() failed: %" CHIP_ERROR_FORMAT, err.Format()));
- ret = bt_adapter_le_add_advertising_service_data(mAdvertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, chip_ble_service_uuid_short,
+ ret = bt_adapter_le_add_advertising_service_data(mAdvertiser, BT_ADAPTER_LE_PACKET_ADVERTISING,
+ Ble::CHIP_BLE_SERVICE_SHORT_UUID_STR,
reinterpret_cast<const char *>(&deviceIdInfo), sizeof(deviceIdInfo));
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "bt_adapter_le_add_advertising_service_data() failed: %s", get_error_message(ret)));
@@ -779,12 +772,12 @@
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "Failed to fetch GATT Attribute from CHAR handle: %s", get_error_message(ret)));
- if (strcasecmp(uuid.get(), chip_ble_char_c1_tx_uuid) == 0)
+ if (strcasecmp(uuid.get(), Ble::CHIP_BLE_CHAR_1_UUID_STR) == 0)
{
ChipLogProgress(DeviceLayer, "CHIP Char C1 TX Found [%s]", StringOrNullMarker(uuid.get()));
conn->gattCharC1Handle = charHandle;
}
- else if (strcasecmp(uuid.get(), chip_ble_char_c2_rx_uuid) == 0)
+ else if (strcasecmp(uuid.get(), Ble::CHIP_BLE_CHAR_2_UUID_STR) == 0)
{
ChipLogProgress(DeviceLayer, "CHIP Char C2 RX Found [%s]", StringOrNullMarker(uuid.get()));
conn->gattCharC2Handle = charHandle;
@@ -806,7 +799,7 @@
VerifyOrExit(ret == BT_ERROR_NONE,
ChipLogError(DeviceLayer, "Failed to fetch GATT Attribute from SVC handle: %s", get_error_message(ret)));
- if (strcasecmp(uuid.get(), chip_ble_service_uuid) == 0)
+ if (strcasecmp(uuid.get(), chip::Ble::CHIP_BLE_SERVICE_LONG_UUID_STR) == 0)
{
ChipLogProgress(DeviceLayer, "CHIP Service UUID Found [%s]", StringOrNullMarker(uuid.get()));
@@ -1142,36 +1135,21 @@
}
break;
case DeviceEventType::kPlatformTizenBLEWriteComplete: {
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_write_uuid;
-
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c1_tx_uuid, char_write_uuid);
-
- HandleWriteConfirmation(apEvent->Platform.BLEWriteComplete.mConnection, &service_uuid, &char_write_uuid);
+ HandleWriteConfirmation(apEvent->Platform.BLEWriteComplete.mConnection, &Ble::CHIP_BLE_SVC_ID, &Ble::CHIP_BLE_CHAR_1_UUID);
break;
}
case DeviceEventType::kPlatformTizenBLESubscribeOpComplete: {
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_notif_uuid;
-
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notif_uuid);
-
if (apEvent->Platform.BLESubscribeOpComplete.mIsSubscribed)
- HandleSubscribeComplete(apEvent->Platform.BLESubscribeOpComplete.mConnection, &service_uuid, &char_notif_uuid);
+ HandleSubscribeComplete(apEvent->Platform.BLESubscribeOpComplete.mConnection, &Ble::CHIP_BLE_SVC_ID,
+ &chip::Ble::CHIP_BLE_CHAR_2_UUID);
else
- HandleUnsubscribeComplete(apEvent->Platform.BLESubscribeOpComplete.mConnection, &service_uuid, &char_notif_uuid);
+ HandleUnsubscribeComplete(apEvent->Platform.BLESubscribeOpComplete.mConnection, &Ble::CHIP_BLE_SVC_ID,
+ &chip::Ble::CHIP_BLE_CHAR_2_UUID);
break;
}
case DeviceEventType::kPlatformTizenBLEIndicationReceived: {
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_notif_uuid;
-
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notif_uuid);
-
- HandleIndicationReceived(apEvent->Platform.BLEIndicationReceived.mConnection, &service_uuid, &char_notif_uuid,
+ HandleIndicationReceived(apEvent->Platform.BLEIndicationReceived.mConnection, &Ble::CHIP_BLE_SVC_ID,
+ &chip::Ble::CHIP_BLE_CHAR_2_UUID,
System::PacketBufferHandle::Adopt(apEvent->Platform.BLEIndicationReceived.mData));
break;
}
@@ -1182,43 +1160,29 @@
void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
{
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_notification_uuid;
- Ble::ChipBleUUID char_write_uuid;
-
switch (event->Type)
{
case DeviceEventType::kCHIPoBLESubscribe:
ChipLogProgress(DeviceLayer, "CHIPoBLESubscribe");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notification_uuid);
-
- HandleSubscribeReceived(event->CHIPoBLESubscribe.ConId, &service_uuid, &char_notification_uuid);
+ HandleSubscribeReceived(event->CHIPoBLESubscribe.ConId, &Ble::CHIP_BLE_SVC_ID, &Ble::CHIP_BLE_CHAR_2_UUID);
NotifyBLEConnectionEstablished(event->CHIPoBLESubscribe.ConId, CHIP_NO_ERROR);
break;
case DeviceEventType::kCHIPoBLEUnsubscribe:
ChipLogProgress(DeviceLayer, "CHIPoBLEUnsubscribe");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notification_uuid);
-
- HandleUnsubscribeReceived(event->CHIPoBLESubscribe.ConId, &service_uuid, &char_notification_uuid);
+ HandleUnsubscribeReceived(event->CHIPoBLESubscribe.ConId, &Ble::CHIP_BLE_SVC_ID, &Ble::CHIP_BLE_CHAR_2_UUID);
break;
case DeviceEventType::kCHIPoBLEWriteReceived:
ChipLogProgress(DeviceLayer, "CHIPoBLEWriteReceived");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c1_tx_uuid, char_write_uuid);
- HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &service_uuid, &char_write_uuid,
+ HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &Ble::CHIP_BLE_SVC_ID, &Ble::CHIP_BLE_CHAR_1_UUID,
System::PacketBufferHandle::Adopt(event->CHIPoBLEWriteReceived.Data));
break;
case DeviceEventType::kCHIPoBLEIndicateConfirm:
ChipLogProgress(DeviceLayer, "CHIPoBLEIndicateConfirm");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notification_uuid);
- HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &service_uuid, &char_notification_uuid);
+ HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &Ble::CHIP_BLE_SVC_ID, &Ble::CHIP_BLE_CHAR_2_UUID);
break;
case DeviceEventType::kCHIPoBLEConnectionError:
ChipLogProgress(DeviceLayer, "CHIPoBLEConnectionError");
@@ -1241,19 +1205,14 @@
bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
const Ble::ChipBleUUID * charId)
{
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_notif_uuid;
int ret;
ChipLogProgress(DeviceLayer, "SubscribeCharacteristic");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notif_uuid);
-
VerifyOrExit(conId != nullptr, ChipLogError(DeviceLayer, "Invalid Connection"));
- VerifyOrExit(Ble::UUIDsMatch(svcId, &service_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(svcId, &Ble::CHIP_BLE_SVC_ID),
ChipLogError(DeviceLayer, "SubscribeCharacteristic() called with invalid service ID"));
- VerifyOrExit(Ble::UUIDsMatch(charId, &char_notif_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(charId, &Ble::CHIP_BLE_CHAR_2_UUID),
ChipLogError(DeviceLayer, "SubscribeCharacteristic() called with invalid characteristic ID"));
VerifyOrExit(conId->gattCharC2Handle != nullptr, ChipLogError(DeviceLayer, "Char C2 is null"));
@@ -1274,19 +1233,14 @@
bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
const Ble::ChipBleUUID * charId)
{
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_notif_uuid;
int ret;
ChipLogProgress(DeviceLayer, "UnSubscribeCharacteristic");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c2_rx_uuid, char_notif_uuid);
-
VerifyOrExit(conId != nullptr, ChipLogError(DeviceLayer, "Invalid Connection"));
- VerifyOrExit(Ble::UUIDsMatch(svcId, &service_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(svcId, &Ble::CHIP_BLE_SVC_ID),
ChipLogError(DeviceLayer, "UnSubscribeCharacteristic() called with invalid service ID"));
- VerifyOrExit(Ble::UUIDsMatch(charId, &char_notif_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(charId, &Ble::CHIP_BLE_CHAR_2_UUID),
ChipLogError(DeviceLayer, "UnSubscribeCharacteristic() called with invalid characteristic ID"));
VerifyOrExit(conId->gattCharC2Handle != nullptr, ChipLogError(DeviceLayer, "Char C2 is null"));
@@ -1360,19 +1314,14 @@
bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
System::PacketBufferHandle pBuf)
{
- Ble::ChipBleUUID service_uuid;
- Ble::ChipBleUUID char_write_uuid;
int ret;
ChipLogProgress(DeviceLayer, "SendWriteRequest");
- StringToUUID(chip_ble_service_uuid, service_uuid);
- StringToUUID(chip_ble_char_c1_tx_uuid, char_write_uuid);
-
VerifyOrExit(conId != nullptr, ChipLogError(DeviceLayer, "Invalid Connection"));
- VerifyOrExit(Ble::UUIDsMatch(svcId, &service_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(svcId, &Ble::CHIP_BLE_SVC_ID),
ChipLogError(DeviceLayer, "SendWriteRequest() called with invalid service ID"));
- VerifyOrExit(Ble::UUIDsMatch(charId, &char_write_uuid),
+ VerifyOrExit(Ble::UUIDsMatch(charId, &Ble::CHIP_BLE_CHAR_1_UUID),
ChipLogError(DeviceLayer, "SendWriteRequest() called with invalid characteristic ID"));
VerifyOrExit(conId->gattCharC1Handle != nullptr, ChipLogError(DeviceLayer, "Char C1 is null"));
@@ -1455,7 +1404,7 @@
}
/* Send StartChipScan Request to Scanner Class */
- strcpy(data.service_uuid, chip_ble_service_uuid_short);
+ strcpy(data.service_uuid, Ble::CHIP_BLE_DESC_SHORT_UUID_STR);
err = mDeviceScanner->StartChipScan(kNewConnectionScanTimeout, ScanFilterType::kServiceData, data);
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "Failed to start BLE scan"));
diff --git a/src/platform/Tizen/ChipDeviceScanner.cpp b/src/platform/Tizen/ChipDeviceScanner.cpp
index aea5aab..2b022f5 100644
--- a/src/platform/Tizen/ChipDeviceScanner.cpp
+++ b/src/platform/Tizen/ChipDeviceScanner.cpp
@@ -30,6 +30,7 @@
#include <bluetooth.h>
#include <bluetooth_internal.h>
+#include <ble/BleUUID.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>
@@ -40,10 +41,6 @@
namespace DeviceLayer {
namespace Internal {
-// CHIPoBLE UUID strings
-const char chip_service_uuid[] = "0000FFF6-0000-1000-8000-00805F9B34FB";
-const char chip_service_uuid_short[] = "FFF6";
-
ChipDeviceScanner::ChipDeviceScanner(ChipDeviceScannerDelegate * delegate) : mDelegate(delegate) {}
ChipDeviceScanner::~ChipDeviceScanner()
@@ -100,8 +97,8 @@
{
for (int i = 0; i < count; i++)
{
- if (g_strcmp0(dataList[i].service_uuid, chip_service_uuid) == 0 ||
- g_strcmp0(dataList[i].service_uuid, chip_service_uuid_short) == 0)
+ if (g_strcmp0(dataList[i].service_uuid, chip::Ble::CHIP_BLE_CHAR_1_UUID_STR) == 0 ||
+ g_strcmp0(dataList[i].service_uuid, chip::Ble::CHIP_BLE_SERVICE_SHORT_UUID_STR) == 0)
{
ChipLogProgress(DeviceLayer, "CHIP Thing Device Found! [Service Data UUID] = %s", dataList[i].service_uuid);
// Print full Service Data