All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] Bluetooth: Connection parameter support
@ 2014-07-02 13:35 johan.hedberg
  2014-07-02 13:35 ` [PATCH 01/10] Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all johan.hedberg
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

This patch set implements the Load Connection Parameters command and
contains other connection parameter related fixes and improvements.

Johan

----------------------------------------------------------------
Johan Hedberg (10):
      Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all
      Bluetooth: Add specific connection parameter clear functions
      Bluetooth: Add new auto_conn value matching mgmt action 0x00
      Bluetooth: Remove only enabled entries with Remove Device command
      Bluetooth: Add Load Connection Parameters command
      Bluetooth: Fix missing update of conn params
      Bluetooth: Make hci_le_conn_update return any updated parameters
      Bluetooth: Pass store hint to mgmt_new_conn_param
      Bluetooth: Make is_identity_address a global function
      Bluetooth: Set store_hint to 0 for non-identity addresses

 include/net/bluetooth/hci_core.h |  26 ++++++--
 include/net/bluetooth/mgmt.h     |  15 +++++
 net/bluetooth/hci_conn.c         |   7 ++-
 net/bluetooth/hci_core.c         |  53 +++++++++++-----
 net/bluetooth/hci_event.c        |  22 ++++++-
 net/bluetooth/l2cap_core.c       |  15 ++++-
 net/bluetooth/mgmt.c             | 113 +++++++++++++++++++++++++++++++++--
 7 files changed, 218 insertions(+), 33 deletions(-)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 02/10] Bluetooth: Add specific connection parameter clear functions johan.hedberg
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

We'll soon have specific clear functions for clearing enabled or
disabled entries, so rename the function that removes everything to
clear_all().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 2 +-
 net/bluetooth/hci_core.c         | 4 ++--
 net/bluetooth/mgmt.c             | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ee480a86e558..091934bcfd84 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -861,7 +861,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
 int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 			u8 auto_connect);
 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
-void hci_conn_params_clear(struct hci_dev *hdev);
+void hci_conn_params_clear_all(struct hci_dev *hdev);
 
 struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 					    bdaddr_t *addr, u8 addr_type);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 63197d70d8eb..cc4babb4fa87 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3580,7 +3580,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
 }
 
 /* This function requires the caller holds hdev->lock */
-void hci_conn_params_clear(struct hci_dev *hdev)
+void hci_conn_params_clear_all(struct hci_dev *hdev)
 {
 	struct hci_conn_params *params, *tmp;
 
@@ -4037,7 +4037,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
 	hci_smp_irks_clear(hdev);
 	hci_remote_oob_data_clear(hdev);
 	hci_white_list_clear(hdev);
-	hci_conn_params_clear(hdev);
+	hci_conn_params_clear_all(hdev);
 	hci_dev_unlock(hdev);
 
 	hci_dev_put(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 93cfefa260d5..29850e76ea3c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5104,7 +5104,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 			goto unlock;
 		}
 
-		hci_conn_params_clear(hdev);
+		hci_conn_params_clear_all(hdev);
 	}
 
 	err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] Bluetooth: Add specific connection parameter clear functions
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
  2014-07-02 13:35 ` [PATCH 01/10] Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 03/10] Bluetooth: Add new auto_conn value matching mgmt action 0x00 johan.hedberg
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

In some circumstances we'll need to either clear only the enabled
parameters or only the disabled ones. This patch adds convenience
functions for this purpose.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_core.c         | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 091934bcfd84..2091e0013b8c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -862,6 +862,8 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 			u8 auto_connect);
 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
 void hci_conn_params_clear_all(struct hci_dev *hdev);
+void hci_conn_params_clear_disabled(struct hci_dev *hdev);
+void hci_conn_params_clear_enabled(struct hci_dev *hdev);
 
 struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 					    bdaddr_t *addr, u8 addr_type);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cc4babb4fa87..1b30b34ee9c7 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3580,6 +3580,40 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
 }
 
 /* This function requires the caller holds hdev->lock */
