linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1
@ 2021-09-28 23:54 Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 2/5] gatt: Add implementation of GattCharacteristic1.MTU Luiz Augusto von Dentz
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-28 23:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds MTU properyt to GattCharacteristic1 which can be used in
order to determine how much data can be read/write using non-long
procedures which sometimes is the only thing the remote device
supports.

Fixes: https://github.com/bluez/bluez/issues/199
---
 doc/gatt-api.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
index 04789c6d3..120b23d1a 100644
--- a/doc/gatt-api.txt
+++ b/doc/gatt-api.txt
@@ -281,6 +281,12 @@ Properties	string UUID [read-only]
 			shall be used which will cause the allocated handle to
 			be set once registered.
 
+		uint16 MTU [read-only]
+
+			Characteristic MTU, this is valid both for ReadValue
+			and WriteValue but either method can use long
+			procedures when supported.
+
 Characteristic Descriptors hierarchy
 ====================================
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ 2/5] gatt: Add implementation of GattCharacteristic1.MTU
  2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
@ 2021-09-28 23:54 ` Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 3/5] shared/att: Add bt_att_register_exchange Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-28 23:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This implements MTU property in GattCharacteristic1 interface.
---
 src/gatt-client.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index 6bed77793..5b10cbfa0 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -873,6 +873,25 @@ characteristic_notify_acquired_exists(const GDBusPropertyTable *property,
 	return (chrc->props & BT_GATT_CHRC_PROP_NOTIFY);
 }
 
+static gboolean characteristic_get_mtu(const GDBusPropertyTable *property,
+				       DBusMessageIter *iter, void *data)
+{
+	struct characteristic *chrc = data;
+	struct bt_gatt_client *gatt = chrc->service->client->gatt;
+	struct bt_att *att;
+	uint16_t mtu;
+
+	att = bt_gatt_client_get_att(gatt);
+	if (!att)
+		return FALSE;
+
+	mtu = bt_att_get_mtu(att);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &mtu);
+
+	return TRUE;
+}
+
 static void write_characteristic_cb(struct gatt_db_attribute *attr, int err,
 								void *user_data)
 {
@@ -1646,6 +1665,7 @@ static const GDBusPropertyTable characteristic_properties[] = {
 				characteristic_write_acquired_exists },
 	{ "NotifyAcquired", "b", characteristic_get_notify_acquired, NULL,
 				characteristic_notify_acquired_exists },
+	{ "MTU", "q", characteristic_get_mtu, NULL, NULL },
 	{ }
 };
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ 3/5] shared/att: Add bt_att_register_exchange
  2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 2/5] gatt: Add implementation of GattCharacteristic1.MTU Luiz Augusto von Dentz
@ 2021-09-28 23:54 ` Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 4/5] gatt: Emit PropertiesChanged("MTU") when MTU is exchanged Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-28 23:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds bt_att_register_exchange which can be used to register
handlers that gets notified when the MTU gets changed via MTU exchange
procedure.
---
 src/shared/att.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/shared/att.h |  6 ++++
 2 files changed, 99 insertions(+), 1 deletion(-)

