Skip to contentSkip to conversation

gatt: Add implementation for Gatt method, Confirm

PATCH In review Yunhan Wang 2 participants 4 messages Aug 23, 2017 – Aug 24, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gatt: Add implementation for Gatt method, Confirm

---
 doc/gatt-api.txt    |  7 +++++++
 src/gatt-client.c   |  9 +++++++++
 src/gatt-database.c | 16 ++++++++++++----
 3 files changed, 28 insertions(+), 4 deletions(-)
doc/gatt-api.txt +7 -0
index c0ad1de25..42b1f55aa 100644
@@ -162,6 +162,13 @@ Methods		array{byte} ReadValue(dict options)
 
 			Possible Errors: org.bluez.Error.Failed
 
+		void Confirm()
+
+			This method doesn't expect a reply so it is just a
+			confirmation that value was received.
+
+			Possible Errors: org.bluez.Error.Failed
+
 Properties	string UUID [read-only]
 
 			128-bit characteristic UUID.
src/gatt-client.c +9 -0
index 1cd7fbcf5..808d3da1d 100644
@@ -1598,6 +1598,13 @@ static DBusMessage *characteristic_stop_notify(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *characteristic_indication_conf(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("indication conf received");
+	return dbus_message_new_method_return(msg);
+}
+
 static const GDBusPropertyTable characteristic_properties[] = {
 	{ "UUID", "s", characteristic_get_uuid, NULL, NULL },
 	{ "Service", "o", characteristic_get_service, NULL, NULL },
@@ -1635,6 +1642,8 @@ static const GDBusMethodTable characteristic_methods[] = {
 					characteristic_start_notify) },
 	{ GDBUS_METHOD("StopNotify", NULL, NULL,
 					characteristic_stop_notify) },
+	{ GDBUS_METHOD("Confirm", NULL, NULL,
+				   characteristic_indication_conf) },
 	{ }
 };
 
src/gatt-database.c +12 -4
index 3b4bc7c8d..0969f8d1f 100644
@@ -867,11 +867,18 @@ struct notify {
 	const uint8_t *value;
 	uint16_t len;
 	bool indicate;
+	GDBusProxy *proxy;
 };
 
 static void conf_cb(void *user_data)
 {
+	GDBusProxy *proxy = user_data;
 	DBG("GATT server received confirmation");
+
+	if (proxy != NULL)
+	{
+		g_dbus_proxy_method_call(proxy, "IndicationConf", NULL, NULL, NULL, NULL);
+	}
 }
 
 static void send_notification_to_device(void *data, void *user_data)
@@ -917,7 +924,7 @@ static void send_notification_to_device(void *data, void *user_data)
 	DBG("GATT server sending indication");
 	bt_gatt_server_send_indication(server, notify->handle, notify->value,
 							notify->len, conf_cb,
-							NULL, NULL);
+							notify->proxy, NULL);
 
 	return;
 
