diff mbox series

Bluetooth: Call HCI cmd to set random addr during MGMT call

Message ID 20221006224937.641179-1-brian.gix@intel.com (mailing list archive)
State Superseded
Headers show
Series Bluetooth: Call HCI cmd to set random addr during MGMT call | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS
tedd_an/subjectprefix success PASS
tedd_an/buildkernel success Build Kernel PASS
tedd_an/buildkernel32 success Build Kernel32 PASS
tedd_an/incremental_build success Pass
tedd_an/testrunnersetup success Test Runner Setup PASS
tedd_an/testrunnerl2cap-tester success Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneriso-tester success Total: 55, Passed: 55 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerbnep-tester success Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnermgmt-tester success Total: 494, Passed: 494 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerrfcomm-tester success Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersco-tester success Total: 12, Passed: 12 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerioctl-tester success Total: 28, Passed: 28 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnermesh-tester success Total: 10, Passed: 10 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersmp-tester success Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneruserchan-tester success Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0

Commit Message

Brian Gix Oct. 6, 2022, 10:49 p.m. UTC
The call to MGMT_OP_SET_STATIC_ADDRESS saved the requested address in
the hdev structure, but never wrote that address out to the controller.
This adds call to hci_set_random_addr_sync() after it has been
validated.

Signed-off-by: Brian Gix <brian.gix@intel.com>
---
 include/net/bluetooth/hci_sync.h |  1 +
 net/bluetooth/hci_sync.c         |  2 +-
 net/bluetooth/mgmt.c             | 35 ++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

Comments

bluez.test.bot@gmail.com Oct. 6, 2022, 11:17 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=683607

---Test result---

Test Summary:
CheckPatch                    PASS      1.83 seconds
GitLint                       PASS      0.77 seconds
SubjectPrefix                 PASS      0.63 seconds
BuildKernel                   PASS      42.25 seconds
BuildKernel32                 PASS      38.27 seconds
Incremental Build with patchesPASS      55.85 seconds
TestRunner: Setup             PASS      626.27 seconds
TestRunner: l2cap-tester      PASS      19.94 seconds
TestRunner: iso-tester        PASS      19.87 seconds
TestRunner: bnep-tester       PASS      7.94 seconds
TestRunner: mgmt-tester       PASS      124.37 seconds
TestRunner: rfcomm-tester     PASS      12.21 seconds
TestRunner: sco-tester        PASS      11.46 seconds
TestRunner: ioctl-tester      PASS      13.02 seconds
TestRunner: mesh-tester       PASS      9.50 seconds
TestRunner: smp-tester        PASS      11.40 seconds
TestRunner: userchan-tester   PASS      8.15 seconds



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 17f5a4c32f36..24864672d12c 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -90,6 +90,7 @@  int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp);
 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
 int hci_update_scan_sync(struct hci_dev *hdev);
 int hci_update_scan(struct hci_dev *hdev);
+int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa);
 
 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul);
 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 422f7c6911d9..8fd16ddd015a 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -839,7 +839,7 @@  static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags)
 	return true;
 }
 
-static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)
+int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)
 {
 	/* If we're advertising or initiating an LE connection we can't
 	 * go ahead and change the random address at this time. This is
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a92e7e485feb..aff861e0e655 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -6501,10 +6501,28 @@  static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
 	return err;
 }
 
+static int set_addr_sync(struct hci_dev *hdev, void *data)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_cp_set_static_address *cp = cmd->param;
+
+	return hci_set_random_addr_sync(hdev, &cp->bdaddr);
+}
+
+static void set_addr_complete(struct hci_dev *hdev, void *data, int err)
+{
+	struct mgmt_pending_cmd *cmd = data;
+
+	mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+			mgmt_status(err));
+	mgmt_pending_remove(cmd);
+}
+
 static int set_static_address(struct sock *sk, struct hci_dev *hdev,
 			      void *data, u16 len)
 {
 	struct mgmt_cp_set_static_address *cp = data;
+	struct mgmt_pending_cmd *cmd = data;
 	int err;
 
 	bt_dev_dbg(hdev, "sock %p", sk);
@@ -6534,6 +6552,23 @@  static int set_static_address(struct sock *sk, struct hci_dev *hdev,
 
 	bacpy(&hdev->static_addr, &cp->bdaddr);
 
+	cmd = mgmt_pending_add(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev, data, len);
+	if (!cmd)
+		err = -ENOMEM;
+	else
+		err = hci_cmd_sync_queue(hdev, set_addr_sync, cmd,
+					 set_addr_complete);
+
+	if (err < 0) {
+		if (cmd)
+			mgmt_pending_remove(cmd);
+
+		mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS,
+				mgmt_status(err));
+
+		goto unlock;
+	}
+
 	err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev);
 	if (err < 0)
 		goto unlock;