2017-09-14 23:47:46

by Yunhan Wang

[permalink] [raw]
Subject: [PATCH BlueZ 3/3] client: Add MTU and UpdateMTU implementation

Add MTU in GDBusPropertyTable and UpdateMTU in GDBusMethodTable for Characteristic.
---
client/gatt.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/client/gatt.c b/client/gatt.c
index 753038303..22cb5679d 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -98,6 +98,8 @@ static GDBusProxy *notify_proxy;
static struct io *notify_io;
static uint16_t notify_mtu;

+static uint16_t att_mtu = 300;
+
static void print_service(struct service *service, const char *description)
{
const char *text;
@@ -1273,6 +1275,15 @@ static gboolean chrc_get_value(const GDBusPropertyTable *property,
return TRUE;
}

+static gboolean chrc_get_mtu(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct chrc *chrc = data;
+ const char * msg = NULL;
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, att_mtu);
+ return TRUE;
+}
+
static gboolean chrc_get_notifying(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
@@ -1308,6 +1319,7 @@ static const GDBusPropertyTable chrc_properties[] = {
{ "UUID", "s", chrc_get_uuid, NULL, NULL },
{ "Service", "o", chrc_get_service, NULL, NULL },
{ "Value", "ay", chrc_get_value, NULL, NULL },
+ { "MTU", "q", chrc_get_mtu, NULL, NULL },
{ "Notifying", "b", chrc_get_notifying, NULL, NULL },
{ "Flags", "as", chrc_get_flags, NULL, NULL },
{ }
@@ -1415,6 +1427,18 @@ static DBusMessage *chrc_confirm(DBusConnection *conn, DBusMessage *msg,
return dbus_message_new_method_return(msg);
}

+static DBusMessage *chrc_update_mtu(DBusConnection *conn, DBusMessage *msg,
+ void *user_data)
+{
+ struct chrc *chrc = user_data;
+ DBusMessageIter iter;
+ dbus_message_iter_init(msg, &iter);
+
+ dbus_message_iter_get_basic(&iter, &att_mtu);
+
+ return dbus_message_new_method_return(msg);
+}
+
static const GDBusMethodTable chrc_methods[] = {
{ GDBUS_ASYNC_METHOD("ReadValue", GDBUS_ARGS({ "options", "a{sv}" }),
GDBUS_ARGS({ "value", "ay" }),
@@ -1422,6 +1446,8 @@ static const GDBusMethodTable chrc_methods[] = {
{ GDBUS_ASYNC_METHOD("WriteValue", GDBUS_ARGS({ "value", "ay" },
{ "options", "a{sv}" }),
NULL, chrc_write_value) },
+ { GDBUS_ASYNC_METHOD("UpdateMTU", GDBUS_ARGS({ "value", "q" }),
+ NULL, chrc_update_mtu) },
{ GDBUS_ASYNC_METHOD("StartNotify", NULL, NULL, chrc_start_notify) },
{ GDBUS_METHOD("StopNotify", NULL, NULL, chrc_stop_notify) },
{ GDBUS_METHOD("Confirm", NULL, NULL, chrc_confirm) },
--
2.14.1.690.gbb1197296e-goog



2017-09-15 06:21:36

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/3] doc/gatt-api: Add UpdateMTU and MTU

Hi Yunhan,

On Fri, Sep 15, 2017 at 2:52 AM, Yunhan Wang <[email protected]> wrote:
> Hi, Luiz
>
> In order to implement packet fragmentation/assembly in upper layer
> application, may we get ATT MTU extraction API in peripheral/server
> side? Basic idea is to get ATT mtu after MTU exchange complete and
> write comes in. This patch is the draft implementation.

Im implementing AcquireWrite and AcquireNotify for server as well,
that should address GATT services that want to emulate serial port or
other protocol on top of it, like mesh.

> Thanks
> Best wishes
> Yunhan
>
> On Thu, Sep 14, 2017 at 4:47 PM, Yunhan Wang <[email protected]> wrote:
>> Add updateMTU in gatt method to get att mtu value in server side.
>> Add MTU property in gatt property.
>> ---
>> doc/gatt-api.txt | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
>> index cdd15f301..419308a7e 100644
>> --- a/doc/gatt-api.txt
>> +++ b/doc/gatt-api.txt
>> @@ -169,6 +169,13 @@ Methods array{byte} ReadValue(dict options)
>>
>> Possible Errors: org.bluez.Error.Failed
>>
>> + void UpdateMTU() [optional] (Server only)
>> +
>> + This method doesn't expect a reply so it is just
>> + MTU value update in user space at server side.
>> +
>> + Possible Errors: org.bluez.Error.Failed
>> +
>> Properties string UUID [read-only]
>>
>> 128-bit characteristic UUID.
>> @@ -225,6 +232,10 @@ Properties string UUID [read-only]
>> "secure-read" (Server only)
>> "secure-write" (Server only)
>>
>> + uint16_t MTU [read-only, optional]
>> +
>> + ATT MTU value
>> +
>> Characteristic Descriptors hierarchy
>> ====================================
>>
>> --
>> 2.14.1.690.gbb1197296e-goog
>>



--
Luiz Augusto von Dentz

2017-09-14 23:52:36

by Yunhan Wang

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/3] doc/gatt-api: Add UpdateMTU and MTU

Hi, Luiz

In order to implement packet fragmentation/assembly in upper layer
application, may we get ATT MTU extraction API in peripheral/server
side? Basic idea is to get ATT mtu after MTU exchange complete and
write comes in. This patch is the draft implementation.

Thanks
Best wishes
Yunhan

On Thu, Sep 14, 2017 at 4:47 PM, Yunhan Wang <[email protected]> wrote:
> Add updateMTU in gatt method to get att mtu value in server side.
> Add MTU property in gatt property.
> ---
> doc/gatt-api.txt | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
> index cdd15f301..419308a7e 100644
> --- a/doc/gatt-api.txt
> +++ b/doc/gatt-api.txt
> @@ -169,6 +169,13 @@ Methods array{byte} ReadValue(dict options)
>
> Possible Errors: org.bluez.Error.Failed
>
> + void UpdateMTU() [optional] (Server only)
> +
> + This method doesn't expect a reply so it is just
> + MTU value update in user space at server side.
> +
> + Possible Errors: org.bluez.Error.Failed
> +
> Properties string UUID [read-only]
>
> 128-bit characteristic UUID.
> @@ -225,6 +232,10 @@ Properties string UUID [read-only]
> "secure-read" (Server only)
> "secure-write" (Server only)
>
> + uint16_t MTU [read-only, optional]
> +
> + ATT MTU value
> +
> Characteristic Descriptors hierarchy
> ====================================
>
> --
> 2.14.1.690.gbb1197296e-goog
>

2017-09-14 23:47:48

by Yunhan Wang

[permalink] [raw]
Subject: [PATCH BlueZ 1/3] doc/gatt-api: Add UpdateMTU and MTU

Add updateMTU in gatt method to get att mtu value in server side.
Add MTU property in gatt property.
---
doc/gatt-api.txt | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
index cdd15f301..419308a7e 100644
--- a/doc/gatt-api.txt
+++ b/doc/gatt-api.txt
@@ -169,6 +169,13 @@ Methods array{byte} ReadValue(dict options)

Possible Errors: org.bluez.Error.Failed

+ void UpdateMTU() [optional] (Server only)
+
+ This method doesn't expect a reply so it is just
+ MTU value update in user space at server side.
+
+ Possible Errors: org.bluez.Error.Failed
+
Properties string UUID [read-only]

128-bit characteristic UUID.
@@ -225,6 +232,10 @@ Properties string UUID [read-only]
"secure-read" (Server only)
"secure-write" (Server only)

+ uint16_t MTU [read-only, optional]
+
+ ATT MTU value
+
Characteristic Descriptors hierarchy
====================================

--
2.14.1.690.gbb1197296e-goog


2017-09-14 23:47:47

by Yunhan Wang

[permalink] [raw]
Subject: [PATCH BlueZ 2/3] gatt: Do UpdateMTU when write comes in

Add mtu in external_chrc strcutre, and call UpdateMTU when MTU exchange complete and write comes in
---
src/gatt-database.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 61eed71d6..2658ac207 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -122,6 +122,7 @@ struct external_chrc {
struct queue *pending_reads;
struct queue *pending_writes;
unsigned int ntfy_cnt;
+ uint16_t mtu;
};

struct external_desc {
@@ -1678,6 +1679,12 @@ static struct pending_op *send_read(struct btd_device *device,
return NULL;
}

+static void update_mtu_setup_cb(DBusMessageIter *iter, void *user_data)
+{
+ struct external_chrc *chrc = user_data;
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &chrc->mtu);
+}
+
static void write_setup_cb(DBusMessageIter *iter, void *user_data)
{
struct pending_op *op = user_data;
@@ -2090,12 +2097,17 @@ static void chrc_write_cb(struct gatt_db_attribute *attrib,
struct external_chrc *chrc = user_data;
struct btd_device *device;
struct queue *queue;
+ uint16_t mtu;

if (chrc->attrib != attrib) {
error("Write callback called with incorrect attribute");
goto fail;
}

+ mtu = bt_att_get_mtu(att);
+ chrc->mtu = mtu;
+ g_dbus_proxy_method_call(chrc->proxy, "UpdateMTU", update_mtu_setup_cb, NULL, user_data, NULL);
+
device = att_get_device(att);
if (!device) {
error("Unable to find device object");
--
2.14.1.690.gbb1197296e-goog