2022-10-10 20:56:30

by Gix, Brian

[permalink] [raw]
Subject: [PATCH 1/2] Bluetooth: hci_sync: Fix not setting static address

From: Luiz Augusto von Dentz <[email protected]>

This attempts to program the address stored in hdev->static_addr after
the init sequence has been complete:

@ MGMT Command: Set Static A.. (0x002b) plen 6
Address: C0:55:44:33:22:11 (Static)
@ MGMT Event: Command Complete (0x0001) plen 7
Set Static Address (0x002b) plen 4
Status: Success (0x00)
Current settings: 0x00008200
Low Energy
Static Address
@ MGMT Event: New Settings (0x0006) plen 4
Current settings: 0x00008200
Low Energy
Static Address
< HCI Command: LE Set Random.. (0x08|0x0005) plen 6
Address: C0:55:44:33:22:11 (Static)
> HCI Event: Command Complete (0x0e) plen 4
LE Set Random Address (0x08|0x0005) ncmd 1
Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 7
Set Powered (0x0005) plen 4
Status: Success (0x00)
Current settings: 0x00008201
Powered
Low Energy
Static Address
@ MGMT Event: New Settings (0x0006) plen 4
Current settings: 0x00008201
Powered
Low Energy
Static Address

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Tested-by: Brian Gix <[email protected]>
---
net/bluetooth/hci_sync.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 76c3107c9f91..b53bb0ee9d39 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -3054,6 +3054,7 @@ int hci_update_name_sync(struct hci_dev *hdev)
* Enable Authentication
* lmp_bredr_capable(Set Fast Connectable -> Set Scan Type -> Set Class ->
* Set Name -> Set EIR)
+ * HCI_FORCE_STATIC_ADDR | BDADDR_ANY && !HCI_BREDR_ENABLED (Set Static Address)
*/
int hci_powered_update_sync(struct hci_dev *hdev)
{
@@ -3093,6 +3094,23 @@ int hci_powered_update_sync(struct hci_dev *hdev)
hci_update_eir_sync(hdev);
}

+ /* If forcing static address is in use or there is no public
+ * address use the static address as random address (but skip
+ * the HCI command if the current random address is already the
+ * static one.
+ *
+ * In case BR/EDR has been disabled on a dual-mode controller
+ * and a static address has been configured, then use that
+ * address instead of the public BR/EDR address.
+ */
+ if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
+ (!bacmp(&hdev->bdaddr, BDADDR_ANY) &&
+ !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))) {
+ if (bacmp(&hdev->static_addr, BDADDR_ANY))
+ return hci_set_random_addr_sync(hdev,
+ &hdev->static_addr);
+ }
+
return 0;
}

--
2.37.3


2022-10-10 20:57:27

by Gix, Brian

[permalink] [raw]
Subject: [PATCH 2/2] Bluetooth: hci_sync: Fix not able to set force_static_address

From: Luiz Augusto von Dentz <[email protected]>

force_static_address shall be writable while hdev is initing but is not
considered powered yet since the static address is written only when
powered.

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Tested-by: Brian Gix <[email protected]>
---
net/bluetooth/hci_debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
index 3f401ec5bb0c..b7f682922a16 100644
--- a/net/bluetooth/hci_debugfs.c
+++ b/net/bluetooth/hci_debugfs.c
@@ -757,7 +757,7 @@ static ssize_t force_static_address_write(struct file *file,
bool enable;
int err;

- if (test_bit(HCI_UP, &hdev->flags))
+ if (hdev_is_powered(hdev))
return -EBUSY;

err = kstrtobool_from_user(user_buf, count, &enable);
--
2.37.3

2022-10-10 21:02:45

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: hci_sync: Fix not setting static address

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Mon, 10 Oct 2022 13:35:21 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This attempts to program the address stored in hdev->static_addr after
> the init sequence has been complete:
>
> @ MGMT Command: Set Static A.. (0x002b) plen 6
> Address: C0:55:44:33:22:11 (Static)
> @ MGMT Event: Command Complete (0x0001) plen 7
> Set Static Address (0x002b) plen 4
> Status: Success (0x00)
> Current settings: 0x00008200
> Low Energy
> Static Address
> @ MGMT Event: New Settings (0x0006) plen 4
> Current settings: 0x00008200
> Low Energy
> Static Address
> < HCI Command: LE Set Random.. (0x08|0x0005) plen 6
> Address: C0:55:44:33:22:11 (Static)
> > HCI Event: Command Complete (0x0e) plen 4
> LE Set Random Address (0x08|0x0005) ncmd 1
> Status: Success (0x00)
> @ MGMT Event: Command Complete (0x0001) plen 7
> Set Powered (0x0005) plen 4
> Status: Success (0x00)
> Current settings: 0x00008201
> Powered
> Low Energy
> Static Address
> @ MGMT Event: New Settings (0x0006) plen 4
> Current settings: 0x00008201
> Powered
> Low Energy
> Static Address
>
> [...]

Here is the summary with links:
- [1/2] Bluetooth: hci_sync: Fix not setting static address
https://git.kernel.org/bluetooth/bluetooth-next/c/ca57023e7c49
- [2/2] Bluetooth: hci_sync: Fix not able to set force_static_address
https://git.kernel.org/bluetooth/bluetooth-next/c/8549542298e9

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


2022-10-10 21:28:21

by bluez.test.bot

[permalink] [raw]
Subject: RE: [1/2] Bluetooth: hci_sync: Fix not setting static address

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=684318

---Test result---

Test Summary:
CheckPatch PASS 2.59 seconds
GitLint PASS 1.52 seconds
SubjectPrefix PASS 1.31 seconds
BuildKernel PASS 34.07 seconds
BuildKernel32 PASS 31.07 seconds
Incremental Build with patchesPASS 51.01 seconds
TestRunner: Setup PASS 511.19 seconds
TestRunner: l2cap-tester PASS 17.17 seconds
TestRunner: iso-tester PASS 16.48 seconds
TestRunner: bnep-tester PASS 6.24 seconds
TestRunner: mgmt-tester FAIL 108.40 seconds
TestRunner: rfcomm-tester PASS 10.01 seconds
TestRunner: sco-tester PASS 9.54 seconds
TestRunner: ioctl-tester PASS 10.59 seconds
TestRunner: mesh-tester PASS 7.67 seconds
TestRunner: smp-tester PASS 9.43 seconds
TestRunner: userchan-tester PASS 6.46 seconds

Details
##############################
Test: TestRunner: mgmt-tester - FAIL - 108.40 seconds
Run test-runner with mgmt-tester
Total: 494, Passed: 492 (99.6%), Failed: 2, Not Run: 0

Failed Test Cases
Set Static Address - Success 1 Timed out 2.669 seconds
Set Static Address - Success 2 Timed out 2.002 seconds



---
Regards,
Linux Bluetooth