@@ -930,7 +937,7 @@ remove:
 static void send_notification_to_devices(struct btd_gatt_database *database,
 					uint16_t handle, const uint8_t *value,
 					uint16_t len, uint16_t ccc_handle,
-					bool indicate)
+					bool indicate, GDBusProxy *proxy)
 {
 	struct notify notify;
 
@@ -942,6 +949,7 @@ static void send_notification_to_devices(struct btd_gatt_database *database,
 	notify.value = value;
 	notify.len = len;
 	notify.indicate = indicate;
+	notify.proxy = proxy;
 
 	queue_foreach(database->device_states, send_notification_to_device,
 								&notify);
@@ -972,7 +980,7 @@ static void send_service_changed(struct btd_gatt_database *database,
 	put_le16(end, value + 2);
 
 	send_notification_to_devices(database, handle, value, sizeof(value),
-							ccc_handle, true);
+							ccc_handle, true, NULL);
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -1861,7 +1869,7 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
 				gatt_db_attribute_get_handle(chrc->attrib),
 				value, len,
 				gatt_db_attribute_get_handle(chrc->ccc),
-				chrc->props & BT_GATT_CHRC_PROP_INDICATE);
+				chrc->props & BT_GATT_CHRC_PROP_INDICATE, proxy);
 }
 
 static bool database_add_ccc(struct external_service *service,
Signature · 1 line
2.14.1.480.gb18f417b89-goog
#1 lore raw

Hi Yunhan,

Quoted 11 lines · Yunhan Wang
---
 doc/gatt-api.txt    |  7 +++++++
 src/gatt-client.c   |  9 +++++++++
 src/gatt-database.c | 16 ++++++++++++----
 3 files changed, 28 insertions(+), 4 deletions(-)
doc/gatt-api.txt +0 -0
index c0ad1de25..42b1f55aa 100644

doc/gatt-api.txt Methods array{byte} ReadValue(dict options) · line 168

Quoted 7 lines
doc/gatt-api.txt +4 -0
@@ -162,6 +162,13 @@ Methods            array{byte} ReadValue(dict options)
 
                        Possible Errors: org.bluez.Error.Failed
 
+               void Confirm()
+
+                       This method doesn't expect a reply so it is just a
+                       confirmation that value was received.

Documentation should go in a separate patch, make Confirm optional and server only.

Quoted 24 lines
doc/gatt-api.txt +2 -0
+                       Possible Errors: org.bluez.Error.Failed
+
 Properties     string UUID [read-only]
 
                        128-bit characteristic UUID.
src/gatt-client.c +7 -0
index 1cd7fbcf5..808d3da1d 100644
@@ -1598,6 +1598,13 @@ static DBusMessage *characteristic_stop_notify(DBusConnection *conn,
        return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *characteristic_indication_conf(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("indication conf received");
+       return dbus_message_new_method_return(msg);
+}
+
 static const GDBusPropertyTable characteristic_properties[] = {
        { "UUID", "s", characteristic_get_uuid, NULL, NULL },
        { "Service", "o", characteristic_get_service, NULL, NULL },

src/gatt-client.c static const GDBusMethodTable characteristic_methods[] = { · line 1646

Quoted 5 lines
src/gatt-client.c +2 -0
@@ -1635,6 +1642,8 @@ static const GDBusMethodTable characteristic_methods[] = {
                                        characteristic_start_notify) },
        { GDBUS_METHOD("StopNotify", NULL, NULL,
                                        characteristic_stop_notify) },
+       { GDBUS_METHOD("Confirm", NULL, NULL,
+                                  characteristic_indication_conf) },

Lets make this server only so we don't need to define a methods that does nothing.

Quoted 77 lines
src/gatt-client.c +0 -0
        { }
 };
 
src/gatt-database.c +12 -5
index 3b4bc7c8d..0969f8d1f 100644
@@ -867,11 +867,18 @@ struct notify {
        const uint8_t *value;
        uint16_t len;
        bool indicate;
+       GDBusProxy *proxy;
 };
 
 static void conf_cb(void *user_data)
 {
+       GDBusProxy *proxy = user_data;
        DBG("GATT server received confirmation");
+
+       if (proxy != NULL)
+       {
+               g_dbus_proxy_method_call(proxy, "IndicationConf", NULL, NULL, NULL, NULL);
+       }
 }
 
 static void send_notification_to_device(void *data, void *user_data)
@@ -917,7 +924,7 @@ static void send_notification_to_device(void *data, void *user_data)
        DBG("GATT server sending indication");
        bt_gatt_server_send_indication(server, notify->handle, notify->value,
                                                        notify->len, conf_cb,
-                                                       NULL, NULL);
+                                                       notify->proxy, NULL);
 
        return;
 
@@ -930,7 +937,7 @@ remove:
 static void send_notification_to_devices(struct btd_gatt_database *database,
                                        uint16_t handle, const uint8_t *value,
                                        uint16_t len, uint16_t ccc_handle,
-                                       bool indicate)
+                                       bool indicate, GDBusProxy *proxy)
 {
        struct notify notify;
 
@@ -942,6 +949,7 @@ static void send_notification_to_devices(struct btd_gatt_database *database,
        notify.value = value;
        notify.len = len;
        notify.indicate = indicate;
+       notify.proxy = proxy;
 
        queue_foreach(database->device_states, send_notification_to_device,
                                                                &notify);
@@ -972,7 +980,7 @@ static void send_service_changed(struct btd_gatt_database *database,
        put_le16(end, value + 2);
 
        send_notification_to_devices(database, handle, value, sizeof(value),
-                                                       ccc_handle, true);
+                                                       ccc_handle, true, NULL);
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -1861,7 +1869,7 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
                                gatt_db_attribute_get_handle(chrc->attrib),
                                value, len,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE);
+                               chrc->props & BT_GATT_CHRC_PROP_INDICATE, proxy);
 }
 
 static bool database_add_ccc(struct external_service *service,
--

2.14.1.480.gb18f417b89-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Luiz Augusto von Dentz
#2 lore raw

Hi Yunhan,

Quoted 127 lines · Luiz Augusto von Dentz

Hi Yunhan,

Quoted 11 lines · Yunhan Wang
---
 doc/gatt-api.txt    |  7 +++++++
 src/gatt-client.c   |  9 +++++++++
 src/gatt-database.c | 16 ++++++++++++----
 3 files changed, 28 insertions(+), 4 deletions(-)
doc/gatt-api.txt +0 -0
index c0ad1de25..42b1f55aa 100644

doc/gatt-api.txt Methods array{byte} ReadValue(dict options) · line 168

Quoted 7 lines
doc/gatt-api.txt +4 -0
@@ -162,6 +162,13 @@ Methods            array{byte} ReadValue(dict options)
 
                        Possible Errors: org.bluez.Error.Failed
 
+               void Confirm()
+
+                       This method doesn't expect a reply so it is just a
+                       confirmation that value was received.

Documentation should go in a separate patch, make Confirm optional and server only.

Quoted 24 lines
doc/gatt-api.txt +2 -0
+                       Possible Errors: org.bluez.Error.Failed
+
 Properties     string UUID [read-only]
 
                        128-bit characteristic UUID.
src/gatt-client.c +7 -0
index 1cd7fbcf5..808d3da1d 100644
@@ -1598,6 +1598,13 @@ static DBusMessage *characteristic_stop_notify(DBusConnection *conn,
        return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *characteristic_indication_conf(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("indication conf received");
+       return dbus_message_new_method_return(msg);
+}
+
 static const GDBusPropertyTable characteristic_properties[] = {
        { "UUID", "s", characteristic_get_uuid, NULL, NULL },
        { "Service", "o", characteristic_get_service, NULL, NULL },

src/gatt-client.c static const GDBusMethodTable characteristic_methods[] = { · line 1646

Quoted 5 lines
src/gatt-client.c +2 -0
@@ -1635,6 +1642,8 @@ static const GDBusMethodTable characteristic_methods[] = {
                                        characteristic_start_notify) },
        { GDBUS_METHOD("StopNotify", NULL, NULL,
                                        characteristic_stop_notify) },
+       { GDBUS_METHOD("Confirm", NULL, NULL,
+                                  characteristic_indication_conf) },

Lets make this server only so we don't need to define a methods that does nothing.

Quoted 69 lines
src/gatt-client.c +0 -0
        { }
 };
 
src/gatt-database.c +12 -4
index 3b4bc7c8d..0969f8d1f 100644
@@ -867,11 +867,18 @@ struct notify {
        const uint8_t *value;
        uint16_t len;
        bool indicate;
+       GDBusProxy *proxy;
 };
 
 static void conf_cb(void *user_data)
 {
+       GDBusProxy *proxy = user_data;
        DBG("GATT server received confirmation");
+
+       if (proxy != NULL)
+       {
+               g_dbus_proxy_method_call(proxy, "IndicationConf", NULL, NULL, NULL, NULL);
+       }
 }
 
 static void send_notification_to_device(void *data, void *user_data)
@@ -917,7 +924,7 @@ static void send_notification_to_device(void *data, void *user_data)
        DBG("GATT server sending indication");
        bt_gatt_server_send_indication(server, notify->handle, notify->value,
                                                        notify->len, conf_cb,
-                                                       NULL, NULL);
+                                                       notify->proxy, NULL);
 
        return;
 
@@ -930,7 +937,7 @@ remove:
 static void send_notification_to_devices(struct btd_gatt_database *database,
                                        uint16_t handle, const uint8_t *value,
                                        uint16_t len, uint16_t ccc_handle,
-                                       bool indicate)
+                                       bool indicate, GDBusProxy *proxy)
 {
        struct notify notify;
 
@@ -942,6 +949,7 @@ static void send_notification_to_devices(struct btd_gatt_database *database,
        notify.value = value;
        notify.len = len;
        notify.indicate = indicate;
+       notify.proxy = proxy;
 
        queue_foreach(database->device_states, send_notification_to_device,
                                                                &notify);
@@ -972,7 +980,7 @@ static void send_service_changed(struct btd_gatt_database *database,
        put_le16(end, value + 2);
 
        send_notification_to_devices(database, handle, value, sizeof(value),
-                                                       ccc_handle, true);
+                                                       ccc_handle, true, NULL);
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -1861,7 +1869,7 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
                                gatt_db_attribute_get_handle(chrc->attrib),
                                value, len,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE);
+                               chrc->props & BT_GATT_CHRC_PROP_INDICATE, proxy);
 }
 