diff --git a/src/shared/att.c b/src/shared/att.c
index 329497728..2387fe4c3 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -64,6 +64,7 @@ struct bt_att {
 
 	struct queue *notify_list;	/* List of registered callbacks */
 	struct queue *disconn_list;	/* List of disconnect handlers */
+	struct queue *exchange_list;	/* List of MTU changed handlers */
 
 	unsigned int next_send_id;	/* IDs for "send" ops */
 	unsigned int next_reg_id;	/* IDs for registered callbacks */
@@ -257,6 +258,14 @@ struct att_disconn {
 	void *user_data;
 };
 
+struct att_exchange {
+	unsigned int id;
+	bool removed;
+	bt_att_exchange_func_t callback;
+	bt_att_destroy_func_t destroy;
+	void *user_data;
+};
+
 static void destroy_att_disconn(void *data)
 {
 	struct att_disconn *disconn = data;
@@ -267,6 +276,16 @@ static void destroy_att_disconn(void *data)
 	free(disconn);
 }
 
+static void destroy_att_exchange(void *data)
+{
+	struct att_exchange *exchange = data;
+
+	if (exchange->destroy)
+		exchange->destroy(exchange->user_data);
+
+	free(exchange);
+}
+
 static bool match_disconn_id(const void *a, const void *b)
 {
 	const struct att_disconn *disconn = a;
@@ -1116,6 +1135,7 @@ static void bt_att_free(struct bt_att *att)
 	queue_destroy(att->write_queue, NULL);
 	queue_destroy(att->notify_list, NULL);
 	queue_destroy(att->disconn_list, NULL);
+	queue_destroy(att->exchange_list, NULL);
 	queue_destroy(att->chans, bt_att_chan_free);
 
 	free(att);
@@ -1242,6 +1262,7 @@ struct bt_att *bt_att_new(int fd, bool ext_signed)
 	att->write_queue = queue_new();
 	att->notify_list = queue_new();
 	att->disconn_list = queue_new();
+	att->exchange_list = queue_new();
 
 	bt_att_attach_chan(att, chan);
 
@@ -1357,6 +1378,18 @@ uint16_t bt_att_get_mtu(struct bt_att *att)
 	return att->mtu;
 }
 
+static void exchange_handler(void *data, void *user_data)
+{
+	struct att_exchange *exchange = data;
+	uint16_t mtu = PTR_TO_INT(user_data);
+
+	if (exchange->removed)
+		return;
+
+	if (exchange->callback)
+		exchange->callback(mtu, exchange->user_data);
+}
+
 bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu)
 {
 	struct bt_att_chan *chan;
@@ -1382,8 +1415,11 @@ bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu)
 	chan->mtu = mtu;
 	chan->buf = buf;
 
-	if (chan->mtu > att->mtu)
+	if (chan->mtu > att->mtu) {
 		att->mtu = chan->mtu;
+		queue_foreach(att->exchange_list, exchange_handler,
+						INT_TO_PTR(att->mtu));
+	}
 
 	return true;
 }
@@ -1474,6 +1510,61 @@ bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id)
 	return true;
 }
 
+unsigned int bt_att_register_exchange(struct bt_att *att,
+					bt_att_exchange_func_t callback,
+					void *user_data,
+					bt_att_destroy_func_t destroy)
+{
+	struct att_exchange *mtu;
+
+	if (!att || queue_isempty(att->chans))
+		return 0;
+
+	mtu = new0(struct att_exchange, 1);
+	mtu->callback = callback;
+	mtu->destroy = destroy;
+	mtu->user_data = user_data;
+
+	if (att->next_reg_id < 1)
+		att->next_reg_id = 1;
+
+	mtu->id = att->next_reg_id++;
+
+	if (!queue_push_tail(att->exchange_list, mtu)) {
+		free(att);
+		return 0;
+	}
+
+	return mtu->id;
+}
+
+bool bt_att_unregister_exchange(struct bt_att *att, unsigned int id)
+{
+	struct att_exchange *mtu;
+
+	if (!att || !id)
+		return false;
+
+	/* Check if disconnect is running */
+	if (queue_isempty(att->chans)) {
+		mtu = queue_find(att->exchange_list, match_disconn_id,
+							UINT_TO_PTR(id));
+		if (!mtu)
+			return false;
+
+		mtu->removed = true;
+		return true;
+	}
+
+	mtu = queue_remove_if(att->exchange_list, match_disconn_id,
+							UINT_TO_PTR(id));
+	if (!mtu)
+		return false;
+
+	destroy_att_exchange(mtu);
+	return true;
+}
+
 unsigned int bt_att_send(struct bt_att *att, uint8_t opcode,
 				const void *pdu, uint16_t length,
 				bt_att_response_func_t callback, void *user_data,
@@ -1785,6 +1876,7 @@ bool bt_att_unregister_all(struct bt_att *att)
 
 	queue_remove_all(att->notify_list, NULL, NULL, destroy_att_notify);
 	queue_remove_all(att->disconn_list, NULL, NULL, destroy_att_disconn);
+	queue_remove_all(att->exchange_list, NULL, NULL, destroy_att_exchange);
 
 	return true;
 }
