From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH v2 05/10] src/shared/att: Add "Find Information" request and response.
Date: Fri, 16 May 2014 13:14:53 -0700 [thread overview]
Message-ID: <1400271298-29769-6-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 Information" request and response
with their corresponding parameter structures.
---
src/shared/att.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
src/shared/att.h | 14 +++++++++
2 files changed, 99 insertions(+), 8 deletions(-)
diff --git a/src/shared/att.c b/src/shared/att.c
index 8b10c30..f124731 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -192,6 +192,8 @@ static bool handle_exchange_mtu_rsp(struct bt_att *att, const uint8_t *pdu,
if (pdu_length != 3)
return false;
+ memset(¶m, 0, sizeof(param));
+
param.server_rx_mtu = get_le16(pdu + 1);
request_complete(att, BT_ATT_OP_EXCHANGE_MTU_REQ, pdu[0],
@@ -200,16 +202,67 @@ static bool handle_exchange_mtu_rsp(struct bt_att *att, const uint8_t *pdu,
return true;
}
+static bool handle_find_info_rsp(struct bt_att *att, const uint8_t *pdu,
+ uint16_t pdu_length)
+{
+ struct bt_att_find_information_rsp_param param;
+ uint8_t *information_data;
+
+ if (pdu_length < 6)
+ return false;
+
+ memset(¶m, 0, sizeof(param));
+
+ param.format = pdu[1];
+ param.length = pdu_length - 2;
+
+ /* param.length is at least 4, as checked above */
+ information_data = malloc(param.length);
+ if (!information_data)
+ return false;
+
+ memcpy(information_data, pdu + 2, param.length);
+
+ param.information_data = information_data;
+
+ request_complete(att, BT_ATT_OP_FIND_INFORMATION_REQ, pdu[0],
+ ¶m, sizeof(param));
+
+ free(information_data);
+
+ return true;
+}
+
static bool handle_response(struct bt_att *att, const uint8_t *pdu,
uint16_t pdu_length)
{
uint8_t opcode = pdu[0];
+ uint8_t req_opcode;
- if (opcode == BT_ATT_OP_ERROR_RESP)
+ switch (opcode) {
+ case BT_ATT_OP_ERROR_RESP:
return handle_error_rsp(att, pdu, pdu_length);
- if (opcode == BT_ATT_OP_EXCHANGE_MTU_RESP)
- return handle_exchange_mtu_rsp(att, pdu, pdu_length);
+ case BT_ATT_OP_EXCHANGE_MTU_RESP:
+ if (!handle_exchange_mtu_rsp(att, pdu, pdu_length)) {
+ req_opcode = BT_ATT_OP_EXCHANGE_MTU_REQ;
+ goto fail;
+ }
+ return true;
+
+ case BT_ATT_OP_FIND_INFORMATION_RESP:
+ if (!handle_find_info_rsp(att, pdu, pdu_length)) {
+ req_opcode = BT_ATT_OP_FIND_INFORMATION_REQ;
+ goto fail;
+ }
+ return true;
+
+ default:
+ break;
+ }
+
+fail:
+ request_complete(att, req_opcode, BT_ATT_OP_ERROR_RESP, NULL, 0);
return false;
}
@@ -405,14 +458,36 @@ static bool encode_mtu_req(const void *param, uint16_t length, void *buf,
{
const struct bt_att_exchange_mtu_req_param *cp = param;
const uint16_t len = 3;
+ uint8_t *bytes = buf;
- if (length != sizeof(struct bt_att_exchange_mtu_req_param))
+ if (length != sizeof(*cp))
return false;
if (len > mtu)
return false;
- put_le16(cp->client_rx_mtu, buf);
+ put_le16(cp->client_rx_mtu, bytes + 1);
+ *pdu_length = len;
+
+ return true;
+}
+
+static bool encode_find_info_req(const void *param, uint16_t length, void *buf,
+ uint16_t mtu, uint16_t *pdu_length)
+{
+ const struct bt_att_find_information_req_param *cp = param;
+ const uint16_t len = 5;
+ 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);
+
*pdu_length = len;
return true;
@@ -439,10 +514,12 @@ static bool encode_pdu(uint8_t opcode, const void *param, uint16_t length,
if (!param)
return false;
- if (opcode == BT_ATT_OP_EXCHANGE_MTU_REQ) {
- return encode_mtu_req(param, length, bytes + 1,
+ if (opcode == BT_ATT_OP_EXCHANGE_MTU_REQ)
+ return encode_mtu_req(param, length, bytes, mtu, pdu_length);
+
+ if (opcode == BT_ATT_OP_FIND_INFORMATION_REQ)
+ return encode_find_info_req(param, length, bytes,
mtu, pdu_length);
- }
return false;
}
diff --git a/src/shared/att.h b/src/shared/att.h
index 8fe8805..16d852d 100644
--- a/src/shared/att.h
+++ b/src/shared/att.h
@@ -43,6 +43,20 @@ struct bt_att_exchange_mtu_rsp_param {
uint16_t server_rx_mtu;
};
+/* Find Information */
+#define BT_ATT_OP_FIND_INFORMATION_REQ 0x04
+struct bt_att_find_information_req_param {
+ uint16_t start_handle;
+ uint16_t end_handle;
+};
+
+#define BT_ATT_OP_FIND_INFORMATION_RESP 0x05
+struct bt_att_find_information_rsp_param {
+ uint8_t format;
+ const uint8_t *information_data;
+ 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 ` Arman Uguray [this message]
2014-05-25 6:20 ` [PATCH v2 05/10] src/shared/att: Add "Find Information" request and response 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 ` [PATCH v2 08/10] src/shared/att: Add "Find By Type Value" request and response Arman Uguray
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-6-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).