From patchwork Tue Dec 17 18:13:33 2024 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: 13912375 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CBAB1DE3D7 for ; Tue, 17 Dec 2024 18:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734459220; cv=none; b=A8ETbu2MI8OAk2th4YqBV3S2PJF2NDzHIHPPeMDqHeZzHsXQ9wuXK10gH8oll15UeB5TK3V4xBVJmB0wtoHuZmDDUWSLr7WMd24RR7g2QB2G1OcGRxF2B55NImNVZaX5zH6dWjoGK23TiY94FOtJPNVwNTGjEZ9Qm4acqWmDvB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734459220; c=relaxed/simple; bh=oizjkpllPsDOEBU/614EOV/Q6NQquysWJqKJKEA9dc4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A2vlKFEAiODWI/yO+cj+puGaOXwwVQN5JDPG49rdZsA7tLATUJSzvheIHF3atNxqIkX8bpUJXZuYsZ5yXnluRjsZfOfEG/WXxP0J1aeaphB/pL6lRjex03Ifc9+5RWanvDscPjaBDx2ZuAWIAOU47etKecohxe5ERPEjiPD193w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NLUp7kcK; arc=none smtp.client-ip=209.85.217.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NLUp7kcK" Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-4afe6a8d2e1so2815761137.1 for ; Tue, 17 Dec 2024 10:13:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734459217; x=1735064017; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=FQ1MoB6UPTuEXkAyk2o/J6km3ElthbdHEvUpYhi5bCU=; b=NLUp7kcKWm274MirYyWtHzIpMoqFWIPVG1j2SjB6x7OQL0gbNXzGgJZ8itEj28FP0n hsScuwTGvY2AsLGBEtNQ6Qe4uQ2hi4cU+AWMO8J/23Q2rBRBaUM8Ur1ADopf2pR/YOyS BsR6hj1391SSJ8FsS43Uiewtgsyl3aUSlq1AQP2A28lUgPnB6zeJzipM1k9haaljILUn 4iltX2jFAucmEeYGemOYxhldUPJ/Dbslhr3ysd9s/3HONdwoAGnjdnpp9jAgHo9l8yeJ BnwFo+hYEmxrO9T3ma5nGL6trGzUtG9p3SyQzZdv6Y6r0kpYXwB03iH9WowdGL/t3ieZ nDCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734459217; x=1735064017; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FQ1MoB6UPTuEXkAyk2o/J6km3ElthbdHEvUpYhi5bCU=; b=PyYNEKWKhXflx5+qn/I9RQc4bH8KKVeH/kCSLNBdVmMw7ApzJl2de7ENOg0ashPN1b I3cSlXjCXXbYQ1nohLL3K8nFtO9FciVgBNeg/EOgKjYHiLGGlbO58FQvB0jZC1lJVam6 IxmiDEHgN7tTAagd0EMQjCmN1YXmG1/LsmnR5id9MAd1X59cJo5isk1VhCj0lQtaFWMp cAdmUb48AGx4mZphSkhcZksTvc/wQUjOcGZEsOzKvOqLlGWJlsTa3/Pz8uTHyKA7P+6+ EH5EHzNblPlvty7GBTHAW4YwcUQ4gOkNtmHyymzCDjRqveUn/tUaD4ZMkzJ829KqSd6d AiMg== X-Gm-Message-State: AOJu0YyLkNmTu3NsS8a504XVoKzh6l54YW2BInJQ/qKQSssCj8qAoyf1 koJMFg/rp7dATo11wSDhUTl9+pZoiRtknHKHmR9S4yI42YhCkJmSQqmyRA== X-Gm-Gg: ASbGncvbdVD9jkmWgoAwzZKwhmllE2BFHZl7ysomIG6nvK69gQbdFMgwxLP/Z9DaTa6 MqbbWrXMD35f0Fy3mIe7scf//dGgocXI38wg3J0jt3DsOaYMGD9+ZIio6wS3SekiZ6DSWMs5R8s RjenqS2f4Rxz4v+UE2WaIXt8823FBxNFBIFFRvZ9erK83JIO7GdBTP0MPETe/nt8X7BXMP0wO4b brnlhz0yhUSMGKOnpCkbuiMs525r054LyGuJCb7OiLERKH8/Sofz3qiT/DJPb/b1WVPNtFytw89 CSq/7dZdgJHL978+M1xqjmEqlV4S X-Google-Smtp-Source: AGHT+IFKHEb/N9FXXcXokmXyHxIIAzvhFmfxFTQh0i5Ke0uDlg3GV9Xze9qdOj0PXdp99L0xoubhVA== X-Received: by 2002:a05:6102:50aa:b0:4af:ed5a:b68d with SMTP id ada2fe7eead31-4b29dc38822mr4070446137.6.1734459216940; Tue, 17 Dec 2024 10:13:36 -0800 (PST) Received: from lvondent-mobl5.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4b270238f25sm1214721137.12.2024.12.17.10.13.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 10:13:36 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 1/2] client: Add command wake Date: Tue, 17 Dec 2024 13:13:33 -0500 Message-ID: <20241217181334.3243011-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds command wake which can be used to set WakeAllowed property: [bluetoothctl]> wake XX:XX:XX:XX:XX:XX off [bluetoothctl]> Changing wake off succeeded [bluetoothctl]> [CHG] Device XX:XX:XX:XX:XX:XX WakeAllowed: no [bluetoothctl]> wake XX:XX:XX:XX:XX:XX on [bluetoothctl]> Changing wake on succeeded [bluetoothctl]> [CHG] Device XX:XX:XX:XX:XX:XX WakeAllowed: yes [bluetoothctl]> wake XX:XX:XX:XX:XX:XX --- client/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/client/main.c b/client/main.c index c4fc49427021..322326ab9b80 100644 --- a/client/main.c +++ b/client/main.c @@ -2050,6 +2050,42 @@ static void cmd_disconn(int argc, char *argv[]) proxy_address(proxy)); } +static void cmd_wake(int argc, char *argv[]) +{ + GDBusProxy *proxy; + dbus_bool_t value; + char *str; + + proxy = find_device(argc, argv); + if (!proxy) + return bt_shell_noninteractive_quit(EXIT_FAILURE); + + if (argc <= 2) { + print_property(proxy, "WakeAllowed"); + return; + } + + if (!strcasecmp(argv[2], "on")) { + value = TRUE; + } else if (!strcasecmp(argv[2], "off")) { + value = FALSE; + } else { + bt_shell_printf("Invalid value %s\n", argv[2]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + str = g_strdup_printf("wake %s", value == TRUE ? "on" : "off"); + + if (g_dbus_proxy_set_property_basic(proxy, "WakeAllowed", + DBUS_TYPE_BOOLEAN, &value, + generic_callback, str, g_free)) + return; + + g_free(str); + + return bt_shell_noninteractive_quit(EXIT_FAILURE); +} + static void cmd_list_attributes(int argc, char *argv[]) { GDBusProxy *proxy; @@ -3130,6 +3166,8 @@ static const struct bt_shell_menu main_menu = { dev_generator }, { "disconnect", "[dev]", cmd_disconn, "Disconnect device", dev_generator }, + { "wake", "[dev] [on/off]", cmd_wake, "Get/Set wake support", + dev_generator }, { } }, }; From patchwork Tue Dec 17 18:13:34 2024 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: 13912376 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6CAF1F75AF for ; Tue, 17 Dec 2024 18:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734459224; cv=none; b=Br+KWDeFnPwjTQnt6Ge8Wq6gYsIBRn6PurwLmJn37XybPFAhpBaDAIMZTWAvaHKDFD1QjnMEZY8zvBJOsbmeVM68OyOQIivm6xiMyUQQo/MC7UUeSJIqYnzGmwjdFYuNi915+KIJobi8nt88DxLfdI8X52KOnkjHOqZ3gXukooE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734459224; c=relaxed/simple; bh=QkmAVq6lb9WVzm/qCney9L03JynJ0PPTFp+Naz69pyo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NDGXBt2MXAlHXOb48rt4ROhLRqSS2q529BBYorXcrHQJ6gYGFH1DFV6PTZdFSVUJC+Mkk3cajqrL2BJzOtfR5pdjIF500SajeSXlgiBtDZU5ps3KAMAaZFlbFjw+q+DaNAy2A6Xk1hu4qv7TCPFPor/2/3CvlTSVvYQn+iiSRnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MXocylLZ; arc=none smtp.client-ip=209.85.217.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MXocylLZ" Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-4b10dd44c8bso1180631137.3 for ; Tue, 17 Dec 2024 10:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734459220; x=1735064020; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=OcqjYN9dtItZka6MagbbfSI5Ja6c0sqMDS2z1F896Fk=; b=MXocylLZwG/zX81xTbRI8R4vdS67krIAIxwSbG/tiwy9DmKqAnjXBT9AnoBwiGWm3Q u+34z1tP37iLkj7Bkzd4rG3Ev8lFU5zre1jK6LLPp/rhdR/CYLPp1g/+FiVAutvYwK3S llU+Eu0Y6fcrXWVQ2SrZ+BCwAgQWyz1QCZyKol8r/jI3MojwNexiHgbUmLiXRGRaUvKQ H1dM0k2z99b3ojHTmSK35oVRAOgnWLeVzcCyvdMh7meQ3Buwk7Lcoce29HbL9C7XkInu TvZ24C0TZtSO44CKXGeC4kstxdcvyi+C4AN+3coETjvYKItSTl72yrtKkaGvfX52Smx3 0yog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734459220; x=1735064020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OcqjYN9dtItZka6MagbbfSI5Ja6c0sqMDS2z1F896Fk=; b=d3MkVKs2Dms1v4+9bkmT2yW2JXecoGRAHHckrb5eqgv7appDeLbbqjNB9u0uheu2bg irWX1oOXj4cCY1rSwKswvJ3iQQ2F5AYcX/qL76D0VmwcnfGC+VOjGRdx49zwV5n8lVzj nThWeNudvQC2TqdCuP4Nqdypg3AUc2wINbFe5qVlY++QF1P83Rs4M3rU+26888QisGRl vfTAIhGffAp24LM7m2//OsN2QNUDqKq5BLT+wRHNngsMtU16dBfXoCb6BQ2P77wMmJ5t VjI/J2cL+Ju6rt1CQ4iFfymqlY4bCp5N4LV3j0Cpj9GGsfdDyNJaybrTxG4N1Yyfu2ig 6Z7w== X-Gm-Message-State: AOJu0Yzv0A1v8ae5LlA0j3SjU6LLYHpYp4NAGWp3m+gErKYeOk2HBbDC OxuUygSFzlnYeppqgXsnEcwUNGIVgMmaeJ8GDJQcwmzazQMkYBsGWECVgA== X-Gm-Gg: ASbGnctwS1oPLzAd60cW5VJ8DtTBBCM+30MxrLNvRQP2lR3w5w8kJ9mjQMox8f9EUbh oYUMOzrASUu+KpDmFsOamPX8U3+I0iqT5OjNB7XegBPrtwTQN8JUd1/MaQD94XPsZVcnB4etzJG PuK7Djxn5ivCBgyOE+CRqWppthPMlo91fIM5ds1DM1noO7sNt4MGCVysvSlyk9hpq0Ogal/usyl KzM+8xIdefXRlN0fALucUSmHD25Zph5lwiLH+SqEtgpcN5P8n/7iQSsIXfeYc039zkk4Hnr4VuA 92QswLNWQ6wU/PGQFcqfK16mb8mu X-Google-Smtp-Source: AGHT+IEmI/IkauPGyWOHUKsq+uNwEztq6i0bqBdWGdt4lIToitYzT+ps+Gtq66GqzxozgSHAualtSA== X-Received: by 2002:a05:6102:4b04:b0:4b1:1def:3d10 with SMTP id ada2fe7eead31-4b25ddb2c56mr18346201137.19.1734459219082; Tue, 17 Dec 2024 10:13:39 -0800 (PST) Received: from lvondent-mobl5.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4b270238f25sm1214721137.12.2024.12.17.10.13.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 10:13:37 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 2/2] device: Fix not being able to set WakeAllowed Date: Tue, 17 Dec 2024 13:13:34 -0500 Message-ID: <20241217181334.3243011-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241217181334.3243011-1-luiz.dentz@gmail.com> References: <20241217181334.3243011-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz Setting WakeAllowed was not working as intended since device_set_wake_override was changing the current_flags which btd_device_flags_changed checks to determine if flags has been changed to only then call device_set_wake_allowed_complete. Fixes: https://github.com/bluez/bluez/issues/1045 --- src/device.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/device.c b/src/device.c index 2d3ac71f6878..24ef3d77948f 100644 --- a/src/device.c +++ b/src/device.c @@ -1515,13 +1515,21 @@ void device_set_wake_support(struct btd_device *device, bool wake_support) device->wake_support = wake_support; - /* If wake configuration has not been made yet, set the initial - * configuration. + if (device->wake_support) + device->supported_flags |= DEVICE_FLAG_REMOTE_WAKEUP; + else + device->supported_flags &= ~DEVICE_FLAG_REMOTE_WAKEUP; + + /* If there is not override set, set the default the same as + * support value. */ - if (device->wake_override == WAKE_FLAG_DEFAULT) { + if (device->wake_override == WAKE_FLAG_DEFAULT) device_set_wake_override(device, wake_support); - device_set_wake_allowed(device, wake_support, -1U); - } + + /* Set wake_allowed according to the override value. */ + device_set_wake_allowed(device, + device->wake_override == WAKE_FLAG_ENABLED, + -1U); } static bool device_get_wake_allowed(struct btd_device *device) @@ -1531,13 +1539,10 @@ static bool device_get_wake_allowed(struct btd_device *device) void device_set_wake_override(struct btd_device *device, bool wake_override) { - if (wake_override) { + if (wake_override) device->wake_override = WAKE_FLAG_ENABLED; - device->current_flags |= DEVICE_FLAG_REMOTE_WAKEUP; - } else { + else device->wake_override = WAKE_FLAG_DISABLED; - device->current_flags &= ~DEVICE_FLAG_REMOTE_WAKEUP; - } } static void device_set_wake_allowed_complete(struct btd_device *device) @@ -1563,6 +1568,12 @@ static void set_wake_allowed_complete(uint8_t status, uint16_t length, if (status != MGMT_STATUS_SUCCESS) { error("Set device flags return status: %s", mgmt_errstr(status)); + if (dev->wake_id != -1U) { + g_dbus_pending_property_error(dev->wake_id, + ERROR_INTERFACE ".Failed", + mgmt_errstr(status)); + dev->wake_id = -1U; + } return; } @@ -1583,8 +1594,11 @@ void device_set_wake_allowed(struct btd_device *device, bool wake_allowed, * progress. Only update wake allowed if pending value doesn't match the * new value. */ - if (wake_allowed == device->pending_wake_allowed) + if (device->wake_id != -1U && id != -1U) { + g_dbus_pending_property_error(id, ERROR_INTERFACE ".Busy", + "Property change in progress"); return; + } device->wake_id = id; device->pending_wake_allowed = wake_allowed; @@ -4358,6 +4372,7 @@ static struct btd_device *device_new(struct btd_adapter *adapter, device->tx_power = 127; device->volume = -1; + device->wake_id = -1U; device->db = gatt_db_new(); if (!device->db) {