Return-Path: From: Claudio Takahasi To: linux-bluetooth@vger.kernel.org Cc: claudio.takahasi@openbossa.org Subject: [PATCH BlueZ v0 06/16] gatt: Assign read callback for external services Date: Mon, 10 Mar 2014 15:50:35 -0300 Message-Id: <1394477445-8987-7-git-send-email-claudio.takahasi@openbossa.org> In-Reply-To: <1394477445-8987-1-git-send-email-claudio.takahasi@openbossa.org> References: <1394477445-8987-1-git-send-email-claudio.takahasi@openbossa.org> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: This patch adds the callback for reading the external characteristic Value. Internally, GDBusProxy implementation tracks all properties Value changes consequently Value can be ready directly from the proxy without additional method calls. --- src/gatt-dbus.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c index a904a97..28604ea 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 == NULL) { + 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) { @@ -192,8 +232,12 @@ static int register_external_characteristics(GSList *proxies) if (bt_string_to_uuid(&uuid, str) < 0) return -EINVAL; - /* TODO: Missing Flags/property */ - attr = btd_gatt_add_char(&uuid, 0x00, NULL); + /* + * TODO: Missing Flags/property + * Add properties according to Core SPEC 4.1 page 2183. + * Reference table 3.5: Characteristic Properties bit field. + */ + attr = btd_gatt_add_char(&uuid, 0x00, proxy_read_cb); if (attr == NULL) return -EINVAL; -- 1.8.3.1