+void hci_conn_params_clear_disabled(struct hci_dev *hdev)
+{
+	struct hci_conn_params *params, *tmp;
+
+	list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) {
+		if (params->auto_connect != HCI_AUTO_CONN_DISABLED)
+			continue;
+		list_del(&params->list);
+		kfree(params);
+	}
+
+	hci_pend_le_conns_clear(hdev);
+
+	BT_DBG("All LE disabled connection parameters were removed");
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_conn_params_clear_enabled(struct hci_dev *hdev)
+{
+	struct hci_conn_params *params, *tmp;
+
+	list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) {
+		if (params->auto_connect == HCI_AUTO_CONN_DISABLED)
+			continue;
+		list_del(&params->list);
+		kfree(params);
+	}
+
+	hci_pend_le_conns_clear(hdev);
+
+	BT_DBG("All enabled LE connection parameters were removed");
+}
+
+/* This function requires the caller holds hdev->lock */
 void hci_conn_params_clear_all(struct hci_dev *hdev)
 {
 	struct hci_conn_params *params, *tmp;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] Bluetooth: Add new auto_conn value matching mgmt action 0x00
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
  2014-07-02 13:35 ` [PATCH 01/10] Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all johan.hedberg
  2014-07-02 13:35 ` [PATCH 02/10] Bluetooth: Add specific connection parameter clear functions johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 04/10] Bluetooth: Remove only enabled entries with Remove Device command johan.hedberg
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The 0x00 action value of mgmt means "scan and report" but do not
connect. This is different from HCI_AUTO_CONN_DISABLED so we need a new
value for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_core.c         | 1 +
 net/bluetooth/mgmt.c             | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 2091e0013b8c..f4a2f50f30b5 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -449,6 +449,7 @@ struct hci_conn_params {
 
 	enum {
 		HCI_AUTO_CONN_DISABLED,
+		HCI_AUTO_CONN_REPORT,
 		HCI_AUTO_CONN_ALWAYS,
 		HCI_AUTO_CONN_LINK_LOSS,
 	} auto_connect;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1b30b34ee9c7..81442c0cc4ac 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3547,6 +3547,7 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 
 	switch (auto_connect) {
 	case HCI_AUTO_CONN_DISABLED:
+	case HCI_AUTO_CONN_REPORT:
 	case HCI_AUTO_CONN_LINK_LOSS:
 		hci_pend_le_conn_del(hdev, addr, addr_type);
 		break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 29850e76ea3c..f7217f9eda03 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5034,7 +5034,7 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
 	if (cp->action)
 		auto_conn = HCI_AUTO_CONN_ALWAYS;
 	else
-		auto_conn = HCI_AUTO_CONN_DISABLED;
+		auto_conn = HCI_AUTO_CONN_REPORT;
 
 	/* If the connection parameters don't exist for this device,
 	 * they will be created and configured with defaults.
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] Bluetooth: Remove only enabled entries with Remove Device command
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (2 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 03/10] Bluetooth: Add new auto_conn value matching mgmt action 0x00 johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 05/10] Bluetooth: Add Load Connection Parameters command johan.hedberg
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The Remove Device mgmt command is supposed to undo what the Add Device
command does. An entry added by Add Device cannot have the
HCI_AUTO_CONN_DISABLED auto_connect value, so we should treat this as an
invalid entry to remove. This patch adds the necessary pieces to the
Remove Device command handler so that it only removes entries which were
added by Add Device.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index f7217f9eda03..574dd9f7c39e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5079,6 +5079,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 	hci_dev_lock(hdev);
 
 	if (bacmp(&cp->addr.bdaddr, BDADDR_ANY)) {
+		struct hci_conn_params *params;
 		u8 addr_type;
 
 		if (!bdaddr_type_is_le(cp->addr.type)) {
@@ -5093,7 +5094,25 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 		else
 			addr_type = ADDR_LE_DEV_RANDOM;
 
-		hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type);
+		params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
+						addr_type);
+		if (!params) {
+			err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
+					   MGMT_STATUS_INVALID_PARAMS,
+					   &cp->addr, sizeof(cp->addr));
+			goto unlock;
+		}
+
+		if (params->auto_connect == HCI_AUTO_CONN_DISABLED) {
+			err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
+					   MGMT_STATUS_INVALID_PARAMS,
+					   &cp->addr, sizeof(cp->addr));
+			goto unlock;
+		}
+
+		hci_pend_le_conn_del(hdev, &cp->addr.bdaddr, addr_type);
+		list_del(&params->list);
+		kfree(params);
 
 		device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type);
 	} else {
@@ -5104,7 +5123,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 			goto unlock;
 		}
 
-		hci_conn_params_clear_all(hdev);
+		hci_conn_params_clear_enabled(hdev);
 	}
 
 	err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] Bluetooth: Add Load Connection Parameters command
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (3 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 04/10] Bluetooth: Remove only enabled entries with Remove Device command johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 06/10] Bluetooth: Fix missing update of conn params johan.hedberg
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch implements the new Load Connection Parameters mgmt command
that's intended to load the desired connection parameters for LE
devices.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/mgmt.h | 15 +++++++++
 net/bluetooth/mgmt.c         | 79 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 3c0f29614d1b..5b3e8009eddd 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -449,6 +449,21 @@ struct mgmt_cp_remove_device {
 } __packed;
 #define MGMT_REMOVE_DEVICE_SIZE		MGMT_ADDR_INFO_SIZE
 
+struct mgmt_conn_param {
+	struct mgmt_addr_info addr;
+	__le16 min_interval;
+	__le16 max_interval;
+	__le16 latency;
+	__le16 timeout;
+} __packed;
+
+#define MGMT_OP_LOAD_CONN_PARAM		0x0035
+struct mgmt_cp_load_conn_param {
+	__le16 param_count;
+	struct mgmt_conn_param params[0];
+} __packed;
+#define MGMT_LOAD_CONN_PARAM_SIZE	2
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 574dd9f7c39e..59bf1ac41429 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -88,6 +88,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_GET_CLOCK_INFO,
 	MGMT_OP_ADD_DEVICE,
 	MGMT_OP_REMOVE_DEVICE,
+	MGMT_OP_LOAD_CONN_PARAM,
 };
 
 static const u16 mgmt_events[] = {
@@ -5134,6 +5135,83 @@ unlock:
 	return err;
 }
 
+static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
+			   u16 len)
+{
+	struct mgmt_cp_load_conn_param *cp = data;
+	u16 param_count, expected_len;
+	int i;
+
+	if (!lmp_le_capable(hdev))
+		return cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM,
+				  MGMT_STATUS_NOT_SUPPORTED);
+
+	param_count = __le16_to_cpu(cp->param_count);
+
+	expected_len = sizeof(*cp) + param_count *
+					sizeof(struct mgmt_conn_param);
+	if (expected_len != len) {
+		BT_ERR("load_conn_param: expected %u bytes, got %u bytes",
+		       expected_len, len);
+		return cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM,
+				  MGMT_STATUS_INVALID_PARAMS);
+	}
+
+	BT_DBG("%s param_count %u", hdev->name, param_count);
+
+	hci_dev_lock(hdev);
+
+	hci_conn_params_clear_disabled(hdev);
+
+	for (i = 0; i < param_count; i++) {
+		struct mgmt_conn_param *param = &cp->params[i];
+		struct hci_conn_params *hci_param;
+		u16 min, max, latency, timeout;
+		u8 addr_type;
+
+		BT_DBG("Adding %pMR (type %u)", &param->addr.bdaddr,
+		       param->addr.type);
+
+		if (param->addr.type == BDADDR_LE_PUBLIC) {
+			addr_type = ADDR_LE_DEV_PUBLIC;
+		} else if (param->addr.type == BDADDR_LE_RANDOM) {
+			addr_type = ADDR_LE_DEV_RANDOM;
+		} else {
+			BT_ERR("Ignoring invalid connection parameters");
+			continue;
+		}
+
+		min = le16_to_cpu(param->min_interval);
+		max = le16_to_cpu(param->max_interval);
+		latency = le16_to_cpu(param->latency);
+		timeout = le16_to_cpu(param->timeout);
+
+		BT_DBG("min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x",
+		       min, max, latency, timeout);
+
+		if (hci_check_conn_params(min, max, latency, timeout) < 0) {
+			BT_ERR("Ignoring invalid connection parameters");
+			continue;
+		}
+
+		hci_param = hci_conn_params_add(hdev, &param->addr.bdaddr,
+						addr_type);
+		if (!hci_param) {
+			BT_ERR("Failed to add connection parameters");
+			continue;
+		}
+
+		hci_param->conn_min_interval = min;
+		hci_param->conn_max_interval = max;
+		hci_param->conn_latency = latency;
+		hci_param->supervision_timeout = timeout;
+	}
+
+	hci_dev_unlock(hdev);
+
+	return cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, NULL, 0);
+}
+
 static const struct mgmt_handler {
 	int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
 		     u16 data_len);
@@ -5193,6 +5271,7 @@ static const struct mgmt_handler {
 	{ get_clock_info,         false, MGMT_GET_CLOCK_INFO_SIZE },
 	{ add_device,             false, MGMT_ADD_DEVICE_SIZE },
 	{ remove_device,          false, MGMT_REMOVE_DEVICE_SIZE },
+	{ load_conn_param,        true, MGMT_LOAD_CONN_PARAM_SIZE },
 };
 
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] Bluetooth: Fix missing update of conn params
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (4 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 05/10] Bluetooth: Add Load Connection Parameters command johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 07/10] Bluetooth: Make hci_le_conn_update return any updated parameters johan.hedberg
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

We should update any stored connection parameters when we receive the LE
Remove Connection Parameter Request HCI event. This patch adds the
necessary code to the function that handles the event.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_event.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b9d16e0ed661..03779e4f21f6 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4417,9 +4417,21 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,
 		return send_conn_param_neg_reply(hdev, handle,
 						 HCI_ERROR_INVALID_LL_PARAMS);
 
-	if (test_bit(HCI_CONN_MASTER, &hcon->flags))
+	if (test_bit(HCI_CONN_MASTER, &hcon->flags)) {
+		struct hci_conn_params *params;
+
+		params = hci_conn_params_lookup(hdev, &hcon->dst,
+						hcon->dst_type);
+		if (params) {
+			params->conn_min_interval = min;
+			params->conn_max_interval = max;
+			params->conn_latency = latency;
+			params->supervision_timeout = timeout;
+		}
+
 		mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, min, max,
 				    latency, timeout);
+	}
 
 	cp.handle = ev->handle;
 	cp.interval_min = ev->interval_min;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] Bluetooth: Make hci_le_conn_update return any updated parameters
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (5 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 06/10] Bluetooth: Fix missing update of conn params johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:35 ` [PATCH 08/10] Bluetooth: Pass store hint to mgmt_new_conn_param johan.hedberg
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

By returning the updated parameters (if there were any) makes it
possible for the calling function to do extra decisions, such as setting
the store_hint on a subsequent mgmt event.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 5 +++--
 net/bluetooth/hci_conn.c         | 7 +++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f4a2f50f30b5..3a8d0e2b1406 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1368,8 +1368,9 @@ struct hci_sec_filter {
 #define hci_req_lock(d)		mutex_lock(&d->req_lock)
 #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
 
-void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
-					u16 latency, u16 to_multiplier);
+struct hci_conn_params *hci_le_conn_update(struct hci_conn *conn, u16 min,
+					   u16 max, u16 latency,
+					   u16 to_multiplier);
 void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
 							__u8 ltk[16]);
 
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index d00aaf976efc..ab5f70e7980e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -213,8 +213,9 @@ bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
 	return true;
 }
 
-void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
-			u16 latency, u16 to_multiplier)
+struct hci_conn_params *hci_le_conn_update(struct hci_conn *conn, u16 min,
+					   u16 max, u16 latency,
+					   u16 to_multiplier)
 {
 	struct hci_dev *hdev = conn->hdev;
 	struct hci_conn_params *params;
@@ -242,6 +243,8 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
 	cp.max_ce_len		= cpu_to_le16(0x0000);
 
 	hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp);
+
+	return params;
 }
 
 void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] Bluetooth: Pass store hint to mgmt_new_conn_param
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (6 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 07/10] Bluetooth: Make hci_le_conn_update return any updated parameters johan.hedberg
@ 2014-07-02 13:35 ` johan.hedberg
  2014-07-02 13:36 ` [PATCH 09/10] Bluetooth: Make is_identity_address a global function johan.hedberg
  2014-07-02 13:36 ` [PATCH 10/10] Bluetooth: Set store_hint to 0 for non-identity addresses johan.hedberg
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:35 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The calling functions of mgmt_new_conn_param have more information about
the parameters, such as whether the kernel is tracking them or not. It
makes therefore sense to have them pass an initial store_hint value to
the mgmt_new_conn_param function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  4 ++--
 net/bluetooth/hci_event.c        |  8 ++++++--
 net/bluetooth/l2cap_core.c       | 15 +++++++++++++--
 net/bluetooth/mgmt.c             |  6 +++---
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3a8d0e2b1406..cf99c20739d9 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1335,8 +1335,8 @@ void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);
 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
 		   bool persistent);
 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
-			 u8 bdaddr_type, u16 min_interval, u16 max_interval,
-			 u16 latency, u16 timeout);
+			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
+			 u16 max_interval, u16 latency, u16 timeout);
 void mgmt_reenable_advertising(struct hci_dev *hdev);
 void mgmt_smp_complete(struct hci_conn *conn, bool complete);
 
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 03779e4f21f6..e26d0177bfaa 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4419,6 +4419,7 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,
 
 	if (test_bit(HCI_CONN_MASTER, &hcon->flags)) {
 		struct hci_conn_params *params;
+		u8 store_hint;
 
 		params = hci_conn_params_lookup(hdev, &hcon->dst,
 						hcon->dst_type);
@@ -4427,10 +4428,13 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,
 			params->conn_max_interval = max;
 			params->conn_latency = latency;
 			params->supervision_timeout = timeout;
+			store_hint = 0x01;
+		} else{
+			store_hint = 0x00;
 		}
 
-		mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, min, max,
-				    latency, timeout);
+		mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type,
+				    store_hint, min, max, latency, timeout);
 	}
 
 	cp.handle = ev->handle;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 058b3b2b59b5..4f0b01be396d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5250,10 +5250,21 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
 		       sizeof(rsp), &rsp);
 
 	if (!err) {
+		struct hci_conn_params *params;
+		u8 store_hint;
+
+		params = hci_le_conn_update(hcon, min, max, latency,
+					    to_multiplier);
+		/* If we're tracking these parameters the set store_hint */
+		if (params)
+			store_hint = 0x01;
+		else
+			store_hint = 0x00;
+
 		mgmt_new_conn_param(hcon->hdev, &hcon->dst, hcon->dst_type,
-				    min, max, latency, to_multiplier);
+				    store_hint, min, max, latency,
+				    to_multiplier);
 
-		hci_le_conn_update(hcon, min, max, latency, to_multiplier);
 	}
 
 	return 0;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 59bf1ac41429..fb1aa0cac137 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5790,15 +5790,15 @@ void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
 }
 
 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
