2016-04-13 21:09:52

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 0/5] Couple fixes and improvements

I've back to work on making Android gatt to make use of shared/gatt.
Here is couple of fixes I've done to shared code when doing this work.

Android gatt still needs testing but will be available sooner or later

v2:
- fix test-gatt for long write seesion testes
- prepare test-gatt test to support other changes
- do aggregation of prep writes for long write session
- support reliable nested long write
- start to look into characteristic extended prop for reliable session

v3:
- rebase
- remove patch adding notification type - that one needs to be reworked

v4:
- Fix according to Luiz comment

v5:
- Fix additional Luiz comments

v6:
- move getting extended properties to gatt_db_attribute_get_char_data instead
of separate API
- added patch which read extended characteristic propertis descriptors
during discovery session when acting as gatt-client. This is needed so
the call of gatt_db_attribute_get_char_data will return correct ext_prop value.
- Added patch fixing charcteristic properties in btgatt-server and test-gatt


Łukasz Rymanowski (5):
btgatt-server: Fix GATT device name properties
test-gatt: Fix characteristic properties
shared/gatt-db: Extend gatt_db_attribute_get_char_data with ext. prop
shared/gatt-server Check for ext. charact. prop. on reliable session
gatt-client: Read extended props on service discovery

profiles/deviceinfo/deviceinfo.c | 2 +-
profiles/gap/gas.c | 2 +-
profiles/scanparam/scan.c | 2 +-
src/device.c | 2 +-
src/gatt-client.c | 3 +-
src/shared/gatt-client.c | 120 ++++++++++++++++++++++++++++++++++++++-
src/shared/gatt-db.c | 63 ++++++++++++++++++++
src/shared/gatt-db.h | 1 +
src/shared/gatt-server.c | 50 +++++++++++++++-
tools/btgatt-client.c | 8 ++-
tools/btgatt-server.c | 11 ++--
unit/test-gatt.c | 41 +++++++++----
12 files changed, 278 insertions(+), 27 deletions(-)

--
2.5.0



2016-04-22 11:36:55

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v6 0/5] Couple fixes and improvements

Hi Łukasz,

On Thu, Apr 14, 2016 at 12:09 AM, Łukasz Rymanowski
<[email protected]> wrote:
> I've back to work on making Android gatt to make use of shared/gatt.
> Here is couple of fixes I've done to shared code when doing this work.
>
> Android gatt still needs testing but will be available sooner or later
>
> v2:
> - fix test-gatt for long write seesion testes
> - prepare test-gatt test to support other changes
> - do aggregation of prep writes for long write session
> - support reliable nested long write
> - start to look into characteristic extended prop for reliable session
>
> v3:
> - rebase
> - remove patch adding notification type - that one needs to be reworked
>
> v4:
> - Fix according to Luiz comment
>
> v5:
> - Fix additional Luiz comments
>
> v6:
> - move getting extended properties to gatt_db_attribute_get_char_data instead
> of separate API
> - added patch which read extended characteristic propertis descriptors
> during discovery session when acting as gatt-client. This is needed so
> the call of gatt_db_attribute_get_char_data will return correct ext_prop value.
> - Added patch fixing charcteristic properties in btgatt-server and test-gatt
>
>
> Łukasz Rymanowski (5):
> btgatt-server: Fix GATT device name properties
> test-gatt: Fix characteristic properties
> shared/gatt-db: Extend gatt_db_attribute_get_char_data with ext. prop
> shared/gatt-server Check for ext. charact. prop. on reliable session
> gatt-client: Read extended props on service discovery
>
> profiles/deviceinfo/deviceinfo.c | 2 +-
> profiles/gap/gas.c | 2 +-
> profiles/scanparam/scan.c | 2 +-
> src/device.c | 2 +-
> src/gatt-client.c | 3 +-
> src/shared/gatt-client.c | 120 ++++++++++++++++++++++++++++++++++++++-
> src/shared/gatt-db.c | 63 ++++++++++++++++++++
> src/shared/gatt-db.h | 1 +
> src/shared/gatt-server.c | 50 +++++++++++++++-
> tools/btgatt-client.c | 8 ++-
> tools/btgatt-server.c | 11 ++--
> unit/test-gatt.c | 41 +++++++++----
> 12 files changed, 278 insertions(+), 27 deletions(-)
>
> --
> 2.5.0