diff --git a/src/shared/att.h b/src/shared/att.h
index 03a450988..de136a066 100644
--- a/src/shared/att.h
+++ b/src/shared/att.h
@@ -43,6 +43,7 @@ typedef void (*bt_att_debug_func_t)(const char *str, void *user_data);
 typedef void (*bt_att_timeout_func_t)(unsigned int id, uint8_t opcode,
 							void *user_data);
 typedef void (*bt_att_disconnect_func_t)(int err, void *user_data);
+typedef void (*bt_att_exchange_func_t)(uint16_t mtu, void *user_data);
 typedef bool (*bt_att_counter_func_t)(uint32_t *sign_cnt, void *user_data);
 
 bool bt_att_set_debug(struct bt_att *att, uint8_t level,
@@ -88,6 +89,11 @@ unsigned int bt_att_register_disconnect(struct bt_att *att,
 					bt_att_destroy_func_t destroy);
 bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id);
 
+unsigned int bt_att_register_exchange(struct bt_att *att,
+					bt_att_exchange_func_t callback,
+					void *user_data,
+					bt_att_destroy_func_t destroy);
+bool bt_att_unregister_exchange(struct bt_att *att, unsigned int id);
 bool bt_att_unregister_all(struct bt_att *att);
 
 int bt_att_get_security(struct bt_att *att, uint8_t *enc_size);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ 4/5] gatt: Emit PropertiesChanged("MTU") when MTU is exchanged
  2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 2/5] gatt: Add implementation of GattCharacteristic1.MTU Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 3/5] shared/att: Add bt_att_register_exchange Luiz Augusto von Dentz
@ 2021-09-28 23:54 ` Luiz Augusto von Dentz
  2021-09-28 23:54 ` [PATCH BlueZ 5/5] client: Print MTU on attribute-info Luiz Augusto von Dentz
  2021-09-29  1:25 ` [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1 bluez.test.bot
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-28 23:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This notifies client when the ATT MTU changes.
---
 src/gatt-client.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index 5b10cbfa0..de18bea97 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -104,6 +104,7 @@ struct characteristic {
 	char *path;
 
 	unsigned int ready_id;
+	unsigned int exchange_id;
 	struct sock_io *write_io;
 	struct sock_io *notify_io;
 
@@ -1707,6 +1708,8 @@ static void remove_client(void *data)
 static void characteristic_free(void *data)
 {
 	struct characteristic *chrc = data;
+	struct bt_gatt_client *gatt = chrc->service->client->gatt;
+	struct bt_att *att;
 
 	/* List should be empty here */
 	queue_destroy(chrc->descs, NULL);
@@ -1723,15 +1726,29 @@ static void characteristic_free(void *data)
 
 	queue_destroy(chrc->notify_clients, remove_client);
 
+	att = bt_gatt_client_get_att(gatt);
+	if (att)
+		bt_att_unregister_exchange(att, chrc->exchange_id);
+
 	g_free(chrc->path);
 	free(chrc);
 }
 
+static void att_exchange(uint16_t mtu, void *user_data)
+{
+	struct characteristic *chrc = user_data;
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), chrc->path,
+					GATT_CHARACTERISTIC_IFACE, "MTU");
+}
+
 static struct characteristic *characteristic_create(
 						struct gatt_db_attribute *attr,
 						struct service *service)
 {
 	struct characteristic *chrc;
+	struct bt_gatt_client *gatt = service->client->gatt;
+	struct bt_att *att;
 	bt_uuid_t uuid;
 
 	chrc = new0(struct characteristic, 1);
@@ -1770,6 +1787,11 @@ static struct characteristic *characteristic_create(
 		return NULL;
 	}
 
+	att = bt_gatt_client_get_att(gatt);
+	if (att)
+		chrc->exchange_id = bt_att_register_exchange(att, att_exchange,
+								chrc, NULL);
+
 	DBG("Exported GATT characteristic: %s", chrc->path);
 
 	return chrc;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH BlueZ 5/5] client: Print MTU on attribute-info
  2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2021-09-28 23:54 ` [PATCH BlueZ 4/5] gatt: Emit PropertiesChanged("MTU") when MTU is exchanged Luiz Augusto von Dentz
