aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2010-07-27 15:17:08 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2010-08-09 18:06:47 -0400
commitdb3bf777b85503ab873ac5f057359e1eb912833a (patch)
treefd06f44f45cd993335bd47a04faab8e4ad9d1731
parentdd5279755e9ba6f487e6c03eab621902f767c0bb (diff)
downloadbluez-db3bf777b85503ab873ac5f057359e1eb912833a.tar.gz
bluez-db3bf777b85503ab873ac5f057359e1eb912833a.tar.xz
bluez-db3bf777b85503ab873ac5f057359e1eb912833a.zip
Add support to storing the discoved GATT Services
This adds support to storing the discovered primary services so they can be loaded from storage later.
-rw-r--r--attrib/client.c44
-rw-r--r--src/storage.c14
-rw-r--r--src/storage.h2
3 files changed, 60 insertions, 0 deletions
diff --git a/attrib/client.c b/attrib/client.c
index 5f167312..d984122d 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -35,6 +35,7 @@
#include "log.h"
#include "gdbus.h"
#include "btio.h"
+#include "storage.h"
#include "att.h"
#include "gattrib.h"
@@ -231,6 +232,46 @@ fail:
gatt_service_free(gatt);
}
+static char *primary_list_to_string(GSList *primary_list)
+{
+ GString *services;
+ GSList *l;
+
+ services = g_string_new(NULL);
+
+ for (l = primary_list; l; l = l->next) {
+ struct primary *primary = l->data;
+ uuid_t *uuid128;
+ char service[64];
+ char uuidstr[MAX_LEN_UUID_STR];
+
+ memset(service, 0, sizeof(service));
+
+ uuid128 = sdp_uuid_to_uuid128(primary->uuid);
+ sdp_uuid2strn(uuid128, uuidstr, MAX_LEN_UUID_STR);
+
+ bt_free(uuid128);
+
+ snprintf(service, sizeof(service), "%d#%d#%s ", primary->start,
+ primary->end, uuidstr);
+
+ services = g_string_append(services, service);
+ }
+
+ return g_string_free(services, FALSE);
+}
+
+static void store_primary_services(struct gatt_service *gatt)
+{
+ char *services;
+
+ services = primary_list_to_string(gatt->primary);
+
+ write_device_services(&gatt->sba, &gatt->dba, services);
+
+ g_free(services);
+}
+
static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
@@ -245,6 +286,9 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
if (gatt->primary == NULL)
return;
+ store_primary_services(gatt);
+
+ /* Start Characteristic Discovery */
gatt->cur_prim = gatt->primary;
prim = gatt->cur_prim->data;
diff --git a/src/storage.c b/src/storage.c
index e09e2576..f07f6d78 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1237,3 +1237,17 @@ int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
return textfile_caseput(filename, addr, "");
}
+
+int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
+ const char *services)
+{
+ char filename[PATH_MAX + 1], addr[18];
+
+ create_filename(filename, PATH_MAX, sba, "primary");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(dba, addr);
+
+ return textfile_put(filename, addr, services);
+}
diff --git a/src/storage.h b/src/storage.h
index eee71d39..99270c5b 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -78,6 +78,8 @@ int read_device_pairable(bdaddr_t *local, gboolean *mode);
gboolean read_blocked(const bdaddr_t *local, const bdaddr_t *remote);
int write_blocked(const bdaddr_t *local, const bdaddr_t *remote,
gboolean blocked);
+int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
+ const char *services);
#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"