summaryrefslogtreecommitdiffstats
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
parent4e6726e8029f20be3e08b44760c56fc7a419090b (diff)
added new function to convert uuid to string(uuid128)
-rw-r--r--common/glib-helper.c50
-rw-r--r--common/glib-helper.h2
-rw-r--r--hcid/adapter.c9
-rw-r--r--hcid/device.c6
-rw-r--r--hcid/device.h4
5 files changed, 62 insertions, 9 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);
diff --git a/hcid/adapter.c b/hcid/adapter.c
index 754c7b1f..77d0b0f8 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -3178,9 +3178,10 @@ static DBusHandlerResult list_devices(DBusConnection *conn,
static void discover_services_cb(gpointer user_data, sdp_list_t *recs, int err)
{
- sdp_list_t *uuids, *seq, *next, *svcclass;
+ sdp_list_t *seq, *next, *svcclass;
struct adapter *adapter = user_data;
DBusMessage *reply;
+ GSList *uuids;
const char *path;
if (err < 0) {
@@ -3199,9 +3200,9 @@ static void discover_services_cb(gpointer user_data, sdp_list_t *recs, int err)
svcclass = NULL;
if (sdp_get_service_classes(rec, &svcclass) == 0) {
/* Extract the first element and skip the remainning */
- uuid_t *u = malloc(sizeof(uuid_t));
- memcpy(u, svcclass->data, sizeof(uuid_t));
- uuids = sdp_list_append(uuids, u);
+ gchar *uuid_str = bt_uuid2string(svcclass->data);
+ if (uuid_str)
+ uuids = g_slist_append(uuids, uuid_str);
sdp_list_free(svcclass, free);
}
diff --git a/hcid/device.c b/hcid/device.c
index b16a8189..538ce853 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -749,8 +749,8 @@ void device_foreach(GFunc func, gpointer user_data)
static void device_free(struct device *device)
{
- sdp_list_free(device->uuids, (sdp_free_func_t) free);
- g_free(device->address);
+ g_slist_foreach(device->uuids, (GFunc) g_free, NULL);
+ g_slist_free(device->uuids);
g_free(device->path);
g_free(device);
}
@@ -885,7 +885,7 @@ static DBusSignalVTable device_signals[] = {
};
const char *device_create(struct adapter *adapter,
- const char *address, sdp_list_t *uuids)
+ const char *address, GSList *uuids)
{
struct device *device;
diff --git a/hcid/device.h b/hcid/device.h
index 91ac8a7b..cdb68a50 100644
--- a/hcid/device.h
+++ b/hcid/device.h
@@ -26,12 +26,12 @@ struct device {
char *address;
char *path;
struct adapter *adapter;
- sdp_list_t *uuids;
+ GSList *uuids;
};
gboolean device_init(DBusConnection *conn);
void device_cleanup(void);
void device_foreach(GFunc func, gpointer user_data);
const char *device_create(struct adapter *adapter,
- const char *address, sdp_list_t *uuids);
+ const char *address, GSList *uuids);
void device_remove(const char *path);