Diff between da7ac99a72528448da96b7859f28f919b0590461 and a1673203a15d1398fd5d273d0a0388f61cac8c18

Changed Files

File Additions Deletions Status
src/gatt-dbus.c +41 -1 modified
src/gatt.h +1 -1 modified

Full Patch

diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index 6c4cdf7..a5a862b 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -139,6 +139,46 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 	eapp->proxies = g_slist_remove(eapp->proxies, proxy);
 }
 
+static void proxy_read_cb(struct btd_attribute *attr,
+				btd_attr_read_result_t result, void *user_data)
+{
+	DBusMessageIter iter, array;
+	GDBusProxy *proxy;
+	uint8_t *value;
+	int len;
+
+	/*
+	 * Remote device is trying to read the informed attribute,
+	 * "Value" should be read from the proxy. GDBusProxy tracks
+	 * properties changes automatically, it is not necessary to
+	 * get the value directly from the GATT server.
+	 */
+	proxy = g_hash_table_lookup(proxy_hash, attr);
+	if (!proxy) {
+		result(-ENOENT, NULL, 0, user_data);
+		return;
+	}
+
+	if (!g_dbus_proxy_get_property(proxy, "Value", &iter)) {
+		/* Unusual situation, read property will checked earlier */
+		result(-EPERM, NULL, 0, user_data);
+		return;
+	}
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
+		DBG("External service inconsistent!");
+		result(-EPERM, NULL, 0, user_data);
+		return;
+	}
+
+	dbus_message_iter_recurse(&iter, &array);
+	dbus_message_iter_get_fixed_array(&array, &value, &len);
+
+	DBG("attribute: %p read %d bytes", attr, len);
+
+	result(0, value, len, user_data);
+}
+
 static int register_external_service(const struct external_app *eapp,
 							GDBusProxy *proxy)
 {
@@ -198,7 +238,7 @@ static int register_external_characteristics(GSList *proxies)
 		 * Reference table 3.5: Characteristic Properties bit field.
 		 */
 
-		attr = btd_gatt_add_char(&uuid, 0x00, NULL);
+		attr = btd_gatt_add_char(&uuid, 0x00, proxy_read_cb);
 		if (attr == NULL)
 			return -EINVAL;
 
diff --git a/src/gatt.h b/src/gatt.h
index e446fa0..daa8d54 100644
--- a/src/gatt.h
+++ b/src/gatt.h
@@ -32,7 +32,7 @@ void gatt_cleanup(void);
  * ready to be read from the service implementation. Result callback is
  * the asynchronous function that should be used to inform the caller
  * the read value.
- * @err:	error in errno format.
+ * @err:	error in -errno format.
  * @value:	pointer to value
  * @len:	length of value
  * @user_data:	user_data passed in btd_attr_read_t callback