diff --git a/src/device.c b/src/device.c
index 50e7f23..def192f 100644
--- a/src/device.c
+++ b/src/device.c
g_free(req);
}
+static bool gatt_cache_is_enabled(struct btd_device *device)
+{
+ switch (main_opts.gatt_cache) {
+ case BT_GATT_CACHE_YES:
+ return device_is_paired(device, device->bdaddr_type);
+ case BT_GATT_CACHE_NO:
+ return false;
+ case BT_GATT_CACHE_ALWAYS:
+ default:
+ return true;
+ }
+}
+
+static void gatt_cache_cleanup(struct btd_device *device)
+{
+ if (gatt_cache_is_enabled(device))
+ return;
+
+ gatt_db_clear(device->db);
+}
+
static void gatt_client_cleanup(struct btd_device *device)
{
if (!device->client)
return;
+ gatt_cache_cleanup(device);
bt_gatt_client_set_service_changed(device->client, NULL, NULL, NULL);
bt_gatt_client_set_ready_handler(device->client, NULL, NULL, NULL);
bt_gatt_client_unref(device->client);
return;
}
+ if (!gatt_cache_is_enabled(device))
+ return;
+
ba2str(btd_adapter_get_address(adapter), src_addr);
ba2str(&device->bdaddr, dst_addr);
char **keys, filename[PATH_MAX];
GKeyFile *key_file;
+ if (!gatt_cache_is_enabled(device))
+ return;
+
DBG("Restoring %s gatt database from file", peer);
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
diff --git a/src/hcid.h b/src/hcid.h
index 0b785ee..552d63b 100644
--- a/src/hcid.h
+++ b/src/hcid.h
BT_MODE_LE,
} bt_mode_t;
+typedef enum {
+ BT_GATT_CACHE_ALWAYS,
+ BT_GATT_CACHE_YES,
+ BT_GATT_CACHE_NO,
+} bt_gatt_cache_t;
+
struct main_opts {
char *name;
uint32_t class;
uint16_t did_version;
bt_mode_t mode;
+ bt_gatt_cache_t gatt_cache;
};
extern struct main_opts main_opts;
diff --git a/src/main.c b/src/main.c
index bcc1e6f..b88cf11 100644
--- a/src/main.c
+++ b/src/main.c
main_opts.did_version = version;
}
+static bt_gatt_cache_t parse_gatt_cache(const char *cache)
+{
+ if (!strcmp(cache, "always")) {
+ return BT_GATT_CACHE_ALWAYS;
+ } else if (!strcmp(cache, "yes")) {
+ return BT_GATT_CACHE_YES;
+ } else if (!strcmp(cache, "no")) {
+ return BT_GATT_CACHE_NO;
+ } else {
+ DBG("Invalid value for KeepCache=%s", cache);
+ return BT_GATT_CACHE_ALWAYS;
+ }
+}
+
static void check_config(GKeyFile *config)
{
- const char *valid_groups[] = { "General", "Policy", NULL };
+ const char *valid_groups[] = { "General", "Policy", "GATT", NULL };
char **keys;
int i;
g_clear_error(&err);
else
main_opts.fast_conn = boolean;
+
+ str = g_key_file_get_string(config, "GATT", "Cache", &err);
+ if (err) {
+ g_clear_error(&err);
+ main_opts.gatt_cache = BT_GATT_CACHE_ALWAYS;
+ return;
+ }
+
+ main_opts.gatt_cache = parse_gatt_cache(str);
+
+ g_free(str);
}
static void init_defaults(void)
diff --git a/src/main.conf b/src/main.conf
index a649276..ba17405 100644
--- a/src/main.conf
+++ b/src/main.conf
# Defaults to "off"
# Privacy = off
+[GATT]
+# GATT attribute cache.
+# Possible values:
+# always: Always cache attributes even for devices not paired, this is
+# recommended as it is best for interoperability, with more consistent
+# reconnection times and enables proper tracking of notifications for all
+# devices.
+# yes: Only cache attributes of paired devices.
+# no: Never cache attributes
+# Default: always
+#Cache = always
+
[Policy]
#
# The ReconnectUUIDs defines the set of remote services that should try