Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4864840rwd; Tue, 30 May 2023 11:00:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RsQfyBz/fWGRIKsbOHcjNIZXZdRylsnX9mNq1seymhmSg2aRZBa/RKo9REvri0WvjRTO9 X-Received: by 2002:a17:90a:fe3:b0:24e:6a6:cd6 with SMTP id 90-20020a17090a0fe300b0024e06a60cd6mr3188635pjz.29.1685469634503; Tue, 30 May 2023 11:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685469634; cv=none; d=google.com; s=arc-20160816; b=u3FxGueLMnBqTSeQF40YsyZyx1BREeKex807RpCNGn6wTgU2iFbWhYYBba2DL5HtBr pbb5KjUqnmV/0vMMTjxeoyPEnIiPCCJl92KVThg4g/rXAnbYyhMGAWU7PcAIejP5T00T byIzZqlUuWm3ctWSGazKX5/WXqXkMgMQUMmufNiIAqu1r41LRwMGxIUTu3KSoogwPELO TAH2QJLgu4dCbQhaAKc+lYe8KFyp7w0DjMwM2N4XALloAIeT3KADszNbhJ15AhKWOnoU R4Upccc1wh/vojGZ1s1AAnfUeWIRnJHy/M1kY6juadOswgsw2ssb1aSRKSPvitLERQbm b+KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uKrPba1smsBTzj3uioyjMa1UsP+6ITA3b8/sqx9fciw=; b=yab1C4dUotCH4gKDW+SzUl3DNK57dCOa3GtehugetRPdEEEeJICDklACbf91xmW5Fv mzoBPb2x1IKiFbAYcnzE168EvLe6+hIK8AZyEVrXgmZhf4nFM9pBBTqr7pyuRoEU7hDT /0ewdbeAVuNQcXLW7b1gJ5eZAOytopOcduHI5FN/QrO3jwt0w4kxqisNWbuvzVnoQwuV ytpXUvWky5/9DSqvK7ruwasBNNIHyJHLnJ81ayXUyyKLI2Nd5bQCwddYl/ahuiQRFMeb 9POMQXguL2Z3l+AhIDLlPcmAq/b+cvDVPi9jaY5H+O8L1HmkAjGwwP1JVkhYrolFcFMt fr8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=bz1QEpSA; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a17090aab0d00b00252b14e5ce4si9875247pjq.190.2023.05.30.11.00.06; Tue, 30 May 2023 11:00:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=bz1QEpSA; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233000AbjE3Rqp (ORCPT + 99 others); Tue, 30 May 2023 13:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233195AbjE3Rqm (ORCPT ); Tue, 30 May 2023 13:46:42 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6677A103 for ; Tue, 30 May 2023 10:46:37 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4f122ff663eso5347476e87.2 for ; Tue, 30 May 2023 10:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685468795; x=1688060795; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uKrPba1smsBTzj3uioyjMa1UsP+6ITA3b8/sqx9fciw=; b=bz1QEpSAAqI93v2o1uHdsWDeEh5D0nq8fs1G/b1NCPCwvbtiVStDFEKvw3brxtQVd3 Gxxf6K75zQSaJyROerFJ5JW2jZPaYCEib75+t4lVhrK3+5dQ/T9bUWSt89a3ylmVIR87 9BWbu6gc56km3lJMJ/q74cD6a+QsWwsrbxedzf4+GClNJLJnW1kgGgFsfV7S6Ap0rWgO x8+ly3LvU6yPXmK402ITzNOpSdEa6cpONUXVv1kdboIs8N4lxg4J5y9bHIT0NVGsW9IJ 9r7BOBI3nnIAnodGkHCDVMYBp6gjiRgFrN2j+q5WxxjEmCwnbIBaO2BRH7viiQzonYc7 u07A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685468795; x=1688060795; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uKrPba1smsBTzj3uioyjMa1UsP+6ITA3b8/sqx9fciw=; b=RWiOnpIc2KUShSGk1oKpMY3eMgroR/FeYrxskExLclx8Zzn2g4uDn5qhRWkjI4YrrR srHFjRGALk/Jox8BydomPZkjiZHUnyg7+Shzh5ktPDt243i9HN2s7noLpCkNv7DA1/ov trL6R2pTWj4p6HdeO2Y21p4DP3jDnh43weURZ0jJ59bGpe+u/fHAd8ms7RS64apmpo7/ 83+GajSXkM3g/Ug6rGLG2xY7HNm0p8eiUdIp7BDTKhkAm6oyhJr++qv1wnrkPwJTobEB r1roL3jASCnWLX5BTdQceM2vmQSniMHz2GI1xG2nLmYQQb/8OY/TUYP7S8TNpNbsdnUd xS/g== X-Gm-Message-State: AC+VfDwvyGDVQQwpyMfvbcU+tPr/XKmBQcM150TEc2UfcWmwHxoWMJpo 4d0g6RnHjldmlLWpGiPCZveySWOJZroeKtjH8mQ= X-Received: by 2002:a2e:924b:0:b0:2ac:763a:1315 with SMTP id v11-20020a2e924b000000b002ac763a1315mr1348443ljg.12.1685468795174; Tue, 30 May 2023 10:46:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 30 May 2023 10:46:23 -0700 Message-ID: Subject: Re: [PATCH 5/6] Bluetooth: ISO: use correct CIS order in Set CIG Parameters event To: Pauli Virtanen Cc: linux-bluetooth@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Pauli, On Sun, May 28, 2023 at 10:49=E2=80=AFAM Pauli Virtanen wrote: > > The order of CIS handle array in Set CIG Parameters response shall match > the order of the CIS_ID array in the command (Core v5.3 Vol 4 Part E Sec > 7.8.97). We send CIS_IDs mainly in the order of increasing CIS_ID (but > with "last" CIS first if it has fixed CIG_ID). In handling of the > reply, we currently assume this is also the same as the order of > hci_conn in hdev->conn_hash, but that is not true. > > Match the correct hci_conn to the correct handle by matching them based > on the CIG+CIS combination. The CIG+CIS combination shall be unique for > ISO_LINK hci_conn at state >=3D BT_BOUND, which we maintain in > hci_le_set_cig_params. > > Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connec= tions") > Signed-off-by: Pauli Virtanen > --- > net/bluetooth/hci_event.c | 66 +++++++++++++++++++++++++++++---------- > 1 file changed, 50 insertions(+), 16 deletions(-) > > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index d00ef6e3fc45..71d8f1442287 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -3804,43 +3804,77 @@ static u8 hci_cc_le_set_cig_params(struct hci_dev= *hdev, void *data, > struct sk_buff *skb) > { > struct hci_rp_le_set_cig_params *rp =3D data; > + struct hci_cp_le_set_cig_params *cp; > struct hci_conn *conn; > - int i =3D 0; > + u16 handles[0x1f]; > + int num_handles; > + u8 status =3D rp->status; > + int i; > > bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); > > + cp =3D hci_sent_cmd_data(hdev, HCI_OP_LE_SET_CIG_PARAMS); > + if (!cp || rp->num_handles !=3D cp->num_cis || rp->cig_id !=3D cp= ->cig_id || > + rp->num_handles > ARRAY_SIZE(handles)) { > + bt_dev_err(hdev, "unexpected Set CIG Parameters response = data"); > + status =3D HCI_ERROR_UNSPECIFIED; > + } > + > hci_dev_lock(hdev); > > - if (rp->status) { > + if (status) { > while ((conn =3D hci_conn_hash_lookup_cig(hdev, rp->cig_i= d))) { > conn->state =3D BT_CLOSED; > - hci_connect_cfm(conn, rp->status); > + hci_connect_cfm(conn, status); > hci_conn_del(conn); > } > goto unlock; > } > > + /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page = 2553 > + * > + * If the Status return parameter is zero, then the Controller sh= all > + * set the Connection_Handle arrayed return parameter to the conn= ection > + * handle(s) corresponding to the CIS configurations specified in > + * the CIS_IDs command parameter, in the same order. > + */ > + > + num_handles =3D rp->num_handles; > + for (i =3D 0; i < rp->num_handles; ++i) > + handles[i] =3D __le16_to_cpu(rp->handle[i]); Using the request is a good idea but the code below sounds a little too complicated, can we just lookup the hci_conn by cig/cis at this point using the request parameters and just assign the handle in a single loop? > rcu_read_lock(); > > list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { > - if (conn->type !=3D ISO_LINK || > - conn->iso_qos.ucast.cig !=3D rp->cig_id || > - conn->state =3D=3D BT_CONNECTED) > + if (conn->type !=3D ISO_LINK || !bacmp(&conn->dst, BDADDR= _ANY) || > + (conn->state !=3D BT_BOUND && conn->state !=3D BT_CON= NECT) || > + conn->iso_qos.ucast.cig !=3D rp->cig_id) > continue; > > - conn->handle =3D __le16_to_cpu(rp->handle[i++]); > + for (i =3D 0; i < rp->num_handles; ++i) { > + if (handles[i] =3D=3D HCI_CONN_HANDLE_UNSET) > + continue; > + if (conn->iso_qos.ucast.cis !=3D cp->cis[i].cis_i= d) > + continue; > > - bt_dev_dbg(hdev, "%p handle 0x%4.4x parent %p", conn, > - conn->handle, conn->parent); > + conn->handle =3D handles[i]; > + handles[i] =3D HCI_CONN_HANDLE_UNSET; > + --num_handles; > > - /* Create CIS if LE is already connected */ > - if (conn->parent && conn->parent->state =3D=3D BT_CONNECT= ED) { > - rcu_read_unlock(); > - hci_le_create_cis(conn); > - rcu_read_lock(); > + bt_dev_dbg(hdev, "%p handle 0x%4.4x parent %p", > + conn, conn->handle, conn->parent); > + > + /* Create CIS if LE is already connected */ > + if (conn->parent && > + conn->parent->state =3D=3D BT_CONNECTED) { > + rcu_read_unlock(); > + hci_le_create_cis(conn); > + rcu_read_lock(); > + } > + > + break; > } > - > - if (i =3D=3D rp->num_handles) > + if (!num_handles) > break; > } > > -- > 2.40.1 > --=20 Luiz Augusto von Dentz