From patchwork Mon May 2 21:05:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 570027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 826B1C433F5 for ; Mon, 2 May 2022 21:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232819AbiEBVJ1 (ORCPT ); Mon, 2 May 2022 17:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232009AbiEBVJ0 (ORCPT ); Mon, 2 May 2022 17:09:26 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CEBBC32 for ; Mon, 2 May 2022 14:05:55 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id n8so13438815plh.1 for ; Mon, 02 May 2022 14:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Pru5JZcj+cHsvQbTgyyfRtFvPSEQ+Gl4fw1M4k+drs=; b=Gheg6X4esOW0qJrQa3HlAnDrRTPJFD5PAosHvyENezR/plXA1SPZt1nfIj44NwTWM4 ExzwLwYctMOHM76tUg/mKuwCRICtFAFfHWPNN7r0w+S7gUkw5MTme66E8QRL5/MVK01y DsNCX9q37Hkl9DR2WWZ1xRXkrcKMY1IpG7J3D4qYloHqjbX555jATT21mkaam9H4Ir7k zkay2740LL/tFzU493+nwYCBJ60SelW/zRFQKyncko2TZyfYPMPUq6p7gEERseJQsZRW HhNkMwi++/XypAc1ze9Bf0DcO21ZN7ifEQI0RXrHNCw4Aca1SFxa+BJSy3H4c4X2voyM bppQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Pru5JZcj+cHsvQbTgyyfRtFvPSEQ+Gl4fw1M4k+drs=; b=kg3q8bZsedrDOwdU1cD4valwvkYLLyoE2uBtT4ehMujk9GnyDk1k/Uw0/4arwW+OP4 QIRZEpwUXkIS+KtX/ASKiJAYdIxGJWo1rv68ZpO5wPXhcTHMHwKW64xmPrfnm/Cd5mJI LCCc04y0Roeznq3IseXE/5mNNgVW/8aObrGRkojMjCIiFfbPRyInmisbeGEUy35uyKWc sSmjBg3bbBmg5DdkaHQ7kpMYaHI5KN/BMP5ASVqJmrdJGfk+jFZnxYHZJggCHZlULjyb Z3BtfK4Ou9S33eIur7Q30bHrCcywIkigZpSc9muqDGfqPq5FgqEdxj/ADRjatNj63Wkq 20bA== X-Gm-Message-State: AOAM531gtPpwTJJ2nUaVlQgiJ4nMttRUbwwN5AhDktH90wkmjtk4kAib 36uK9cRML9tm36LF6WU0vWXWuMvEMDA= X-Google-Smtp-Source: ABdhPJzj8pFz3gRjonNQY3xvTavYVbwz1cTh8eleKzHe5p/p20ZNXm6mrHTGetxoiK/hc5sdZk48Ig== X-Received: by 2002:a17:902:f70f:b0:153:ebfe:21b3 with SMTP id h15-20020a170902f70f00b00153ebfe21b3mr13512709plo.119.1651525554899; Mon, 02 May 2022 14:05:54 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g2-20020a170902e38200b0015e8d4eb2d8sm846255ple.290.2022.05.02.14.05.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 14:05:54 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] btdev: Fix not removing connection and advertising set on reset Date: Mon, 2 May 2022 14:05:52 -0700 Message-Id: <20220502210553.2271064-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes sure that all connections and advertising sets are cleanup on reset. --- emulator/btdev.c | 76 +++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index d3f565438..641e308b3 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -509,6 +509,42 @@ void btdev_set_rl_len(struct btdev *btdev, uint8_t len) btdev->le_rl_len = len; } +static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2) +{ + conn1->link = NULL; + conn2->link = NULL; +} + +static void conn_remove(void *data) +{ + struct btdev_conn *conn = data; + + if (conn->link) { + struct btdev_conn *link = conn->link; + + conn_unlink(conn, conn->link); + conn_remove(link); + } + + queue_remove(conn->dev->conns, conn); + + free(conn->data); + free(conn); +} + +static void le_ext_adv_free(void *data) +{ + struct le_ext_adv *ext_adv = data; + + /* Remove to queue */ + queue_remove(ext_adv->dev->le_ext_adv, ext_adv); + + if (ext_adv->id) + timeout_remove(ext_adv->id); + + free(ext_adv); +} + static void btdev_reset(struct btdev *btdev) { /* FIXME: include here clearing of all states that should be @@ -517,12 +553,16 @@ static void btdev_reset(struct btdev *btdev) btdev->le_scan_enable = 0x00; btdev->le_adv_enable = 0x00; + btdev->le_pa_enable = 0x00; al_clear(btdev); rl_clear(btdev); btdev->le_al_len = AL_SIZE; btdev->le_rl_len = RL_SIZE; + + queue_remove_all(btdev->conns, NULL, NULL, conn_remove); + queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free); } static int cmd_reset(struct btdev *dev, const void *data, uint8_t len) @@ -674,29 +714,6 @@ static bool match_handle(const void *data, const void *match_data) return conn->handle == handle; } -static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2) -{ - conn1->link = NULL; - conn2->link = NULL; -} - -static void conn_remove(void *data) -{ - struct btdev_conn *conn = data; - - if (conn->link) { - struct btdev_conn *link = conn->link; - - conn_unlink(conn, conn->link); - conn_remove(link); - } - - queue_remove(conn->dev->conns, conn); - - free(conn->data); - free(conn); -} - static void disconnect_complete(struct btdev *dev, uint16_t handle, uint8_t status, uint8_t reason) { @@ -4627,19 +4644,6 @@ static struct le_ext_adv *le_ext_adv_new(struct btdev *btdev, uint8_t handle) return ext_adv; } -static void le_ext_adv_free(void *data) -{ - struct le_ext_adv *ext_adv = data; - - /* Remove to queue */ - queue_remove(ext_adv->dev->le_ext_adv, ext_adv); - - if (ext_adv->id) - timeout_remove(ext_adv->id); - - free(ext_adv); -} - static int cmd_set_adv_rand_addr(struct btdev *dev, const void *data, uint8_t len) { From patchwork Mon May 2 21:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 568794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9AEBC433EF for ; Mon, 2 May 2022 21:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232133AbiEBVJ1 (ORCPT ); Mon, 2 May 2022 17:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbiEBVJ0 (ORCPT ); Mon, 2 May 2022 17:09:26 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6B2FBC36 for ; Mon, 2 May 2022 14:05:56 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id x18so2252464plg.6 for ; Mon, 02 May 2022 14:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mZFJU8oGnSo9NfWXq+X3qpT08JftfIhhfeGmT7oGTVo=; b=kZjypGl+uT0xL9z2ytFoHLzKR+H4j2rSPPBmprQ2eDPLjjloEaOkcwQZPV3a8auGkJ Jrt11QApqMQv5afw0zp3VckO8lA6iLXNdVeV9yNn5OG8beFBHYh8MimUHUT4W/D2sOXV XSCGVTMBSEPaoEpJUG1LB9Hg4ju8EaZWEoYVL1BBcDg5ow3CPOXTP19q3lud1pMSleo+ 2vGV8NFIYwpQY2QW/3ZBcg0wcc+NvjLXLZ0IY8idJGUtRFFXSSQLzbYtEoJSsDS08YKh Hsju5/PzWBS85P54q66I/ZyhsB2qxst6yHlWHF+Rl6NUeCLf5glRHC62f0OTbLVhPjQ+ oXcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mZFJU8oGnSo9NfWXq+X3qpT08JftfIhhfeGmT7oGTVo=; b=kbppU4K7BisxK5x84ptDrmbUc7oaLuTHOLQqVqyNLqQqAroN9ZnbtFjGzRRfRglOGy UWkK0lozMOnPKapiXWwnePa0fOOazDNw2ykwaW/gvtdxH4dyP85TldZjJ+Xzu3DNNoP2 XMIhgZnKMtmzIgfP1AhG0CAWjluNTVnPjibe1yIWC1cukW665032U/tYgh14nbnWn7Z3 UNc8fOqnYlub21HNerbfyfeN8oA+0xHubdFEr9VsSHjEU+VTq+Q3tC9xszak5usQFujL b/eO2ldnzP+ta3wLk8XahgU/SU48oUP5SIYNc0LaGDc1gu/PlL3Y/bMT/j3KrDSGSVLS gt+w== X-Gm-Message-State: AOAM5336VdZRd6kMGYQOGvEkLee+/SXWyh46daywCoo6ic8g5K/nSMOj iVFEbGmYYVADeWjAk3aDm3t70IBndLQ= X-Google-Smtp-Source: ABdhPJyFmgCcryvrgu9+uMuE1g/rtWpRLAMwSKdpC0N8sF8hGM9kZR/jV1FvWjhf70vj2jaw6pKj2w== X-Received: by 2002:a17:902:ef47:b0:156:646b:58e7 with SMTP id e7-20020a170902ef4700b00156646b58e7mr13238584plx.57.1651525555934; Mon, 02 May 2022 14:05:55 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g2-20020a170902e38200b0015e8d4eb2d8sm846255ple.290.2022.05.02.14.05.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 14:05:55 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] monitor: Decode LTV fields of Basic Audio Announcements Date: Mon, 2 May 2022 14:05:53 -0700 Message-Id: <20220502210553.2271064-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220502210553.2271064-1-luiz.dentz@gmail.com> References: <20220502210553.2271064-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This decodes the LTV fields of Basic Audio Announcements: < HCI Command: LE Set Periodic Advertising Data (0x08|0x003f) plen 41 Handle: 0 Operation: Complete ext advertising data (0x03) Data length: 0x26 Service Data: Basic Audio Announcement (0x1851) Presetation Delay: 40000 Number of Subgroups: 1 Subgroup #0: Number of BIS(s): 1 Codec: LC3 (0x06) Codec Specific Configuration #0: len 0x02 type 0x01 Codec Specific Configuration: 03 Codec Specific Configuration #1: len 0x02 type 0x02 Codec Specific Configuration: 01 Codec Specific Configuration #2: len 0x05 type 0x03 Codec Specific Configuration: 01000000 Codec Specific Configuration #3: len 0x03 type 0x04 Codec Specific Configuration: 2800 Metadata #0: len 0x03 type 0x02 Metadata: 0200 BIS #0: Index: 1 Codec Specific Configuration: --- monitor/packet.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index d409e4e63..99ed9c281 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -3318,6 +3318,44 @@ static void *iov_pull(struct iovec *iov, size_t len) return data; } +static void print_ltv(const char *label, const uint8_t *data, uint8_t len) +{ + struct iovec iov; + int i; + + iov.iov_base = (void *) data; + iov.iov_len = len; + + for (i = 0; iov.iov_len; i++) { + uint8_t l, t, *v; + + l = get_u8(iov_pull(&iov, sizeof(l))); + if (!l) { + print_field("%s #%d: len 0x%02x", label, i, l); + break; + } + + v = iov_pull(&iov, sizeof(*v)); + if (!v) + break; + + t = get_u8(v); + + print_field("%s #%d: len 0x%02x type 0x%02x", label, i, l, t); + + l -= 1; + + v = iov_pull(&iov, l); + if (!v) + break; + + print_hex_field(label , v, l); + } + + if (iov.iov_len) + print_hex_field(label , iov.iov_base, iov.iov_len); +} + static void print_base_annoucement(const uint8_t *data, uint8_t data_len) { struct iovec iov; @@ -3368,7 +3406,7 @@ static void print_base_annoucement(const uint8_t *data, uint8_t data_len) if (!iov_pull(&iov, codec_cfg->len)) goto done; - print_hex_field(" Codec Specific Configuration", + print_ltv(" Codec Specific Configuration", codec_cfg->data, codec_cfg->len); metadata = iov_pull(&iov, sizeof(*metadata)); @@ -3378,7 +3416,7 @@ static void print_base_annoucement(const uint8_t *data, uint8_t data_len) if (!iov_pull(&iov, metadata->len)) goto done; - print_hex_field(" Metadata", metadata->data, metadata->len); + print_ltv(" Metadata", metadata->data, metadata->len); /* Level 3 - BIS(s)*/ for (j = 0; j < subgroup->num_bis; j++) {