From f7986f1a31c6d9cd52bb8e1f7b61d6a254bd5795 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Wed, 5 Jun 2024 13:39:10 -0700 Subject: [PATCH 1/2] HCI: Return the interface from EV_INDEX_ADDED Bug: 345058678 Test: mma -j32 Connect passthrough mode with AAOS Change-Id: I59872b1a5f84401c19106ebb0ffe1dbcc72f6aff --- bluetooth/aidl/default/net_bluetooth_mgmt.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp index 0699781459..db6caae436 100644 --- a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp +++ b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp @@ -173,7 +173,7 @@ int NetBluetoothMgmt::waitHciDev(int hci_interface) { // Received [Index Added] event. if (ev.opcode == MGMT_EV_INDEX_ADDED && ev.index == hci_interface) { ALOGI("hci interface %d added", hci_interface); - ret = 0; + ret = hci_interface; goto end; } } @@ -253,9 +253,9 @@ int NetBluetoothMgmt::openHci(int hci_interface) { rfkill(1); // Wait for the HCI interface to complete initialization or to come online. - hci_interface = waitHciDev(hci_interface); - if (hci_interface < 0) { - ALOGE("hci interface not found"); + int hci = waitHciDev(hci_interface); + if (hci < 0) { + ALOGE("hci interface %d not found", hci_interface); return -1; } @@ -268,7 +268,7 @@ int NetBluetoothMgmt::openHci(int hci_interface) { struct sockaddr_hci hci_addr = { .hci_family = AF_BLUETOOTH, - .hci_dev = static_cast(hci_interface), + .hci_dev = static_cast(hci), .hci_channel = HCI_CHANNEL_USER, }; @@ -279,7 +279,7 @@ int NetBluetoothMgmt::openHci(int hci_interface) { return -1; } - ALOGI("hci interface %d ready", hci_interface); + ALOGI("hci interface %d ready", hci); bt_fd_ = fd; return fd; } From 1f0e88bff97616fce7de9ed14b388b6e0e2d8fd2 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Wed, 5 Jun 2024 13:39:54 -0700 Subject: [PATCH 2/2] HCI: Prefer the requested hci_interface Bug: 345058678 Test: mma -j32 Connect passthrough mode with AAOS Change-Id: I9fd5e4cba1e14e6260f485f56f473ce506f18437 --- bluetooth/aidl/default/net_bluetooth_mgmt.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp index db6caae436..24693effcd 100644 --- a/bluetooth/aidl/default/net_bluetooth_mgmt.cpp +++ b/bluetooth/aidl/default/net_bluetooth_mgmt.cpp @@ -161,6 +161,16 @@ int NetBluetoothMgmt::waitHciDev(int hci_interface) { struct mgmt_ev_read_index_list* data = (struct mgmt_ev_read_index_list*)ev.data; + // Prefer the exact hci_interface + for (int i = 0; i < data->num_controllers; i++) { + if (data->index[i] == hci_interface) { + ALOGI("hci interface %d found", data->index[i]); + ret = data->index[i]; + goto end; + } + } + + // Accept a larger one if we can't find the exact one for (int i = 0; i < data->num_controllers; i++) { if (data->index[i] >= hci_interface) { ALOGI("hci interface %d found", data->index[i]);