From ecad887c2e144bc9b21d25ff1e265c0abbbc2d03 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Wed, 22 Feb 2017 12:02:47 +0100 Subject: [PATCH] gattlib: Introduced 'gattlib_uuid_cmp()' --- include/gattlib.h | 1 + src/gattlib_connect.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/gattlib.h b/include/gattlib.h index 9e8f3f0..1aad1de 100644 --- a/include/gattlib.h +++ b/include/gattlib.h @@ -123,5 +123,6 @@ void gattlib_register_indication(gatt_connection_t* connection, gattlib_event_ha int gattlib_uuid_to_string(const uuid_t *uuid, char *str, size_t n); int gattlib_string_to_uuid(const char *str, size_t n, uuid_t *uuid); +int gattlib_uuid_cmp(const uuid_t *uuid1, const uuid_t *uuid2); #endif diff --git a/src/gattlib_connect.c b/src/gattlib_connect.c index eb8be5a..6e7ef56 100644 --- a/src/gattlib_connect.c +++ b/src/gattlib_connect.c @@ -459,3 +459,29 @@ int gattlib_string_to_uuid(const char *str, size_t n, uuid_t *uuid) { return ret; } + +int gattlib_uuid_cmp(const uuid_t *uuid1, const uuid_t *uuid2) { + if (uuid1->type != uuid2->type) { + return 1; + } else if (uuid1->type == SDP_UUID16) { + if (uuid1->value.uuid16 == uuid2->value.uuid16) { + return 0; + } else { + return 2; + } + } else if (uuid1->type == SDP_UUID32) { + if (uuid1->value.uuid32 == uuid2->value.uuid32) { + return 0; + } else { + return 2; + } + } else if (uuid1->type == SDP_UUID128) { + if (memcmp(&uuid1->value.uuid128, &uuid2->value.uuid128, sizeof(uuid1->value.uuid128)) == 0) { + return 0; + } else { + return 2; + } + } else { + return 3; + } +}