-			 u8 bdaddr_type, u16 min_interval, u16 max_interval,
-			 u16 latency, u16 timeout)
+			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
+			 u16 max_interval, u16 latency, u16 timeout)
 {
 	struct mgmt_ev_new_conn_param ev;
 
 	memset(&ev, 0, sizeof(ev));
 	bacpy(&ev.addr.bdaddr, bdaddr);
 	ev.addr.type = link_to_bdaddr(LE_LINK, bdaddr_type);
-	ev.store_hint = 0x00;
+	ev.store_hint = store_hint;
 	ev.min_interval = cpu_to_le16(min_interval);
 	ev.max_interval = cpu_to_le16(max_interval);
 	ev.latency = cpu_to_le16(latency);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] Bluetooth: Make is_identity_address a global function
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (7 preceding siblings ...)
  2014-07-02 13:35 ` [PATCH 08/10] Bluetooth: Pass store hint to mgmt_new_conn_param johan.hedberg
@ 2014-07-02 13:36 ` johan.hedberg
  2014-07-02 13:36 ` [PATCH 10/10] Bluetooth: Set store_hint to 0 for non-identity addresses johan.hedberg
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

There are more places that can take advantage of is_identity_address()
besides hci_core.c. This patch moves the function to hci_core.h and
gives it the appropriate hci_ prefix.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 12 ++++++++++++
 net/bluetooth/hci_core.c         | 14 +-------------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index cf99c20739d9..3f1fb2760823 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1179,6 +1179,18 @@ static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
 	return false;
 }
 
+static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
+{
+	if (addr_type == ADDR_LE_DEV_PUBLIC)
+		return true;
+
+	/* Check for Random Static address type */
+	if ((addr->b[5] & 0xc0) == 0xc0)
+		return true;
+
+	return false;
+}
+
 static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
 					  bdaddr_t *bdaddr, u8 addr_type)
 {
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 81442c0cc4ac..d1cf3b59022a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3412,18 +3412,6 @@ static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)
 	return true;
 }
 
-static bool is_identity_address(bdaddr_t *addr, u8 addr_type)
-{
-	if (addr_type == ADDR_LE_DEV_PUBLIC)
-		return true;
-
-	/* Check for Random Static address type */
-	if ((addr->b[5] & 0xc0) == 0xc0)
-		return true;
-
-	return false;
-}
-
 /* This function requires the caller holds hdev->lock */
 struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 					    bdaddr_t *addr, u8 addr_type)
@@ -3504,7 +3492,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
 {
 	struct hci_conn_params *params;
 
-	if (!is_identity_address(addr, addr_type))
+	if (!hci_is_identity_address(addr, addr_type))
 		return NULL;
 
 	params = hci_conn_params_lookup(hdev, addr, addr_type);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] Bluetooth: Set store_hint to 0 for non-identity addresses
  2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
                   ` (8 preceding siblings ...)
  2014-07-02 13:36 ` [PATCH 09/10] Bluetooth: Make is_identity_address a global function johan.hedberg
@ 2014-07-02 13:36 ` johan.hedberg
  9 siblings, 0 replies; 11+ messages in thread
