linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sathish Narasimman <nsathish41@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Sathish Narasimman <sathish.narasimman@intel.com>
Subject: [PATCH 8/8] Bluetooth: Enable controller RPA resolution using Experimental feature
Date: Mon, 13 Jul 2020 11:42:20 +0530	[thread overview]
Message-ID: <20200713061220.3252-9-sathish.narasimman@intel.com> (raw)
In-Reply-To: <20200713061220.3252-1-sathish.narasimman@intel.com>

This patch adds support to enable the use of RPA Address resolution
using expermental feature mgmt command.

Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
---
 include/net/bluetooth/hci.h |  1 +
 net/bluetooth/hci_event.c   |  3 ++-
 net/bluetooth/hci_request.c |  6 +++--
 net/bluetooth/mgmt.c        | 52 +++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 4ff2fc4498f3..cb284365b4c1 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -307,6 +307,7 @@ enum {
 	HCI_FORCE_BREDR_SMP,
 	HCI_FORCE_STATIC_ADDR,
 	HCI_LL_RPA_RESOLUTION,
+	HCI_ENABLE_RPA_RESOLUTION,
 	HCI_CMD_PENDING,
 	HCI_FORCE_NO_MITM,
 
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 684c68cb5c76..c8a5e1e4dba2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5222,7 +5222,8 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
 			     le16_to_cpu(ev->latency),
 			     le16_to_cpu(ev->supervision_timeout));
 
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
 		hci_req_disable_address_resolution(hdev);
 }
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index c3193f7f9ff0..cb44b83539e6 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -677,7 +677,8 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn)
 	}
 
 	/* Disable address resolution */
-	if (use_ll_privacy(hdev) &&
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) &&
 	    hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
 		__u8 enable = 0x00;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
@@ -870,7 +871,8 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval,
 		return;
 	}
 
-	if (use_ll_privacy(hdev) && addr_resolv) {
+	if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION) &&
+	    use_ll_privacy(hdev) && addr_resolv) {
 		u8 enable = 0x01;
 		hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable);
 	}
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c292d5de4dc3..fbe02ab5fa05 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3759,6 +3759,12 @@ static const u8 simult_central_periph_uuid[16] = {
 	0x96, 0x46, 0xc0, 0x42, 0xb5, 0x10, 0x1b, 0x67,
 };
 
+/* 15c0a148-c273-11ea-b3de-0242ac130004 */
+static const u8 rpa_resolution_uuid[16] = {
+	0x04, 0x00, 0x13, 0xac, 0x42, 0x02, 0xde, 0xb3,
+	0xea, 0x11, 0x73, 0xc2, 0x48, 0xa1, 0xc0, 0x15,
+};
+
 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 				  void *data, u16 data_len)
 {
@@ -3795,6 +3801,17 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 		idx++;
 	}
 
+	if (hdev) {
+		if (hci_dev_test_flag(hdev, HCI_ENABLE_RPA_RESOLUTION))
+			flags = BIT(0);
+		else
+			flags = 0;
+
+		memcpy(rp->features[idx].uuid, rpa_resolution_uuid, 16);
+		rp->features[idx].flags = cpu_to_le32(flags);
+		idx++;
+	}
+
 	rp->feature_count = cpu_to_le16(idx);
 
 	/* After reading the experimental features information, enable
@@ -3895,6 +3912,41 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
 	}
 #endif
 
+	if (!memcmp(cp->uuid, rpa_resolution_uuid, 16)) {
+		bool val;
+		int err;
+
+		/* Parameters are limited to a single octet */
+		if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
+			return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+					       MGMT_OP_SET_EXP_FEATURE,
+					       MGMT_STATUS_INVALID_PARAMS);
+
+		/* Only boolean on/off is supported */
+		if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
+			return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+					       MGMT_OP_SET_EXP_FEATURE,
+					       MGMT_STATUS_INVALID_PARAMS);
+
+		val = !!cp->param[0];
+
+		if (val)
+			hci_dev_set_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+		else
+			hci_dev_clear_flag(hdev, HCI_ENABLE_RPA_RESOLUTION);
+
+		memcpy(rp.uuid, rpa_resolution_uuid, 16);
+		rp.flags = cpu_to_le32(val ? BIT(0) : 0);
+
+		hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
+
+		err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE,
+					MGMT_OP_SET_EXP_FEATURE, 0,
+					&rp, sizeof(rp));
+
+		return err;
+	}
+
 	return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
 			       MGMT_OP_SET_EXP_FEATURE,
 			       MGMT_STATUS_NOT_SUPPORTED);
-- 
2.17.1


  parent reply	other threads:[~2020-07-13  6:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13  6:12 [PATCH 0/8] LL Privacy Support Sathish Narasimman
2020-07-13  6:12 ` [PATCH 1/8] Bluetooth: Translate additional address type correctly Sathish Narasimman
2020-07-13  6:12 ` [PATCH 2/8] Bluetooth: Configure controller address resolution if available Sathish Narasimman
2020-07-13  6:12 ` [PATCH 3/8] Bluetooth: Update resolving list when updating whitelist Sathish Narasimman
2020-07-13  6:12 ` [PATCH 4/8] Bluetooth: Translate additional address type during le_conn Sathish Narasimman
2020-07-13  6:12 ` [PATCH 5/8] Bluetooth: Let controller creates RPA during le create conn Sathish Narasimman
2020-07-13  6:12 ` [PATCH 6/8] Bluetooth: Enable/Disable address resolution " Sathish Narasimman
2020-07-13  6:12 ` [PATCH 7/8] Bluetooth: Enable RPA Timeout Sathish Narasimman
2020-07-13  6:12 ` Sathish Narasimman [this message]
2020-07-13  6:17 ` [PATCH 0/8] LL Privacy Support Sathish Narasimman
2020-07-30  9:14 [PATCH 8/8] Bluetooth: Enable controller RPA resolution using Experimental feature Marcel Holtmann
2020-07-30  9:23 ` Sathish Narasimman
2020-07-30  9:56   ` Marcel Holtmann

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=20200713061220.3252-9-sathish.narasimman@intel.com \
    --to=nsathish41@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=sathish.narasimman@intel.com \
    /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).