Linux bluetooth development
 help / color / mirror / Atom feed
From: "Felipe F. Tonello" <eu@felipetonello.com>
To: linux-bluetooth@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Subject: [PATCH v5 BlueZ 2/4] Bluetooth: L2CAP: Add handler for Connection Parameter Update Response
Date: Thu, 13 Apr 2017 13:22:01 +0100	[thread overview]
Message-ID: <20170413122203.4247-3-eu@felipetonello.com> (raw)
In-Reply-To: <20170413122203.4247-1-eu@felipetonello.com>

In case of connected hosts that doesn't support the Connection
Parameters Request Link Layer Control Procedure, we should support this
event response from a slave device.

The slave device will answer based on a previous request done by the
master (BlueZ in this case) and update current connection parameters
accordingly. If the request was rejected, we don't do anything.

Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
 include/net/bluetooth/l2cap.h |  2 ++
 net/bluetooth/l2cap_core.c    | 47 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 803a7f4d93a7..eb7ecd5df9a3 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -654,6 +654,8 @@ struct l2cap_conn {
 	struct mutex		chan_lock;
 	struct kref		ref;
 	struct list_head	users;
+
+	struct l2cap_conn_param_update_req conn_param_req;
 };
 
 struct l2cap_user {
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 585d15ce0a33..1e8539c59cfd 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1489,6 +1489,14 @@ void l2cap_le_conn_update_req(struct l2cap_conn *conn, u8 min_interval,
 {
 	struct l2cap_conn_param_update_req req;
 
+	/* set temporary parameters in case of a successful
+	 * response from the peer device
+	 */
+	conn->conn_param_req.min = min_interval;
+	conn->conn_param_req.max = max_interval;
+	conn->conn_param_req.latency = latency;
+	conn->conn_param_req.to_multiplier = supv_timeout;
+
 	req.min = cpu_to_le16(min_interval);
 	req.max = cpu_to_le16(max_interval);
 	req.latency = cpu_to_le16(latency);
@@ -5261,6 +5269,44 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 	return 0;
 }
 
+static inline int l2cap_conn_param_update_rsp(struct l2cap_conn *conn,
+					      struct l2cap_cmd_hdr *cmd,
+					      u16 cmd_len, u8 *data)
+{
+	struct hci_conn *hcon = conn->hcon;
+	struct l2cap_conn_param_update_rsp *rsp;
+	u8 result;
+
+	if (hcon->role != HCI_ROLE_SLAVE)
+		return -EINVAL;
+
+	if (cmd_len != sizeof(struct l2cap_conn_param_update_rsp))
+		return -EPROTO;
+
+	rsp = (struct l2cap_conn_param_update_rsp *)data;
+	result = le16_to_cpu(rsp->result);
+
+	BT_DBG("result 0x%4.4x", result);
+
+	if (result == 0) {
+		u8 store_hint;
+
+		store_hint =
+			hci_le_conn_update(hcon,
+					   conn->conn_param_req.min,
+					   conn->conn_param_req.max,
+					   conn->conn_param_req.latency,
+					   conn->conn_param_req.to_multiplier);
+		mgmt_new_conn_param(hcon->hdev, &hcon->dst, hcon->dst_type,
+				    store_hint, conn->conn_param_req.min,
+				    conn->conn_param_req.max,
+				    conn->conn_param_req.latency,
+				    conn->conn_param_req.to_multiplier);
+	}
+
+	return 0;
+}
+
 static int l2cap_le_connect_rsp(struct l2cap_conn *conn,
 				struct l2cap_cmd_hdr *cmd, u16 cmd_len,
 				u8 *data)
@@ -5641,6 +5687,7 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
 		break;
 
 	case L2CAP_CONN_PARAM_UPDATE_RSP:
+		err = l2cap_conn_param_update_rsp(conn, cmd, cmd_len, data);
 		break;
 
 	case L2CAP_LE_CONN_RSP:
-- 
2.12.2

  parent reply	other threads:[~2017-04-13 12:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 12:21 [PATCH v5 BlueZ 0/4] Connection Update improvements Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 1/4] Bluetooth: L2CAP: Refactor L2CAP_CONN_PARAM_UPDATE_REQ into a function Felipe F. Tonello
2017-04-13 12:22 ` Felipe F. Tonello [this message]
2017-04-13 12:22 ` [PATCH v5 BlueZ 3/4] Bluetooth: L2CAP: Add BT_LE_CONN_PARAM socket option Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 4/4] Bluetooth: Handle Slave Connection Interval Range AD Felipe F. Tonello
2017-04-13 18:24   ` Vinicius Costa Gomes
2017-04-13 18:40     ` Luiz Augusto von Dentz
2017-04-13 20:01   ` kbuild test robot
2017-04-13 22:04   ` kbuild test robot

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=20170413122203.4247-3-eu@felipetonello.com \
    --to=eu@felipetonello.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.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