Diff between 279be570ed794a141350c86c70876d958fa7df09 and 501fa6124ad27386b93ebd0c69347628433a6c6b

Changed Files

File Additions Deletions Status
android/gatt.c +51 -0 modified

Full Patch

diff --git a/android/gatt.c b/android/gatt.c
index 90a7d64..bf42200 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -133,6 +133,8 @@ struct gatt_device {
 	GIOChannel *att_io;
 	struct queue *services;
 
+	bool notify_services_changed;
+
 	guint watch_id;
 	guint server_id;
 
@@ -3907,6 +3909,54 @@ static void register_device_info_service(void)
 	gatt_db_service_set_active(gatt_db, srvc_handle, true);
 }
 
+static void gatt_srvc_change_register_cb(uint16_t handle, uint16_t offset,
+						const uint8_t *val, size_t len,
+						uint8_t att_opcode,
+						bdaddr_t *bdaddr,
+						void *user_data)
+{
+	uint8_t pdu[ATT_DEFAULT_LE_MTU];
+	struct gatt_device *dev;
+	uint16_t length;
+
+	dev = find_device_by_addr(bdaddr);
+	if (!dev) {
+		error("gatt: Could not find device ?!");
+		return;
+	}
+
+	/* TODO handle CCC */
+
+	/* Set services changed notification flag */
+	dev->notify_services_changed = !!(*val);
+
+	length = enc_write_resp(pdu);
+
+	g_attrib_send(dev->attrib, 0, pdu, length, NULL, NULL, NULL);
+}
+
+static void register_gatt_service(void)
+{
+	bt_uuid_t uuid;
+	uint16_t srvc_handle;
+
+	DBG("");
+
+	bt_uuid16_create(&uuid, 0x1801);
+	srvc_handle = gatt_db_add_service(gatt_db, &uuid, true, 4);
+
+	bt_uuid16_create(&uuid, GATT_CHARAC_SERVICE_CHANGED);
+	gatt_db_add_characteristic(gatt_db, srvc_handle, &uuid, 0,
+					GATT_CHR_PROP_INDICATE, NULL, NULL,
+					NULL);
+
+	bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
+	gatt_db_add_char_descriptor(gatt_db, srvc_handle, &uuid, 0, NULL,
+					gatt_srvc_change_register_cb, NULL);
+
+	gatt_db_service_set_active(gatt_db, srvc_handle, true);
+}
+
 static bool start_listening_io(void)
 {
 	GError *gerr = NULL;
@@ -3974,6 +4024,7 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
 
 	register_gap_service();
 	register_device_info_service();
+	register_gatt_service();
 
 	return true;
 }