From patchwork Thu Sep 16 20:40:19 2021 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: 12500229 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07A38C433F5 for ; Thu, 16 Sep 2021 20:40:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D25DE6108F for ; Thu, 16 Sep 2021 20:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233142AbhIPUlo (ORCPT ); Thu, 16 Sep 2021 16:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231982AbhIPUln (ORCPT ); Thu, 16 Sep 2021 16:41:43 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B03D8C061574 for ; Thu, 16 Sep 2021 13:40:22 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id t4so4736627plo.0 for ; Thu, 16 Sep 2021 13:40:22 -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=DaTlYmrTZ4vigxHL9Yiu6ffVmbBgOdNv+JmqZQCZico=; b=RSq0v51vHmKxJSiC8RZdacoNnEXRvvqdCUJ5rd2h4rehn1SDK9RBcc3o9qbrCTvW+i Vq2ZnRfUPlqSaVKECXUmxsDXw7A4HSK6RSr0du5V4qVtL/JqadBkFMPI3bapOcBoxlLn jmD9dTVdqOtkXzd6DmM7b0umPxc+0ueoyHg/tijV7RIBFR3PLiL5wBLaZUUxNLR9M43m 1HEUiP8MLOW8G9sQV4ZZgrpljzwxnbrVg8LsgoAYnPwb3CAfkcUStExLbfDH9ZMK/Iyt 9pITobD3EOw+VGIGlbcJlrzudXDDHYOws4q+MvJ00cZWHt4IKzRmnJUVRa51Rqiv8fqU fXxQ== 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=DaTlYmrTZ4vigxHL9Yiu6ffVmbBgOdNv+JmqZQCZico=; b=SCsaK9UHYm6N7APOtb0Umd7yWYvT5YYGJoiFnuYCrw0T0+RCFlODQSTHjH/SLiJ+c6 z9iWk/uQyrhjPA0BFERYRChL15frKMJnSXQerAz+QHTO3eIY/+INY9VjQ/hAa1ipqAC3 cW1TQAQ7eMVMu+rIUYUZCvozC5KIRNJh4ta+U5gIvjzWyQPxNW63/puIW1JuWeJil/Dv lJtMbDu+o+ENj9nszF/6bHn9G49vEmV730W+EK3xQ8RIoQXFtZx8bPCKdihttFov6BYl Axc4grgp1gfoWFYvMVE/Lb2gix7METRbyuyDroQD4Q9Qpcyjaj13KYmtxwUoJ3Ky+vN2 iM+Q== X-Gm-Message-State: AOAM532jf39omV0NiLQ4pH4YNhrt7nk6rn5slYvzgJSw47ybVP/+r/MN IMdac0qXDCFrUn2mRMDScYj1A3Q9jxk= X-Google-Smtp-Source: ABdhPJxnDQksIf1k66Wj83wlxxixoyIJ7KFxOqxAKI5+pNsTc/0VyT9nuCR3OvI1nCwJMBYVxRsn1g== X-Received: by 2002:a17:902:bcc6:b0:138:d3ca:c356 with SMTP id o6-20020a170902bcc600b00138d3cac356mr6301192pls.6.1631824821806; Thu, 16 Sep 2021 13:40:21 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id u21sm4283355pgk.57.2021.09.16.13.40.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 13:40:21 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/2] service: Add btd_service_is_initiator Date: Thu, 16 Sep 2021 13:40:19 -0700 Message-Id: <20210916204020.118310-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz Since BTD_SERVICE_STATE_CONNECTING is being used for both initiator and responder case it is no longer possible to use the state distint when the service connection was initiated locally or not, so to fix this a new flag is introduce to track when btd_service_connect has been called. --- src/service.c | 10 ++++++++++ src/service.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/service.c b/src/service.c index 84fbb208a..14a4c292b 100644 --- a/src/service.c +++ b/src/service.c @@ -42,6 +42,7 @@ struct btd_service { btd_service_state_t state; int err; bool is_allowed; + bool initiator; }; struct service_state_callback { @@ -96,6 +97,9 @@ static void change_state(struct btd_service *service, btd_service_state_t state, cb->cb(service, old, state, cb->user_data); } + + if (state == BTD_SERVICE_STATE_DISCONNECTED) + service->initiator = false; } struct btd_service *btd_service_ref(struct btd_service *service) @@ -261,6 +265,7 @@ int btd_service_connect(struct btd_service *service) err = profile->connect(service); if (err == 0) { + service->initiator = true; change_state(service, BTD_SERVICE_STATE_CONNECTING, 0); return 0; } @@ -343,6 +348,11 @@ int btd_service_get_error(const struct btd_service *service) return service->err; } +bool btd_service_is_initiator(const struct btd_service *service) +{ + return service->initiator; +} + unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data) { struct service_state_callback *state_cb; diff --git a/src/service.h b/src/service.h index 5a2a02447..fa930f985 100644 --- a/src/service.h +++ b/src/service.h @@ -47,6 +47,7 @@ struct btd_device *btd_service_get_device(const struct btd_service *service); struct btd_profile *btd_service_get_profile(const struct btd_service *service); btd_service_state_t btd_service_get_state(const struct btd_service *service); int btd_service_get_error(const struct btd_service *service); +bool btd_service_is_initiator(const struct btd_service *service); unsigned int btd_service_add_state_cb(btd_service_state_cb cb, void *user_data); From patchwork Thu Sep 16 20:40:20 2021 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: 12500231 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9404EC433EF for ; Thu, 16 Sep 2021 20:40:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70FE66108F for ; Thu, 16 Sep 2021 20:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234835AbhIPUlo (ORCPT ); Thu, 16 Sep 2021 16:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbhIPUlo (ORCPT ); Thu, 16 Sep 2021 16:41:44 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B420C061756 for ; Thu, 16 Sep 2021 13:40:23 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id p12-20020a17090adf8c00b0019c959bc795so83045pjv.1 for ; Thu, 16 Sep 2021 13:40:23 -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=A1Q2SJQiyX5am4iuB5/d2/2hGMWNzQxjOdbN8yc7+bQ=; b=OM7dfngzg5/2QSKetqmzkyDkhUYqlWnQIuu6D+OFNGiy+UyWDNYVW+yhUgRnjqZFgK ljScOiALuo6u67xJ6Ybn8Kcg3iqga3aVRidWyHto2Lg1TWb/aDMhEWtQGaBLOS+4BQ6O o2aFltsrTNnaIjBe7kGd3dro/7AgdmP/ftgP3r6gDcLgaiYtjtKrarQPV2bGCUXgQy8F ilZSxPnK743cB6CMZK0ISNxyisRtHdYUifvsr/BkXcZpHyUVV4phAQNiRnpyE3oBrc62 vEM6v8RA1/msuGboLf+ODH+dCyuKWdOm1OBblZZSKHChNy0MPudVcLWvoINHqloGYNaS 2hew== 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=A1Q2SJQiyX5am4iuB5/d2/2hGMWNzQxjOdbN8yc7+bQ=; b=N0ssI9utblm5sCMu6SkP2EOn6ZtIuj3iMeLFyJsf7ziNszghY5B1v8n6wTS9hIIqEe y6Qm/Y+LL4bKaxcd8HrYmPZHsk7VdzFFV3KiPzPDq3q5L1XBc/n2zAWp1pxpU8N8wMeu x1HtXc7FyHNr8vw5vyu3lBg6GQAM/MCPKtqrocY1VIl7f1asgnfq1yQuwuoig54eMVLK 11Hzu61KhvE3YvrSwvYlg6t9Velq8x6+M51fvF4NKZT4swgjrZzkldJSlhe5gQkPlQg/ 6D4zpDUoo6iaTYjIN7WO6gRvIjrCPbGXPm7/h3W+aZstRvXmz5E54+byipdLH8cm4YaF p5sQ== X-Gm-Message-State: AOAM533uNaRyT7w5vtlqdyw47gZjRHxWYWbN4aTbotcrRjkq4ah3jKON r6W2YAy1aP7HeUj97K/s5SRC/Vah4bo= X-Google-Smtp-Source: ABdhPJxZXh7W4rKgldP6Wd2euRQyo7Df7mua/zq8LcUMlcEpkoxe2W/QchIx8yOYPIa2XaImDxTJ3g== X-Received: by 2002:a17:90b:4f8a:: with SMTP id qe10mr6475512pjb.5.1631824822420; Thu, 16 Sep 2021 13:40:22 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id u21sm4283355pgk.57.2021.09.16.13.40.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 13:40:22 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/2] policy: Use btd_service_is_initiator Date: Thu, 16 Sep 2021 13:40:20 -0700 Message-Id: <20210916204020.118310-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210916204020.118310-1-luiz.dentz@gmail.com> References: <20210916204020.118310-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 Instead of using BTD_SERVICE_STATE_CONNECTING use btd_service_is_initiator to determine if the service initiated the connection and then proceed to connect other service immediately. Fixes: https://github.com/bluez/bluez/issues/205 --- plugins/policy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index bf93df096..051db82e1 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -279,7 +279,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state, /* Check if service initiate the connection then proceed * immediatelly otherwise set timer */ - if (old_state == BTD_SERVICE_STATE_CONNECTING) + if (btd_service_is_initiator(service)) policy_connect(data, controller); else if (btd_service_get_state(controller) != BTD_SERVICE_STATE_CONNECTED) @@ -315,7 +315,7 @@ static void hs_cb(struct btd_service *service, btd_service_state_t old_state, /* Check if service initiate the connection then proceed * immediately otherwise set timer */ - if (old_state == BTD_SERVICE_STATE_CONNECTING) + if (btd_service_is_initiator(service)) policy_connect(data, sink); else if (btd_service_get_state(sink) != BTD_SERVICE_STATE_CONNECTED) @@ -430,7 +430,7 @@ static void source_cb(struct btd_service *service, /* Check if service initiate the connection then proceed * immediatelly otherwise set timer */ - if (old_state == BTD_SERVICE_STATE_CONNECTING) + if (btd_service_is_initiator(service)) policy_connect(data, target); else if (btd_service_get_state(target) != BTD_SERVICE_STATE_CONNECTED)