aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/device.c1
-rw-r--r--src/storage.c68
-rw-r--r--src/storage.h1
3 files changed, 70 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c
index 9055eca1..f6ba4457 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1100,6 +1100,7 @@ static void device_remove_stored(struct btd_device *device)
delete_entry(&src, "profiles", addr);
delete_entry(&src, "trusts", addr);
delete_all_records(&src, &device->bdaddr);
+ delete_device_service(&src, &device->bdaddr);
if (device->blocked)
device_unblock(conn, device, TRUE);
diff --git a/src/storage.c b/src/storage.c
index 8bfe953a..06b36f19 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -48,6 +48,11 @@
#include "glib-helper.h"
#include "storage.h"
+struct match {
+ GSList *keys;
+ char *pattern;
+};
+
static inline int create_filename(char *buf, size_t size,
const bdaddr_t *bdaddr, const char *name)
{
@@ -1252,6 +1257,69 @@ int write_device_services(const bdaddr_t *sba, const bdaddr_t *dba,
return textfile_put(filename, addr, services);
}
+static void filter_keys(char *key, char *value, void *data)
+{
+ struct match *match = data;
+ const char *address = match->pattern;
+
+ /* Each key contains: MAC#handle*/
+ if (g_strncasecmp(key, address, 17) == 0)
+ match->keys = g_slist_append(match->keys, g_strdup(key));
+}
+
+int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba)
+{
+ GSList *l;
+ struct match match;
+ char filename[PATH_MAX + 1], address[18];
+ int err;
+
+ create_filename(filename, PATH_MAX, sba, "primary");
+
+ memset(address, 0, sizeof(address));
+ ba2str(dba, address);
+
+ err = textfile_del(filename, address);
+ if (err < 0)
+ return err;
+
+ /* Deleting all characteristics of a given address */
+ memset(&match, 0, sizeof(match));
+ match.pattern = address;
+
+ create_filename(filename, PATH_MAX, sba, "characteristic");
+ err = textfile_foreach(filename, filter_keys, &match);
+ if (err < 0)
+ return err;
+
+ for (l = match.keys; l; l = l->next) {
+ const char *key = l->data;
+ textfile_del(filename, key);
+ }
+
+ g_slist_foreach(match.keys, (GFunc) g_free, NULL);
+ g_slist_free(match.keys);
+
+ /* Deleting all attributes values of a given address */
+ memset(&match, 0, sizeof(match));
+ match.pattern = address;
+
+ create_filename(filename, PATH_MAX, sba, "attributes");
+ err = textfile_foreach(filename, filter_keys, &match);
+ if (err < 0)
+ return err;
+
+ for (l = match.keys; l; l = l->next) {
+ const char *key = l->data;
+ textfile_del(filename, key);
+ }
+
+ g_slist_foreach(match.keys, (GFunc) g_free, NULL);
+ g_slist_free(match.keys);
+
+ return 0;
+}
+
char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba)
{
char filename[PATH_MAX + 1], addr[18];
diff --git a/src/storage.h b/src/storage.h
index cf1ffdcf..c7e342ca 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -82,6 +82,7 @@ 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);
+int delete_device_service(const bdaddr_t *sba, const bdaddr_t *dba);
char *read_device_services(const bdaddr_t *sba, const bdaddr_t *dba);
int write_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
uint16_t handle, const char *chars);