Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2231125rwd; Sun, 28 May 2023 10:48:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56QqMtWV9JDYAkzPrTAdXH8ktR9eMho5XBRFKoOP6DrsY+UuDdYzVWqypClXLyUUKFxhtB X-Received: by 2002:a17:903:189:b0:1aa:f203:781c with SMTP id z9-20020a170903018900b001aaf203781cmr10548051plg.44.1685296124007; Sun, 28 May 2023 10:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685296123; cv=none; d=google.com; s=arc-20160816; b=kB4bZGg7wipGRMDtJWeO23rG+/fjy24OFewz/aXdx0NbFDQD77UmmoWdNDLJvoaOqw LYO6cD9Iw1EOpS7gYXoAh0YtaKXeFWzB4exWKckxeQohaIjFGeWBcg07qK+8nBiBCkkC MoEkvHUMpYdTbDl9okVezS++VIwCzF9956PSU8A5b+XrnmTZhc5iC6tYYVoGv9Ezeh5P FgHCaaqQAdYw8oMXtbpJNTPHSaaE+e5zPqOk2IBXv+gBa6DH9vhn5HhxDTDvfsFcruv4 4H0Wyf36AI2cKLioWC/eifAK/oJL5jJ4oVpzV9Iy27cwUPxIyX2yLA803w5l4TUkrRCO 3Ulg== 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=dV4UrxRD9IwsXimtQOa7hc+PxVky27kVeFqxlBk8BLU=; b=fm+Nr9C0SqhsUiVCcXh2K5oPYTD2+yKVjz0mT18Y/RuOLHf81QLfMDKofthL5sV8ZH EGprFt4vfh9o+j65lAKu7Bw3PYKIadFWuD9mxdtjrgINhNt23a5y/ACwjuLnRrAQPn8w ipc+EYHiRlgsR6tKvxCQMo/B2httYdPdymGciaccQc8FWl4gklBi5wvjiPCj+1mGN8Bp cnhe8D8gc8Taotnbq9AksbF9BSltjc2FnulxPFYNgi269kMCyWuwRAsP6XfryXkJlTWp lWmG50KcSMtGihREFZLMevWowviGrKfLjgpXlmcbppUvOxCX2pdL3Sn4JpPeMdKa6qp9 iibw== 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 k12-20020a170902c40c00b001ab1d1a6802si5970110plk.1.2023.05.28.10.48.30; Sun, 28 May 2023 10:48:43 -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 S229484AbjE1RoV (ORCPT + 99 others); Sun, 28 May 2023 13:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbjE1RoU (ORCPT ); Sun, 28 May 2023 13:44:20 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4BDA9 for ; Sun, 28 May 2023 10:44:18 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 394BE240101 for ; Sun, 28 May 2023 19:44:17 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QTmHh5vwpz6trs; Sun, 28 May 2023 19:44:16 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH 2/6] Bluetooth: ISO: use hci_sync for setting CIG parameters Date: Sun, 28 May 2023 17:44:10 +0000 Message-Id: <3b6c687cc86352b78e69f23aa065d512f93b07d4.1685294131.git.pav@iki.fi> 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 When reconfiguring CIG after disconnection of the last CIS, LE Remove CIG shall be sent before LE Set CIG Parameters. Otherwise, it fails because CIG is in the inactive state and not configurable (Core v5.3 Vol 6 Part B Sec. 4.5.14.3). This ordering is currently wrong under suitable timing conditions, because LE Remove CIG is sent via the hci_sync queue and may be delayed, but Set CIG Parameters is via hci_send_cmd. Make the ordering well-defined by sending also Set CIG Parameters via hci_sync. Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections") Signed-off-by: Pauli Virtanen --- net/bluetooth/hci_conn.c | 47 +++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 7b1a83ec50ae..182dba4a19b5 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -775,6 +775,11 @@ static void le_conn_timeout(struct work_struct *work) hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM); } +struct iso_cig_params { + struct hci_cp_le_set_cig_params cp; + struct hci_cis_params cis[0x1f]; +}; + struct iso_list_data { union { u8 cig; @@ -786,10 +791,7 @@ struct iso_list_data { u16 sync_handle; }; int count; - struct { - struct hci_cp_le_set_cig_params cp; - struct hci_cis_params cis[0x1f]; - } pdu; + struct iso_cig_params pdu; }; static void bis_list(struct hci_conn *conn, void *data) @@ -1762,10 +1764,33 @@ static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos) return hci_send_cmd(hdev, HCI_OP_LE_CREATE_BIG, sizeof(cp), &cp); } +static void set_cig_params_complete(struct hci_dev *hdev, void *data, int err) +{ + struct iso_cig_params *pdu = data; + + bt_dev_dbg(hdev, ""); + + if (err) + bt_dev_err(hdev, "Unable to set CIG parameters: %d", err); + + kfree(pdu); +} + +static int set_cig_params_sync(struct hci_dev *hdev, void *data) +{ + struct iso_cig_params *pdu = data; + u32 plen; + + plen = sizeof(pdu->cp) + pdu->cp.num_cis * sizeof(pdu->cis[0]); + return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_CIG_PARAMS, plen, pdu, + HCI_CMD_TIMEOUT); +} + static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos) { struct hci_dev *hdev = conn->hdev; struct iso_list_data data; + struct iso_cig_params *pdu; memset(&data, 0, sizeof(data)); @@ -1836,12 +1861,18 @@ static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos) if (qos->ucast.cis == BT_ISO_QOS_CIS_UNSET || !data.pdu.cp.num_cis) return false; - if (hci_send_cmd(hdev, HCI_OP_LE_SET_CIG_PARAMS, - sizeof(data.pdu.cp) + - (data.pdu.cp.num_cis * sizeof(*data.pdu.cis)), - &data.pdu) < 0) + pdu = kzalloc(sizeof(*pdu), GFP_KERNEL); + if (!pdu) return false; + memcpy(pdu, &data.pdu, sizeof(*pdu)); + + if (hci_cmd_sync_queue(hdev, set_cig_params_sync, pdu, + set_cig_params_complete) < 0) { + kfree(pdu); + return false; + } + return true; } -- 2.40.1