aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2011-11-07 10:59:35 -0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-11-14 20:45:34 +0200
commitf2ec605b58468bc0db3550d25ae22fb6714ac0e7 (patch)
tree35826a04a8b992d701ddeb34989fce4a060a4df4
parenta267bc2dcd37e9c09bc77faf268e7ff4e2e6040e (diff)
downloadbluez-f2ec605b58468bc0db3550d25ae22fb6714ac0e7.tar.gz
bluez-f2ec605b58468bc0db3550d25ae22fb6714ac0e7.tar.xz
bluez-f2ec605b58468bc0db3550d25ae22fb6714ac0e7.zip
Add storage functions to deal with CCC
CCC (Client Characteristic Configuration) is used to allow configuration whether to send updates about an characteristic value.
-rw-r--r--src/storage.c44
-rw-r--r--src/storage.h4
2 files changed, 48 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c
index cc0213bd..babe7c73 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -1263,3 +1263,47 @@ int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data)
return textfile_foreach(filename, func, data);
}
+
+int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
+ uint16_t *value)
+{
+ char filename[PATH_MAX + 1], addr[18], key[23];
+ char *str;
+ unsigned int config;
+ int err = 0;
+
+ create_filename(filename, PATH_MAX, local, "ccc");
+
+ ba2str(peer, addr);
+ snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+
+ str = textfile_caseget(filename, key);
+ if (str == NULL)
+ return -ENOENT;
+
+ if (sscanf(str, "%04X", &config) != 1)
+ err = -ENOENT;
+ else
+ *value = config;
+
+ free(str);
+
+ return err;
+}
+
+int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
+ uint16_t value)
+{
+ char filename[PATH_MAX + 1], addr[18], key[23], config[5];
+
+ create_filename(filename, PATH_MAX, local, "ccc");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(peer, addr);
+
+ snprintf(key, sizeof(key), "%17s#%04X", addr, handle);
+ snprintf(config, sizeof(config), "%04X", value);
+
+ return textfile_put(filename, key, config);
+}
diff --git a/src/storage.h b/src/storage.h
index dbe717f6..1cb36379 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -83,6 +83,10 @@ char *read_device_characteristics(const bdaddr_t *sba, const bdaddr_t *dba,
int write_device_attribute(const bdaddr_t *sba, const bdaddr_t *dba,
uint16_t handle, const char *chars);
int read_device_attributes(const bdaddr_t *sba, textfile_cb func, void *data);
+int read_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
+ uint16_t *value);
+int write_device_ccc(bdaddr_t *local, bdaddr_t *peer, uint16_t handle,
+ uint16_t value);
#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"