Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1448835rwd; Wed, 31 May 2023 14:14:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TmXMouPTo2AdGhNi7PTY5P9xCKUuGTXNZ26T7O33gbuMtOrZ8/NJD2oV2jRb3sSuSJNmI X-Received: by 2002:a05:6358:7e0b:b0:123:3b73:4dc2 with SMTP id o11-20020a0563587e0b00b001233b734dc2mr1916297rwm.11.1685567689093; Wed, 31 May 2023 14:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685567689; cv=none; d=google.com; s=arc-20160816; b=tJROwA/lzFFSR5cThf3113w7bqWrYYAi43s+D81IIOyc+g2jlW1GAivdF/KP+9CICb 2GQ0lSV8aF6Nk4cdB88KD6UCAucf8OqNZspxukvxbzkc2x0q89l5uw1eMUQ4KAB7YmuU beZIc8ZVqYC3aYZfsXymM680fErhtAf126l4peM1aVVtsu3AeNfTQM4ZlEuZN0AHJU0B EeN5ioRfDq4OLl17ZMu/KShSJTzCua2n1WEDSB7Ro6D+inbzqOjrpe4oIj5h0eOLLZgB Mknb/F/ff6WFYFvLo0FyNxzaVWowW2baYzKZ/YJ/sQo6XJkMhr73+2sYICLPcSfEVlWy GWZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+moHLVNvi16naetVhBMjngVC/O1PPSoMHNM+8/hecLM=; b=ZlLon6YT5EV91k9su0lU1I3T2JMtRGVeRtM7szueSkdmiUE65PSDdQc0FdNQYkxwtv ti49+JeZOxXojLVWxt7+1yMmwlM9+XCmxq+XP4coARyQ4DHd98wYGMgAz4zizoOGj14A +rbJNVarGXyY4BcT1dY/RR6ENJX6zSb9GT8C2fAfgiSVZUUFoyIQh8TtV+jkxiBdsemH cQYUGmTHjqrmEfeGEtigWPzhhI8PD3hjp7+qH+VA6bMhYcLeX8A6+sydund0PvKZhDTE cFw2YWclYzCJ1XykzGCgKO27Zk9D7jWcHHbJ8ddOesbuobsJCF9bwsWtDlE6K5e7TSXx zFrQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a17090a7bc800b0023fb875a929si1602835pjl.106.2023.05.31.14.13.54; Wed, 31 May 2023 14:14:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjEaVIE (ORCPT + 99 others); Wed, 31 May 2023 17:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229922AbjEaVIB (ORCPT ); Wed, 31 May 2023 17:08:01 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDC2B12E for ; Wed, 31 May 2023 14:07:56 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id AA28D240109 for ; Wed, 31 May 2023 23:07:54 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QWhgG1FhCz9rxH; Wed, 31 May 2023 23:07:54 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH v2 3/4] Bluetooth: ISO: use correct CIS order in Set CIG Parameters event Date: Wed, 31 May 2023 21:07:48 +0000 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NEUTRAL,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 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 >= BT_BOUND, which we maintain in hci_le_set_cig_params. Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections") Signed-off-by: Pauli Virtanen --- Notes: v2: simplify and swap loops net/bluetooth/hci_event.c | 59 +++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index fe8177512a89..d0ccb8ebdcc9 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3804,44 +3804,67 @@ 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 = data; + struct hci_cp_le_set_cig_params *cp; struct hci_conn *conn; - int i = 0; + u8 status = rp->status; + int i; bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); + cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_CIG_PARAMS); + if (!cp || rp->num_handles != cp->num_cis || rp->cig_id != cp->cig_id) { + bt_dev_err(hdev, "unexpected Set CIG Parameters response data"); + status = HCI_ERROR_UNSPECIFIED; + } + hci_dev_lock(hdev); - if (rp->status) { + if (status) { while ((conn = hci_conn_hash_lookup_cig(hdev, rp->cig_id))) { conn->state = 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 shall + * set the Connection_Handle arrayed return parameter to the connection + * handle(s) corresponding to the CIS configurations specified in + * the CIS_IDs command parameter, in the same order. + */ + rcu_read_lock(); - list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { - if (conn->type != ISO_LINK || - conn->iso_qos.ucast.cig != rp->cig_id || - conn->state == BT_CONNECTED) - continue; + for (i = 0; i < rp->num_handles; ++i) { + list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { + if (conn->type != ISO_LINK || + !bacmp(&conn->dst, BDADDR_ANY)) + continue; + if (conn->state != BT_BOUND && + conn->state != BT_CONNECT) + continue; + if (conn->iso_qos.ucast.cig != rp->cig_id || + conn->iso_qos.ucast.cis != cp->cis[i].cis_id) + continue; - conn->handle = __le16_to_cpu(rp->handle[i++]); + conn->handle = __le16_to_cpu(rp->handle[i]); - bt_dev_dbg(hdev, "%p handle 0x%4.4x parent %p", conn, - conn->handle, conn->parent); + 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 == BT_CONNECTED) { - rcu_read_unlock(); - hci_le_create_cis(conn); - rcu_read_lock(); - } + /* Create CIS if LE is already connected */ + if (conn->parent && + conn->parent->state == BT_CONNECTED) { + rcu_read_unlock(); + hci_le_create_cis(conn); + rcu_read_lock(); + } - if (i == rp->num_handles) break; + } } rcu_read_unlock(); -- 2.40.1