Applied, thanks.


--
Luiz Augusto von Dentz

2016-04-13 21:09:57

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 5/5] gatt-client: Read extended props on service discovery

Now once extended props can be taken with characteristic data
we need to makes sure that after discovery correct value is in
database.

With this patch, value of all the extended properties descriptors
are read during discovery just after discover of descriptors
---
src/shared/gatt-client.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++
unit/test-gatt.c | 2 +
2 files changed, 116 insertions(+)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index ff49be1..84689f6 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -316,6 +316,7 @@ struct discovery_op {
struct queue *pending_svcs;
struct queue *pending_chrcs;
struct queue *svcs;
+ struct queue *ext_prop_desc;
struct gatt_db_attribute *cur_svc;
bool success;
uint16_t start;
@@ -331,6 +332,7 @@ static void discovery_op_free(struct discovery_op *op)
queue_destroy(op->pending_svcs, NULL);
queue_destroy(op->pending_chrcs, free);
queue_destroy(op->svcs, NULL);
+ queue_destroy(op->ext_prop_desc, NULL);
free(op);
}

@@ -360,6 +362,7 @@ static struct discovery_op *discovery_op_create(struct bt_gatt_client *client,
op->pending_svcs = queue_new();
op->pending_chrcs = queue_new();
op->svcs = queue_new();
+ op->ext_prop_desc = queue_new();
op->client = client;
op->complete_func = complete_func;
op->failure_func = failure_func;
@@ -604,6 +607,107 @@ failed:
return false;
}

