Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2460919pxb; Mon, 18 Apr 2022 00:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzjLltGJdGfA87pKKr7DFxeljAuCEGa/8ypGtqnHn97JsUKJmbJwsLSBCfA94IDSS3hmLA X-Received: by 2002:a63:1d19:0:b0:3aa:1670:d190 with SMTP id d25-20020a631d19000000b003aa1670d190mr569491pgd.263.1650265464156; Mon, 18 Apr 2022 00:04:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650265464; cv=none; d=google.com; s=arc-20160816; b=FocH6XdeOlc7xgwLDYlYJoyVUjWdyMRACSj4wEeNiYs9SaiTTUzRPkF0F5hrPmbA+u wASxMBfHmuSPIEeEwA1ISDIfR+fM5ANEgbfQ+42FJ6IZdpr030FRCefugaAiywJX4Kd8 y+jRWIJ8uCabyQKXa3ZMdzQ1mip7fq7cRohBlxRCYGT7aAbx4oc0jqiuSsM5baAIkA+2 oMdKgg6yW1C0lFYzE8yP1hfa5ThxNplOL8gqZ1vG/Q6b0zJlCZQFnBYsU/zCSC4bXmn3 btu4AihU9AQT87O06Viw5yMkwx85l956Q5FD5jZQwmF/1s8UFVxfmXZyI1qO5pEFa5Ov YZMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=M8MeO3rtYNrekpsED43M2F331S3C89tiDxngPJ9YSzY=; b=x2AeS1M2YlrkuD8lwv1V/YpsIgLQHCDKVax/94C+tLY8xxwJNuayJ6fW9ADht6VDJL 10f8Zo3+oCoYDiOFLnC2pc+UvppaQMQazIDnYsMoyhYqfJKbKTSxVv+Sw/axeTcXF2ZY uS1FhvhSiL/0EGY1dXKw+lkttVzX/yzx7Hqzy9z7z4t1e+8knbrJSWcWi9FoMsXb4e78 4PdVsrqyRQaj3Rx2aD6GbGkntMbjCdtis5bIKSo9mpt2GE1DG7V6wcLqgrGm4h86HEvd pV7bDqi3Sx95f58Txc40JdEEleKpx8wcb+jZbth8eNLS9a1MEiAAXXXKL/h4ThqM2XOc livw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F3Ah0n4P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a1709029a0800b00155f37a9df9si7805325plp.525.2022.04.18.00.03.48; Mon, 18 Apr 2022 00:04:24 -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=@google.com header.s=20210112 header.b=F3Ah0n4P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236477AbiDREaG (ORCPT + 99 others); Mon, 18 Apr 2022 00:30:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233504AbiDREaG (ORCPT ); Mon, 18 Apr 2022 00:30:06 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE9EDF7E for ; Sun, 17 Apr 2022 21:27:28 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id i10-20020a170902e48a00b00153f493fa9aso7004169ple.17 for ; Sun, 17 Apr 2022 21:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=M8MeO3rtYNrekpsED43M2F331S3C89tiDxngPJ9YSzY=; b=F3Ah0n4Pn8lNe3/hUDOlabcqHajTrp+GIh27Z7EeC1E84jNzf4RrT4GRTUZwBX45y2 TB5NAjo1q3AF9qxYbp7BS5F015oFUyaZV6hd7IGXNyVlREchxqanUYNXJOynrUqzzgz1 CALkVaQQV/5+uXcv4xVTvwUfFlcRl9VWK2pOIAQ43Oj3dJ/dUk/Ega45xvprtWEPklWa rKxjc/ASL9teo89I85GjxWM2ojQnNaTZzmlpMqexnQGWSgeHxMhYis58MuhRnfQtDKM8 aiQ5PB5Fhdj2XlcibziT66pLmOanQ8XVKnP787UjV7qHvBQKuSJRbhoW3VKNuG95T7PW 9SRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=M8MeO3rtYNrekpsED43M2F331S3C89tiDxngPJ9YSzY=; b=ZzTV+W4qJFERDdGT9SOJguEXZPGHBwE4jBt+jbE3JccI9XA2h+ywq/9pKwMeXXkRZ3 qBdXzTA137LFRlUJv7YU8Cjts16JUG9Ii9QaVxrOcEQVWZxCpymMM0DEKSbZnUVDmyDK BWRaDvJzyYnyojlH2HuZIYMzeNc6l70DTcBJ4e9Z2Ly8O4rmg9iXkHJaOu2A4lptzH0H 91giGmVk8ZKUUYjBBSdTaMNzn2jTPXvNPJIQOkSex8iZ9gDOz74jMTcvgBuILT9LFExf vUMtAmeX/qjTUW9u0lVBMARjAs2PRUW99s15kSEtmxwZGd92todO1ABUBnE5Ty1dsb9z 8hgg== X-Gm-Message-State: AOAM530Z+3G33kX//zVUFplwT7xxCX7yzjyfdc+hydmX0M4RZSQaVyYR KYVimA2r7fJ0LZaLyeCyAjbXoLmD5GRXkX5iy1XvHfSe3Buoznu0PkS7jroockreQBZshXM8ACJ 7xH8iswm7Apv5/NgBTyEavB/6AWGrkJZYrlDo8fJ+Zn0MKZqav86aHVR35Jrg8EHt4QIeItd//7 K5 X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4c52]) (user=jiangzp job=sendgmr) by 2002:a17:90a:9105:b0:1d2:9e98:7e1e with SMTP id k5-20020a17090a910500b001d29e987e1emr179264pjo.0.1650256047189; Sun, 17 Apr 2022 21:27:27 -0700 (PDT) Date: Mon, 18 Apr 2022 04:26:33 +0000 In-Reply-To: <20220418042635.2567170-1-jiangzp@google.com> Message-Id: <20220418042629.Bluez.v1.1.I6ab300fa4999c9310f4cb6fc09b1290edb6b2c2b@changeid> Mime-Version: 1.0 References: <20220418042635.2567170-1-jiangzp@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [Bluez PATCH v1 1/2] device: Add "Bonded" flag to dbus property From: Zhengping Jiang To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Zhengping Jiang , Sonny Sasaka , Yun-Hao Chung Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 Add "Bonded" to dbus device property table. When setting the "Bonded flag, check the status of the Bonded property first. If the Bonded property is changed, send property changed signal. Reviewed-by: Sonny Sasaka Reviewed-by: Yun-Hao Chung Signed-off-by: Zhengping Jiang --- Changes in v1: - Add "Bonded" to D-Bus interface - Send property changed signal if the bonded flag is changed doc/device-api.txt | 4 ++++ src/device.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/doc/device-api.txt b/doc/device-api.txt index 4e824d2dec17..6162755f954c 100644 --- a/doc/device-api.txt +++ b/doc/device-api.txt @@ -171,6 +171,10 @@ Properties string Address [readonly] Indicates if the remote device is paired. + boolean Bonded [readonly] + + Indicates if the remote device is bonded. + boolean Connected [readonly] Indicates if the remote device is currently connected. diff --git a/src/device.c b/src/device.c index 8dc12d026827..1a7afa8fc5c0 100644 --- a/src/device.c +++ b/src/device.c @@ -1042,6 +1042,22 @@ static gboolean dev_property_get_paired(const GDBusPropertyTable *property, return TRUE; } +static gboolean dev_property_get_bonded(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct btd_device *dev = data; + dbus_bool_t val; + + if (dev->bredr_state.bonded || dev->le_state.bonded) + val = TRUE; + else + val = FALSE; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val); + + return TRUE; +} + static gboolean dev_property_get_legacy(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { @@ -3120,6 +3136,7 @@ static const GDBusPropertyTable device_properties[] = { { "Icon", "s", dev_property_get_icon, NULL, dev_property_exists_icon }, { "Paired", "b", dev_property_get_paired }, + { "Bonded", "b", dev_property_get_bonded }, { "Trusted", "b", dev_property_get_trusted, dev_property_set_trusted }, { "Blocked", "b", dev_property_get_blocked, dev_property_set_blocked }, { "LegacyPairing", "b", dev_property_get_legacy }, @@ -6117,14 +6134,25 @@ void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type) if (!device) return; - DBG(""); + struct bearer_state *state = get_state(device, bdaddr_type); - if (bdaddr_type == BDADDR_BREDR) - device->bredr_state.bonded = true; - else - device->le_state.bonded = true; + if (state->bonded) + return; + + DBG("setting bonded for device to true"); + + state->bonded = true; btd_device_set_temporary(device, false); + + /* If the other bearer state was already true we don't need to + * send any property signals. + */ + if (device->bredr_state.bonded == device->le_state.bonded) + return; + + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "Bonded"); } void device_set_legacy(struct btd_device *device, bool legacy) -- 2.36.0.rc0.470.gd361397f0d-goog