diff mbox series

[BlueZ] btproxy: Attempt to bind the next index

Message ID 20220225215505.560382-1-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ] btproxy: Attempt to bind the next index | expand

Commit Message

Luiz Augusto von Dentz Feb. 25, 2022, 9:55 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If no specific index is given attempt to bind the next index if the
current one is already in use.
---
 tools/btproxy.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

Comments

Luiz Augusto von Dentz March 2, 2022, 11:21 p.m. UTC | #1
Hi,

On Sat, Feb 26, 2022 at 12:25 AM <bluez.test.bot@gmail.com> wrote:
>
> 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=618201
>
> ---Test result---
>
> Test Summary:
> CheckPatch                    PASS      1.54 seconds
> GitLint                       PASS      1.12 seconds
> Prep - Setup ELL              PASS      49.94 seconds
> Build - Prep                  PASS      0.81 seconds
> Build - Configure             PASS      10.22 seconds
> Build - Make                  PASS      1453.81 seconds
> Make Check                    PASS      12.85 seconds
> Make Check w/Valgrind         PASS      516.33 seconds
> Make Distcheck                PASS      271.07 seconds
> Build w/ext ELL - Configure   PASS      10.39 seconds
> Build w/ext ELL - Make        PASS      1434.14 seconds
> Incremental Build with patchesPASS      0.00 seconds
>
>
>
> ---
> Regards,
> Linux Bluetooth
>

Pushed
diff mbox series

Patch

diff --git a/tools/btproxy.c b/tools/btproxy.c
index f6143038c..94ca1c7fd 100644
--- a/tools/btproxy.c
+++ b/tools/btproxy.c
@@ -47,8 +47,9 @@  struct sockaddr_hci {
 	unsigned short  hci_channel;
 };
 #define HCI_CHANNEL_USER	1
+#define HCI_INDEX_NONE		0xffff
 
-static uint16_t hci_index = 0;
+static uint16_t hci_index = HCI_INDEX_NONE;
 static bool client_active = false;
 static bool debug_enabled = false;
 static bool emulate_ecc = false;
@@ -535,9 +536,12 @@  static bool setup_proxy(int host_fd, bool host_shutdown,
 static int open_channel(uint16_t index)
 {
 	struct sockaddr_hci addr;
-	int fd;
+	int fd, err;
+
+	if (index == HCI_INDEX_NONE)
+		index = 0;
 
-	printf("Opening user channel for hci%u\n", hci_index);
+	printf("Opening user channel for hci%u\n", index);
 
 	fd = socket(PF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
 	if (fd < 0) {
@@ -551,7 +555,16 @@  static int open_channel(uint16_t index)
 	addr.hci_channel = HCI_CHANNEL_USER;
 
 	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		err = -errno;
 		close(fd);
+
+		/* Open next available controller if no specific index was
+		 * provided and the error indicates that the controller.
+		 */
+		if (hci_index == HCI_INDEX_NONE &&
+				(err == -EBUSY || err == -EUSERS))
+			return open_channel(++index);
+
 		perror("Failed to bind Bluetooth socket");
 		return -1;
 	}
@@ -588,7 +601,7 @@  static void server_callback(int fd, uint32_t events, void *user_data)
 		return;
 	}
 
-	if (client_active) {
+	if (client_active && hci_index != HCI_INDEX_NONE) {
 		fprintf(stderr, "Active client already present\n");
 		close(host_fd);
 		return;