+static void ext_prop_write_cb(struct gatt_db_attribute *attrib,
+ int err, void *user_data)
+{
+ struct bt_gatt_client *client = user_data;
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Value set status: %d", err);
+}
+
+static void ext_prop_read_cb(bool success, uint8_t att_ecode,
+ const uint8_t *value, uint16_t length,
+ void *user_data);
+
+static bool read_ext_prop_desc(struct discovery_op *op)
+{
+ struct bt_gatt_client *client = op->client;
+ uint16_t handle;
+ struct gatt_db_attribute *attr;
+
+ attr = queue_peek_head(op->ext_prop_desc);
+ if (!attr)
+ return false;
+
+ handle = gatt_db_attribute_get_handle(attr);
+ bt_gatt_client_read_value(client, handle, ext_prop_read_cb,
+ discovery_op_ref(op),
+ discovery_op_unref);
+
+ return true;
+}
+
+static void ext_prop_read_cb(bool success, uint8_t att_ecode,
+ const uint8_t *value, uint16_t length,
+ void *user_data)
+{
+ struct discovery_op *op = user_data;
+ struct bt_gatt_client *client = op->client;
+ bool discovering;
+ struct gatt_db_attribute *desc_attr = NULL;
+ struct gatt_db_attribute *next_srv;
+ uint16_t start, end;
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Ext. prop value: 0x%04x", (uint16_t)value[0]);
+
+ desc_attr = queue_pop_head(op->ext_prop_desc);
+ if (!desc_attr)
+ goto failed;
+
+ if (!gatt_db_attribute_write(desc_attr, 0, value, length, 0, NULL,
+ ext_prop_write_cb, client))
+ goto failed;
+
+ /* Any other descriptor to read? */
+ if (read_ext_prop_desc(op))
+ return;
+
+ /* Continue with discovery */
+ do {
+ if (!discover_descs(op, &discovering))
+ goto failed;
+
+ if (discovering)
+ return;
+
+ /* Done with the current service */
+ gatt_db_service_set_active(op->cur_svc, true);
+
+ next_srv = queue_pop_head(op->svcs);
+ if (!next_srv)
+ goto done;
+
+ if (!gatt_db_attribute_get_service_handles(next_srv, &start,
+ &end))
+ goto failed;
+
+ } while (start == end);
+
+ /* Move on to the next service */
+ op->cur_svc = next_srv;
+
+ client->discovery_req = bt_gatt_discover_characteristics(client->att,
+ start, end,
+ discover_chrcs_cb,
+ discovery_op_ref(op),
+ discovery_op_unref);
+ if (client->discovery_req)
+ return;
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to start characteristic discovery");
+
+ discovery_op_unref(op);
+
+failed:
+ success = false;
+
+done:
+ discovery_op_complete(op, success, att_ecode);
+}
+
static void discover_descs_cb(bool success, uint8_t att_ecode,
struct bt_gatt_result *result,
void *user_data)
@@ -618,6 +722,7 @@ static void discover_descs_cb(bool success, uint8_t att_ecode,
char uuid_str[MAX_LEN_UUID_STR];
unsigned int desc_count;
bool discovering;
+ bt_uuid_t ext_prop_uuid;

discovery_req_clear(client);

@@ -640,6 +745,8 @@ static void discover_descs_cb(bool success, uint8_t att_ecode,
util_debug(client->debug_callback, client->debug_data,
"Descriptors found: %u", desc_count);

+ bt_uuid16_create(&ext_prop_uuid, GATT_CHARAC_EXT_PROPER_UUID);
+
while (bt_gatt_iter_next_descriptor(&iter, &handle, u128.data)) {
bt_uuid128_create(&uuid, u128);

@@ -657,8 +764,15 @@ static void discover_descs_cb(bool success, uint8_t att_ecode,

if (gatt_db_attribute_get_handle(attr) != handle)
goto failed;
+
+ if (!bt_uuid_cmp(&ext_prop_uuid, &uuid))
+ queue_push_tail(op->ext_prop_desc, attr);
}

+ /* If we got extended prop descriptor, lets read it right away */
+ if (read_ext_prop_desc(op))
+ return;
+
next:
if (!discover_descs(op, &discovering))
goto failed;
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 6e4dcee..8129719 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -267,6 +267,8 @@ struct context {
raw_pdu(0x01, 0x08, 0x18, 0xf0, 0x0a), \
raw_pdu(0x04, 0x16, 0xf0, 0x16, 0xf0), \
raw_pdu(0x05, 0x01, 0x16, 0xf0, 0x00, 0x29), \
+ raw_pdu(0x0a, 0x16, 0xf0), \
+ raw_pdu(0x0b, 0x01, 0x00), \
raw_pdu(0x08, 0x01, 0x00, 0x10, 0x00, 0x03, 0x28), \
raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29, \
0x2a), \
--
2.5.0


2016-04-13 21:09:56

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 4/5] shared/gatt-server Check for ext. charact. prop. on reliable session

With this patch we make sure that reliable session is done on
characteristics which does support it.
---
src/shared/gatt-server.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
unit/test-gatt.c | 14 ++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
index f1fca92..123d9c1 100644
--- a/src/shared/gatt-server.c
+++ b/src/shared/gatt-server.c
@@ -72,6 +72,8 @@ struct prep_write_data {
uint16_t handle;
uint16_t offset;
uint16_t length;
+
+ bool reliable_supported;
};

static void prep_write_data_destroy(void *user_data)
@@ -1111,6 +1113,23 @@ static bool append_prep_data(struct prep_write_data *prep_data, uint16_t handle,
return true;
}

+static bool is_reliable_write_supported(const struct bt_gatt_server *server,
+ uint16_t handle)
+{
+ struct gatt_db_attribute *attr;
+ uint16_t ext_prop;
+
+ attr = gatt_db_get_attribute(server->db, handle);
+ if (!attr)
+ return false;
+
+ if (!gatt_db_attribute_get_char_data(attr, NULL, NULL, NULL, &ext_prop,
+ NULL))
+ return false;
+
+ return (ext_prop & BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE);
+}
+
static bool prep_data_new(struct bt_gatt_server *server,
uint16_t handle, uint16_t offset,
uint16_t length, uint8_t *value)
@@ -1128,6 +1147,13 @@ static bool prep_data_new(struct bt_gatt_server *server,
prep_data->handle = handle;
prep_data->offset = offset;

+ /*
+ * Handle is the value handle. We need characteristic declaration
+ * handle which in BlueZ is handle_value -1
+ */
+ prep_data->reliable_supported = is_reliable_write_supported(server,
+ handle - 1);
+
queue_push_tail(server->prep_queue, prep_data);

return true;
@@ -1258,6 +1284,14 @@ error:
ehandle, err);
}

+static bool find_no_reliable_characteristic(const void *data,
+ const void *match_data)
+{
+ const struct prep_write_data *prep_data = data;
+
+ return !prep_data->reliable_supported;
+}
+
static void exec_write_cb(uint8_t opcode, const void *pdu,
uint16_t length, void *user_data)
{
@@ -1265,6 +1299,7 @@ static void exec_write_cb(uint8_t opcode, const void *pdu,
uint8_t flags;
uint8_t ecode;
bool write;
+ uint16_t ehandle = 0;

if (length != 1) {
ecode = BT_ATT_ERROR_INVALID_PDU;
@@ -1293,6 +1328,19 @@ static void exec_write_cb(uint8_t opcode, const void *pdu,
return;
}

+ /* If there is more than one prep request, we are in reliable session */
+ if (queue_length(server->prep_queue) > 1) {
+ struct prep_write_data *prep_data;
+
+ prep_data = queue_find(server->prep_queue,
+ find_no_reliable_characteristic, NULL);
+ if (prep_data) {
+ ecode = BT_ATT_ERROR_REQUEST_NOT_SUPPORTED;
+ ehandle = prep_data->handle;
+ goto error;
+ }
+ }
+
exec_next_prep_write(server, 0, 0);

return;
@@ -1300,7 +1348,7 @@ static void exec_write_cb(uint8_t opcode, const void *pdu,
error:
queue_remove_all(server->prep_queue, NULL, NULL,
prep_write_data_destroy);
- bt_att_send_error_rsp(server->att, opcode, 0, ecode);
+ bt_att_send_error_rsp(server->att, opcode, ehandle, ecode);
}

static void exchange_mtu_cb(uint8_t opcode, const void *pdu,
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 03925e9..6e4dcee 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -4437,5 +4437,19 @@ int main(int argc, char *argv[])
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff),
raw_pdu(0x01, 0x16, 0x04, 0x00, 0x03));

+ define_test_server("/robustness/no-reliable-characteristic",
+ test_server, ts_large_db_1, NULL,
+ raw_pdu(0x03, 0x00, 0x02),
+ raw_pdu(0x16, 0x82, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+ raw_pdu(0x17, 0x82, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+ raw_pdu(0x16, 0x25, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+ raw_pdu(0x17, 0x25, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03),
+ raw_pdu(0x16, 0x82, 0x00, 0x03, 0x00, 0x04, 0x05, 0x06),
+ raw_pdu(0x17, 0x82, 0x00, 0x03, 0x00, 0x04, 0x05, 0x06),
+ raw_pdu(0x16, 0x25, 0x00, 0x03, 0x00, 0x04, 0x05, 0x06),
+ raw_pdu(0x17, 0x25, 0x00, 0x03, 0x00, 0x04, 0x05, 0x06),
+ raw_pdu(0x18, 0x01),
+ raw_pdu(0x01, 0x18, 0x25, 0x00, 0x06));
+
return tester_run();
}
--
2.5.0


2016-04-13 21:09:55

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 3/5] shared/gatt-db: Extend gatt_db_attribute_get_char_data with ext. prop

This patch adds way to get extended properties from characteristic
extended property descriptor
---
profiles/deviceinfo/deviceinfo.c | 2 +-
profiles/gap/gas.c | 2 +-
profiles/scanparam/scan.c | 2 +-
src/device.c | 2 +-
src/gatt-client.c | 3 +-
src/shared/gatt-client.c | 6 ++--
src/shared/gatt-db.c | 63 ++++++++++++++++++++++++++++++++++++++++
src/shared/gatt-db.h | 1 +
tools/btgatt-client.c | 8 +++--
tools/btgatt-server.c | 8 +++--
unit/test-gatt.c | 4 +--
11 files changed, 85 insertions(+), 16 deletions(-)

diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index d1f51a0..0c48f00 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -88,7 +88,7 @@ static void handle_characteristic(struct gatt_db_attribute *attr,
bt_string_to_uuid(&pnpid_uuid, PNPID_UUID);

if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, NULL,
- &uuid)) {
+ NULL, &uuid)) {
error("Failed to obtain characteristic data");
return;
}
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 877c4fd..35b996c 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -181,7 +181,7 @@ static void handle_characteristic(struct gatt_db_attribute *attr,
bt_uuid_t uuid;

if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, NULL,
- &uuid)) {
+ NULL, &uuid)) {
error("Failed to obtain characteristic data");
return;
}
diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
index 4015b3f..d3ca762 100644
--- a/profiles/scanparam/scan.c
+++ b/profiles/scanparam/scan.c
@@ -140,7 +140,7 @@ static void handle_characteristic(struct gatt_db_attribute *attr,
bt_uuid_t uuid, scan_interval_wind_uuid, scan_refresh_uuid;

if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, NULL,
- &uuid)) {
+ NULL, &uuid)) {
error("Failed to obtain characteristic data");
return;
}
diff --git a/src/device.c b/src/device.c
index 0d46eba..cd82ef2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1987,7 +1987,7 @@ static void store_chrc(struct gatt_db_attribute *attr, void *user_data)
bt_uuid_t uuid;

