linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Łukasz Rymanowski" <lukasz.rymanowski@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: "Łukasz Rymanowski" <lukasz.rymanowski@codecoup.pl>
Subject: [PATCH v5 2/3] shared/gatt-db: Add API to get extended prop
Date: Sat,  2 Apr 2016 22:26:48 +0200	[thread overview]
Message-ID: <1459628809-32348-3-git-send-email-lukasz.rymanowski@codecoup.pl> (raw)
In-Reply-To: <1459628809-32348-1-git-send-email-lukasz.rymanowski@codecoup.pl>

This patch adds way to get extended properties from
characteristic extended property descriptor
---
 src/shared/gatt-db.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h |  4 ++++
 unit/test-gatt.c     | 14 ++++++++++++
 3 files changed, 80 insertions(+)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index cc49458..1a1704b 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,6 +1458,66 @@ bool gatt_db_attribute_get_service_data(const struct gatt_db_attribute *attrib,
 	return le_to_uuid(decl->value, decl->value_len, uuid);
 }
 
+struct ext_prop_data {
+	bool present;
+	uint8_t prop;
+};
+
+static void set_ext_prop_data(struct gatt_db_attribute *attrib,
+						int err, const uint8_t *value,
+						size_t length, void *user_data)
+{
+	struct ext_prop_data *ext_prop_data = user_data;
+
+	if (err || (length != sizeof(uint8_t)))
+		return;
+
+	ext_prop_data->prop = value[0];
+}
+
+static void check_reliable_supported(struct gatt_db_attribute *attrib,
+							void *user_data)
+{
+	struct ext_prop_data *ext_prop_data = user_data;
+
+	if (ext_prop_data->present)
+		return;
+
+	if (bt_uuid_cmp(&ext_desc_uuid, &attrib->uuid))
+		return;
+
+	ext_prop_data->present = true;
+	ext_prop_data->prop = gatt_db_attribute_read(attrib, 0,
+						BT_ATT_OP_READ_REQ, NULL,
+						set_ext_prop_data, user_data);
+}
+
+bool gatt_db_attribute_get_characteristic_extended_prop(
+					const struct gatt_db_attribute *attrib,
+					uint8_t *ext_prop)
+{
+	struct ext_prop_data ext_prop_data;
+
+	if (!attrib)
+		return false;
+
+	if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+		return false;
+
+	memset(&ext_prop_data, 0, sizeof(ext_prop_data));
+
+	/*
+	 * Cast needed for foreach function. We do not change attrib during
+	 * this call
+	 */
+	gatt_db_service_foreach_desc((struct gatt_db_attribute *) attrib,
+						check_reliable_supported,
+						&ext_prop_data);
+
+	*ext_prop = ext_prop_data.prop;
+	return ext_prop_data.present;
+}
+
 bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
 							uint16_t *handle,
 							uint16_t *value_handle,
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 96cceb9..0cb713e 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -195,6 +195,10 @@ bool gatt_db_attribute_get_service_data(const struct gatt_db_attribute *attrib,
 							bool *primary,
 							bt_uuid_t *uuid);
 
+bool gatt_db_attribute_get_characteristic_extended_prop(
+					const struct gatt_db_attribute *attrib,
+					uint8_t *ext_prop);
+
 bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
 							uint16_t *handle,
 							uint16_t *value_handle,
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 0912348..85e4d75 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -4434,5 +4434,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


  parent reply	other threads:[~2016-04-02 20:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-02 20:26 [PATCH v5 0/3] shared/gatt: Couple fixes and improvements Łukasz Rymanowski
2016-04-02 20:26 ` [PATCH v5 1/3] shared/gatt-server: Add support for long write Łukasz Rymanowski
2016-04-04 13:17   ` Luiz Augusto von Dentz
2016-04-02 20:26 ` Łukasz Rymanowski [this message]
2016-04-04 13:18   ` [PATCH v5 2/3] shared/gatt-db: Add API to get extended prop Luiz Augusto von Dentz
2016-04-05  7:51     ` Łukasz Rymanowski
2016-04-05  8:08       ` Luiz Augusto von Dentz
2016-04-02 20:26 ` [PATCH v5 3/3] shared/gatt-server: Check for ext. charact. prop. on reliable session Łukasz Rymanowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459628809-32348-3-git-send-email-lukasz.rymanowski@codecoup.pl \
    --to=lukasz.rymanowski@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).