From: johan.hedberg @ 2014-07-02 13:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

If we don't have an identity address for connection parameters it's not
very valuable to store them persistently. Therefore, set the store_hint
to 0 in case we don't have an identity address.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index fb1aa0cac137..76cd22a43dec 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5795,6 +5795,9 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
 {
 	struct mgmt_ev_new_conn_param ev;
 
+	if (!hci_is_identity_address(bdaddr, bdaddr_type))
+		store_hint = 0x00;
+
 	memset(&ev, 0, sizeof(ev));
 	bacpy(&ev.addr.bdaddr, bdaddr);
 	ev.addr.type = link_to_bdaddr(LE_LINK, bdaddr_type);
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-02 13:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-02 13:35 [PATCH 00/10] Bluetooth: Connection parameter support johan.hedberg
2014-07-02 13:35 ` [PATCH 01/10] Bluetooth: Rename hci_conn_params_clear to hci_conn_params_clear_all johan.hedberg
2014-07-02 13:35 ` [PATCH 02/10] Bluetooth: Add specific connection parameter clear functions johan.hedberg
2014-07-02 13:35 ` [PATCH 03/10] Bluetooth: Add new auto_conn value matching mgmt action 0x00 johan.hedberg
2014-07-02 13:35 ` [PATCH 04/10] Bluetooth: Remove only enabled entries with Remove Device command johan.hedberg
2014-07-02 13:35 ` [PATCH 05/10] Bluetooth: Add Load Connection Parameters command johan.hedberg
2014-07-02 13:35 ` [PATCH 06/10] Bluetooth: Fix missing update of conn params johan.hedberg
2014-07-02 13:35 ` [PATCH 07/10] Bluetooth: Make hci_le_conn_update return any updated parameters johan.hedberg
2014-07-02 13:35 ` [PATCH 08/10] Bluetooth: Pass store hint to mgmt_new_conn_param johan.hedberg
2014-07-02 13:36 ` [PATCH 09/10] Bluetooth: Make is_identity_address a global function johan.hedberg
2014-07-02 13:36 ` [PATCH 10/10] Bluetooth: Set store_hint to 0 for non-identity addresses johan.hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.