Skip to contentSkip to conversation

btdev: Add support for setting bdaddr

PATCH Applied Luiz Augusto von Dentz 3 participants 5 messages Oct 8, 2022 – Oct 10, 2022 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/3 btdev: Add support for setting bdaddr

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

This adds btdev_set_bdaddr so it is possible to set an arbritrary address.

---
 emulator/btdev.c | 10 ++++++++++
 emulator/btdev.h |  2 ++
 2 files changed, 12 insertions(+)
emulator/btdev.c +10 -0
index 3fdfb64a9eba..549f93645684 100644
@@ -6960,6 +6960,16 @@ const uint8_t *btdev_get_bdaddr(struct btdev *btdev)
 	return btdev->bdaddr;
 }
 
+bool btdev_set_bdaddr(struct btdev *btdev, const uint8_t *bdaddr)
+{
+	if (!btdev || !bdaddr)
+		return false;
+
+	memcpy(btdev->bdaddr, bdaddr, sizeof(btdev->bdaddr));
+
+	return true;
+}
+
 uint8_t *btdev_get_features(struct btdev *btdev)
 {
 	return btdev->features;
emulator/btdev.h +2 -0
index 228bf205cf4b..cad5f699f801 100644
@@ -72,6 +72,8 @@ bool btdev_set_debug(struct btdev *btdev, btdev_debug_func_t callback,
 			void *user_data, btdev_destroy_func_t destroy);
 
 const uint8_t *btdev_get_bdaddr(struct btdev *btdev);
+bool btdev_set_bdaddr(struct btdev *btdev, const uint8_t *bdaddr);
+
 uint8_t *btdev_get_features(struct btdev *btdev);
 
 uint8_t btdev_get_scan_enable(struct btdev *btdev);
Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH 2/3 vhci: Add function to interact with force_static_address

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

This adds functions that can be used to set debugfs force_static_address.

---
 emulator/vhci.c | 10 ++++++++++
 emulator/vhci.h |  1 +
 2 files changed, 11 insertions(+)
emulator/vhci.c +10 -0
index 4295e30ef980..a12b11e0f305 100644
@@ -257,3 +257,13 @@ int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode)
 {
 	return btdev_set_emu_opcode(vhci->btdev, opcode);
 }
+
+int vhci_set_force_static_address(struct vhci *vhci, bool enable)
+{
+	char val;
+
+	val = (enable) ? 'Y' : 'N';
+
+	return vhci_debugfs_write(vhci, "force_static_address", &val,
+							sizeof(val));
+}
emulator/vhci.h +1 -0
index c42e8bde1cd5..6da56cb589fe 100644
@@ -28,3 +28,4 @@ int vhci_set_force_wakeup(struct vhci *vhci, bool enable);
 int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode);
 int vhci_set_aosp_capable(struct vhci *vhci, bool enable);
 int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode);
+int vhci_set_force_static_address(struct vhci *vhci, bool enable);
Signature · 1 line
2.37.3
author maintainer
#2 lore raw

PATCH 3/3 mgmt-tester: Fix Set Static Address tests

In reply to Luiz Augusto von Dentz

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

Set Static Address tests needs to power after setting the address since the programming of the address using the HCI command only happens during power on procedure.

---
 tools/mgmt-tester.c | 63 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 51 insertions(+), 12 deletions(-)
tools/mgmt-tester.c +51 -12
index 7bb219953a7c..a56c38173fb7 100644
@@ -14,6 +14,7 @@
 
 #include <stdlib.h>
 #include <stdbool.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -33,6 +34,7 @@
 #include "emulator/vhci.h"
 #include "emulator/bthost.h"
 #include "emulator/hciemu.h"
+#include "emulator/btdev.h"
 
 #include "src/shared/util.h"
 #include "src/shared/tester.h"
