Diff between 9be48fd3423ed3f673976aee028d098fb5c7ec3a and 5e1174fb01bdb196efceb0f8bd801f262aeed4cd

Changed Files

File Additions Deletions Status
profiles/gatt/gas.c +36 -0 modified

Full Patch

diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index 8b6a0bd..da6d555 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -25,9 +25,11 @@
 #endif
 
 #include <stdbool.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
 
 #include <glib.h>
 #include <bluetooth/uuid.h>
@@ -102,6 +104,32 @@ static int write_ctp_handle(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type,
 	return textfile_put(filename, key, value);
 }
 
+static int read_ctp_handle(bdaddr_t *sba, bdaddr_t *dba, uint8_t bdaddr_type,
+						uint16_t uuid, uint16_t *value)
+{
+	char filename[PATH_MAX + 1], addr[18], key[27];
+	char *str;
+
+	create_filename(filename, PATH_MAX, sba, "gatt");
+
+	ba2str(dba, addr);
+	snprintf(key, sizeof(key), "%17s#%hhu#0x%04x", addr, bdaddr_type,
+									uuid);
+
+	str = textfile_get(filename, key);
+	if (str == NULL)
+		return -errno;
+
+	if (sscanf(str, "%hx", value) != 1) {
+		free(str);
+		return -ENOENT;
+	}
+
+	free(str);
+
+	return 0;
+}
+
 static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
 							gpointer user_data)
 {
@@ -349,6 +377,8 @@ int gas_register(struct btd_device *device, struct att_range *gap,
 						struct att_range *gatt)
 {
 	struct gas *gas;
+	bdaddr_t sba, dba;
+	uint8_t bdaddr_type;
 
 	gas = g_new0(struct gas, 1);
 	gas->gap.start = gap->start;
@@ -364,6 +394,12 @@ int gas_register(struct btd_device *device, struct att_range *gap,
 						attio_connected_cb,
 						attio_disconnected_cb, gas);
 
+	adapter_get_address(device_get_adapter(gas->device), &sba);
+	device_get_address(gas->device, &dba, &bdaddr_type);
+
+	read_ctp_handle(&sba, &dba, bdaddr_type, GATT_CHARAC_SERVICE_CHANGED,
+							&gas->changed_handle);
+
 	return 0;
 }