linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH 04/10] shared/att: Implement outgoing "Read" request/response.
Date: Thu, 26 Jun 2014 16:14:11 -0700	[thread overview]
Message-ID: <1403824457-22461-5-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1403824457-22461-1-git-send-email-armansito@chromium.org>

This patch adds support for "Read" requests sent via bt_att_send and the
corresponding response.
---
 src/shared/att.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/shared/att.c b/src/shared/att.c
index abf1440..288442f 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -261,6 +261,30 @@ static bool encode_read_by_type_req(struct att_send_op *op,
 	return true;
 }
 
+static bool encode_read_req(struct att_send_op *op,
+					const void *param, uint16_t length,
+					uint16_t mtu)
+{
+	const struct bt_att_read_req_param *p = param;
+	uint16_t len = 3;
+
+	if (length != sizeof(*p))
+		return false;
+
+	if (len > mtu)
+		return false;
+
+	op->pdu = malloc(len);
+	if (!op->pdu)
+		return false;
+
+	((uint8_t *) op->pdu)[0] = op->opcode;
+	put_le16(p->handle, ((uint8_t *) op->pdu) + 1);
+	op->len = len;
+
+	return true;
+}
+
 static bool encode_pdu(struct att_send_op *op, const void *param,
 						uint16_t length, uint16_t mtu)
 {
@@ -293,6 +317,8 @@ static bool encode_pdu(struct att_send_op *op, const void *param,
 		return encode_find_by_type_val_req(op, param, length, mtu);
 	case BT_ATT_OP_READ_BY_TYPE_REQ:
 		return encode_read_by_type_req(op, param, length, mtu);
+	case BT_ATT_OP_READ_REQ:
+		return encode_read_req(op, param, length, mtu);
 	default:
 		break;
 	}
@@ -649,6 +675,22 @@ static bool handle_read_by_type_rsp(struct bt_att *att, uint8_t opcode,
 							&param, sizeof(param));
 }
 
+static bool handle_read_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
+								ssize_t pdu_len)
+{
+	struct bt_att_read_rsp_param param;
+
+	memset(&param, 0, sizeof(param));
+
+	if (pdu_len > 1) {
+		param.length = pdu_len - 1;
+		param.value = pdu + 1;
+	}
+
+	return request_complete(att, BT_ATT_OP_READ_REQ, opcode, &param,
+								sizeof(param));
+}
+
 static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
 								ssize_t pdu_len)
 {
@@ -671,6 +713,9 @@ static void handle_rsp(struct bt_att *att, uint8_t opcode, uint8_t *pdu,
 	case BT_ATT_OP_READ_BY_TYPE_RSP:
 		success = handle_read_by_type_rsp(att, opcode, pdu, pdu_len);
 		break;
+	case BT_ATT_OP_READ_RSP:
+		success = handle_read_rsp(att, opcode, pdu, pdu_len);
+		break;
 	default:
 		success = false;
 		util_debug(att->debug_callback, att->debug_data,
-- 
2.0.0.526.g5318336


  parent reply	other threads:[~2014-06-26 23:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 23:14 [PATCH 00/10] shared/att: Implement sending ATT protocol requests Arman Uguray
2014-06-26 23:14 ` [PATCH 01/10] shared/att: Implement outgoing "Find Information" request/response Arman Uguray
2014-07-07  7:20   ` Marcel Holtmann
2014-07-07  7:49     ` Szymon Janc
2014-07-07  8:44       ` Marcel Holtmann
2014-07-07  8:18     ` Arman Uguray
2014-07-07  8:42       ` Marcel Holtmann
2014-07-07  9:02         ` Arman Uguray
2014-07-07  9:48           ` Marcel Holtmann
2014-06-26 23:14 ` [PATCH 02/10] shared/att: Implement outgoing "Find By Type Value" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 03/10] shared/att: Implement outgoing "Read By Type" request/response Arman Uguray
2014-06-26 23:14 ` Arman Uguray [this message]
2014-06-26 23:14 ` [PATCH 05/10] shared/att: Implement outgoing "Read Blob" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 06/10] shared/att: Implement outgoing "Read Multiple" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 07/10] shared/att: Implement outgoing "Read By Group Type" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 08/10] shared/att: Implement outgoing "Write" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 09/10] shared/att: Implement outgoing "Prepare Write" request/response Arman Uguray
2014-06-26 23:14 ` [PATCH 10/10] shared/att: Implement outgoing "Execute " 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=1403824457-22461-5-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).