doc/gatt-api: Add options dictionary to ReadValue/WriteValue
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/4 doc/gatt-api: Add options dictionary to ReadValue/WriteValue
From: Luiz Augusto von Dentz <[email protected]>
This adds the possibility to pass an offset to these operations, and also in the server case to give the device object.
--- doc/gatt-api.txt | 20 ++++-- src/gatt-client.c | 135 +++++++++++++++++++++++++++++---------- src/gatt-database.c | 177 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 245 insertions(+), 87 deletions(-)
doc/gatt-api.txt +16 -4
@@ -61,23 +61,29 @@ Service org.bluez Interface org.bluez.GattCharacteristic1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict options) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": uint16 offset + "device": Object Device (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict options) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted
@@ -154,23 +160,29 @@ Service org.bluez Interface org.bluez.GattDescriptor1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict flags) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict flags) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted
src/gatt-client.c +103 -32
249 lines not on this page · raw message
src/gatt-database.c +126 -51
299 lines not on this page · raw message
Signature · 1 line
2.5.5
Luiz Augusto von Dentz
maintainerPATCH 2/4 doc/gatt-api: Merge RegisterProfile with RegisterApplication
From: Luiz Augusto von Dentz <[email protected]>
Since RegisterApplication makes use of ObjectManager it is also possible to verify the existance of GattProfile objects unifying the API for both services (GATT server) and profiles (GATT client).
--- doc/gatt-api.txt | 37 ++--- src/gatt-database.c | 414 +++++++++++++++++++++------------------------------- 2 files changed, 172 insertions(+), 279 deletions(-)
doc/gatt-api.txt +9 -28
@@ -218,8 +218,8 @@ Properties string UUID [read-only] "encrypt-authenticated-read" "encrypt-authenticated-write" -Profile hierarcy -================ +GATT Profile hierarcy +===================== Local profile (GATT client) instance. By registering this type of object an application effectively indicates support for a specific GATT profile
@@ -238,6 +238,10 @@ Methods void Release() profile, because when this method gets called it has already been unregistered. +Properties array{string} UUIDs [read-only] + + 128-bit GATT service UUIDs. + GATT Manager hierarchy ======================
@@ -306,11 +310,12 @@ Object path [variable prefix]/{hci0,hci1,...} Methods void RegisterApplication(object application, dict options) Registers a local GATT services hierarchy as described - above. + above (GATT Server) and/or GATT profiles (GATT Client). The application object path together with the D-Bus system bus connection ID define the identification of - the application registering a GATT based service. + the application registering a GATT based + service or profile. Possible errors: org.bluez.Error.InvalidArguments org.bluez.Error.AlreadyExists
@@ -324,27 +329,3 @@ Methods void RegisterApplication(object application, dict options) Possible errors: org.bluez.Error.InvalidArguments org.bluez.Error.DoesNotExist - - void RegisterProfile(object profile, array{string} UUIDs, - dict options) - - Registers a GATT (client role) profile exported - under interface GattProfile1. The array of UUIDs - specifies the mandatory set of remote service - UUIDs that should all be available for the - remote device to match this profile. Matching - devices will be added to the auto-connection - list and connected whenever available. - - Possible errors: org.bluez.Error.InvalidArguments - org.bluez.Error.AlreadyExists - - void UnregisterProfile(object profile) - - This unregisters the profile that has been - previously registered. The object path parameter - must match the same value that has been used - on registration. - - Possible errors: org.bluez.Error.InvalidArguments - org.bluez.Error.DoesNotExist
src/gatt-database.c +163 -251
495 lines not on this page · raw message
Signature · 1 line
2.5.5
Luiz Augusto von Dentz
maintainerPATCH 3/4 doc/gatt-api: Add secure flags
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This add secure-{read,write} which shall be used by servers that want to restrict attribute access to secure connection only (BT_SECURITY_FIPS)
--- doc/gatt-api.txt | 4 +++ lib/bluetooth.h | 1 + src/gatt-database.c | 90 ++++++++++++++++++++---------------------------- src/shared/att-types.h | 5 +++ src/shared/gatt-server.c | 3 ++ 5 files changed, 51 insertions(+), 52 deletions(-)
doc/gatt-api.txt +4 -0
@@ -150,6 +150,8 @@ Properties string UUID [read-only] "encrypt-write" "encrypt-authenticated-read" "encrypt-authenticated-write" + "secure-read" (Server only) + "secure-write" (Server only) Characteristic Descriptors hierarchy ====================================
@@ -217,6 +219,8 @@ Properties string UUID [read-only] "encrypt-write" "encrypt-authenticated-read" "encrypt-authenticated-write" + "secure-read" (Server Only) + "secure-write" (Server Only) GATT Profile hierarcy =====================
lib/bluetooth.h +1 -0
@@ -69,6 +69,7 @@ struct bt_security {#define BT_SECURITY_LOW 1#define BT_SECURITY_MEDIUM 2#define BT_SECURITY_HIGH 3 +#define BT_SECURITY_FIPS 4#define BT_DEFER_SETUP 7
src/gatt-database.c +38 -52
172 lines not on this page · raw message
src/shared/att-types.h +5 -0
@@ -31,6 +31,7 @@#define BT_ATT_SECURITY_LOW 1#define BT_ATT_SECURITY_MEDIUM 2#define BT_ATT_SECURITY_HIGH 3 +#define BT_ATT_SECURITY_FIPS 4#define BT_ATT_DEFAULT_LE_MTU 23#define BT_ATT_MAX_LE_MTU 517
@@ -123,6 +124,10 @@ struct bt_att_pdu_error_rsp { BT_ATT_PERM_WRITE_AUTHEN)#define BT_ATT_PERM_AUTHOR 0x40#define BT_ATT_PERM_NONE 0x80 +#define BT_ATT_PERM_READ_SECURE 0x0100 +#define BT_ATT_PERM_WRITE_SECURE 0x0200 +#define BT_ATT_PERM_SECURE (BT_ATT_PERM_READ_SECURE | \ + BT_ATT_PERM_WRITE_SECURE)/* GATT Characteristic Properties Bitfield values */ #define BT_GATT_CHRC_PROP_BROADCAST 0x01
src/shared/gatt-server.c +3 -0
@@ -398,6 +398,9 @@ static uint8_t check_permissions(struct bt_gatt_server *server,return 0 ; security =bt_att_get_security (server->att); +if (perm &BT_ATT_PERM_SECURE && security <BT_ATT_SECURITY_FIPS ) +return BT_ATT_ERROR_AUTHENTICATION ; +if (perm &BT_ATT_PERM_AUTHEN && security <BT_ATT_SECURITY_HIGH )return BT_ATT_ERROR_AUTHENTICATION ;
Signature · 1 line
2.5.5
Luiz Augusto von Dentz
maintainerPATCH 4/4 test: Update GATT examples with the new API
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- test/example-gatt-client | 2 +- test/example-gatt-server | 90 +++++++++++++++++++++++++------- test/test-gatt-profile | 130 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 172 insertions(+), 50 deletions(-)
test/example-gatt-client +1 -1
@@ -113,7 +113,7 @@ def hr_msrmt_changed_cb(iface, changed_props, invalidated_props): def start_client(): # Read the Body Sensor Location value and print it asynchronously. - body_snsr_loc_chrc[0].ReadValue(reply_handler=body_sensor_val_cb, + body_snsr_loc_chrc[0].ReadValue({}, reply_handler=body_sensor_val_cb, error_handler=generic_error_cb, dbus_interface=GATT_CHRC_IFACE)
test/example-gatt-server +71 -19
170 lines not on this page · raw message
test/test-gatt-profile +100 -30
146 lines not on this page · raw message
Signature · 1 line
2.5.5
Quoted 28 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the possibility to pass an offset to these operations, and also in the server case to give the device object.
--- doc/gatt-api.txt | 20 ++++-- src/gatt-client.c | 135 +++++++++++++++++++++++++++++---------- src/gatt-database.c | 177 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 245 insertions(+), 87 deletions(-)doc/gatt-api.txt +4
-1@@ -61,23 +61,29 @@ Service org.bluez Interface org.bluez.GattCharacteristic1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict options) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": uint16 offset + "device": Object Device (Server only) +
[...]
Quoted 5 lines
doc/gatt-api.txt +4
-0+static int parse_options(DBusMessage *msg, uint16_t *offset) +{ + DBusMessageIter args, flags; +
doc/gatt-api.txt
Quoted 10 lines
doc/gatt-api.txt +10
-0+ if (!dbus_message_iter_init(msg, &args)) + return -EINVAL; + + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) + return -EINVAL; + + dbus_message_iter_recurse(&args, &flags); + if (dbus_message_iter_get_arg_type(&flags) != DBUS_TYPE_DICT_ENTRY) + return -EINVAL; +
I would think that from the documentation, "Possible options", that providing the offset would be optional. I don't think much is gained making this mandatory.
Quoted 12 lines
doc/gatt-api.txt +12
-0+ while (dbus_message_iter_get_arg_type(&flags) == DBUS_TYPE_DICT_ENTRY) { + const char *key; + DBusMessageIter value, entry; + int var; + + dbus_message_iter_recurse(&flags, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + var = dbus_message_iter_get_arg_type(&value);
doc/gatt-api.txt
Quoted 10 lines
doc/gatt-api.txt +10
-0+ if (strcasecmp(key, "offset") == 0) { + if (var != DBUS_TYPE_UINT16) + return -EINVAL; + dbus_message_iter_get_basic(&value, offset); + } + } + + return 0; +} +
Cheers,
--
Vinicius
Luiz Augusto von Dentz
maintainerHi Vinicius,
Quoted 43 lines · Vinicius Costa Gomes
Quoted 28 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the possibility to pass an offset to these operations, and also in the server case to give the device object.
--- doc/gatt-api.txt | 20 ++++-- src/gatt-client.c | 135 +++++++++++++++++++++++++++++---------- src/gatt-database.c | 177 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 245 insertions(+), 87 deletions(-)doc/gatt-api.txt +4
-1@@ -61,23 +61,29 @@ Service org.bluez Interface org.bluez.GattCharacteristic1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict options) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": uint16 offset + "device": Object Device (Server only) +[...]
Quoted 10 lines
doc/gatt-api.txt +9
-0+static int parse_options(DBusMessage *msg, uint16_t *offset) +{ + DBusMessageIter args, flags; + + if (!dbus_message_iter_init(msg, &args)) + return -EINVAL; + + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) + return -EINVAL;
Quoted 8 lines
doc/gatt-api.txt
Quoted 5 lines
doc/gatt-api.txt +5
-0+ + dbus_message_iter_recurse(&args, &flags); + if (dbus_message_iter_get_arg_type(&flags) != DBUS_TYPE_DICT_ENTRY) + return -EINVAL; +I would think that from the documentation, "Possible options", that providing the offset would be optional. I don't think much is gained making this mandatory.
I guess you are referring to empty array, so yes we should probably drop the check for dict entry so it can be empty since it is optional.
Quoted 27 lines
Quoted 12 lines
doc/gatt-api.txt +12
-0+ while (dbus_message_iter_get_arg_type(&flags) == DBUS_TYPE_DICT_ENTRY) { + const char *key; + DBusMessageIter value, entry; + int var; + + dbus_message_iter_recurse(&flags, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + var = dbus_message_iter_get_arg_type(&value);doc/gatt-api.txt
Quoted 10 lines
doc/gatt-api.txt +10
-0+ if (strcasecmp(key, "offset") == 0) { + if (var != DBUS_TYPE_UINT16) + return -EINVAL; + dbus_message_iter_get_basic(&value, offset); + } + } + + return 0; +} +Cheers,
--
Vinicius
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 18 lines · Luiz Augusto von Dentz
Quoted 9 lines
Quoted 9 lines
src/gatt-client.c +9
-0+static int parse_options (DBusMessage *msg,uint16_t *offset) +{ +DBusMessageIter args, flags; + +if (!dbus_message_iter_init (msg, &args)) +return -EINVAL ; + +if (dbus_message_iter_get_arg_type (&args) !=DBUS_TYPE_ARRAY ) +return -EINVAL ;Quoted 8 lines
src/gatt-client.c fail: · line 407
Quoted 5 lines
src/gatt-client.c +5
-0+ +dbus_message_iter_recurse (&args, &flags); +if (dbus_message_iter_get_arg_type (&flags) !=DBUS_TYPE_DICT_ENTRY ) +return -EINVAL ; +I would think that from the documentation, "Possible options", that providing the offset would be optional. I don't think much is gained making this mandatory.
Quoted 3 lines
I guess you are referring to empty array, so yes we should probably drop the check for dict entry so it can be empty since it is optional.
I was thinking that a ReadValue() message without any arguments would make sense to be valid. And one less thing to change in applications if they don't need the offset.
Quoted 30 lines
Quoted 19 lines
Quoted 19 lines
src/gatt-client.c +19
-0+while (dbus_message_iter_get_arg_type (&flags) ==DBUS_TYPE_DICT_ENTRY ) { +const char *key; +DBusMessageIter value, entry; +int var; + +dbus_message_iter_recurse (&flags, &entry); +dbus_message_iter_get_basic (&entry, &key); + +dbus_message_iter_next (&entry); +dbus_message_iter_recurse (&entry, &value); + + var =dbus_message_iter_get_arg_type (&value); +if (strcasecmp (key,"offset" ) ==0 ) { +if (var !=DBUS_TYPE_UINT16 ) +return -EINVAL ; +dbus_message_iter_get_basic (&value, offset); + } + } +Quoted 8 lines
src/gatt-client.c fail: · line 429
Quoted 3 lines
src/gatt-client.c +3
-0+return 0 ; +} +Cheers,
--
Vinicius
Quoted 2 lines
--
Luiz Augusto von Dentz
Cheers,
--
Vinicius
Hi Luiz,
Quoted 166 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the possibility to pass an offset to these operations, and also in the server case to give the device object.
--- doc/gatt-api.txt | 20 ++++-- src/gatt-client.c | 135 +++++++++++++++++++++++++++++---------- src/gatt-database.c | 177 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 245 insertions(+), 87 deletions(-)doc/gatt-api.txt +16
-4@@ -61,23 +61,29 @@ Service org.bluez Interface org.bluez.GattCharacteristic1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict options) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": uint16 offset + "device": Object Device (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict options) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted@@ -154,23 +160,29 @@ Service org.bluez Interface org.bluez.GattDescriptor1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict flags) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict flags) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermittedsrc/gatt-client.c +57
-2@@ -23,6 +23,7 @@#include <stdbool.h> #include <stdint.h> +#include <errno.h> #include <dbus/dbus.h> @@ -390,12 +391,67 @@ fail:return ; } +static int parse_options (DBusMessage *msg,uint16_t *offset) +{ +DBusMessageIter args, flags; + +if (!dbus_message_iter_init (msg, &args)) +return -EINVAL ; + +if (dbus_message_iter_get_arg_type (&args) !=DBUS_TYPE_ARRAY ) +return -EINVAL ; + +dbus_message_iter_recurse (&args, &flags); +if (dbus_message_iter_get_arg_type (&flags) !=DBUS_TYPE_DICT_ENTRY ) +return -EINVAL ; + +while (dbus_message_iter_get_arg_type (&flags) ==DBUS_TYPE_DICT_ENTRY ) { +const char *key; +DBusMessageIter value, entry; +int var; + +dbus_message_iter_recurse (&flags, &entry); +dbus_message_iter_get_basic (&entry, &key); + +dbus_message_iter_next (&entry); +dbus_message_iter_recurse (&entry, &value); + + var =dbus_message_iter_get_arg_type (&value); +if (strcasecmp (key,"offset" ) ==0 ) { +if (var !=DBUS_TYPE_UINT16 ) +return -EINVAL ; +dbus_message_iter_get_basic (&value, offset); + } + } + +return 0 ; +} + +static unsigned int read_value (struct bt_gatt_client *gatt,uint16_t handle, +bt_gatt_client_read_callback_t callback, +struct async_dbus_op *op) +{ +if (op->offset) +return bt_gatt_client_read_long_value (gatt, handle, op->offset, + callback, +async_dbus_op_ref (op), + async_dbus_op_unref); +else +return bt_gatt_client_read_value (gatt, handle, callback, +async_dbus_op_ref (op), + async_dbus_op_unref); +} +static DBusMessage *descriptor_read_value (DBusConnection *conn,DBusMessage *msg,void *user_data) {struct descriptor *desc = user_data;struct bt_gatt_client *gatt = desc->chrc->service->client->gatt;struct async_dbus_op *op; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -406,17 +462,16 @@ static DBusMessage *descriptor_read_value(DBusConnection *conn, op = new0(struct async_dbus_op, 1); op->msg =dbus_message_ref (msg); op->data = desc; + op->offset = offset; - desc->read_id = bt_gatt_client_read_value(gatt, desc->handle, - desc_read_cb,
src/gatt-client.c static DBusMessage *descriptor_read_value(DBusConnection *conn, · line 474
Quoted 10 lines
src/gatt-client.c +2
-2-async_dbus_op_ref (op), - async_dbus_op_unref); + desc->read_id =read_value (gatt, desc->handle, desc_read_cb, op);if (desc->read_id)return NULL ;async_dbus_op_free (op);return btd_error_failed (msg,"Failed to send read request" ); +
Extra empty line.
Quoted 193 lines
src/gatt-client.c +44
-28} static void write_result_cb(bool success, bool reliable_error,@@ -459,7 +514,8 @@ static void write_cb(bool success, uint8_t att_ecode, void *user_data)static unsigned int start_long_write (DBusMessage *msg,uint16_t handle,struct bt_gatt_client *gatt,bool reliable,const uint8_t *value, -size_t value_len,void *data, +size_t value_len,uint16_t offset, +void *data,async_dbus_op_complete_t complete) {struct async_dbus_op *op;@@ -469,9 +525,10 @@ static unsigned int start_long_write(DBusMessage *msg, uint16_t handle, op->msg =dbus_message_ref (msg); op->data = data; op->complete = complete; + op->offset = offset; - id =bt_gatt_client_write_long_value (gatt, reliable, handle, -0 , value, value_len, + id =bt_gatt_client_write_long_value (gatt, reliable, handle, offset, + value, value_len, write_result_cb, op, async_dbus_op_free);@@ -524,6 +581,10 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,struct bt_gatt_client *gatt = desc->chrc->service->client->gatt;uint8_t *value =NULL ;size_t value_len =0 ; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -546,15 +607,15 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,* Based on the value length and the MTU, either use a write or a long * write. */ -if (value_len <= (unsigned )bt_gatt_client_get_mtu (gatt) -3 ) +if (value_len <= (unsigned )bt_gatt_client_get_mtu (gatt) -3 && !offset) desc->write_id =start_write_request (msg, desc->handle, gatt, value, value_len, desc, desc_write_complete);else - desc->write_id =start_long_write (msg, desc->handle, - gatt, false, value, - value_len, desc, + desc->write_id =start_long_write (msg, desc->handle, gatt, + false, value, + value_len, offset, desc, desc_write_complete);if (!desc->write_id)@@ -574,13 +635,15 @@ static const GDBusPropertyTable descriptor_properties[] = { };static const GDBusMethodTable descriptor_methods[] = { - {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" ,NULL , - GDBUS_ARGS({ "value", "ay" }), - descriptor_read_value) }, + {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" , + GDBUS_ARGS({ "options", "a{sv}" }), + GDBUS_ARGS({ "value", "ay" }), + descriptor_read_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("WriteValue" , - GDBUS_ARGS({ "value", "ay" }), -NULL , - descriptor_write_value) }, + GDBUS_ARGS({ "value", "ay" }, + { "options", "a{sv}" }), +NULL , + descriptor_write_value) }, { } };@@ -838,6 +901,10 @@ static DBusMessage *characteristic_read_value(DBusConnection *conn,struct characteristic *chrc = user_data;struct bt_gatt_client *gatt = chrc->service->client->gatt;struct async_dbus_op *op; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -848,11 +915,9 @@ static DBusMessage *characteristic_read_value(DBusConnection *conn, op = new0(struct async_dbus_op, 1); op->msg =dbus_message_ref (msg); op->data = chrc; + op->offset = offset; - chrc->read_id =bt_gatt_client_read_value (gatt, chrc->value_handle, - chrc_read_cb, -async_dbus_op_ref (op), - async_dbus_op_unref); + chrc->read_id =read_value (gatt, chrc->value_handle, chrc_read_cb, op);if (chrc->read_id)return NULL ;@@ -882,6 +947,10 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,uint8_t *value =NULL ;size_t value_len =0 ;bool supported = false; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -906,7 +975,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,if ((chrc->ext_props &BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE )) { supported = true; chrc->write_id =start_long_write (msg, chrc->value_handle, gatt, - true, value, value_len, + true, value, value_len, offset, chrc, chrc_write_complete);if (chrc->write_id)return NULL ;@@ -920,7 +989,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,if (!mtu)return btd_error_failed (msg,"No ATT transport" ); -if (value_len <= (unsigned ) mtu -3 ) +if (value_len <= (unsigned ) mtu -3 && !offset) chrc->write_id = start_write_request(msg, chrc->value_handle, gatt, value, value_len,@@ -928,7 +997,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,else chrc->write_id =start_long_write (msg, chrc->value_handle, gatt, - false, value, value_len, + false, value, value_len, offset, chrc, chrc_write_complete);if (chrc->write_id)@@ -1242,17 +1311,19 @@ static const GDBusPropertyTable characteristic_properties[] = { };static const GDBusMethodTable characteristic_methods[] = { - {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" ,NULL , - GDBUS_ARGS({ "value", "ay" }), - characteristic_read_value) }, + {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" , + GDBUS_ARGS({ "options", "a{sv}" }), + GDBUS_ARGS({ "value", "ay" }), + characteristic_read_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("WriteValue" , - GDBUS_ARGS({ "value", "ay" }), -NULL , - characteristic_write_value) }, + GDBUS_ARGS({ "value", "ay" }, + { "options", "a{sv}" }), +NULL , + characteristic_write_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("StartNotify" ,NULL ,NULL , - characteristic_start_notify) }, + characteristic_start_notify) }, {GDBUS_EXPERIMENTAL_METHOD ("StopNotify" ,NULL ,NULL , - characteristic_stop_notify) }, + characteristic_stop_notify) }, { } };src/gatt-database.c +3
-1@@ -135,6 +135,7 @@ struct external_desc { };struct pending_op { +struct btd_device *device;unsigned int id;struct gatt_db_attribute *attrib;struct queue *owner_queue;@@ -1592,7 +1593,8 @@ static void pending_op_free(void *data)free (op); } -static struct pending_op *pending_read_new (struct queue *owner_queue, +static struct pending_op *pending_read_new (struct btd_device *device, +struct queue *owner_queue,struct gatt_db_attribute *attrib,unsigned int id) {
src/gatt-database.c static struct pending_op *pending_read_new(struct queue *owner_queue, · line 1606
Quoted 4 lines
src/gatt-database.c +1
-0@@ -1601,6 +1603,7 @@ static struct pending_op *pending_read_new(struct queue *owner_queue, op = new0(struct pending_op, 1); op->owner_queue = owner_queue; + op->device = device;
Increase the device's reference counting?
Quoted 133 lines
src/gatt-database.c +60
-12op->attrib = attrib; op->id = id;queue_push_tail (owner_queue, op);@@ -1608,17 +1611,44 @@ static struct pending_op *pending_read_new(struct queue *owner_queue,return op; } -static void send_read (struct gatt_db_attribute *attrib,GDBusProxy *proxy, -struct queue *owner_queue, -unsigned int id) +static void append_options (DBusMessageIter *iter,void *user_data) +{ +struct pending_op *op = user_data; +const char *path =device_get_path (op->device); + +dict_append_entry (iter,"device" ,DBUS_TYPE_OBJECT_PATH , &path); +} + +static void read_setup_cb (DBusMessageIter *iter,void *user_data) +{ +struct pending_op *op = user_data; +DBusMessageIter dict; + +dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY , +DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + +append_options (&dict, op); + +dbus_message_iter_close_container (iter, &dict); +} + +static void send_read (struct btd_device *device, +struct gatt_db_attribute *attrib, +GDBusProxy *proxy, +struct queue *owner_queue, +unsigned int id) {struct pending_op *op;uint8_t ecode =BT_ATT_ERROR_UNLIKELY ; - op =pending_read_new (owner_queue, attrib, id); + op =pending_read_new (device, owner_queue, attrib, id); -if (g_dbus_proxy_method_call (proxy,"ReadValue" ,NULL , read_reply_cb, - op, pending_op_free) == TRUE) +if (g_dbus_proxy_method_call (proxy,"ReadValue" , read_setup_cb, + read_reply_cb, op, pending_op_free) == TRUE)return ;pending_op_free (op);@@ -1629,12 +1659,28 @@ static void send_read(struct gatt_db_attribute *attrib, GDBusProxy *proxy,static void write_setup_cb (DBusMessageIter *iter,void *user_data) {struct pending_op *op = user_data; -DBusMessageIter array; +DBusMessageIter array, dict;dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY ,"y" , &array);dbus_message_iter_append_fixed_array (&array,DBUS_TYPE_BYTE , &op->data.iov_base, op->data.iov_len);dbus_message_iter_close_container (iter, &array); + +dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY , +DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + +append_options (&dict, op); + +dbus_message_iter_close_container (iter, &dict); + +if (!op->owner_queue) { +gatt_db_attribute_write_result (op->attrib, op->id,0 ); +pending_op_free (op); + } }static void write_reply_cb (DBusMessage *message,void *user_data)@@ -1673,7 +1719,8 @@ done:gatt_db_attribute_write_result (op->attrib, op->id, ecode); } -static struct pending_op *pending_write_new(struct queue *owner_queue, +static struct pending_op *pending_write_new(struct btd_device *device, + struct queue *owner_queue, struct gatt_db_attribute *attrib, unsigned int id, const uint8_t *value,@@ -1686,6 +1733,7 @@ static struct pending_op *pending_write_new(struct queue *owner_queue, op->data.iov_base = (uint8_t *) value; op->data.iov_len = len; + op->device = device; op->owner_queue = owner_queue; op->attrib = attrib; op->id = id;@@ -1694,7 +1742,9 @@ static struct pending_op *pending_write_new(struct queue *owner_queue,return op; } -static void send_write (struct gatt_db_attribute *attrib,GDBusProxy *proxy, +static void send_write (struct btd_device *device, +struct gatt_db_attribute *attrib, +GDBusProxy *proxy,struct queue *owner_queue,unsigned int id,const uint8_t *value,size_t len)@@ -1702,11 +1752,11 @@ static void send_write(struct gatt_db_attribute *attrib, GDBusProxy *proxy,struct pending_op *op;uint8_t ecode =BT_ATT_ERROR_UNLIKELY ; - op =pending_write_new (owner_queue, attrib, id, value, len); + op =pending_write_new (device, owner_queue, attrib, id, value, len);if (g_dbus_proxy_method_call (proxy,"WriteValue" , write_setup_cb, - write_reply_cb, op, - pending_op_free) == TRUE) + owner_queue ? write_reply_cb :NULL , + op, pending_op_free) == TRUE)return ;pending_op_free (op);@@ -1895,19 +1945,58 @@ static bool database_add_cep(struct external_service *service,return true; } +static struct btd_device *att_get_device (struct bt_att *att)
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1958
Quoted 10 lines
src/gatt-database.c +10
-0+{ +GIOChannel *io =NULL ; +GError *gerr =NULL ; +bdaddr_t src, dst; +uint8_t dst_type; +struct btd_adapter *adapter; + + io =g_io_channel_unix_new (bt_att_get_fd (att)); +if (!io) +return false;
return NULL?
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1968
Quoted 10 lines
src/gatt-database.c +10
-0+ +bt_io_get (io, &gerr,BT_IO_OPT_SOURCE_BDADDR , &src, +BT_IO_OPT_DEST_BDADDR , &dst, +BT_IO_OPT_DEST_TYPE , &dst_type, +BT_IO_OPT_INVALID ); +if (gerr) { +error ("bt_io_get: %s" , gerr->message); +g_error_free (gerr); +g_io_channel_unref (io); +return false;
also here.
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1976
Quoted 8 lines
src/gatt-database.c +8
-0+ } + +g_io_channel_unref (io); + + adapter =adapter_find (&src); +if (!adapter) { +error ("Unable to find adapter object" ); +return false;
and here.
Quoted 32 lines
src/gatt-database.c +12
-1+ } + +return btd_adapter_find_device (adapter, &dst, dst_type); +} +static void desc_read_cb (struct gatt_db_attribute *attrib,unsigned int id,uint16_t offset,uint8_t opcode,struct bt_att *att,void *user_data) {struct external_desc *desc = user_data; +struct btd_device *device;if (desc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; } -send_read (attrib, desc->proxy, desc->pending_reads, id); + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); + +send_read (device, attrib, desc->proxy, desc->pending_reads, id); } static void desc_write_cb(struct gatt_db_attribute *attrib,@@ -1917,13 +2006,19 @@ static void desc_write_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_desc *desc = user_data; +struct btd_device *device;
src/gatt-database.c static void desc_write_cb(struct gatt_db_attribute *attrib, · line 2018
Quoted 10 lines
src/gatt-database.c +3
-1if (desc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; } -send_write (attrib, desc->proxy, desc->pending_writes, id, value, len); + device =att_get_device (att); +if (!device) +error ("Unable to find device object" );
I guess you should return here. There are couple of places like this. If this is not a mistake, I guess you could make append_options() not append the NULL path, if there's no device associated.
Quoted 89 lines
src/gatt-database.c +19
-37+ +send_write (device, attrib, desc->proxy, desc->pending_writes, id, + value, len); } static bool database_add_desc(struct external_service *service,@@ -1956,43 +2051,18 @@ static void chrc_read_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_chrc *chrc = user_data; +struct btd_device *device;if (chrc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; } -send_read (attrib, chrc->proxy, chrc->pending_reads, id); -} - -static void write_without_response_setup_cb (DBusMessageIter *iter, -void *user_data) -{ -struct iovec *iov = user_data; -DBusMessageIter array; - -dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY ,"y" , &array); -dbus_message_iter_append_fixed_array (&array,DBUS_TYPE_BYTE , - &iov->iov_base, iov->iov_len); -dbus_message_iter_close_container (iter, &array); -} - -static void send_write_without_response (struct gatt_db_attribute *attrib, -GDBusProxy *proxy,unsigned int id, -const uint8_t *value,size_t len) -{ -struct iovec iov; -uint8_t ecode =0 ; - - iov.iov_base = (uint8_t *) value; - iov.iov_len = len; - -if (!g_dbus_proxy_method_call (proxy,"WriteValue" , - write_without_response_setup_cb, -NULL , &iov,NULL )) - ecode =BT_ATT_ERROR_UNLIKELY ; + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); -gatt_db_attribute_write_result (attrib, id, ecode); +send_read (device, attrib, chrc->proxy, chrc->pending_reads, id); } static void chrc_write_cb(struct gatt_db_attribute *attrib,@@ -2002,19 +2072,24 @@ static void chrc_write_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_chrc *chrc = user_data; +struct btd_device *device; +struct queue *queue;if (chrc->attrib != attrib) {error ("Write callback called with incorrect attribute" );return ; } -if (chrc->props &BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP ) { -send_write_without_response (attrib, chrc->proxy, id, value, - len); -return ; - } +if (!(chrc->props &BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP )) + queue = chrc->pending_writes; +else + queue =NULL ; + + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); -send_write (attrib, chrc->proxy, chrc->pending_writes, id, value, len); +send_write (device, attrib, chrc->proxy, queue, id, value, len); } static bool database_add_chrc(struct external_service *service, --2.5.5
Quoted 4 lines
--
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
Cheers,
--
Vinicius
Re: [PATCH BlueZ 2/4] doc/gatt-api: Merge RegisterProfile with RegisterApplication
In reply to Luiz Augusto von DentzHi Luiz,
Quoted 6 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
Since RegisterApplication makes use of ObjectManager it is also possible to verify the existance of GattProfile objects unifying the API for both services (GATT server) and profiles (GATT client).
---
Just cosmetic stuff.
Quoted 12 lines
doc/gatt-api.txt | 37 ++--- src/gatt-database.c | 414 +++++++++++++++++++++------------------------------- 2 files changed, 172 insertions(+), 279 deletions(-)doc/gatt-api.txt +0
-0@@ -218,8 +218,8 @@ Properties string UUID [read-only] "encrypt-authenticated-read" "encrypt-authenticated-write"
[...]
doc/gatt-api.txt
Quoted 12 lines
doc/gatt-api.txt +12
-0+static void add_profile(void *data, void *user_data) +{ + struct btd_adapter *adapter = user_data; + + btd_profile_register(data); + adapter_add_profile(adapter, data); +} + +static struct external_profile *create_profile(struct gatt_app *app, + GDBusProxy *proxy, + const char *path) +
Extra empty line.
Quoted 34 lines
doc/gatt-api.txt +34
-0+{ + struct external_profile *profile; + DBusMessageIter iter, array; + + if (!path || !g_str_has_prefix(path, "/")) + return NULL; + + profile = new0(struct external_profile, 1); + + profile->app = app; + profile->proxy = g_dbus_proxy_ref(proxy); + profile->profiles = queue_new(); + + if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter)) { + DBG("UUIDs property not found"); + goto fail; + } + + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) { + const char *uuid; + + dbus_message_iter_get_basic(&array, &uuid); + + if (profile_add(profile, uuid) < 0) + goto fail; + + dbus_message_iter_next(&array); + } + + if (queue_isempty(profile->profiles)) + goto fail; +
doc/gatt-api.txt
Quoted 10 lines
doc/gatt-api.txt +10
-0+ queue_foreach(profile->profiles, add_profile, app->database->adapter); + queue_push_tail(app->profiles, profile); + + return profile; + +fail: + profile_free(profile); + return NULL; +} +
Cheers,
--
Vinicius
Luiz Augusto von Dentz
maintainerHi Vinicius,
Quoted 378 lines · Vinicius Costa Gomes
Hi Luiz,
Quoted 166 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the possibility to pass an offset to these operations, and also in the server case to give the device object.
--- doc/gatt-api.txt | 20 ++++-- src/gatt-client.c | 135 +++++++++++++++++++++++++++++---------- src/gatt-database.c | 177 +++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 245 insertions(+), 87 deletions(-)doc/gatt-api.txt +16
-4@@ -61,23 +61,29 @@ Service org.bluez Interface org.bluez.GattCharacteristic1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict options) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": uint16 offset + "device": Object Device (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict options) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted@@ -154,23 +160,29 @@ Service org.bluez Interface org.bluez.GattDescriptor1 [Experimental] Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ -Methods array{byte} ReadValue() +Methods array{byte} ReadValue(dict flags) Issues a request to read the value of the characteristic and returns the value if the operation was successful. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermitted org.bluez.Error.NotAuthorized org.bluez.Error.NotSupported - void WriteValue(array{byte} value) + void WriteValue(array{byte} value, dict flags) Issues a request to write the value of the characteristic. + Possible options: "offset": Start offset + "device": Device path (Server only) + Possible Errors: org.bluez.Error.Failed org.bluez.Error.InProgress org.bluez.Error.NotPermittedsrc/gatt-client.c +57
-2@@ -23,6 +23,7 @@#include <stdbool.h> #include <stdint.h> +#include <errno.h> #include <dbus/dbus.h> @@ -390,12 +391,67 @@ fail:return ; } +static int parse_options (DBusMessage *msg,uint16_t *offset) +{ +DBusMessageIter args, flags; + +if (!dbus_message_iter_init (msg, &args)) +return -EINVAL ; + +if (dbus_message_iter_get_arg_type (&args) !=DBUS_TYPE_ARRAY ) +return -EINVAL ; + +dbus_message_iter_recurse (&args, &flags); +if (dbus_message_iter_get_arg_type (&flags) !=DBUS_TYPE_DICT_ENTRY ) +return -EINVAL ; + +while (dbus_message_iter_get_arg_type (&flags) ==DBUS_TYPE_DICT_ENTRY ) { +const char *key; +DBusMessageIter value, entry; +int var; + +dbus_message_iter_recurse (&flags, &entry); +dbus_message_iter_get_basic (&entry, &key); + +dbus_message_iter_next (&entry); +dbus_message_iter_recurse (&entry, &value); + + var =dbus_message_iter_get_arg_type (&value); +if (strcasecmp (key,"offset" ) ==0 ) { +if (var !=DBUS_TYPE_UINT16 ) +return -EINVAL ; +dbus_message_iter_get_basic (&value, offset); + } + } + +return 0 ; +} + +static unsigned int read_value (struct bt_gatt_client *gatt,uint16_t handle, +bt_gatt_client_read_callback_t callback, +struct async_dbus_op *op) +{ +if (op->offset) +return bt_gatt_client_read_long_value (gatt, handle, op->offset, + callback, +async_dbus_op_ref (op), + async_dbus_op_unref); +else +return bt_gatt_client_read_value (gatt, handle, callback, +async_dbus_op_ref (op), + async_dbus_op_unref); +} +static DBusMessage *descriptor_read_value (DBusConnection *conn,DBusMessage *msg,void *user_data) {struct descriptor *desc = user_data;struct bt_gatt_client *gatt = desc->chrc->service->client->gatt;struct async_dbus_op *op; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -406,17 +462,16 @@ static DBusMessage *descriptor_read_value(DBusConnection *conn, op = new0(struct async_dbus_op, 1); op->msg =dbus_message_ref (msg); op->data = desc; + op->offset = offset; - desc->read_id = bt_gatt_client_read_value(gatt, desc->handle, - desc_read_cb,src/gatt-client.c static DBusMessage *descriptor_read_value(DBusConnection *conn, · line 474
Quoted 10 lines
src/gatt-client.c +2
-2-async_dbus_op_ref (op), - async_dbus_op_unref); + desc->read_id =read_value (gatt, desc->handle, desc_read_cb, op);if (desc->read_id)return NULL ;async_dbus_op_free (op);return btd_error_failed (msg,"Failed to send read request" ); +Extra empty line.
Quoted 195 lines
src/gatt-client.c +44
-28} static void write_result_cb(bool success, bool reliable_error,@@ -459,7 +514,8 @@ static void write_cb(bool success, uint8_t att_ecode, void *user_data)static unsigned int start_long_write (DBusMessage *msg,uint16_t handle,struct bt_gatt_client *gatt,bool reliable,const uint8_t *value, -size_t value_len,void *data, +size_t value_len,uint16_t offset, +void *data,async_dbus_op_complete_t complete) {struct async_dbus_op *op;@@ -469,9 +525,10 @@ static unsigned int start_long_write(DBusMessage *msg, uint16_t handle, op->msg =dbus_message_ref (msg); op->data = data; op->complete = complete; + op->offset = offset; - id =bt_gatt_client_write_long_value (gatt, reliable, handle, -0 , value, value_len, + id =bt_gatt_client_write_long_value (gatt, reliable, handle, offset, + value, value_len, write_result_cb, op, async_dbus_op_free);@@ -524,6 +581,10 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,struct bt_gatt_client *gatt = desc->chrc->service->client->gatt;uint8_t *value =NULL ;size_t value_len =0 ; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -546,15 +607,15 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,* Based on the value length and the MTU, either use a write or a long * write. */ -if (value_len <= (unsigned )bt_gatt_client_get_mtu (gatt) -3 ) +if (value_len <= (unsigned )bt_gatt_client_get_mtu (gatt) -3 && !offset) desc->write_id =start_write_request (msg, desc->handle, gatt, value, value_len, desc, desc_write_complete);else - desc->write_id =start_long_write (msg, desc->handle, - gatt, false, value, - value_len, desc, + desc->write_id =start_long_write (msg, desc->handle, gatt, + false, value, + value_len, offset, desc, desc_write_complete);if (!desc->write_id)@@ -574,13 +635,15 @@ static const GDBusPropertyTable descriptor_properties[] = { };static const GDBusMethodTable descriptor_methods[] = { - {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" ,NULL , - GDBUS_ARGS({ "value", "ay" }), - descriptor_read_value) }, + {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" , + GDBUS_ARGS({ "options", "a{sv}" }), + GDBUS_ARGS({ "value", "ay" }), + descriptor_read_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("WriteValue" , - GDBUS_ARGS({ "value", "ay" }), -NULL , - descriptor_write_value) }, + GDBUS_ARGS({ "value", "ay" }, + { "options", "a{sv}" }), +NULL , + descriptor_write_value) }, { } };@@ -838,6 +901,10 @@ static DBusMessage *characteristic_read_value(DBusConnection *conn,struct characteristic *chrc = user_data;struct bt_gatt_client *gatt = chrc->service->client->gatt;struct async_dbus_op *op; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -848,11 +915,9 @@ static DBusMessage *characteristic_read_value(DBusConnection *conn, op = new0(struct async_dbus_op, 1); op->msg =dbus_message_ref (msg); op->data = chrc; + op->offset = offset; - chrc->read_id =bt_gatt_client_read_value (gatt, chrc->value_handle, - chrc_read_cb, -async_dbus_op_ref (op), - async_dbus_op_unref); + chrc->read_id =read_value (gatt, chrc->value_handle, chrc_read_cb, op);if (chrc->read_id)return NULL ;@@ -882,6 +947,10 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,uint8_t *value =NULL ;size_t value_len =0 ;bool supported = false; +uint16_t offset =0 ; + +if (parse_options (msg, &offset)) +return btd_error_invalid_args (msg);if (!gatt)return btd_error_failed (msg,"Not connected" );@@ -906,7 +975,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,if ((chrc->ext_props &BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE )) { supported = true; chrc->write_id =start_long_write (msg, chrc->value_handle, gatt, - true, value, value_len, + true, value, value_len, offset, chrc, chrc_write_complete);if (chrc->write_id)return NULL ;@@ -920,7 +989,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,if (!mtu)return btd_error_failed (msg,"No ATT transport" ); -if (value_len <= (unsigned ) mtu -3 ) +if (value_len <= (unsigned ) mtu -3 && !offset) chrc->write_id = start_write_request(msg, chrc->value_handle, gatt, value, value_len,@@ -928,7 +997,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,else chrc->write_id =start_long_write (msg, chrc->value_handle, gatt, - false, value, value_len, + false, value, value_len, offset, chrc, chrc_write_complete);if (chrc->write_id)@@ -1242,17 +1311,19 @@ static const GDBusPropertyTable characteristic_properties[] = { };static const GDBusMethodTable characteristic_methods[] = { - {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" ,NULL , - GDBUS_ARGS({ "value", "ay" }), - characteristic_read_value) }, + {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("ReadValue" , + GDBUS_ARGS({ "options", "a{sv}" }), + GDBUS_ARGS({ "value", "ay" }), + characteristic_read_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("WriteValue" , - GDBUS_ARGS({ "value", "ay" }), -NULL , - characteristic_write_value) }, + GDBUS_ARGS({ "value", "ay" }, + { "options", "a{sv}" }), +NULL , + characteristic_write_value) }, {GDBUS_EXPERIMENTAL_ASYNC_METHOD ("StartNotify" ,NULL ,NULL , - characteristic_start_notify) }, + characteristic_start_notify) }, {GDBUS_EXPERIMENTAL_METHOD ("StopNotify" ,NULL ,NULL , - characteristic_stop_notify) }, + characteristic_stop_notify) }, { } };src/gatt-database.c +3
-1@@ -135,6 +135,7 @@ struct external_desc { };struct pending_op { +struct btd_device *device;unsigned int id;struct gatt_db_attribute *attrib;struct queue *owner_queue;@@ -1592,7 +1593,8 @@ static void pending_op_free(void *data)free (op); } -static struct pending_op *pending_read_new (struct queue *owner_queue, +static struct pending_op *pending_read_new (struct btd_device *device, +struct queue *owner_queue,struct gatt_db_attribute *attrib,unsigned int id) {@@ -1601,6 +1603,7 @@ static struct pending_op *pending_read_new(struct queue *owner_queue, op = new0(struct pending_op, 1);
Quoted 4 lines
src/gatt-database.c static struct pending_op *pending_read_new(struct queue *owner_queue, · line 1606
Quoted 2 lines
src/gatt-database.c +1
-0op->owner_queue = owner_queue; + op->device = device;Increase the device's reference counting?
Actually this can be a weak reference since we only use it on append_options which is actually called synchronously so there is no chance the device would be freed in the meantime.
Quoted 132 lines
Quoted 132 lines
src/gatt-database.c +59
-12op->attrib = attrib; op->id = id;queue_push_tail (owner_queue, op);@@ -1608,17 +1611,44 @@ static struct pending_op *pending_read_new(struct queue *owner_queue,return op; } -static void send_read (struct gatt_db_attribute *attrib,GDBusProxy *proxy, -struct queue *owner_queue, -unsigned int id) +static void append_options (DBusMessageIter *iter,void *user_data) +{ +struct pending_op *op = user_data; +const char *path =device_get_path (op->device); + +dict_append_entry (iter,"device" ,DBUS_TYPE_OBJECT_PATH , &path); +} + +static void read_setup_cb (DBusMessageIter *iter,void *user_data) +{ +struct pending_op *op = user_data; +DBusMessageIter dict; + +dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY , + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING +DBUS_DICT_ENTRY_END_CHAR_AS_STRING , + &dict); + +append_options (&dict, op); + +dbus_message_iter_close_container (iter, &dict); +} + +static void send_read (struct btd_device *device, +struct gatt_db_attribute *attrib, +GDBusProxy *proxy, +struct queue *owner_queue, +unsigned int id) {struct pending_op *op;uint8_t ecode =BT_ATT_ERROR_UNLIKELY ; - op =pending_read_new (owner_queue, attrib, id); + op =pending_read_new (device, owner_queue, attrib, id); -if (g_dbus_proxy_method_call (proxy,"ReadValue" ,NULL , read_reply_cb, - op, pending_op_free) == TRUE) +if (g_dbus_proxy_method_call (proxy,"ReadValue" , read_setup_cb, + read_reply_cb, op, pending_op_free) == TRUE)return ;pending_op_free (op);@@ -1629,12 +1659,28 @@ static void send_read(struct gatt_db_attribute *attrib, GDBusProxy *proxy,static void write_setup_cb (DBusMessageIter *iter,void *user_data) {struct pending_op *op = user_data; -DBusMessageIter array; +DBusMessageIter array, dict;dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY ,"y" , &array);dbus_message_iter_append_fixed_array (&array,DBUS_TYPE_BYTE , &op->data.iov_base, op->data.iov_len);dbus_message_iter_close_container (iter, &array); + +dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY , + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING +DBUS_DICT_ENTRY_END_CHAR_AS_STRING , + &dict); + +append_options (&dict, op); + +dbus_message_iter_close_container (iter, &dict); + +if (!op->owner_queue) { +gatt_db_attribute_write_result (op->attrib, op->id,0 ); +pending_op_free (op); + } }static void write_reply_cb (DBusMessage *message,void *user_data)@@ -1673,7 +1719,8 @@ done:gatt_db_attribute_write_result (op->attrib, op->id, ecode); } -static struct pending_op *pending_write_new(struct queue *owner_queue, +static struct pending_op *pending_write_new(struct btd_device *device, + struct queue *owner_queue, struct gatt_db_attribute *attrib, unsigned int id, const uint8_t *value,@@ -1686,6 +1733,7 @@ static struct pending_op *pending_write_new(struct queue *owner_queue, op->data.iov_base = (uint8_t *) value; op->data.iov_len = len; + op->device = device; op->owner_queue = owner_queue; op->attrib = attrib; op->id = id;@@ -1694,7 +1742,9 @@ static struct pending_op *pending_write_new(struct queue *owner_queue,return op; } -static void send_write (struct gatt_db_attribute *attrib,GDBusProxy *proxy, +static void send_write (struct btd_device *device, +struct gatt_db_attribute *attrib, +GDBusProxy *proxy,struct queue *owner_queue,unsigned int id,const uint8_t *value,size_t len)@@ -1702,11 +1752,11 @@ static void send_write(struct gatt_db_attribute *attrib, GDBusProxy *proxy,struct pending_op *op;uint8_t ecode =BT_ATT_ERROR_UNLIKELY ; - op =pending_write_new (owner_queue, attrib, id, value, len); + op =pending_write_new (device, owner_queue, attrib, id, value, len);if (g_dbus_proxy_method_call (proxy,"WriteValue" , write_setup_cb, - write_reply_cb, op, - pending_op_free) == TRUE) + owner_queue ? write_reply_cb :NULL , + op, pending_op_free) == TRUE)return ;pending_op_free (op);@@ -1895,19 +1945,58 @@ static bool database_add_cep(struct external_service *service,return true; }
Quoted 13 lines
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1958
Quoted 11 lines
src/gatt-database.c +11
-0+static struct btd_device *att_get_device (struct bt_att *att) +{ +GIOChannel *io =NULL ; +GError *gerr =NULL ; +bdaddr_t src, dst; +uint8_t dst_type; +struct btd_adapter *adapter; + + io =g_io_channel_unix_new (bt_att_get_fd (att)); +if (!io) +return false;return NULL?
Yep, gonna fix these errors, thanks for the review.
Quoted 62 lines
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1968
Quoted 10 lines
src/gatt-database.c +10
-0+ +bt_io_get (io, &gerr,BT_IO_OPT_SOURCE_BDADDR , &src, +BT_IO_OPT_DEST_BDADDR , &dst, +BT_IO_OPT_DEST_TYPE , &dst_type, +BT_IO_OPT_INVALID ); +if (gerr) { +error ("bt_io_get: %s" , gerr->message); +g_error_free (gerr); +g_io_channel_unref (io); +return false;also here.
src/gatt-database.c static bool database_add_cep(struct external_service *service, · line 1976
Quoted 8 lines
src/gatt-database.c +8
-0+ } + +g_io_channel_unref (io); + + adapter =adapter_find (&src); +if (!adapter) { +error ("Unable to find adapter object" ); +return false;and here.
Quoted 38 lines
src/gatt-database.c +12
-1+ } + +return btd_adapter_find_device (adapter, &dst, dst_type); +} +static void desc_read_cb (struct gatt_db_attribute *attrib,unsigned int id,uint16_t offset,uint8_t opcode,struct bt_att *att,void *user_data) {struct external_desc *desc = user_data; +struct btd_device *device;if (desc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; } -send_read (attrib, desc->proxy, desc->pending_reads, id); + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); + +send_read (device, attrib, desc->proxy, desc->pending_reads, id); } static void desc_write_cb(struct gatt_db_attribute *attrib,@@ -1917,13 +2006,19 @@ static void desc_write_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_desc *desc = user_data; +struct btd_device *device;if (desc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; }
Quoted 8 lines
src/gatt-database.c static void desc_write_cb(struct gatt_db_attribute *attrib, · line 2018
Quoted 4 lines
src/gatt-database.c +3
-1-send_write (attrib, desc->proxy, desc->pending_writes, id, value, len); + device =att_get_device (att); +if (!device) +error ("Unable to find device object" );I guess you should return here. There are couple of places like this. If this is not a mistake, I guess you could make
append_options()not append the NULL path, if there's no device associated.
The idea is to skip the device but this in fact shall never fail since we do create the device once connected so perhaps returning here is fine.
Quoted 99 lines
Quoted 90 lines
src/gatt-database.c +19
-37+ +send_write (device, attrib, desc->proxy, desc->pending_writes, id, + value, len); } static bool database_add_desc(struct external_service *service,@@ -1956,43 +2051,18 @@ static void chrc_read_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_chrc *chrc = user_data; +struct btd_device *device;if (chrc->attrib != attrib) {error ("Read callback called with incorrect attribute" );return ; } -send_read (attrib, chrc->proxy, chrc->pending_reads, id); -} - -static void write_without_response_setup_cb (DBusMessageIter *iter, -void *user_data) -{ -struct iovec *iov = user_data; -DBusMessageIter array; - -dbus_message_iter_open_container (iter,DBUS_TYPE_ARRAY ,"y" , &array); -dbus_message_iter_append_fixed_array (&array,DBUS_TYPE_BYTE , - &iov->iov_base, iov->iov_len); -dbus_message_iter_close_container (iter, &array); -} - -static void send_write_without_response (struct gatt_db_attribute *attrib, -GDBusProxy *proxy,unsigned int id, -const uint8_t *value,size_t len) -{ -struct iovec iov; -uint8_t ecode =0 ; - - iov.iov_base = (uint8_t *) value; - iov.iov_len = len; - -if (!g_dbus_proxy_method_call (proxy,"WriteValue" , - write_without_response_setup_cb, -NULL , &iov,NULL )) - ecode =BT_ATT_ERROR_UNLIKELY ; + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); -gatt_db_attribute_write_result (attrib, id, ecode); +send_read (device, attrib, chrc->proxy, chrc->pending_reads, id); } static void chrc_write_cb(struct gatt_db_attribute *attrib,@@ -2002,19 +2072,24 @@ static void chrc_write_cb(struct gatt_db_attribute *attrib, void *user_data) {struct external_chrc *chrc = user_data; +struct btd_device *device; +struct queue *queue;if (chrc->attrib != attrib) {error ("Write callback called with incorrect attribute" );return ; } -if (chrc->props &BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP ) { -send_write_without_response (attrib, chrc->proxy, id, value, - len); -return ; - } +if (!(chrc->props &BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP )) + queue = chrc->pending_writes; +else + queue =NULL ; + + device =att_get_device (att); +if (!device) +error ("Unable to find device object" ); -send_write (attrib, chrc->proxy, chrc->pending_writes, id, value, len); +send_write (device, attrib, chrc->proxy, queue, id, value, len); } static bool database_add_chrc(struct external_service *service, --2.5.5
Quoted 4 lines
--
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.htmlCheers,
--
Vinicius
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerHi Vinicius,
Quoted 22 lines · Vinicius Costa Gomes
Hi Luiz,
Quoted 18 lines · Luiz Augusto von Dentz
Quoted 17 lines
Quoted 4 lines
src/gatt-client.c +4
-0+static int parse_options (DBusMessage *msg,uint16_t *offset) +{ +DBusMessageIter args, flags; +src/gatt-client.c fail: · line 407
Quoted 10 lines
src/gatt-client.c +10
-0+if (!dbus_message_iter_init (msg, &args)) +return -EINVAL ; + +if (dbus_message_iter_get_arg_type (&args) !=DBUS_TYPE_ARRAY ) +return -EINVAL ; + +dbus_message_iter_recurse (&args, &flags); +if (dbus_message_iter_get_arg_type (&flags) !=DBUS_TYPE_DICT_ENTRY ) +return -EINVAL ; +I would think that from the documentation, "Possible options", that providing the offset would be optional. I don't think much is gained making this mandatory.
Quoted 7 lines
Quoted 3 lines
I guess you are referring to empty array, so yes we should probably drop the check for dict entry so it can be empty since it is optional.
I was thinking that a
ReadValue()message without any arguments would make sense to be valid. And one less thing to change in applications if they don't need the offset.
We can't do that because D-Bus doesn't support method overloading thus the signature must be a{sv}, but it can be an empty container so we would default to offset 0 as it is currently.
Luiz Augusto von Dentz