Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp165634iob; Mon, 2 May 2022 16:04:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+ZCe8y8lozlwDlxsfLrQsYqVCw0X9+CsGhc7QpOAIe/N8XTV5OKekOQVhaco9BoEyfLHp X-Received: by 2002:a17:902:ce86:b0:15d:1950:835c with SMTP id f6-20020a170902ce8600b0015d1950835cmr13840834plg.52.1651532681549; Mon, 02 May 2022 16:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651532681; cv=none; d=google.com; s=arc-20160816; b=HsVgt1+258SAHY6NA2RJnk3X7ld+5JZ7E5gus4sPhz/Dg1xWQw+49UiP3qzt0m0QdA uqIlzDyRjCMJTR+Di+W00Jx7mcoY1V1sZG6CYwijEYXBuipsXlGRgOQswQkjtrNJMIZd L79wRSmleSR45HTJgv3M12s5ocJyOtTqv+5zw49Yyoyax54RzlHfvea2e6FqMaAzJHdA nG+CbZ4L0oXAp308XrYa6KEOtjzDjLeG4M/eMLcgXZXnJJQ6aPptypBzg61lZB4WKC2s gigEAeDLuq+xgVRECg15NiKm800vkSgc/we1+SBLGJznLb8WccRJRBelJAGv+SLBMCl2 9pEg== 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 :message-id:date:subject:to:from:dkim-signature; bh=6Pru5JZcj+cHsvQbTgyyfRtFvPSEQ+Gl4fw1M4k+drs=; b=EldbzMXcuZnjAgmXmO3A3vh92XKvoNPOIxzdTWyG/p2Iye//JofgRC2K9m+yxDyQjr AnWWynH2N1+dAVtlttq6LtwXGG2X6ZTrWHQ+mbKNwMVpRiawKDexBgPcrF7xnRQIKiqE eSQo6Jv5GbaoPb7zzBVS+WZrRpaf0na7DuGrF3oTnIjJrIvttiqBPNHqBUY4Qkxhs14J 7R8dQwiXWsu0CBYZ9FKBECDOMYGHRx1owYRnunQhi+GpXkGpO3EBhXt5fl+u2R+icJHB CSkUKFIhtqS/ust0VvyfjKPohoEoupnklvrEmIMPurDRqAjC1vJpyIym0lLzzUCTic4v 1YlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Gheg6X4e; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k8-20020a628408000000b004fa63c4434fsi14836872pfd.322.2022.05.02.16.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 16:04:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Gheg6X4e; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BACF62E696; Mon, 2 May 2022 16:04:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbiEBVJ1 (ORCPT + 99 others); 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-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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) { -- 2.35.1