@@ -299,6 +301,7 @@ struct hci_entry {
 };
 
 struct generic_data {
+	bdaddr_t *setup_bdaddr;
 	bool setup_le_states;
 	const uint8_t *le_states;
 	const uint16_t *setup_settings;
@@ -416,6 +419,16 @@ static void read_index_list_callback(uint8_t status, uint16_t length,
 	if (tester_use_debug())
 		hciemu_set_debug(data->hciemu, print_debug, "hciemu: ", NULL);
 
+	if (test && test->setup_bdaddr) {
+		struct vhci *vhci = hciemu_get_vhci(data->hciemu);
+		struct btdev *btdev = vhci_get_btdev(vhci);
+
+		if (!btdev_set_bdaddr(btdev, test->setup_bdaddr->b)) {
+			tester_warn("btdev_set_bdaddr failed");
+			tester_pre_setup_failed();
+		}
+	}
+
 	if (test && test->setup_le_states)
 		hciemu_set_central_le_states(data->hciemu, test->le_states);
 
@@ -4055,30 +4068,38 @@ static const struct generic_data unblock_device_invalid_param_test_1 = {
 
 static const char set_static_addr_valid_param[] = {
 			0x11, 0x22, 0x33, 0x44, 0x55, 0xc0 };
-static const char set_static_addr_settings[] = { 0x00, 0x82, 0x00, 0x00 };
+static const char set_static_addr_settings_param[] = { 0x01, 0x82, 0x00, 0x00 };
 
 static const struct generic_data set_static_addr_success_test = {
-	.send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
-	.send_param = set_static_addr_valid_param,
-	.send_len = sizeof(set_static_addr_valid_param),
+	.setup_bdaddr = BDADDR_ANY,
+	.setup_send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
+	.setup_send_param = set_static_addr_valid_param,
+	.setup_send_len = sizeof(set_static_addr_valid_param),
+	.send_opcode = MGMT_OP_SET_POWERED,
+	.send_param = set_powered_on_param,
+	.send_len = sizeof(set_powered_on_param),
 	.expect_status = MGMT_STATUS_SUCCESS,
-	.expect_param = set_static_addr_settings,
-	.expect_len = sizeof(set_static_addr_settings),
+	.expect_param = set_static_addr_settings_param,
+	.expect_len = sizeof(set_static_addr_settings_param),
 	.expect_settings_set = MGMT_SETTING_STATIC_ADDRESS,
 	.expect_hci_command = BT_HCI_CMD_LE_SET_RANDOM_ADDRESS,
 	.expect_hci_param = set_static_addr_valid_param,
 	.expect_hci_len = sizeof(set_static_addr_valid_param),
 };
 
-static const char set_static_addr_settings_dual[] = { 0x80, 0x00, 0x00, 0x00 };
+static const char set_static_addr_settings_dual[] = { 0x81, 0x80, 0x00, 0x00 };
 
 static const struct generic_data set_static_addr_success_test_2 = {
-	.send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
-	.send_param = set_static_addr_valid_param,
-	.send_len = sizeof(set_static_addr_valid_param),
+	.setup_send_opcode = MGMT_OP_SET_STATIC_ADDRESS,
+	.setup_send_param = set_static_addr_valid_param,
+	.setup_send_len = sizeof(set_static_addr_valid_param),
+	.send_opcode = MGMT_OP_SET_POWERED,
+	.send_param = set_powered_on_param,
+	.send_len = sizeof(set_powered_on_param),
 	.expect_status = MGMT_STATUS_SUCCESS,
 	.expect_param = set_static_addr_settings_dual,
 	.expect_len = sizeof(set_static_addr_settings_dual),
+	.expect_settings_set = MGMT_SETTING_STATIC_ADDRESS,
 	.expect_hci_command = BT_HCI_CMD_LE_SET_RANDOM_ADDRESS,
 	.expect_hci_param = set_static_addr_valid_param,
 	.expect_hci_len = sizeof(set_static_addr_valid_param),
@@ -11386,6 +11407,23 @@ static void test_command_generic(const void *test_data)
 	test_add_condition(data);
 }
 
+static void setup_set_static_addr_success_2(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
+	int err;
+
+	/* Force use of static address */
+	err = vhci_set_force_static_address(vhci, true);
+	if (err) {
+		tester_warn("Unable to set force_static_address: %s (%d)",
+					strerror(-err), -err);
+		tester_test_failed();
+		return;
+	}
+	setup_command_generic(test_data);
+}
+
 static void check_scan(void *user_data)
 {
 	struct test_data *data = tester_get_data();
@@ -13233,10 +13271,11 @@ int main(int argc, char *argv[])
 
 	test_le("Set Static Address - Success 1",
 				&set_static_addr_success_test,
-				NULL, test_command_generic);
+				setup_command_generic, test_command_generic);
 	test_bredrle("Set Static Address - Success 2",
 				&set_static_addr_success_test_2,
-				NULL, test_command_generic);
+				setup_set_static_addr_success_2,
+				test_command_generic);
 	test_bredrle("Set Static Address - Failure 1",
 				&set_static_addr_failure_test,
 				NULL, test_command_generic);
Signature · 1 line
2.37.3
#3 lore raw
In reply to Luiz Augusto von Dentz

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

---Test result---

Test Summary:

CheckPatch                    PASS      3.44 seconds
GitLint                       PASS      2.31 seconds
Prep - Setup ELL              PASS      26.22 seconds
Build - Prep                  PASS      0.68 seconds
Build - Configure             PASS      8.22 seconds
Build - Make                  PASS      739.73 seconds
Make Check                    PASS      11.41 seconds
Make Check w/Valgrind         PASS      290.45 seconds
Make Distcheck                PASS      237.93 seconds
Build w/ext ELL - Configure   PASS      8.38 seconds
Build w/ext ELL - Make        PASS      84.79 seconds
Incremental Build w/ patches  PASS      297.39 seconds
Scan Build                    PASS      506.66 seconds

---
Regards,
Linux Bluetooth

#4 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

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

Quoted 8 lines · On Fri, 7 Oct 2022 18:14:08 -0700 you wrote:

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

This adds btdev_set_bdaddr so it is possible to set an arbritrary address.

---
 emulator/btdev.c | 10 ++++++++++
 emulator/btdev.h |  2 ++
 2 files changed, 12 insertions(+)

Here is the summary with links:
- [BlueZ,1/3] btdev: Add support for setting bdaddr

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c94cdbc6d73f
  - [BlueZ,2/3] vhci: Add function to interact with force_static_address
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2bf15137410
  - [BlueZ,3/3] mgmt-tester: Fix Set Static Address tests
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9065853fe5c7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html