Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp612433iob; Thu, 12 May 2022 00:18:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy+WR23OjF80aObnn8osz859h1BMsGaJ1FeaETCSrhquQKFHGhOnWc4rsvmy6mBnIdRbj0 X-Received: by 2002:a17:907:94cd:b0:6f4:da4d:6ec2 with SMTP id dn13-20020a17090794cd00b006f4da4d6ec2mr27817444ejc.702.1652339913954; Thu, 12 May 2022 00:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652339913; cv=none; d=google.com; s=arc-20160816; b=f/Q9ltleqKn17fdSqTXrdmwDAquP5ISvCGS4acPGUdwyHK+nZxRwcsqzzW/aHvU2sz tq8RrU5cW/5jKrjkBjwUdgYm4aUznTzXmitGUpBjr5MCBf32Ox0eA+VzUI6j/5Fmb+dS CmPj8gFpcs2tKdMRf44FbKQqIRBaW+fgZ5iCDi2sxtUaFmO3nmXSIM+vuGQjk5VJTgBw d8S0xTyseCth92l9nThw6VQS4zc04lwO/UV6ziGb6QtPsUHe8iI/BB8AicxWe6Gcf/Nb kTsrG77vUDFuiFXGDRYZrRupNKTo2m1IZd1GdD9VxU0mw2J8HvJq12Ii19ORVDnkaR3+ A35Q== 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:to:from :dkim-signature; bh=2bPaQQOKSXG/fl2BdmohaiLMnjYT9dp+p5sZticNedE=; b=JQpk8mcH8AiKiAsmconV9rtlX+CztlMpUv6iL3LtOdVy2vxnQhhj6I9Dqyss6olKoY At6mKSNaLSmSyaTAqBuRPPN8A1UslDU2qONdDN3UVeWmWJts5rQobvgEX+sMXeZU7Cpa V3RUmROQ3jMvMOKflvOesZ5u4G8hKYPpy2GuaLaW0J+czQ+iaYkxg1gg0pwQDMrCuS9g SK5+mhGB+ZXEZRav+FiiUpj5p+hTewo2yZ/ZCgZuFEMFEDB9sBzl2uk4zpLOq1C/0kmT oYxuXy1CugV0nDFjJ+RE4ScUofdLvm87fjwk6rXdKdlHNrU/YAy1COnU2CXzVHS46fYE opTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Xmoohfhn; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a1709064fd000b006f3c5c57309si4987494ejw.389.2022.05.12.00.17.58; Thu, 12 May 2022 00:18:33 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Xmoohfhn; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239927AbiELAzU (ORCPT + 99 others); Wed, 11 May 2022 20:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245328AbiELAzT (ORCPT ); Wed, 11 May 2022 20:55:19 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE0860ABC for ; Wed, 11 May 2022 17:55:18 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d25so3382677pfo.10 for ; Wed, 11 May 2022 17:55:18 -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=2bPaQQOKSXG/fl2BdmohaiLMnjYT9dp+p5sZticNedE=; b=Xmoohfhng62wNpgq4b/P4DcymjyRQ/tFBcSEJ6zDLKfmsrDDyP1qM2lgCFW0jp8hNI 0C2rugyOhDEbHK4RUlA0yVHXnkVT1lCEYiY8gS7euLN851JHQsUVQdd/n6FP1hvFfpxM YDfpQb+O07i0bETfT8o1oML/4roQABsJ8j7Qu34qV7p+Si5eLWlZ+dF9aMuThapE2Ipm 8zH9QpDG7enSCsSmqCgHQjbRSU38Ut8HEvCoUomuQFxlZxP8+XUnh7d+m3ldOxLSRt+m 52orAX0d32tdRbkfjcS2ubHMHWjFEh7n+BJ5CqVW1bcFyU9nUMVHtztcmvMPjKvabDER 7EDw== 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=2bPaQQOKSXG/fl2BdmohaiLMnjYT9dp+p5sZticNedE=; b=mFpwXF7t8NFCAoa4HU+1f+acMGPXFfThQXeqyWsCKOQNAbTOIIeDDf9epaYWvAmQwQ QHAGwp0USKmqEJw+v58MNg2PxqWKR5GJtIa61ajxCcmJMfyBjcj0IQf2Uwd/5Y3VM7Xo wVwdrulinRMeolZ1D1IJ0PQ55EqJNPw5+5LTG4nosJ3PptV5JNdboKEHXuP6j/F7t1bR NJHUd3vVfdcZO4VmeWGrjePbM5+MWXdt+MYcYepLXYhm9zmxWj+t9Z9dJot3ZhYx1DR+ Dl4t+5uWvrzeL1I0q2D7jQvsUUMGZTrJDZpjNpQedEKsG+0usYs9lUwLs72MyoYZ8yyu i1DQ== X-Gm-Message-State: AOAM531p2746jXTWePDEa37Tw222oTp/CvjKwv6h8Frs7ln+WdpFsBHu M6mj1LY2uJKqnw/qw9KbXDd2TDu3ECc= X-Received: by 2002:a05:6a00:8cb:b0:510:9ec4:8f85 with SMTP id s11-20020a056a0008cb00b005109ec48f85mr18774107pfu.24.1652316917923; Wed, 11 May 2022 17:55:17 -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 n17-20020a170903111100b0015e8d4eb2c6sm2590176plh.272.2022.05.11.17.55.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 17:55:17 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] service: Add initiator argument to service_accept Date: Wed, 11 May 2022 17:55:15 -0700 Message-Id: <20220512005515.844857-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512005515.844857-1-luiz.dentz@gmail.com> References: <20220512005515.844857-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 From: Luiz Augusto von Dentz This adds initiator argument to service_accept so profiles accepting the connection can use btd_service_is_initiator to determine if the connection was initiated locally (central) or remotely (peripheral). --- src/device.c | 18 ++++++++++++++++-- src/service.c | 4 +++- src/service.h | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/device.c b/src/device.c index b0309a1e7..a39eb8c64 100644 --- a/src/device.c +++ b/src/device.c @@ -158,6 +158,7 @@ struct bearer_state { bool bonded; bool connected; bool svc_resolved; + bool initiator; }; struct csrk_info { @@ -297,6 +298,16 @@ static struct bearer_state *get_state(struct btd_device *dev, return &dev->le_state; } +static bool get_initiator(struct btd_device *dev) +{ + if (dev->le_state.connected) + return dev->le_state.initiator; + if (dev->bredr_state.connected) + return dev->bredr_state.initiator; + + return false; +} + static GSList *find_service_with_profile(GSList *list, struct btd_profile *p) { GSList *l; @@ -3256,6 +3267,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) return; state->connected = false; + state->initiator = false; device->general_connect = FALSE; device_set_svc_refreshed(device, false); @@ -4169,7 +4181,7 @@ done: } /* Notify driver about the new connection */ - service_accept(service); + service_accept(service, get_initiator(device)); } static void device_add_gatt_services(struct btd_device *device) @@ -4191,7 +4203,7 @@ static void device_accept_gatt_profiles(struct btd_device *device) GSList *l; for (l = device->services; l != NULL; l = g_slist_next(l)) - service_accept(l->data); + service_accept(l->data, get_initiator(device)); } static void device_remove_gatt_service(struct btd_device *device, @@ -5899,6 +5911,8 @@ int device_connect_le(struct btd_device *dev) /* Keep this, so we can cancel the connection */ dev->att_io = io; + /* Set as initiator */ + dev->le_state.initiator = true; return 0; } diff --git a/src/service.c b/src/service.c index 14a4c292b..7c4dc8fe0 100644 --- a/src/service.c +++ b/src/service.c @@ -172,7 +172,7 @@ void service_remove(struct btd_service *service) btd_service_unref(service); } -int service_accept(struct btd_service *service) +int service_accept(struct btd_service *service, bool initiator) { char addr[18]; int err; @@ -198,6 +198,8 @@ int service_accept(struct btd_service *service) return -ECONNABORTED; } + service->initiator = initiator; + err = service->profile->accept(service); if (!err) goto done; diff --git a/src/service.h b/src/service.h index fa930f985..dc0d1d132 100644 --- a/src/service.h +++ b/src/service.h @@ -35,7 +35,7 @@ struct btd_service *service_create(struct btd_device *device, int service_probe(struct btd_service *service); void service_remove(struct btd_service *service); -int service_accept(struct btd_service *service); +int service_accept(struct btd_service *service, bool initiator); int service_set_connecting(struct btd_service *service); /* Connection control API */ -- 2.35.1