diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index b42aa64..8b6a0bd 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
#endif
#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <glib.h>
#include <bluetooth/uuid.h>
#include "btio.h"
#include "gatt.h"
#include "log.h"
+#include "textfile.h"
#include "gas.h"
/* Generic Attribute/Access Service */
return (gas->device == device ? 0 : -1);
}
+static inline int create_filename(char *buf, size_t size,
+ const bdaddr_t *bdaddr, const char *name)
+{
+ char addr[18];
+
+ ba2str(bdaddr, addr);
+
+ return create_name(buf, size, STORAGEDIR, addr, name);
+}
+
+static int write_ctp_handle(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type,
+ uint16_t uuid, uint16_t handle)
+{
+ char filename[PATH_MAX + 1], addr[18], key[27], value[7];
+
+ create_filename(filename, PATH_MAX, sba, "gatt");
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ ba2str(dba, addr);
+
+ snprintf(key, sizeof(key), "%17s#%hhu#0x%4.4x", addr, bdaddr_type,
+ uuid);
+ snprintf(value, sizeof(value), "0x%4.4x", handle);
+
+ return textfile_put(filename, key, value);
+}
+
static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
static void ccc_written_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
+ struct gas *gas = user_data;
+ bdaddr_t sba, dba;
+ uint8_t bdaddr_type;
+
if (status) {
error("Write Service Changed CCC failed: %s",
att_ecode2str(status));
}
DBG("Service Changed indications enabled");
+
+ adapter_get_address(device_get_adapter(gas->device), &sba);
+ device_get_address(gas->device, &dba, &bdaddr_type);
+
+ write_ctp_handle(&sba, &dba, bdaddr_type, GATT_CHARAC_SERVICE_CHANGED,
+ gas->changed_handle);
}
static void write_ccc(GAttrib *attrib, uint16_t handle, gpointer user_data)