Message ID | 20240108183938.468426-5-verdre@v0yd.nl |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp1207164dyq; Mon, 8 Jan 2024 10:43:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1WSjWrAFO77MMha+FKR//Uvbmjg86liulqlz568V6O6vBUw1BvL32uP1WmDScOSVekbym X-Received: by 2002:a17:902:d652:b0:1d4:5dcd:45a2 with SMTP id y18-20020a170902d65200b001d45dcd45a2mr1897512plh.72.1704739412903; Mon, 08 Jan 2024 10:43:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704739412; cv=none; d=google.com; s=arc-20160816; b=s9uHDGCxrLP7NDmUkfq8i0l5v1+oczdYb24gElfnIgwPMR6FS16nbHMv7z/SHxJvm3 a2kOisUPeameDVwT1RgbiNA9DrVSySZHGwLCEXhNeAQTYCjmRY1QfouOWocPs6yJdDSb y5za4Ef4oYYCimVceqvVq5uI5u1L/OzMlPiehI/ZnHkUNWMLh/L4SEhnWMDsfiTMbZAg aYq1W6drRF8+sgkfKYG7Qdgr3rfTjSiRaF2+LbL41u2izxR5MyJZuPQc/Rix9kuM+Yyu AtRsTcVNaDvpd4K8FeWlDhZX1aQ9TtxSOXOXb12cXE4e+ZnLir+0uxXPIr982K+04iwQ 20DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xZkQa94kF/MeY+yJ0tFpbd0Kp/G9G/cHXDnHLHVwEdU=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=NO0rIADKJsb4vcHyP22nhZBUDjxKR28lRZDkIC8FNho1njH7osF03WUA2/BZ53mR4P M6H2FzKrZiT7IdAvazvaoNNfiOvroJq0cqMQBmtfcqUX0lMkj8AG0Fh3OSEqM89u/h+P 1PcDKSNcrAh7H7twdWzJNSPMOxK4JS5my2MZcV4R0yEOW5sFJiqHRAo6NLB9pEXeFkcp 81K3FHcsFFm28K5waClg2u2gHozmQqvhVXmswNlnXyIxXcQOzobEnO8sQPV2jLUYiqZu pJTtPWIPdYnePFMOA8GSClAVhKGDUOU90PMkllz54m605xylMb2NWDiMGS2iowkou7z0 ZWxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ay8-20020a1709028b8800b001d50ccf36c9si222830plb.629.2024.01.08.10.43.32 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 10:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19984-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 349BCB2139C for <ouuuleilei@gmail.com>; Mon, 8 Jan 2024 18:41:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C570456449; Mon, 8 Jan 2024 18:40:02 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E666355C12; Mon, 8 Jan 2024 18:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4T82sx5tQGz9sk7; Mon, 8 Jan 2024 19:39:49 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= <verdre@v0yd.nl> To: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com> Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= <verdre@v0yd.nl>, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 4/4] Bluetooth: Remove pending ACL connection attempts Date: Mon, 8 Jan 2024 19:39:36 +0100 Message-ID: <20240108183938.468426-5-verdre@v0yd.nl> In-Reply-To: <20240108183938.468426-1-verdre@v0yd.nl> References: <20240108183938.468426-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4T82sx5tQGz9sk7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787548834270924487 X-GMAIL-MSGID: 1787548834270924487 |
Series |
Bluetooth: Improve retrying of connection attempts
|
|
Commit Message
Jonas Dreßler
Jan. 8, 2024, 6:39 p.m. UTC
With the last commit we moved to using the hci_sync queue for "Create Connection" requests, removing the need for retrying the paging after finished/failed "Create Connection" requests and after the end of inquiries. hci_conn_check_pending() was used to trigger this retry, we can remove it now. Note that we can also remove the special handling for COMMAND_DISALLOWED errors in the completion handler of "Create Connection", because "Create Connection" requests are now always serialized. This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support concurrent connect requests"). With this, the BT_CONNECT2 state of ACL hci_conn objects should now be back to meaning only one thing: That we received a connection request from another device (see hci_conn_request_evt), but the actual connect should be deferred. --- include/net/bluetooth/hci_core.h | 1 - net/bluetooth/hci_conn.c | 16 ---------------- net/bluetooth/hci_event.c | 21 ++++----------------- 3 files changed, 4 insertions(+), 34 deletions(-)
Comments
On 1/8/24 19:39, Jonas Dreßler wrote: > With the last commit we moved to using the hci_sync queue for "Create > Connection" requests, removing the need for retrying the paging after > finished/failed "Create Connection" requests and after the end of > inquiries. > > hci_conn_check_pending() was used to trigger this retry, we can remove it > now. > > Note that we can also remove the special handling for COMMAND_DISALLOWED > errors in the completion handler of "Create Connection", because "Create > Connection" requests are now always serialized. > > This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support > concurrent connect requests"). > > With this, the BT_CONNECT2 state of ACL hci_conn objects should now be > back to meaning only one thing: That we received a connection request > from another device (see hci_conn_request_evt), but the actual connect > should be deferred. > --- > include/net/bluetooth/hci_core.h | 1 - > net/bluetooth/hci_conn.c | 16 ---------------- > net/bluetooth/hci_event.c | 21 ++++----------------- > 3 files changed, 4 insertions(+), 34 deletions(-) > > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h > index 2c30834c1..d7483958d 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, > u8 role); > void hci_conn_del(struct hci_conn *conn); > void hci_conn_hash_flush(struct hci_dev *hdev); > -void hci_conn_check_pending(struct hci_dev *hdev); > > struct hci_chan *hci_chan_create(struct hci_conn *conn); > void hci_chan_del(struct hci_chan *chan); > diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > index 541d55301..22033057b 100644 > --- a/net/bluetooth/hci_conn.c > +++ b/net/bluetooth/hci_conn.c > @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) > } > } > > -/* Check pending connect attempts */ > -void hci_conn_check_pending(struct hci_dev *hdev) > -{ > - struct hci_conn *conn; > - > - BT_DBG("hdev %s", hdev->name); > - > - hci_dev_lock(hdev); > - > - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); > - if (conn) > - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, conn, NULL); > - > - hci_dev_unlock(hdev); > -} > - > static u32 get_link_mode(struct hci_conn *conn) > { > u32 link_mode = 0; > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index e8b4a0126..91973d6d1 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data, > hci_discovery_set_state(hdev, DISCOVERY_STOPPED); > hci_dev_unlock(hdev); > > - hci_conn_check_pending(hdev); > - > return rp->status; > } > > @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data, > > hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); > > - hci_conn_check_pending(hdev); > - > return rp->status; > } > > @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) > { > bt_dev_dbg(hdev, "status 0x%2.2x", status); > > - if (status) { > - hci_conn_check_pending(hdev); > + if (status) > return; > - } > > set_bit(HCI_INQUIRY, &hdev->flags); > } > @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) > > if (status) { > if (conn && conn->state == BT_CONNECT) { > - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { > - conn->state = BT_CLOSED; > - hci_connect_cfm(conn, status); > - hci_conn_del(conn); > - } else > - conn->state = BT_CONNECT2; > + conn->state = BT_CLOSED; > + hci_connect_cfm(conn, status); > + hci_conn_del(conn); > } > } else { > if (!conn) { > @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data, > > bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); > > - hci_conn_check_pending(hdev); > - > if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) > return; > > @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, > > unlock: > hci_dev_unlock(hdev); > - > - hci_conn_check_pending(hdev); > } > > static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) Please take a special look at this one: I'm not sure if I'm breaking the functionality of deferred connecting using BT_CONNECT2 in hci_conn_request_evt() here, as I don't see anywhere where we check for this state and establish a connection later. It seems that this is how hci_conn_request_evt() was initially written though, hci_conn_check_pending() only got introduced later and seems unrelated. Thanks, Jonas
On 1/8/24 19:44, Jonas Dreßler wrote: > On 1/8/24 19:39, Jonas Dreßler wrote: >> With the last commit we moved to using the hci_sync queue for "Create >> Connection" requests, removing the need for retrying the paging after >> finished/failed "Create Connection" requests and after the end of >> inquiries. >> >> hci_conn_check_pending() was used to trigger this retry, we can remove it >> now. >> >> Note that we can also remove the special handling for COMMAND_DISALLOWED >> errors in the completion handler of "Create Connection", because "Create >> Connection" requests are now always serialized. >> >> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support >> concurrent connect requests"). >> >> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be >> back to meaning only one thing: That we received a connection request >> from another device (see hci_conn_request_evt), but the actual connect >> should be deferred. >> --- >> include/net/bluetooth/hci_core.h | 1 - >> net/bluetooth/hci_conn.c | 16 ---------------- >> net/bluetooth/hci_event.c | 21 ++++----------------- >> 3 files changed, 4 insertions(+), 34 deletions(-) >> >> diff --git a/include/net/bluetooth/hci_core.h >> b/include/net/bluetooth/hci_core.h >> index 2c30834c1..d7483958d 100644 >> --- a/include/net/bluetooth/hci_core.h >> +++ b/include/net/bluetooth/hci_core.h >> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev >> *hdev, int type, bdaddr_t *dst, >> u8 role); >> void hci_conn_del(struct hci_conn *conn); >> void hci_conn_hash_flush(struct hci_dev *hdev); >> -void hci_conn_check_pending(struct hci_dev *hdev); >> struct hci_chan *hci_chan_create(struct hci_conn *conn); >> void hci_chan_del(struct hci_chan *chan); >> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c >> index 541d55301..22033057b 100644 >> --- a/net/bluetooth/hci_conn.c >> +++ b/net/bluetooth/hci_conn.c >> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) >> } >> } >> -/* Check pending connect attempts */ >> -void hci_conn_check_pending(struct hci_dev *hdev) >> -{ >> - struct hci_conn *conn; >> - >> - BT_DBG("hdev %s", hdev->name); >> - >> - hci_dev_lock(hdev); >> - >> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); >> - if (conn) >> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, >> conn, NULL); >> - >> - hci_dev_unlock(hdev); >> -} >> - >> static u32 get_link_mode(struct hci_conn *conn) >> { >> u32 link_mode = 0; >> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >> index e8b4a0126..91973d6d1 100644 >> --- a/net/bluetooth/hci_event.c >> +++ b/net/bluetooth/hci_event.c >> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev >> *hdev, void *data, >> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); >> hci_dev_unlock(hdev); >> - hci_conn_check_pending(hdev); >> - >> return rp->status; >> } >> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev >> *hdev, void *data, >> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); >> - hci_conn_check_pending(hdev); >> - >> return rp->status; >> } >> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev >> *hdev, __u8 status) >> { >> bt_dev_dbg(hdev, "status 0x%2.2x", status); >> - if (status) { >> - hci_conn_check_pending(hdev); >> + if (status) >> return; >> - } >> set_bit(HCI_INQUIRY, &hdev->flags); >> } >> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev >> *hdev, __u8 status) >> if (status) { >> if (conn && conn->state == BT_CONNECT) { >> - if (status != HCI_ERROR_COMMAND_DISALLOWED || >> conn->attempt > 2) { >> - conn->state = BT_CLOSED; >> - hci_connect_cfm(conn, status); >> - hci_conn_del(conn); >> - } else >> - conn->state = BT_CONNECT2; >> + conn->state = BT_CLOSED; >> + hci_connect_cfm(conn, status); >> + hci_conn_del(conn); >> } >> } else { >> if (!conn) { >> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct >> hci_dev *hdev, void *data, >> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); >> - hci_conn_check_pending(hdev); >> - >> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) >> return; >> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev >> *hdev, void *data, >> unlock: >> hci_dev_unlock(hdev); >> - >> - hci_conn_check_pending(hdev); >> } >> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) > > Please take a special look at this one: I'm not sure if I'm breaking the > functionality of deferred connecting using BT_CONNECT2 in > hci_conn_request_evt() here, as I don't see anywhere where we check for > this state and establish a connection later. > > It seems that this is how hci_conn_request_evt() was initially written > though, hci_conn_check_pending() only got introduced later and seems > unrelated. Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect requests). And later the deferred connection setup on "Conn Request event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred sco socket setup"). I assume the latter commit was relying on the "Create Connection" request "Conn Complete event" that got introduced with the former commit then? That would imply that we use BT_CONNECT2 if there's already a "Create Connection" going on when the "Conn Request event" happens, and we must wait for that existing request to finish.. Is that how those deferred connections are supposed to work? > > Thanks, > Jonas
Hi Jonas, On Mon, Jan 8, 2024 at 1:55 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > > On 1/8/24 19:44, Jonas Dreßler wrote: > > On 1/8/24 19:39, Jonas Dreßler wrote: > >> With the last commit we moved to using the hci_sync queue for "Create > >> Connection" requests, removing the need for retrying the paging after > >> finished/failed "Create Connection" requests and after the end of > >> inquiries. > >> > >> hci_conn_check_pending() was used to trigger this retry, we can remove it > >> now. > >> > >> Note that we can also remove the special handling for COMMAND_DISALLOWED > >> errors in the completion handler of "Create Connection", because "Create > >> Connection" requests are now always serialized. > >> > >> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support > >> concurrent connect requests"). > >> > >> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be > >> back to meaning only one thing: That we received a connection request > >> from another device (see hci_conn_request_evt), but the actual connect > >> should be deferred. > >> --- > >> include/net/bluetooth/hci_core.h | 1 - > >> net/bluetooth/hci_conn.c | 16 ---------------- > >> net/bluetooth/hci_event.c | 21 ++++----------------- > >> 3 files changed, 4 insertions(+), 34 deletions(-) > >> > >> diff --git a/include/net/bluetooth/hci_core.h > >> b/include/net/bluetooth/hci_core.h > >> index 2c30834c1..d7483958d 100644 > >> --- a/include/net/bluetooth/hci_core.h > >> +++ b/include/net/bluetooth/hci_core.h > >> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev > >> *hdev, int type, bdaddr_t *dst, > >> u8 role); > >> void hci_conn_del(struct hci_conn *conn); > >> void hci_conn_hash_flush(struct hci_dev *hdev); > >> -void hci_conn_check_pending(struct hci_dev *hdev); > >> struct hci_chan *hci_chan_create(struct hci_conn *conn); > >> void hci_chan_del(struct hci_chan *chan); > >> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > >> index 541d55301..22033057b 100644 > >> --- a/net/bluetooth/hci_conn.c > >> +++ b/net/bluetooth/hci_conn.c > >> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) > >> } > >> } > >> -/* Check pending connect attempts */ > >> -void hci_conn_check_pending(struct hci_dev *hdev) > >> -{ > >> - struct hci_conn *conn; > >> - > >> - BT_DBG("hdev %s", hdev->name); > >> - > >> - hci_dev_lock(hdev); > >> - > >> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); > >> - if (conn) > >> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, > >> conn, NULL); > >> - > >> - hci_dev_unlock(hdev); > >> -} > >> - > >> static u32 get_link_mode(struct hci_conn *conn) > >> { > >> u32 link_mode = 0; > >> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > >> index e8b4a0126..91973d6d1 100644 > >> --- a/net/bluetooth/hci_event.c > >> +++ b/net/bluetooth/hci_event.c > >> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev > >> *hdev, void *data, > >> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); > >> hci_dev_unlock(hdev); > >> - hci_conn_check_pending(hdev); > >> - > >> return rp->status; > >> } > >> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev > >> *hdev, void *data, > >> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); > >> - hci_conn_check_pending(hdev); > >> - > >> return rp->status; > >> } > >> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev > >> *hdev, __u8 status) > >> { > >> bt_dev_dbg(hdev, "status 0x%2.2x", status); > >> - if (status) { > >> - hci_conn_check_pending(hdev); > >> + if (status) > >> return; > >> - } > >> set_bit(HCI_INQUIRY, &hdev->flags); > >> } > >> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev > >> *hdev, __u8 status) > >> if (status) { > >> if (conn && conn->state == BT_CONNECT) { > >> - if (status != HCI_ERROR_COMMAND_DISALLOWED || > >> conn->attempt > 2) { > >> - conn->state = BT_CLOSED; > >> - hci_connect_cfm(conn, status); > >> - hci_conn_del(conn); > >> - } else > >> - conn->state = BT_CONNECT2; > >> + conn->state = BT_CLOSED; > >> + hci_connect_cfm(conn, status); > >> + hci_conn_del(conn); > >> } > >> } else { > >> if (!conn) { > >> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct > >> hci_dev *hdev, void *data, > >> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); > >> - hci_conn_check_pending(hdev); > >> - > >> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) > >> return; > >> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev > >> *hdev, void *data, > >> unlock: > >> hci_dev_unlock(hdev); > >> - > >> - hci_conn_check_pending(hdev); > >> } > >> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) > > > > Please take a special look at this one: I'm not sure if I'm breaking the > > functionality of deferred connecting using BT_CONNECT2 in > > hci_conn_request_evt() here, as I don't see anywhere where we check for > > this state and establish a connection later. > > > > It seems that this is how hci_conn_request_evt() was initially written > > though, hci_conn_check_pending() only got introduced later and seems > > unrelated. > > Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got > introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect > requests). And later the deferred connection setup on "Conn Request > event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred > sco socket setup"). > > I assume the latter commit was relying on the "Create Connection" > request "Conn Complete event" that got introduced with the former commit > then? That would imply that we use BT_CONNECT2 if there's already a > "Create Connection" going on when the "Conn Request event" happens, and > we must wait for that existing request to finish.. Is that how those > deferred connections are supposed to work? Well if you are not sure that works we better make sure we have tests that cover this, for LE I know for sure it works because we have the likes of iso-tester that do connect 2 peers simultaneously, but for classic I don't recall having any test that does multiple connections. > > > > Thanks, > > Jonas
Hi Luiz, On 1/8/24 20:14, Luiz Augusto von Dentz wrote: > Hi Jonas, > > On Mon, Jan 8, 2024 at 1:55 PM Jonas Dreßler <verdre@v0yd.nl> wrote: >> >> On 1/8/24 19:44, Jonas Dreßler wrote: >>> On 1/8/24 19:39, Jonas Dreßler wrote: >>>> With the last commit we moved to using the hci_sync queue for "Create >>>> Connection" requests, removing the need for retrying the paging after >>>> finished/failed "Create Connection" requests and after the end of >>>> inquiries. >>>> >>>> hci_conn_check_pending() was used to trigger this retry, we can remove it >>>> now. >>>> >>>> Note that we can also remove the special handling for COMMAND_DISALLOWED >>>> errors in the completion handler of "Create Connection", because "Create >>>> Connection" requests are now always serialized. >>>> >>>> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support >>>> concurrent connect requests"). >>>> >>>> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be >>>> back to meaning only one thing: That we received a connection request >>>> from another device (see hci_conn_request_evt), but the actual connect >>>> should be deferred. >>>> --- >>>> include/net/bluetooth/hci_core.h | 1 - >>>> net/bluetooth/hci_conn.c | 16 ---------------- >>>> net/bluetooth/hci_event.c | 21 ++++----------------- >>>> 3 files changed, 4 insertions(+), 34 deletions(-) >>>> >>>> diff --git a/include/net/bluetooth/hci_core.h >>>> b/include/net/bluetooth/hci_core.h >>>> index 2c30834c1..d7483958d 100644 >>>> --- a/include/net/bluetooth/hci_core.h >>>> +++ b/include/net/bluetooth/hci_core.h >>>> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev >>>> *hdev, int type, bdaddr_t *dst, >>>> u8 role); >>>> void hci_conn_del(struct hci_conn *conn); >>>> void hci_conn_hash_flush(struct hci_dev *hdev); >>>> -void hci_conn_check_pending(struct hci_dev *hdev); >>>> struct hci_chan *hci_chan_create(struct hci_conn *conn); >>>> void hci_chan_del(struct hci_chan *chan); >>>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c >>>> index 541d55301..22033057b 100644 >>>> --- a/net/bluetooth/hci_conn.c >>>> +++ b/net/bluetooth/hci_conn.c >>>> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) >>>> } >>>> } >>>> -/* Check pending connect attempts */ >>>> -void hci_conn_check_pending(struct hci_dev *hdev) >>>> -{ >>>> - struct hci_conn *conn; >>>> - >>>> - BT_DBG("hdev %s", hdev->name); >>>> - >>>> - hci_dev_lock(hdev); >>>> - >>>> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); >>>> - if (conn) >>>> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, >>>> conn, NULL); >>>> - >>>> - hci_dev_unlock(hdev); >>>> -} >>>> - >>>> static u32 get_link_mode(struct hci_conn *conn) >>>> { >>>> u32 link_mode = 0; >>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >>>> index e8b4a0126..91973d6d1 100644 >>>> --- a/net/bluetooth/hci_event.c >>>> +++ b/net/bluetooth/hci_event.c >>>> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev >>>> *hdev, void *data, >>>> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); >>>> hci_dev_unlock(hdev); >>>> - hci_conn_check_pending(hdev); >>>> - >>>> return rp->status; >>>> } >>>> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev >>>> *hdev, void *data, >>>> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); >>>> - hci_conn_check_pending(hdev); >>>> - >>>> return rp->status; >>>> } >>>> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev >>>> *hdev, __u8 status) >>>> { >>>> bt_dev_dbg(hdev, "status 0x%2.2x", status); >>>> - if (status) { >>>> - hci_conn_check_pending(hdev); >>>> + if (status) >>>> return; >>>> - } >>>> set_bit(HCI_INQUIRY, &hdev->flags); >>>> } >>>> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev >>>> *hdev, __u8 status) >>>> if (status) { >>>> if (conn && conn->state == BT_CONNECT) { >>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || >>>> conn->attempt > 2) { >>>> - conn->state = BT_CLOSED; >>>> - hci_connect_cfm(conn, status); >>>> - hci_conn_del(conn); >>>> - } else >>>> - conn->state = BT_CONNECT2; >>>> + conn->state = BT_CLOSED; >>>> + hci_connect_cfm(conn, status); >>>> + hci_conn_del(conn); >>>> } >>>> } else { >>>> if (!conn) { >>>> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct >>>> hci_dev *hdev, void *data, >>>> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); >>>> - hci_conn_check_pending(hdev); >>>> - >>>> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) >>>> return; >>>> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev >>>> *hdev, void *data, >>>> unlock: >>>> hci_dev_unlock(hdev); >>>> - >>>> - hci_conn_check_pending(hdev); >>>> } >>>> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) >>> >>> Please take a special look at this one: I'm not sure if I'm breaking the >>> functionality of deferred connecting using BT_CONNECT2 in >>> hci_conn_request_evt() here, as I don't see anywhere where we check for >>> this state and establish a connection later. >>> >>> It seems that this is how hci_conn_request_evt() was initially written >>> though, hci_conn_check_pending() only got introduced later and seems >>> unrelated. >> >> Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got >> introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect >> requests). And later the deferred connection setup on "Conn Request >> event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred >> sco socket setup"). >> >> I assume the latter commit was relying on the "Create Connection" >> request "Conn Complete event" that got introduced with the former commit >> then? That would imply that we use BT_CONNECT2 if there's already a >> "Create Connection" going on when the "Conn Request event" happens, and >> we must wait for that existing request to finish.. Is that how those >> deferred connections are supposed to work? > > Well if you are not sure that works we better make sure we have tests > that cover this, for LE I know for sure it works because we have the > likes of iso-tester that do connect 2 peers simultaneously, but for > classic I don't recall having any test that does multiple connections. The sequential "Create Connection" logic works, I tested that (of course I'm happy to add tests if it's not too much work). What I'm unsure about is if and how incoming connection requests from other devices with HCI_PROTO_DEFER flag are supposed to work and whether they are meant to trigger a "Create Connection" from us? > >>> >>> Thanks, >>> Jonas > > >
Hi Jonas, On Mon, Jan 8, 2024 at 2:29 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > > Hi Luiz, > > On 1/8/24 20:14, Luiz Augusto von Dentz wrote: > > Hi Jonas, > > > > On Mon, Jan 8, 2024 at 1:55 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > >> > >> On 1/8/24 19:44, Jonas Dreßler wrote: > >>> On 1/8/24 19:39, Jonas Dreßler wrote: > >>>> With the last commit we moved to using the hci_sync queue for "Create > >>>> Connection" requests, removing the need for retrying the paging after > >>>> finished/failed "Create Connection" requests and after the end of > >>>> inquiries. > >>>> > >>>> hci_conn_check_pending() was used to trigger this retry, we can remove it > >>>> now. > >>>> > >>>> Note that we can also remove the special handling for COMMAND_DISALLOWED > >>>> errors in the completion handler of "Create Connection", because "Create > >>>> Connection" requests are now always serialized. > >>>> > >>>> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support > >>>> concurrent connect requests"). > >>>> > >>>> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be > >>>> back to meaning only one thing: That we received a connection request > >>>> from another device (see hci_conn_request_evt), but the actual connect > >>>> should be deferred. > >>>> --- > >>>> include/net/bluetooth/hci_core.h | 1 - > >>>> net/bluetooth/hci_conn.c | 16 ---------------- > >>>> net/bluetooth/hci_event.c | 21 ++++----------------- > >>>> 3 files changed, 4 insertions(+), 34 deletions(-) > >>>> > >>>> diff --git a/include/net/bluetooth/hci_core.h > >>>> b/include/net/bluetooth/hci_core.h > >>>> index 2c30834c1..d7483958d 100644 > >>>> --- a/include/net/bluetooth/hci_core.h > >>>> +++ b/include/net/bluetooth/hci_core.h > >>>> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev > >>>> *hdev, int type, bdaddr_t *dst, > >>>> u8 role); > >>>> void hci_conn_del(struct hci_conn *conn); > >>>> void hci_conn_hash_flush(struct hci_dev *hdev); > >>>> -void hci_conn_check_pending(struct hci_dev *hdev); > >>>> struct hci_chan *hci_chan_create(struct hci_conn *conn); > >>>> void hci_chan_del(struct hci_chan *chan); > >>>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > >>>> index 541d55301..22033057b 100644 > >>>> --- a/net/bluetooth/hci_conn.c > >>>> +++ b/net/bluetooth/hci_conn.c > >>>> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) > >>>> } > >>>> } > >>>> -/* Check pending connect attempts */ > >>>> -void hci_conn_check_pending(struct hci_dev *hdev) > >>>> -{ > >>>> - struct hci_conn *conn; > >>>> - > >>>> - BT_DBG("hdev %s", hdev->name); > >>>> - > >>>> - hci_dev_lock(hdev); > >>>> - > >>>> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); > >>>> - if (conn) > >>>> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, > >>>> conn, NULL); > >>>> - > >>>> - hci_dev_unlock(hdev); > >>>> -} > >>>> - > >>>> static u32 get_link_mode(struct hci_conn *conn) > >>>> { > >>>> u32 link_mode = 0; > >>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > >>>> index e8b4a0126..91973d6d1 100644 > >>>> --- a/net/bluetooth/hci_event.c > >>>> +++ b/net/bluetooth/hci_event.c > >>>> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev > >>>> *hdev, void *data, > >>>> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); > >>>> hci_dev_unlock(hdev); > >>>> - hci_conn_check_pending(hdev); > >>>> - > >>>> return rp->status; > >>>> } > >>>> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev > >>>> *hdev, void *data, > >>>> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); > >>>> - hci_conn_check_pending(hdev); > >>>> - > >>>> return rp->status; > >>>> } > >>>> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev > >>>> *hdev, __u8 status) > >>>> { > >>>> bt_dev_dbg(hdev, "status 0x%2.2x", status); > >>>> - if (status) { > >>>> - hci_conn_check_pending(hdev); > >>>> + if (status) > >>>> return; > >>>> - } > >>>> set_bit(HCI_INQUIRY, &hdev->flags); > >>>> } > >>>> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev > >>>> *hdev, __u8 status) > >>>> if (status) { > >>>> if (conn && conn->state == BT_CONNECT) { > >>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || > >>>> conn->attempt > 2) { > >>>> - conn->state = BT_CLOSED; > >>>> - hci_connect_cfm(conn, status); > >>>> - hci_conn_del(conn); > >>>> - } else > >>>> - conn->state = BT_CONNECT2; > >>>> + conn->state = BT_CLOSED; > >>>> + hci_connect_cfm(conn, status); > >>>> + hci_conn_del(conn); > >>>> } > >>>> } else { > >>>> if (!conn) { > >>>> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct > >>>> hci_dev *hdev, void *data, > >>>> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); > >>>> - hci_conn_check_pending(hdev); > >>>> - > >>>> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) > >>>> return; > >>>> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev > >>>> *hdev, void *data, > >>>> unlock: > >>>> hci_dev_unlock(hdev); > >>>> - > >>>> - hci_conn_check_pending(hdev); > >>>> } > >>>> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) > >>> > >>> Please take a special look at this one: I'm not sure if I'm breaking the > >>> functionality of deferred connecting using BT_CONNECT2 in > >>> hci_conn_request_evt() here, as I don't see anywhere where we check for > >>> this state and establish a connection later. > >>> > >>> It seems that this is how hci_conn_request_evt() was initially written > >>> though, hci_conn_check_pending() only got introduced later and seems > >>> unrelated. > >> > >> Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got > >> introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect > >> requests). And later the deferred connection setup on "Conn Request > >> event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred > >> sco socket setup"). > >> > >> I assume the latter commit was relying on the "Create Connection" > >> request "Conn Complete event" that got introduced with the former commit > >> then? That would imply that we use BT_CONNECT2 if there's already a > >> "Create Connection" going on when the "Conn Request event" happens, and > >> we must wait for that existing request to finish.. Is that how those > >> deferred connections are supposed to work? > > > > Well if you are not sure that works we better make sure we have tests > > that cover this, for LE I know for sure it works because we have the > > likes of iso-tester that do connect 2 peers simultaneously, but for > > classic I don't recall having any test that does multiple connections. > > The sequential "Create Connection" logic works, I tested that (of course > I'm happy to add tests if it's not too much work). > > What I'm unsure about is if and how incoming connection requests from > other devices with HCI_PROTO_DEFER flag are supposed to work and whether > they are meant to trigger a "Create Connection" from us? For incoming connections on Classic that should result in an accept/reject connection command, so it should cause another Create Connection if that is what you are afraid of. > > > >>> > >>> Thanks, > >>> Jonas > > > > > >
Hi Luiz, On 1/8/24 20:41, Luiz Augusto von Dentz wrote: > Hi Jonas, > > On Mon, Jan 8, 2024 at 2:29 PM Jonas Dreßler <verdre@v0yd.nl> wrote: >> >> Hi Luiz, >> >> On 1/8/24 20:14, Luiz Augusto von Dentz wrote: >>> Hi Jonas, >>> >>> On Mon, Jan 8, 2024 at 1:55 PM Jonas Dreßler <verdre@v0yd.nl> wrote: >>>> >>>> On 1/8/24 19:44, Jonas Dreßler wrote: >>>>> On 1/8/24 19:39, Jonas Dreßler wrote: >>>>>> With the last commit we moved to using the hci_sync queue for "Create >>>>>> Connection" requests, removing the need for retrying the paging after >>>>>> finished/failed "Create Connection" requests and after the end of >>>>>> inquiries. >>>>>> >>>>>> hci_conn_check_pending() was used to trigger this retry, we can remove it >>>>>> now. >>>>>> >>>>>> Note that we can also remove the special handling for COMMAND_DISALLOWED >>>>>> errors in the completion handler of "Create Connection", because "Create >>>>>> Connection" requests are now always serialized. >>>>>> >>>>>> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support >>>>>> concurrent connect requests"). >>>>>> >>>>>> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be >>>>>> back to meaning only one thing: That we received a connection request >>>>>> from another device (see hci_conn_request_evt), but the actual connect >>>>>> should be deferred. >>>>>> --- >>>>>> include/net/bluetooth/hci_core.h | 1 - >>>>>> net/bluetooth/hci_conn.c | 16 ---------------- >>>>>> net/bluetooth/hci_event.c | 21 ++++----------------- >>>>>> 3 files changed, 4 insertions(+), 34 deletions(-) >>>>>> >>>>>> diff --git a/include/net/bluetooth/hci_core.h >>>>>> b/include/net/bluetooth/hci_core.h >>>>>> index 2c30834c1..d7483958d 100644 >>>>>> --- a/include/net/bluetooth/hci_core.h >>>>>> +++ b/include/net/bluetooth/hci_core.h >>>>>> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev >>>>>> *hdev, int type, bdaddr_t *dst, >>>>>> u8 role); >>>>>> void hci_conn_del(struct hci_conn *conn); >>>>>> void hci_conn_hash_flush(struct hci_dev *hdev); >>>>>> -void hci_conn_check_pending(struct hci_dev *hdev); >>>>>> struct hci_chan *hci_chan_create(struct hci_conn *conn); >>>>>> void hci_chan_del(struct hci_chan *chan); >>>>>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c >>>>>> index 541d55301..22033057b 100644 >>>>>> --- a/net/bluetooth/hci_conn.c >>>>>> +++ b/net/bluetooth/hci_conn.c >>>>>> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) >>>>>> } >>>>>> } >>>>>> -/* Check pending connect attempts */ >>>>>> -void hci_conn_check_pending(struct hci_dev *hdev) >>>>>> -{ >>>>>> - struct hci_conn *conn; >>>>>> - >>>>>> - BT_DBG("hdev %s", hdev->name); >>>>>> - >>>>>> - hci_dev_lock(hdev); >>>>>> - >>>>>> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); >>>>>> - if (conn) >>>>>> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, >>>>>> conn, NULL); >>>>>> - >>>>>> - hci_dev_unlock(hdev); >>>>>> -} >>>>>> - >>>>>> static u32 get_link_mode(struct hci_conn *conn) >>>>>> { >>>>>> u32 link_mode = 0; >>>>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >>>>>> index e8b4a0126..91973d6d1 100644 >>>>>> --- a/net/bluetooth/hci_event.c >>>>>> +++ b/net/bluetooth/hci_event.c >>>>>> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev >>>>>> *hdev, void *data, >>>>>> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); >>>>>> hci_dev_unlock(hdev); >>>>>> - hci_conn_check_pending(hdev); >>>>>> - >>>>>> return rp->status; >>>>>> } >>>>>> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev >>>>>> *hdev, void *data, >>>>>> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); >>>>>> - hci_conn_check_pending(hdev); >>>>>> - >>>>>> return rp->status; >>>>>> } >>>>>> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev >>>>>> *hdev, __u8 status) >>>>>> { >>>>>> bt_dev_dbg(hdev, "status 0x%2.2x", status); >>>>>> - if (status) { >>>>>> - hci_conn_check_pending(hdev); >>>>>> + if (status) >>>>>> return; >>>>>> - } >>>>>> set_bit(HCI_INQUIRY, &hdev->flags); >>>>>> } >>>>>> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev >>>>>> *hdev, __u8 status) >>>>>> if (status) { >>>>>> if (conn && conn->state == BT_CONNECT) { >>>>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || >>>>>> conn->attempt > 2) { >>>>>> - conn->state = BT_CLOSED; >>>>>> - hci_connect_cfm(conn, status); >>>>>> - hci_conn_del(conn); >>>>>> - } else >>>>>> - conn->state = BT_CONNECT2; >>>>>> + conn->state = BT_CLOSED; >>>>>> + hci_connect_cfm(conn, status); >>>>>> + hci_conn_del(conn); >>>>>> } >>>>>> } else { >>>>>> if (!conn) { >>>>>> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct >>>>>> hci_dev *hdev, void *data, >>>>>> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); >>>>>> - hci_conn_check_pending(hdev); >>>>>> - >>>>>> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) >>>>>> return; >>>>>> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev >>>>>> *hdev, void *data, >>>>>> unlock: >>>>>> hci_dev_unlock(hdev); >>>>>> - >>>>>> - hci_conn_check_pending(hdev); >>>>>> } >>>>>> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) >>>>> >>>>> Please take a special look at this one: I'm not sure if I'm breaking the >>>>> functionality of deferred connecting using BT_CONNECT2 in >>>>> hci_conn_request_evt() here, as I don't see anywhere where we check for >>>>> this state and establish a connection later. >>>>> >>>>> It seems that this is how hci_conn_request_evt() was initially written >>>>> though, hci_conn_check_pending() only got introduced later and seems >>>>> unrelated. >>>> >>>> Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got >>>> introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect >>>> requests). And later the deferred connection setup on "Conn Request >>>> event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred >>>> sco socket setup"). >>>> >>>> I assume the latter commit was relying on the "Create Connection" >>>> request "Conn Complete event" that got introduced with the former commit >>>> then? That would imply that we use BT_CONNECT2 if there's already a >>>> "Create Connection" going on when the "Conn Request event" happens, and >>>> we must wait for that existing request to finish.. Is that how those >>>> deferred connections are supposed to work? >>> >>> Well if you are not sure that works we better make sure we have tests >>> that cover this, for LE I know for sure it works because we have the >>> likes of iso-tester that do connect 2 peers simultaneously, but for >>> classic I don't recall having any test that does multiple connections. >> >> The sequential "Create Connection" logic works, I tested that (of course >> I'm happy to add tests if it's not too much work). >> >> What I'm unsure about is if and how incoming connection requests from >> other devices with HCI_PROTO_DEFER flag are supposed to work and whether >> they are meant to trigger a "Create Connection" from us? > > For incoming connections on Classic that should result in an > accept/reject connection command, so it should cause another Create > Connection if that is what you are afraid of. > Hmm, do you mean it *shouldn't* cause another "Create Connection"? I just checked in the spec: It sounds like once we send the "Accept Connection Request" to the controller, the controller takes care of establishing the connection by itself (no "Create Connection" necessary), and will then later give us a "Connection Complete" event to indicate that the connection is done. If I'm reading all this correctly, that sounds like my commit is correct, and we had a bug in this logic before by interpreting BT_CONNECT2 in two different ways. >>> >>>>> >>>>> Thanks, >>>>> Jonas >>> >>> >>> > > >
Hi Jonas, On Mon, Jan 8, 2024 at 3:26 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > > Hi Luiz, > > On 1/8/24 20:41, Luiz Augusto von Dentz wrote: > > Hi Jonas, > > > > On Mon, Jan 8, 2024 at 2:29 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > >> > >> Hi Luiz, > >> > >> On 1/8/24 20:14, Luiz Augusto von Dentz wrote: > >>> Hi Jonas, > >>> > >>> On Mon, Jan 8, 2024 at 1:55 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > >>>> > >>>> On 1/8/24 19:44, Jonas Dreßler wrote: > >>>>> On 1/8/24 19:39, Jonas Dreßler wrote: > >>>>>> With the last commit we moved to using the hci_sync queue for "Create > >>>>>> Connection" requests, removing the need for retrying the paging after > >>>>>> finished/failed "Create Connection" requests and after the end of > >>>>>> inquiries. > >>>>>> > >>>>>> hci_conn_check_pending() was used to trigger this retry, we can remove it > >>>>>> now. > >>>>>> > >>>>>> Note that we can also remove the special handling for COMMAND_DISALLOWED > >>>>>> errors in the completion handler of "Create Connection", because "Create > >>>>>> Connection" requests are now always serialized. > >>>>>> > >>>>>> This is somewhat reverting commit 4c67bc74f016 ("[Bluetooth] Support > >>>>>> concurrent connect requests"). > >>>>>> > >>>>>> With this, the BT_CONNECT2 state of ACL hci_conn objects should now be > >>>>>> back to meaning only one thing: That we received a connection request > >>>>>> from another device (see hci_conn_request_evt), but the actual connect > >>>>>> should be deferred. > >>>>>> --- > >>>>>> include/net/bluetooth/hci_core.h | 1 - > >>>>>> net/bluetooth/hci_conn.c | 16 ---------------- > >>>>>> net/bluetooth/hci_event.c | 21 ++++----------------- > >>>>>> 3 files changed, 4 insertions(+), 34 deletions(-) > >>>>>> > >>>>>> diff --git a/include/net/bluetooth/hci_core.h > >>>>>> b/include/net/bluetooth/hci_core.h > >>>>>> index 2c30834c1..d7483958d 100644 > >>>>>> --- a/include/net/bluetooth/hci_core.h > >>>>>> +++ b/include/net/bluetooth/hci_core.h > >>>>>> @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev > >>>>>> *hdev, int type, bdaddr_t *dst, > >>>>>> u8 role); > >>>>>> void hci_conn_del(struct hci_conn *conn); > >>>>>> void hci_conn_hash_flush(struct hci_dev *hdev); > >>>>>> -void hci_conn_check_pending(struct hci_dev *hdev); > >>>>>> struct hci_chan *hci_chan_create(struct hci_conn *conn); > >>>>>> void hci_chan_del(struct hci_chan *chan); > >>>>>> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c > >>>>>> index 541d55301..22033057b 100644 > >>>>>> --- a/net/bluetooth/hci_conn.c > >>>>>> +++ b/net/bluetooth/hci_conn.c > >>>>>> @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) > >>>>>> } > >>>>>> } > >>>>>> -/* Check pending connect attempts */ > >>>>>> -void hci_conn_check_pending(struct hci_dev *hdev) > >>>>>> -{ > >>>>>> - struct hci_conn *conn; > >>>>>> - > >>>>>> - BT_DBG("hdev %s", hdev->name); > >>>>>> - > >>>>>> - hci_dev_lock(hdev); > >>>>>> - > >>>>>> - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); > >>>>>> - if (conn) > >>>>>> - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, > >>>>>> conn, NULL); > >>>>>> - > >>>>>> - hci_dev_unlock(hdev); > >>>>>> -} > >>>>>> - > >>>>>> static u32 get_link_mode(struct hci_conn *conn) > >>>>>> { > >>>>>> u32 link_mode = 0; > >>>>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > >>>>>> index e8b4a0126..91973d6d1 100644 > >>>>>> --- a/net/bluetooth/hci_event.c > >>>>>> +++ b/net/bluetooth/hci_event.c > >>>>>> @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev > >>>>>> *hdev, void *data, > >>>>>> hci_discovery_set_state(hdev, DISCOVERY_STOPPED); > >>>>>> hci_dev_unlock(hdev); > >>>>>> - hci_conn_check_pending(hdev); > >>>>>> - > >>>>>> return rp->status; > >>>>>> } > >>>>>> @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev > >>>>>> *hdev, void *data, > >>>>>> hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); > >>>>>> - hci_conn_check_pending(hdev); > >>>>>> - > >>>>>> return rp->status; > >>>>>> } > >>>>>> @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev > >>>>>> *hdev, __u8 status) > >>>>>> { > >>>>>> bt_dev_dbg(hdev, "status 0x%2.2x", status); > >>>>>> - if (status) { > >>>>>> - hci_conn_check_pending(hdev); > >>>>>> + if (status) > >>>>>> return; > >>>>>> - } > >>>>>> set_bit(HCI_INQUIRY, &hdev->flags); > >>>>>> } > >>>>>> @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev > >>>>>> *hdev, __u8 status) > >>>>>> if (status) { > >>>>>> if (conn && conn->state == BT_CONNECT) { > >>>>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || > >>>>>> conn->attempt > 2) { > >>>>>> - conn->state = BT_CLOSED; > >>>>>> - hci_connect_cfm(conn, status); > >>>>>> - hci_conn_del(conn); > >>>>>> - } else > >>>>>> - conn->state = BT_CONNECT2; > >>>>>> + conn->state = BT_CLOSED; > >>>>>> + hci_connect_cfm(conn, status); > >>>>>> + hci_conn_del(conn); > >>>>>> } > >>>>>> } else { > >>>>>> if (!conn) { > >>>>>> @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct > >>>>>> hci_dev *hdev, void *data, > >>>>>> bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); > >>>>>> - hci_conn_check_pending(hdev); > >>>>>> - > >>>>>> if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) > >>>>>> return; > >>>>>> @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev > >>>>>> *hdev, void *data, > >>>>>> unlock: > >>>>>> hci_dev_unlock(hdev); > >>>>>> - > >>>>>> - hci_conn_check_pending(hdev); > >>>>>> } > >>>>>> static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) > >>>>> > >>>>> Please take a special look at this one: I'm not sure if I'm breaking the > >>>>> functionality of deferred connecting using BT_CONNECT2 in > >>>>> hci_conn_request_evt() here, as I don't see anywhere where we check for > >>>>> this state and establish a connection later. > >>>>> > >>>>> It seems that this is how hci_conn_request_evt() was initially written > >>>>> though, hci_conn_check_pending() only got introduced later and seems > >>>>> unrelated. > >>>> > >>>> Ahh nevermind... The check for BT_CONNECT2 on "Conn Complete event" got > >>>> introduced with 4c67bc74f01 ([Bluetooth] Support concurrent connect > >>>> requests). And later the deferred connection setup on "Conn Request > >>>> event" got introduced with 20714bfef8 ("Bluetooth: Implement deferred > >>>> sco socket setup"). > >>>> > >>>> I assume the latter commit was relying on the "Create Connection" > >>>> request "Conn Complete event" that got introduced with the former commit > >>>> then? That would imply that we use BT_CONNECT2 if there's already a > >>>> "Create Connection" going on when the "Conn Request event" happens, and > >>>> we must wait for that existing request to finish.. Is that how those > >>>> deferred connections are supposed to work? > >>> > >>> Well if you are not sure that works we better make sure we have tests > >>> that cover this, for LE I know for sure it works because we have the > >>> likes of iso-tester that do connect 2 peers simultaneously, but for > >>> classic I don't recall having any test that does multiple connections. > >> > >> The sequential "Create Connection" logic works, I tested that (of course > >> I'm happy to add tests if it's not too much work). > >> > >> What I'm unsure about is if and how incoming connection requests from > >> other devices with HCI_PROTO_DEFER flag are supposed to work and whether > >> they are meant to trigger a "Create Connection" from us? > > > > For incoming connections on Classic that should result in an > > accept/reject connection command, so it should cause another Create > > Connection if that is what you are afraid of. > > > > Hmm, do you mean it *shouldn't* cause another "Create Connection"? Yeah, sorry about that, it is Monday I should probably double check if what I wrote makes any sense before sending :D > I just checked in the spec: It sounds like once we send the "Accept > Connection Request" to the controller, the controller takes care of > establishing the connection by itself (no "Create Connection" > necessary), and will then later give us a "Connection Complete" event to > indicate that the connection is done. Yep, it will follow up with a Connection Complete. > If I'm reading all this correctly, that sounds like my commit is > correct, and we had a bug in this logic before by interpreting > BT_CONNECT2 in two different ways. > > >>> > >>>>> > >>>>> Thanks, > >>>>> Jonas > >>> > >>> > >>> > > > > > >
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 2c30834c1..d7483958d 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1330,7 +1330,6 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, u8 role); void hci_conn_del(struct hci_conn *conn); void hci_conn_hash_flush(struct hci_dev *hdev); -void hci_conn_check_pending(struct hci_dev *hdev); struct hci_chan *hci_chan_create(struct hci_conn *conn); void hci_chan_del(struct hci_chan *chan); diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 541d55301..22033057b 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -2534,22 +2534,6 @@ void hci_conn_hash_flush(struct hci_dev *hdev) } } -/* Check pending connect attempts */ -void hci_conn_check_pending(struct hci_dev *hdev) -{ - struct hci_conn *conn; - - BT_DBG("hdev %s", hdev->name); - - hci_dev_lock(hdev); - - conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); - if (conn) - hci_cmd_sync_queue(hdev, hci_acl_create_connection_sync, conn, NULL); - - hci_dev_unlock(hdev); -} - static u32 get_link_mode(struct hci_conn *conn) { u32 link_mode = 0; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index e8b4a0126..91973d6d1 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -117,8 +117,6 @@ static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data, hci_discovery_set_state(hdev, DISCOVERY_STOPPED); hci_dev_unlock(hdev); - hci_conn_check_pending(hdev); - return rp->status; } @@ -149,8 +147,6 @@ static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data, hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); - hci_conn_check_pending(hdev); - return rp->status; } @@ -2296,10 +2292,8 @@ static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) { bt_dev_dbg(hdev, "status 0x%2.2x", status); - if (status) { - hci_conn_check_pending(hdev); + if (status) return; - } set_bit(HCI_INQUIRY, &hdev->flags); } @@ -2323,12 +2317,9 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { - conn->state = BT_CLOSED; - hci_connect_cfm(conn, status); - hci_conn_del(conn); - } else - conn->state = BT_CONNECT2; + conn->state = BT_CLOSED; + hci_connect_cfm(conn, status); + hci_conn_del(conn); } } else { if (!conn) { @@ -3020,8 +3011,6 @@ static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data, bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); - hci_conn_check_pending(hdev); - if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) return; @@ -3247,8 +3236,6 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, unlock: hci_dev_unlock(hdev); - - hci_conn_check_pending(hdev); } static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr)