From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH v2 08/10] src/shared/att: Add "Find By Type Value" request and response.
Date: Fri, 16 May 2014 13:14:56 -0700 [thread overview]
Message-ID: <1400271298-29769-9-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1400271298-29769-1-git-send-email-armansito@chromium.org>
This patch adds support for the "Find By Type Value" request and
response with their corresponding parameter structures.
---
src/shared/att.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shared/att.h | 16 +++++++++++
2 files changed, 102 insertions(+)
diff --git a/src/shared/att.c b/src/shared/att.c
index f124731..23af33c 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -208,6 +208,11 @@ static bool handle_find_info_rsp(struct bt_att *att, const uint8_t *pdu,
struct bt_att_find_information_rsp_param param;
uint8_t *information_data;
+ /* PDU must contain at least the following:
+ * - Attribute Opcode (1 octet)
+ * - Format (1 octet)
+ * - Information Data (4 to MTU-2 octets)
+ */
if (pdu_length < 6)
return false;
@@ -233,6 +238,45 @@ static bool handle_find_info_rsp(struct bt_att *att, const uint8_t *pdu,
return true;
}
+static bool handle_find_by_type_value_rsp(struct bt_att *att,
+ const uint8_t *pdu,
+ uint16_t pdu_length)
+{
+ struct bt_att_find_by_type_value_rsp_param param;
+ uint8_t *handles_info_list;
+
+ /* PDU must contain at least the following:
+ * - Attribute Opcode (1 octet)
+ * - Handles Information List (4 to MTU-1 octets)
+ */
+ if (pdu_length < 5)
+ return false;
+
+ /* Each Handle Information field is composed of 4 octets. Return error,
+ * if the length of the field is not a multiple of 4.
+ */
+ if ((pdu_length - 1) % 4)
+ return false;
+
+ memset(¶m, 0, sizeof(param));
+
+ param.length = pdu_length - 1;
+ handles_info_list = malloc(param.length);
+ if (!handles_info_list)
+ return false;
+
+ memcpy(handles_info_list, pdu + 1, param.length);
+
+ param.handles_information_list = handles_info_list;
+
+ request_complete(att, BT_ATT_OP_FIND_BY_TYPE_VALUE_REQ, pdu[0], ¶m,
+ sizeof(param));
+
+ free(handles_info_list);
+
+ return true;
+}
+
static bool handle_response(struct bt_att *att, const uint8_t *pdu,
uint16_t pdu_length)
{
@@ -257,6 +301,13 @@ static bool handle_response(struct bt_att *att, const uint8_t *pdu,
}
return true;
+ case BT_ATT_OP_FIND_BY_TYPE_VALUE_RESP:
+ if (!handle_find_by_type_value_rsp(att, pdu, pdu_length)) {
+ req_opcode = BT_ATT_OP_FIND_BY_TYPE_VALUE_REQ;
+ goto fail;
+ }
+ return true;
+
default:
break;
}
@@ -493,6 +544,37 @@ static bool encode_find_info_req(const void *param, uint16_t length, void *buf,
return true;
}
+static bool encode_find_by_type_value_req(const void *param, uint16_t length,
+ void *buf, uint16_t mtu,
+ uint16_t *pdu_length)
+{
+ const struct bt_att_find_by_type_value_req_param *cp = param;
+ const uint16_t len = 7 + cp->length;
+ uint8_t *bytes = buf;
+
+ if (length != sizeof(*cp))
+ return false;
+
+ if (len > mtu)
+ return false;
+
+ put_le16(cp->start_handle, bytes + 1);
+ put_le16(cp->end_handle, bytes + 3);
+ put_le16(cp->type, bytes + 5);
+
+ *pdu_length = len;
+
+ if (cp->length == 0)
+ return true;
+
+ if (!cp->value)
+ return false;
+
+ memcpy(bytes + 7, cp->value, cp->length);
+
+ return true;
+}
+
static bool encode_pdu(uint8_t opcode, const void *param, uint16_t length,
uint16_t mtu, void *pdu, uint16_t *pdu_length)
{
@@ -521,6 +603,10 @@ static bool encode_pdu(uint8_t opcode, const void *param, uint16_t length,
return encode_find_info_req(param, length, bytes,
mtu, pdu_length);
+ if (opcode == BT_ATT_OP_FIND_BY_TYPE_VALUE_REQ)
+ return encode_find_by_type_value_req(param, length, bytes,
+ mtu, pdu_length);
+
return false;
}
diff --git a/src/shared/att.h b/src/shared/att.h
index 16d852d..8649c25 100644
--- a/src/shared/att.h
+++ b/src/shared/att.h
@@ -57,6 +57,22 @@ struct bt_att_find_information_rsp_param {
uint16_t length;
};
+/* Find By Type Value */
+#define BT_ATT_OP_FIND_BY_TYPE_VALUE_REQ 0x06
+struct bt_att_find_by_type_value_req_param {
+ uint16_t start_handle;
+ uint16_t end_handle;
+ uint16_t type; /* 2 octet UUID */
+ const uint8_t *value;
+ uint16_t length; /* MAX length: (ATT_MTU - 7) */
+};
+
+#define BT_ATT_OP_FIND_BY_TYPE_VALUE_RESP 0x07
+struct bt_att_find_by_type_value_rsp_param {
+ const uint8_t *handles_information_list;
+ uint16_t length;
+};
+
/* Error codes for Error response PDU */
#define BT_ATT_ERROR_INVALID_HANDLE 0x01
#define BT_ATT_ERROR_READ_NOT_PERMITTED 0x02
--
1.8.3.2
next prev parent reply other threads:[~2014-05-16 20:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 20:14 [PATCH v2 00/10] bt_att initial implementation Arman Uguray
2014-05-16 20:14 ` [PATCH v2 01/10] src/shared/att: Introduce struct bt_att Arman Uguray
2014-05-25 5:32 ` Marcel Holtmann
2014-05-28 6:07 ` Arman Uguray
2014-05-28 8:37 ` Marcel Holtmann
2014-05-28 14:00 ` Luiz Augusto von Dentz
2014-05-28 18:28 ` Marcel Holtmann
2014-05-28 18:45 ` Arman Uguray
2014-05-29 20:56 ` Luiz Augusto von Dentz
2014-05-31 5:02 ` Marcel Holtmann
2014-06-02 8:05 ` Luiz Augusto von Dentz
2014-06-02 8:32 ` Marcel Holtmann
2014-05-31 5:13 ` Marcel Holtmann
2014-05-31 7:14 ` Arman Uguray
2014-05-16 20:14 ` [PATCH v2 02/10] unit/test-att: Add unit tests for src/shared/att Arman Uguray
2014-05-25 6:03 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 03/10] tools/btatt: Add command-line tool for ATT protocol testing Arman Uguray
2014-05-25 6:10 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 04/10] tools/btatt: Add "exchange-mtu" command Arman Uguray
2014-05-25 6:16 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 05/10] src/shared/att: Add "Find Information" request and response Arman Uguray
2014-05-25 6:20 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 06/10] unit/test-att: Add unit test for "Find Information" request/response Arman Uguray
2014-05-25 6:22 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 07/10] tools/btatt: Add "find-information" command Arman Uguray
2014-05-16 20:14 ` Arman Uguray [this message]
2014-05-16 20:14 ` [PATCH v2 09/10] unit/test-att: Add unit test for "Find By Type Value" request/response Arman Uguray
2014-05-16 20:14 ` [PATCH v2 10/10] tools/btatt: Add "find-by-type-value" command Arman Uguray
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=1400271298-29769-9-git-send-email-armansito@chromium.org \
--to=armansito@chromium.org \
--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).