summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-10 14:20:50 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-10 14:20:50 +0000
commitea00a446dbacead62040dd2bd7e663774c205c04 (patch)
tree08f24f974723748e5a63b68329193f43d8d9d24d /common
parent4e6726e8029f20be3e08b44760c56fc7a419090b (diff)
added new function to convert uuid to string(uuid128)
Diffstat (limited to 'common')
-rw-r--r--common/glib-helper.c50
-rw-r--r--common/glib-helper.h2
2 files changed, 52 insertions, 0 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c
index be3f7a25..eef6ad8d 100644
--- a/common/glib-helper.c
+++ b/common/glib-helper.c
@@ -26,6 +26,7 @@
#endif
#include <errno.h>
+#include <arpa/inet.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
@@ -91,6 +92,7 @@ static void search_completed_cb(uint8_t type, uint16_t status,
recs = sdp_list_append(recs, rec);
} while (scanned < size);
+
done:
ctxt->cb(ctxt->user_data, recs, err);
@@ -207,3 +209,51 @@ int bt_discover_services(const bdaddr_t *src, const bdaddr_t *dst,
return 0;
}
+
+char *bt_uuid2string(uuid_t *uuid)
+{
+ gchar *str;
+ uuid_t uuid128;
+ unsigned int data0;
+ unsigned short data1;
+ unsigned short data2;
+ unsigned short data3;
+ unsigned int data4;
+ unsigned short data5;
+
+ if (!uuid)
+ return NULL;
+
+ switch (uuid->type) {
+ case SDP_UUID16:
+ sdp_uuid16_to_uuid128(&uuid128, uuid);
+ break;
+ case SDP_UUID32:
+ sdp_uuid32_to_uuid128(&uuid128, uuid);
+ break;
+ case SDP_UUID128:
+ memcpy(&uuid128, uuid, sizeof(uuid_t));
+ break;
+ default:
+ /* Type of UUID unknown */
+ return NULL;
+ }
+
+ memcpy(&data0, &uuid128.value.uuid128.data[0], 4);
+ memcpy(&data1, &uuid128.value.uuid128.data[4], 2);
+ memcpy(&data2, &uuid128.value.uuid128.data[6], 2);
+ memcpy(&data3, &uuid128.value.uuid128.data[8], 2);
+ memcpy(&data4, &uuid128.value.uuid128.data[10], 4);
+ memcpy(&data5, &uuid128.value.uuid128.data[14], 2);
+
+ str = g_try_malloc0(MAX_LEN_UUID_STR);
+ if (!str)
+ return NULL;
+
+ sprintf(str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
+ ntohl(data0), ntohs(data1),
+ ntohs(data2), ntohs(data3),
+ ntohl(data4), ntohs(data5));
+
+ return str;
+}
diff --git a/common/glib-helper.h b/common/glib-helper.h
index 7426a6ad..e64eccca 100644
--- a/common/glib-helper.h
+++ b/common/glib-helper.h
@@ -26,3 +26,5 @@ typedef void (*bt_destroy_t) (gpointer user_data);
int bt_discover_services(const bdaddr_t *src, const bdaddr_t *dst,
bt_callback_t cb, void *user_data, bt_destroy_t destroy);
+
+gchar *bt_uuid2string(uuid_t *uuid);