if (!gatt_db_attribute_get_char_data(attr, &handle_num, &value_handle,
- &properties, &uuid)) {
+ &properties, NULL, &uuid)) {
warn("Error storing characteristic - can't get data");
return;
}
diff --git a/src/gatt-client.c b/src/gatt-client.c
index 52add1d..ebb7b35 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -1283,7 +1283,8 @@ static struct characteristic *characteristic_create(

gatt_db_attribute_get_char_data(attr, &chrc->handle,
&chrc->value_handle,
- &chrc->props, &uuid);
+ &chrc->props, NULL,
+ &uuid);

chrc->attr = gatt_db_get_attribute(service->client->db,
chrc->value_handle);
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 34b6cc7..ff49be1 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -243,9 +243,9 @@ static struct notify_chrc *notify_chrc_create(struct bt_gatt_client *client,
if (bt_uuid_cmp(&uuid, gatt_db_attribute_get_type(attr)))
return NULL;

- if (!gatt_db_attribute_get_char_data(attr, NULL, NULL,
- &properties, NULL))
- return NULL;
+ if (!gatt_db_attribute_get_char_data(attr, NULL, NULL, &properties,
+ NULL, NULL))
+ return NULL;

chrc = new0(struct notify_chrc, 1);

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index cc49458..513451f 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -52,6 +52,8 @@ static const bt_uuid_t characteristic_uuid = { .type = BT_UUID16,
.value.u16 = GATT_CHARAC_UUID };
static const bt_uuid_t included_service_uuid = { .type = BT_UUID16,
.value.u16 = GATT_INCLUDE_UUID };
+static const bt_uuid_t ext_desc_uuid = { .type = BT_UUID16,
+ .value.u16 = GATT_CHARAC_EXT_PROPER_UUID };

struct gatt_db {
int ref_count;
@@ -1456,10 +1458,68 @@ bool gatt_db_attribute_get_service_data(const struct gatt_db_attribute *attrib,
return le_to_uuid(decl->value, decl->value_len, uuid);
}

+static void read_ext_prop_value(struct gatt_db_attribute *attrib,
+ int err, const uint8_t *value,
+ size_t length, void *user_data)
+{
+ uint16_t *ext_prop = user_data;
+
+ if (err || (length != sizeof(uint16_t)))
+ return;
+
+ *ext_prop = (uint16_t) value[0];
+}
+
+static void read_ext_prop(struct gatt_db_attribute *attrib,
+ void *user_data)
+{
+ uint16_t *ext_prop = user_data;
+
+ /*
+ * If ext_prop is set that means extended properties descriptor
+ * has been already found
+ */
+ if (*ext_prop != 0)
+ return;
+
+ if (bt_uuid_cmp(&ext_desc_uuid, &attrib->uuid))
+ return;
+
+ gatt_db_attribute_read(attrib, 0, BT_ATT_OP_READ_REQ, NULL,
+ read_ext_prop_value, ext_prop);
+}
+
+static uint8_t get_char_extended_prop(const struct gatt_db_attribute *attrib)
+{
+ uint16_t ext_prop;
+
+ if (!attrib)
+ return 0;
+
+ if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+ return 0;
+
+ /* Check properties first */
+ if (!(attrib->value[0] & BT_GATT_CHRC_PROP_EXT_PROP))
+ return 0;
+
+ ext_prop = 0;
+
+ /*
+ * Cast needed for foreach function. We do not change attrib during
+ * this call
+ */
+ gatt_db_service_foreach_desc((struct gatt_db_attribute *) attrib,
+ read_ext_prop, &ext_prop);
+
+ return ext_prop;
+}
+
bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
uint16_t *handle,
uint16_t *value_handle,
uint8_t *properties,
+ uint16_t *ext_prop,
bt_uuid_t *uuid)
{
if (!attrib)
@@ -1484,6 +1544,9 @@ bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
if (properties)
*properties = attrib->value[0];

+ if (ext_prop)
+ *ext_prop = get_char_extended_prop(attrib);
+
if (value_handle)
*value_handle = get_le16(attrib->value + 1);

diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 96cceb9..134ec63 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -199,6 +199,7 @@ bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
uint16_t *handle,
uint16_t *value_handle,
uint8_t *properties,
+ uint16_t *ext_prop,
bt_uuid_t *uuid);

bool gatt_db_attribute_get_incl_data(const struct gatt_db_attribute *attrib,
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 2153bec..4c8c9dd 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -297,18 +297,20 @@ static void print_chrc(struct gatt_db_attribute *attr, void *user_data)
{
uint16_t handle, value_handle;
uint8_t properties;
+ uint16_t ext_prop;
bt_uuid_t uuid;

if (!gatt_db_attribute_get_char_data(attr, &handle,
&value_handle,
&properties,
+ &ext_prop,
&uuid))
return;

printf("\t " COLOR_YELLOW "charac" COLOR_OFF
- " - start: 0x%04x, value: 0x%04x, "
- "props: 0x%02x, uuid: ",
- handle, value_handle, properties);
+ " - start: 0x%04x, value: 0x%04x, "
+ "props: 0x%02x, ext_props: 0x%04x, uuid: ",
+ handle, value_handle, properties, ext_prop);
print_uuid(&uuid);

gatt_db_service_foreach_desc(attr, print_desc, NULL);
diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
index 099db8a..fadaff2 100644
--- a/tools/btgatt-server.c
+++ b/tools/btgatt-server.c
@@ -932,18 +932,20 @@ static void print_chrc(struct gatt_db_attribute *attr, void *user_data)
{
uint16_t handle, value_handle;
uint8_t properties;
+ uint16_t ext_prop;
bt_uuid_t uuid;

if (!gatt_db_attribute_get_char_data(attr, &handle,
&value_handle,
&properties,
+ &ext_prop,
&uuid))
return;

printf("\t " COLOR_YELLOW "charac" COLOR_OFF
- " - start: 0x%04x, value: 0x%04x, "
- "props: 0x%02x, uuid: ",
- handle, value_handle, properties);
+ " - start: 0x%04x, value: 0x%04x, "
+ "props: 0x%02x, ext_prop: 0x%04x, uuid: ",
+ handle, value_handle, properties, ext_prop);
print_uuid(&uuid);

gatt_db_service_foreach_desc(attr, print_desc, NULL);
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 126a59f..03925e9 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -526,9 +526,9 @@ static bool matching_char_data(struct gatt_db_attribute *a,
bt_uuid_t a_uuid, b_uuid;

gatt_db_attribute_get_char_data(a, &a_handle, &a_value_handle,
- &a_properties, &a_uuid);
+ &a_properties, NULL, &a_uuid);
gatt_db_attribute_get_char_data(b, &b_handle, &b_value_handle,
- &b_properties, &b_uuid);
+ &b_properties, NULL, &b_uuid);

return a_handle == b_handle && a_value_handle == b_value_handle &&
a_properties == b_properties &&
--
2.5.0


2016-04-13 21:09:54

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 2/5] test-gatt: Fix characteristic properties

