diff mbox series

[v3] btproxy: Allow to select multiple BT controllers

Message ID 20220603145447.45655-1-frederic.danis@collabora.com
State New
Headers show
Series [v3] btproxy: Allow to select multiple BT controllers | expand

Commit Message

Frédéric Danis June 3, 2022, 2:54 p.m. UTC
When running on a computer with a real Bluetooth controller (e.g. hci0) and
multiple emulators (e.g. hci1 and hci2) it isn't possible to use the
emulators with 2 test-runner vms.
If btproxy is started without index parameter the first test-runner will
use hci0, and btprox can't be started with multiple index parameters
(e.g. -i1 -i2).

This patch keeps the old beahvior when used without -i option, in this case
it will try to use the first controller available.
It also allows to select multiple controllers to be used by btproxy.
---
changes since v2:
 - replace get_next_hci_index() by util_get_uid()

 tools/btproxy.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

Comments

bluez.test.bot@gmail.com June 3, 2022, 4:27 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=647234

---Test result---

Test Summary:
CheckPatch                    PASS      1.55 seconds
GitLint                       PASS      1.03 seconds
Prep - Setup ELL              PASS      42.53 seconds
Build - Prep                  PASS      0.68 seconds
Build - Configure             PASS      8.56 seconds
Build - Make                  PASS      1398.83 seconds
Make Check                    PASS      11.29 seconds
Make Check w/Valgrind         PASS      442.76 seconds
Make Distcheck                PASS      229.56 seconds
Build w/ext ELL - Configure   PASS      8.57 seconds
Build w/ext ELL - Make        PASS      1377.99 seconds
Incremental Build with patchesPASS      0.00 seconds



---
Regards,
Linux Bluetooth
patchwork-bot+bluetooth@kernel.org June 13, 2022, 6:10 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Fri,  3 Jun 2022 16:54:47 +0200 you wrote:
> When running on a computer with a real Bluetooth controller (e.g. hci0) and
> multiple emulators (e.g. hci1 and hci2) it isn't possible to use the
> emulators with 2 test-runner vms.
> If btproxy is started without index parameter the first test-runner will
> use hci0, and btprox can't be started with multiple index parameters
> (e.g. -i1 -i2).
> 
> [...]

Here is the summary with links:
  - [v3] btproxy: Allow to select multiple BT controllers
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6e2066fdab73

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/btproxy.c b/tools/btproxy.c
index 94ca1c7fd..305ef7893 100644
--- a/tools/btproxy.c
+++ b/tools/btproxy.c
@@ -48,8 +48,9 @@  struct sockaddr_hci {
 };
 #define HCI_CHANNEL_USER	1
 #define HCI_INDEX_NONE		0xffff
+#define HCI_INDEX_MAX		16
 
-static uint16_t hci_index = HCI_INDEX_NONE;
+static uint64_t hci_index = HCI_INDEX_NONE;
 static bool client_active = false;
 static bool debug_enabled = false;
 static bool emulate_ecc = false;
@@ -533,13 +534,18 @@  static bool setup_proxy(int host_fd, bool host_shutdown,
 	return true;
 }
 
-static int open_channel(uint16_t index)
+static int open_channel(uint64_t hci_index)
 {
 	struct sockaddr_hci addr;
 	int fd, err;
+	uint8_t index;
 
-	if (index == HCI_INDEX_NONE)
-		index = 0;
+	index = util_get_uid(&hci_index, HCI_INDEX_MAX);
+	if (index == 0) {
+		perror("No controller available");
+		return -1;
+	}
+	index--;
 
 	printf("Opening user channel for hci%u\n", index);
 
@@ -558,12 +564,11 @@  static int open_channel(uint16_t index)
 		err = -errno;
 		close(fd);
 
-		/* Open next available controller if no specific index was
-		 * provided and the error indicates that the controller.
+		/* Open next available controller if the error indicates
+		 * that the controller is in use.
 		 */
-		if (hci_index == HCI_INDEX_NONE &&
-				(err == -EBUSY || err == -EUSERS))
-			return open_channel(++index);
+		if (err == -EBUSY || err == -EUSERS)
+			return open_channel(hci_index);
 
 		perror("Failed to bind Bluetooth socket");
 		return -1;
@@ -601,12 +606,6 @@  static void server_callback(int fd, uint32_t events, void *user_data)
 		return;
 	}
 
-	if (client_active && hci_index != HCI_INDEX_NONE) {
-		fprintf(stderr, "Active client already present\n");
-		close(host_fd);
-		return;
-	}
-
 	dev_fd = open_channel(hci_index);
 	if (dev_fd < 0) {
 		close(host_fd);
@@ -800,6 +799,7 @@  int main(int argc, char *argv[])
 
 	for (;;) {
 		int opt;
+		int index;
 
 		opt = getopt_long(argc, argv, "rc:l::u::p:i:aezdvh",
 						main_options, NULL);
@@ -844,7 +844,13 @@  int main(int argc, char *argv[])
 				usage();
 				return EXIT_FAILURE;
 			}
-			hci_index = atoi(str);
+			index = atoi(str) + 1;
+			if (index > HCI_INDEX_MAX) {
+				fprintf(stderr, "Invalid controller index\n");
+				usage();
+				return EXIT_FAILURE;
+			}
+			util_clear_uid(&hci_index, index);
 			break;
 		case 'a':
 			type = HCI_AMP;
@@ -884,6 +890,9 @@  int main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
+	if (hci_index == HCI_INDEX_NONE)
+		hci_index = 0;
+
 	mainloop_init();
 
 	if (connect_address || use_redirect) {