@ 2021-09-28 23:54 ` Luiz Augusto von Dentz
  2021-09-29  1:25 ` [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1 bluez.test.bot
  4 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-28 23:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This prints the MTU of the characteristic when available.
---
 client/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/client/main.c b/client/main.c
index 229d53262..1746b8c7c 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2232,6 +2232,7 @@ static void cmd_attribute_info(int argc, char *argv[])
 		print_property(proxy, "Value");
 		print_property(proxy, "Notifying");
 		print_property(proxy, "Flags");
+		print_property(proxy, "MTU");
 		print_property(proxy, "Descriptors");
 	} else if (!strcmp(iface, "org.bluez.GattDescriptor1")) {
 		bt_shell_printf("Descriptor - %s\n", text);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1
  2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2021-09-28 23:54 ` [PATCH BlueZ 5/5] client: Print MTU on attribute-info Luiz Augusto von Dentz
@ 2021-09-29  1:25 ` bluez.test.bot
  2021-09-29 22:47   ` Luiz Augusto von Dentz
  4 siblings, 1 reply; 7+ messages in thread
From: bluez.test.bot @ 2021-09-29  1:25 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 884 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=554631

---Test result---

Test Summary:
CheckPatch                    PASS      6.84 seconds
GitLint                       PASS      4.61 seconds
Prep - Setup ELL              PASS      50.24 seconds
Build - Prep                  PASS      0.49 seconds
Build - Configure             PASS      9.07 seconds
Build - Make                  PASS      219.53 seconds
Make Check                    PASS      9.21 seconds
Make Distcheck                PASS      256.90 seconds
Build w/ext ELL - Configure   PASS      9.34 seconds
Build w/ext ELL - Make        PASS      205.94 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1
  2021-09-29  1:25 ` [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1 bluez.test.bot
@ 2021-09-29 22:47   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-29 22:47 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Tue, Sep 28, 2021 at 6:25 PM <bluez.test.bot@gmail.com> wrote:
>
> This is automated email and please do not reply to this email!
>
> Dear submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=554631
>
> ---Test result---
>
> Test Summary:
> CheckPatch                    PASS      6.84 seconds
> GitLint                       PASS      4.61 seconds
> Prep - Setup ELL              PASS      50.24 seconds
> Build - Prep                  PASS      0.49 seconds
> Build - Configure             PASS      9.07 seconds
> Build - Make                  PASS      219.53 seconds
> Make Check                    PASS      9.21 seconds
> Make Distcheck                PASS      256.90 seconds
> Build w/ext ELL - Configure   PASS      9.34 seconds
> Build w/ext ELL - Make        PASS      205.94 seconds
>
>
>
> ---
> Regards,
> Linux Bluetooth

Pushed.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-29 22:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 23:54 [PATCH BlueZ 1/5] gatt-api: Add MTU property to GattCharacteristic1 Luiz Augusto von Dentz
2021-09-28 23:54 ` [PATCH BlueZ 2/5] gatt: Add implementation of GattCharacteristic1.MTU Luiz Augusto von Dentz
2021-09-28 23:54 ` [PATCH BlueZ 3/5] shared/att: Add bt_att_register_exchange Luiz Augusto von Dentz
2021-09-28 23:54 ` [PATCH BlueZ 4/5] gatt: Emit PropertiesChanged("MTU") when MTU is exchanged Luiz Augusto von Dentz
2021-09-28 23:54 ` [PATCH BlueZ 5/5] client: Print MTU on attribute-info Luiz Augusto von Dentz
2021-09-29  1:25 ` [BlueZ,1/5] gatt-api: Add MTU property to GattCharacteristic1 bluez.test.bot
2021-09-29 22:47   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).