This patch fixes characteristic property for those characteristics
which contains extended characteristic properties descriptor.
---
unit/test-gatt.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 0912348..126a59f 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -257,7 +257,7 @@ struct context {
raw_pdu(0x09, 0x07, 0x12, 0xf0, 0x02, 0x13, 0xf0, 0x00, \
0x2a), \
raw_pdu(0x08, 0x13, 0xf0, 0x18, 0xf0, 0x03, 0x28), \
- raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x02, 0x15, 0xf0, 0xef, \
+ raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x82, 0x15, 0xf0, 0xef, \
0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, \
0x00, 0x00, 0x00, 0x09, 0xB0, 0x00, 0x00), \
raw_pdu(0x08, 0x15, 0xf0, 0x18, 0xf0, 0x03, 0x28), \
@@ -268,7 +268,7 @@ struct context {
raw_pdu(0x04, 0x16, 0xf0, 0x16, 0xf0), \
raw_pdu(0x05, 0x01, 0x16, 0xf0, 0x00, 0x29), \
raw_pdu(0x08, 0x01, 0x00, 0x10, 0x00, 0x03, 0x28), \
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x32, 0x03, 0x00, 0x29, \
+ raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29, \
0x2a), \
raw_pdu(0x08, 0x03, 0x00, 0x10, 0x00, 0x03, 0x28), \
raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a)
@@ -1556,7 +1556,8 @@ static struct gatt_db *make_test_spec_small_db(void)
BT_ATT_PERM_WRITE,
BT_GATT_CHRC_PROP_READ |
BT_GATT_CHRC_PROP_NOTIFY |
- BT_GATT_CHRC_PROP_INDICATE,
+ BT_GATT_CHRC_PROP_INDICATE |
+ BT_GATT_CHRC_PROP_EXT_PROP,
"BlueZ"),
DESCRIPTOR(GATT_CLIENT_CHARAC_CFG_UUID, BT_ATT_PERM_READ |
BT_ATT_PERM_WRITE, 0x00, 0x00),
@@ -1572,7 +1573,8 @@ static struct gatt_db *make_test_spec_small_db(void)
"BlueZ Unit Tester"),
CHARACTERISTIC(0000B009-0000-0000-0123-456789abcdef,
BT_ATT_PERM_READ | BT_ATT_PERM_WRITE,
- BT_GATT_CHRC_PROP_READ, 0x09),
+ BT_GATT_CHRC_PROP_READ |
+ BT_GATT_CHRC_PROP_EXT_PROP, 0x09),
DESCRIPTOR(GATT_CHARAC_EXT_PROPER_UUID, BT_ATT_PERM_READ, 0x01,
0x00),
CHARACTERISTIC(GATT_CHARAC_APPEARANCE, BT_ATT_PERM_READ,
@@ -1617,7 +1619,8 @@ static struct gatt_db *make_test_spec_large_db_1(void)
PRIMARY_SERVICE(0x0080, "a00b", 7),
CHARACTERISTIC(0xb008, BT_ATT_PERM_READ | BT_ATT_PERM_WRITE,
BT_GATT_CHRC_PROP_READ |
- BT_GATT_CHRC_PROP_WRITE,
+ BT_GATT_CHRC_PROP_WRITE |
+ BT_GATT_CHRC_PROP_EXT_PROP,
0x08),
DESCRIPTOR(0xb015, BT_ATT_PERM_READ | BT_ATT_PERM_WRITE, 0x01),
DESCRIPTOR(0xb016, BT_ATT_PERM_READ | BT_ATT_PERM_WRITE, 0x02),
@@ -2546,7 +2549,7 @@ int main(int argc, char *argv[])
raw_pdu(0x09, 0x07, 0x12, 0xf0, 0x02, 0x13, 0xf0, 0x00,
0x2a),
raw_pdu(0x08, 0x13, 0xf0, 0x18, 0xf0, 0x03, 0x28),
- raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x02, 0x15, 0xf0, 0xef,
+ raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x82, 0x15, 0xf0, 0xef,
0xcd, 0xab, 0x89, 0x67, 0x45, 0x23,
0x01, 0x00, 0x00, 0x00, 0x00, 0x09,
0xb0, 0x00, 0x00),
@@ -2560,7 +2563,7 @@ int main(int argc, char *argv[])
ts_small_db, NULL,
raw_pdu(0x03, 0x00, 0x02),
raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x32, 0x03, 0x00, 0x29,
+ raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29,
0x2a),
raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28),
raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a));
@@ -2599,7 +2602,7 @@ int main(int argc, char *argv[])
raw_pdu(0x09, 0x07, 0x12, 0xf0, 0x02, 0x13, 0xf0, 0x00,
0x2a),
raw_pdu(0x08, 0x13, 0xf0, 0x17, 0xf0, 0x03, 0x28),
- raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x02, 0x15, 0xf0, 0xef,
+ raw_pdu(0x09, 0x15, 0x14, 0xf0, 0x82, 0x15, 0xf0, 0xef,
0xcd, 0xab, 0x89, 0x67, 0x45, 0x23,
0x01, 0x00, 0x00, 0x00, 0x00, 0x09,
0xb0, 0x00, 0x00),
@@ -2613,7 +2616,7 @@ int main(int argc, char *argv[])
ts_small_db, NULL,
raw_pdu(0x03, 0x00, 0x02),
raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x32, 0x03, 0x00, 0x29,
+ raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29,
0x2a),
raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28),
raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a));
--
2.5.0


2016-04-13 21:09:53

by Łukasz Rymanowski

[permalink] [raw]
Subject: [PATCH BlueZ v6 1/5] btgatt-server: Fix GATT device name properties

Since GATT device name characteristic has extended characteristic
property descriptor, that should be set in properties as well.
This patch fixes that.
---
tools/btgatt-server.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
index 292b584..099db8a 100644
--- a/tools/btgatt-server.c
+++ b/tools/btgatt-server.c
@@ -419,7 +419,8 @@ static void populate_gap_service(struct server *server)
bt_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
gatt_db_service_add_characteristic(service, &uuid,
BT_ATT_PERM_READ | BT_ATT_PERM_WRITE,
- BT_GATT_CHRC_PROP_READ,
+ BT_GATT_CHRC_PROP_READ |
+ BT_GATT_CHRC_PROP_EXT_PROP,
gap_device_name_read_cb,
gap_device_name_write_cb,
server);
--
2.5.0