Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793607569; b=wMU7r+hfpgUhpG8wUS/bT84KDekbC9N5ECkfW+X8Q+653XiMFSY4fD9HZ1R0K07ExZZj VUAA0v9zYD5bk5UIyQ2uAZ+odeXRX4ol2hM+fteDGdfl9sX+riCm8iYZLApDLHRRgPqFo 4QxX+xVd8wvNbO4Z/35iJHM2N4bXpiLnr0m9LW6tiqIJv74I6H1y8YhYa3Ssx+CVOXYQr 60UXMPf4xTiVgMqOAaDGOEFAz6rpqTsKCfx9Q3fSI7XGyDg6BDj1Vm1DHlTITFG3Lu1qL KkqseG44HWzgPPC5hY6Fpo2+OC932KmfxNdujTPJy4UwxwiWGXwQR66FQsgfvuJKJNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793607569; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:X-Proofpoint-Reinject: X-QCInternal:X-QCInternal:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=Mj/ctYAhumDjBCLHOGMYV4podchycZohH4OCuO1ZgUM=; b=aA6wrlaTMSBoVUZi29K0MVmZp1bdoBIUr4g1ihzdsDR6ZPNITp1ZH8xJGI5VubBEa020 K2/6JR0GwqCKvbAb4BeXyBWO8Ckd+TJHmWvSuSlk7qu+TGzhtBxUi+rKi2VlmHlu+Cnce AI2lHyx5ihbijaqQUY0IOUJ+qXasFUUUsZ9GGd4YJOYiwZBoHXdxbflsMwxIY1AVYLNBg gMHudZfxXKA2ExuGEXH6cBJDyJRmetFssOas3OZa+CIQCEUwuUKmZcpUfpWrTrd7lbVDq Cud03NibCcfuPAXwISzOOi5oZRAakKhnXgIcbPkkywSCWjGFmE5TtAc5NnbsKwH6pPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=dXuPuDvY; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C70F606A32C for ; Mon, 2 Nov 2026 08:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6C70F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=dXuPuDvY Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A24DObr2433830 for ; Mon, 2 Nov 2026 08:19:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=Mj/ctYAhumD jBCLHOGMYV4podchycZohH4OCuO1ZgUM=; b=dXuPuDvYD5SUQls8Iy+yRF/KBCF LNXiRnPtWaDK/5wZtprZX5ffydV0L5Ge14ZES+Q7iL0B74mFg7rD6ljNt268QANI aGVsJ4RYmAMS0vb2y22XoW58g6tMVdY+tljVk9amxW2bJ4UICJAWBALR5WtQsJ5j PHmjtm6Yjz0b2ClW7uVy6WF85XKmn7vVMNh3UGQRpsPfzF5/mCeEE7WwuG82qUzW oMEx/AwyQAHYf/vQESbj7NOgehVnqb0vqWmpYKZR1YrSBUMWv8itWf33XJdk0gMA iyrbM8evvvHvZrSpgRrfkMIw7YrDgS3q89GvKOjBdg6mw4UE9/qjMZy7lyg== Received: from aptaippmta02.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com [103.229.16.4]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hpka60t87-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Mon, 02 Nov 2026 08:19:24 +0000 (GMT) Received: from pps.filterd (aptaippmta02.qualcomm.com [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (8.18.1.11/8.18.1.11) with ESMTP id 6A28JLN03331096 for ; Mon, 2 Nov 2026 08:19:22 GMT Received: from bt-iot-sh04-lnx.qualcomm.com (smtphost-taiwan.qualcomm.com [10.249.136.33]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 6A28JJg13331043; Mon, 02 Nov 2026 08:19:22 +0000 (GMT) From: Cheng Jiang To: linux-bluetooth@vger.kernel.org Cc: jinwang.li@oss.qualcomm.com, wei.deng@oss.qualcomm.com, xiuzhuo.shang@oss.qualcomm.com, shuai.zhang@oss.qualcomm.com, Cheng Jiang Subject: [PATCH BlueZ 06/15] shared/hci: Look up the connection handle on the right link Date: Mon, 2 Nov 2026 16:19:03 +0800 Message-ID: <20261102081913.1623864-7-cheng.jiang@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102081913.1623864-1-cheng.jiang@oss.qualcomm.com> References: <20261102081913.1623864-1-cheng.jiang@oss.qualcomm.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Reinject: loops=2 maxloops=12 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-ORIG-GUID: dB0dSWFEuewayFfTu4YOm37_VXpBJVXc X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMiBTYWx0ZWRfX2GaK38IoZTxB bmWwfoKaZLW60hTtNuLoewwdNW9Na6fOifKc1FKlSSVouM2id+2Hr9HbNQhaxStQWy202i0weIo 5XI+QlSspu4jAIDILLqDQHab6IJUkXM= X-Authority-Analysis: v=2.4 cv=ZbyIpcVA c=1 sm=1 tr=0 ts=6ae8478d cx=c_pps a=nuhDOHQX5FNHPW3J6Bj6AA==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=PS027pwReTtRM5c9:21 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=tdWRa-og8BfZM2Ss03MA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMiBTYWx0ZWRfX22WehXAgkrSY MQKzHJFNRo4gMogS4ixF5UB3Tvw9WtGWF6JltrClsFtc44qiknwsZBVglKHpqDJ0H8I+6AJ/St9 decRDWHw9ngrEeIvDIjTCtVNx51toLOdjIJkwyk2sckFHRxPMlQVkSFl9tRbFDYvo+Z9xYsPFgU bOKN/f+FZQsAp7nRP2q9yQhXukm+w2Gdn6fKcCBAo98KR2pn7hW1ayIO43ChsG8+7yHflWtTaZO 9ou2LyUX7VnkZE5eMGnyiOMYDj/0IJQgmh3F2xdGBy0EpBF1EgpOhXJ13uyGK/QXZ4V5dONkchg T7AMaPIw1/yzmmHMAfcLb5gpf17Qe5SwYbzrRfeh5u7kdJUXLylYAO4UKwR24gypa0M74rnSfia N1v2rkmha3IdpLigN/DUNCI/J9B0tA933P2Kxz5TzbNprK5GKSOmhvJnzovhSgB1dfsO7vtqjpv IE/9FMr+MtKWJkVBj0Q== X-Proofpoint-GUID: dB0dSWFEuewayFfTu4YOm37_VXpBJVXc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1015 bulkscore=0 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020032 bt_hci_get_conn_handle() set dev_id to 0 in its HCIGETCONNLIST request, expecting the ioctl to fill it in. The kernel reads it instead, to pick the controller whose connections it lists, so the lookup always went to hci0 whatever adapter the channel was opened for. The list also holds every link of that controller, and the first one with a matching address was taken. With a dual-mode peer connected over BR/EDR first, that is the BR/EDR ACL, and after a quick reconnection it can be the old link that is still being torn down. Remember the index the raw channel was opened for and use it in the request. Take the link type from the caller and only accept a connected link of that type, so that the function works for any link type. Add LE_LINK next to the other link types for that, which also replaces the local copy in hcitool. Assisted-by: Claude:claude-opus-5-5 --- lib/bluetooth/hci.h | 1 + profiles/ranging/rap.c | 3 ++- src/shared/hci.c | 12 +++++++----- src/shared/hci.h | 2 +- tools/hcitool.c | 3 --- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/bluetooth/hci.h b/lib/bluetooth/hci.h index 2e4aa394e..6f51a2e10 100644 --- a/lib/bluetooth/hci.h +++ b/lib/bluetooth/hci.h @@ -210,6 +210,7 @@ enum { #define SCO_LINK 0x00 #define ACL_LINK 0x01 #define ESCO_LINK 0x02 +#define LE_LINK 0x80 /* LMP features */ #define LMP_3SLOT 0x01 diff --git a/profiles/ranging/rap.c b/profiles/ranging/rap.c index 2d8b1a7a1..d23c3f8e2 100644 --- a/profiles/ranging/rap.c +++ b/profiles/ranging/rap.c @@ -18,6 +18,7 @@ #include "gdbus/gdbus.h" #include "bluetooth/bluetooth.h" +#include "bluetooth/hci.h" #include "bluetooth/l2cap.h" #include "bluetooth/uuid.h" @@ -1099,7 +1100,7 @@ static int rap_setup_reflector(struct rap_data *data) if (att && data->adapter_data->hci) { if (bt_hci_get_conn_handle(data->adapter_data->hci, - (const uint8_t *)bdaddr, &handle)) { + (const uint8_t *)bdaddr, LE_LINK, &handle)) { DBG("conn handle 0x%04X for %s", handle, addr); data->conn_handle = handle; bt_rap_set_conn_hndl(data->hci_sm, diff --git a/src/shared/hci.c b/src/shared/hci.c index e8586ab50..f1d663be1 100644 --- a/src/shared/hci.c +++ b/src/shared/hci.c @@ -34,9 +34,9 @@ #include "src/shared/timeout.h" #include "src/shared/hci.h" - struct bt_hci { int ref_count; + uint16_t index; struct io *io; bool is_stream; bool writer_active; @@ -463,6 +463,7 @@ struct bt_hci *bt_hci_new_raw_device(uint16_t index) } hci->is_stream = false; + hci->index = index; bt_hci_set_close_on_unref(hci, true); @@ -972,7 +973,7 @@ bool bt_hci_unregister_subevent(struct bt_hci *hci, unsigned int id) } bool bt_hci_get_conn_handle(struct bt_hci *hci, const uint8_t *bdaddr, - uint16_t *handle) + uint8_t link_type, uint16_t *handle) { struct hci_conn_list_req *cl; struct hci_conn_info *ci; @@ -992,7 +993,7 @@ bool bt_hci_get_conn_handle(struct bt_hci *hci, const uint8_t *bdaddr, return false; memset(cl, 0, 10 * sizeof(*ci) + sizeof(*cl)); - cl->dev_id = 0; /* Will be filled by ioctl */ + cl->dev_id = hci->index; cl->conn_num = 10; /* Get connection list via ioctl */ @@ -1001,10 +1002,11 @@ bool bt_hci_get_conn_handle(struct bt_hci *hci, const uint8_t *bdaddr, return false; } - /* Search for the connection with matching bdaddr */ + /* The list holds every link of the controller, so match the type too */ ci = cl->conn_info; for (i = 0; i < cl->conn_num; i++, ci++) { - if (memcmp(&ci->bdaddr, bdaddr, 6) == 0) { + if (ci->type == link_type && ci->state == BT_CONNECTED && + memcmp(&ci->bdaddr, bdaddr, 6) == 0) { *handle = ci->handle; found = true; break; diff --git a/src/shared/hci.h b/src/shared/hci.h index 5be48577f..a91d24523 100644 --- a/src/shared/hci.h +++ b/src/shared/hci.h @@ -49,4 +49,4 @@ unsigned int bt_hci_register_subevent(struct bt_hci *hci, bool bt_hci_unregister_subevent(struct bt_hci *hci, unsigned int id); bool bt_hci_get_conn_handle(struct bt_hci *hci, const uint8_t *bdaddr, - uint16_t *handle); + uint8_t link_type, uint16_t *handle); diff --git a/tools/hcitool.c b/tools/hcitool.c index 1903d859b..fc4fc1709 100644 --- a/tools/hcitool.c +++ b/tools/hcitool.c @@ -34,9 +34,6 @@ #include "src/oui.h" -/* Unofficial value, might still change */ -#define LE_LINK 0x80 - #define FLAGS_AD_TYPE 0x01 #define FLAGS_LIMITED_MODE_BIT 0x01 #define FLAGS_GENERAL_MODE_BIT 0x02 -- 2.43.0