Quoted 3 lines
Quoted 3 lines
src/gatt-database.c +0 -1
 static bool database_add_ccc(struct external_service *service,
--

2.14.1.480.gb18f417b89-goog

Btw, please add a patch to bluetoothctl implementing the Confirm so we are able to see the confirmations while using it.

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

Hi, Luiz

Thank you. All fixes have been sent. Please help on review.

Best wishes
Yunhan

Quoted 140 lines · Luiz Augusto von Dentz

Hi Yunhan,

Quoted 127 lines · Luiz Augusto von Dentz

Hi Yunhan,

Quoted 11 lines · Yunhan Wang
---
 doc/gatt-api.txt    |  7 +++++++
 src/gatt-client.c   |  9 +++++++++
 src/gatt-database.c | 16 ++++++++++++----
 3 files changed, 28 insertions(+), 4 deletions(-)
doc/gatt-api.txt +0 -0
index c0ad1de25..42b1f55aa 100644

doc/gatt-api.txt Methods array{byte} ReadValue(dict options) · line 168

Quoted 7 lines
doc/gatt-api.txt +4 -0
@@ -162,6 +162,13 @@ Methods            array{byte} ReadValue(dict options)
 
                        Possible Errors: org.bluez.Error.Failed
 
+               void Confirm()
+
+                       This method doesn't expect a reply so it is just a
+                       confirmation that value was received.

Documentation should go in a separate patch, make Confirm optional and server only.

Quoted 24 lines
doc/gatt-api.txt +2 -0
+                       Possible Errors: org.bluez.Error.Failed
+
 Properties     string UUID [read-only]
 
                        128-bit characteristic UUID.
src/gatt-client.c +7 -0
index 1cd7fbcf5..808d3da1d 100644
@@ -1598,6 +1598,13 @@ static DBusMessage *characteristic_stop_notify(DBusConnection *conn,
        return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *characteristic_indication_conf(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("indication conf received");
+       return dbus_message_new_method_return(msg);
+}
+
 static const GDBusPropertyTable characteristic_properties[] = {
        { "UUID", "s", characteristic_get_uuid, NULL, NULL },
        { "Service", "o", characteristic_get_service, NULL, NULL },

src/gatt-client.c static const GDBusMethodTable characteristic_methods[] = { · line 1646

Quoted 5 lines
src/gatt-client.c +2 -0
@@ -1635,6 +1642,8 @@ static const GDBusMethodTable characteristic_methods[] = {
                                        characteristic_start_notify) },
        { GDBUS_METHOD("StopNotify", NULL, NULL,
                                        characteristic_stop_notify) },
+       { GDBUS_METHOD("Confirm", NULL, NULL,
+                                  characteristic_indication_conf) },

Lets make this server only so we don't need to define a methods that does nothing.

Quoted 69 lines
src/gatt-client.c +0 -0
        { }
 };
 
src/gatt-database.c +12 -4
index 3b4bc7c8d..0969f8d1f 100644
@@ -867,11 +867,18 @@ struct notify {
        const uint8_t *value;
        uint16_t len;
        bool indicate;
+       GDBusProxy *proxy;
 };
 
 static void conf_cb(void *user_data)
 {
+       GDBusProxy *proxy = user_data;
        DBG("GATT server received confirmation");
+
+       if (proxy != NULL)
+       {
+               g_dbus_proxy_method_call(proxy, "IndicationConf", NULL, NULL, NULL, NULL);
+       }
 }
 
 static void send_notification_to_device(void *data, void *user_data)
@@ -917,7 +924,7 @@ static void send_notification_to_device(void *data, void *user_data)
        DBG("GATT server sending indication");
        bt_gatt_server_send_indication(server, notify->handle, notify->value,
                                                        notify->len, conf_cb,
-                                                       NULL, NULL);
+                                                       notify->proxy, NULL);
 
        return;
 
@@ -930,7 +937,7 @@ remove:
 static void send_notification_to_devices(struct btd_gatt_database *database,
                                        uint16_t handle, const uint8_t *value,
                                        uint16_t len, uint16_t ccc_handle,
-                                       bool indicate)
+                                       bool indicate, GDBusProxy *proxy)
 {
        struct notify notify;
 
@@ -942,6 +949,7 @@ static void send_notification_to_devices(struct btd_gatt_database *database,
        notify.value = value;
        notify.len = len;
        notify.indicate = indicate;
+       notify.proxy = proxy;
 
        queue_foreach(database->device_states, send_notification_to_device,
                                                                &notify);
@@ -972,7 +980,7 @@ static void send_service_changed(struct btd_gatt_database *database,
        put_le16(end, value + 2);
 
        send_notification_to_devices(database, handle, value, sizeof(value),
-                                                       ccc_handle, true);
+                                                       ccc_handle, true, NULL);
 }
 
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
@@ -1861,7 +1869,7 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
                                gatt_db_attribute_get_handle(chrc->attrib),
                                value, len,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE);
+                               chrc->props & BT_GATT_CHRC_PROP_INDICATE, proxy);
 }
 
Quoted 3 lines
Quoted 3 lines
src/gatt-database.c +0 -1
 static bool database_add_ccc(struct external_service *service,
--

2.14.1.480.gb18f417b89-goog

Btw, please add a patch to bluetoothctl implementing the Confirm so we are able to see the confirmations while using it.

--
Luiz Augusto von Dentz