From patchwork Mon Jul 13 20:14:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Sasaka X-Patchwork-Id: 11660995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BE6013B4 for ; Mon, 13 Jul 2020 20:15:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41A992075D for ; Mon, 13 Jul 2020 20:15:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eRfNJtyw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbgGMUPD (ORCPT ); Mon, 13 Jul 2020 16:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbgGMUPC (ORCPT ); Mon, 13 Jul 2020 16:15:02 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3558C061755 for ; Mon, 13 Jul 2020 13:15:02 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id x9so6011016plr.2 for ; Mon, 13 Jul 2020 13:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zPLCESdS/Ve1h9h7+XMTn1nlcKJ28YFSVJfO0CW+h5Q=; b=eRfNJtywXo3LygM13DluPcmtp1uxJcCcbYpA/gcHHRI5glgbWwyrx+NWBYH/rJpA9y 7FxcYqbcwMLdYmGqly6KSs4Pf/CyU5c79QNQovyIT8BdT5DTxQ/WjAL5ipZ5Ns/ROKYj dmCfo9/h+AIcfu/x6tozDcUb6v4cGQfpIm7DY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zPLCESdS/Ve1h9h7+XMTn1nlcKJ28YFSVJfO0CW+h5Q=; b=cg3C4xfO4ZyV6zAcNarJJZti79JYizQa8Bsx/fClgm8QHjYB86pPAiIs+ObhsvNuBq AKMH/oe46v5Ndl3xDk5eos36j/Ua0YNkO8slezhiA7/gTdk5TFmsR2nBWv3slld1Ahq5 q0jr76swDZsJArPiZneYQD/novLCqdR7rHaC0uMtTdOCPBs3u1eTx0sfB9w9ye2nM+1e wh27lLpLtjPLyRJdkA/8jjQqMXcdUaWEBz0w22amniN3kEeUC4q60CfR8JUHrq6Q1TTV SlH2/FoAj4cfHi4r+G4Ebk2tD2GWpNhgs38D8tJmT8e0zbc5zy103ooUWkiErSMzILqX AXWA== X-Gm-Message-State: AOAM532IUW9cMdYwVGYeufs7p2xmkwbP53qxIcs/sVJGffymwY0I/Lwr RfgvGEr/HpOUMBQ0rgjTXJdXfQ== X-Google-Smtp-Source: ABdhPJx90lgXLXGMBM07VI7NfT+wBeZIIGLGjq10C5JzG2M/Udv0vGnBiPKT4cV4dBGJRVRhivlX6w== X-Received: by 2002:a17:90a:6948:: with SMTP id j8mr984297pjm.45.1594671302200; Mon, 13 Jul 2020 13:15:02 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id h18sm7866135pfr.186.2020.07.13.13.15.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jul 2020 13:15:01 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth-@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Alain Michaud Subject: [PATCH BlueZ 1/3] doc: Add "AllowInternalProfiles" property to org.bluez.Device1 Date: Mon, 13 Jul 2020 13:14:39 -0700 Message-Id: <20200713201441.235959-2-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200713201441.235959-1-sonnysasaka@chromium.org> References: <20200713201441.235959-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Reviewed-by: Alain Michaud --- doc/device-api.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/device-api.txt b/doc/device-api.txt index 4e824d2de..5c2b2b26b 100644 --- a/doc/device-api.txt +++ b/doc/device-api.txt @@ -189,6 +189,19 @@ Properties string Address [readonly] drivers will also be removed and no new ones will be probed as long as the device is blocked. + boolean AllowInternalProfiles [readwrite] + + If set to true, connection to this device will activate + BlueZ internal profiles (e.g. A2DP, HOG, Battery). + If set to false, internal profiles will not be activated + allowing the client to handle profiles which would + otherwise be controlled by internal handlers. + The default is configurable in main.conf. + + Write operation to this property can only be accepted + when the device is not connected, otherwise + org.bluez.Error.Failed is returned. + boolean WakeAllowed [readwrite] If set to true this device will be allowed to wake the From patchwork Mon Jul 13 20:14:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Sasaka X-Patchwork-Id: 11660997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1CE413B1 for ; Mon, 13 Jul 2020 20:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C20BD20674 for ; Mon, 13 Jul 2020 20:15:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="W/KC/3P+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbgGMUPF (ORCPT ); Mon, 13 Jul 2020 16:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbgGMUPF (ORCPT ); Mon, 13 Jul 2020 16:15:05 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E23C061755 for ; Mon, 13 Jul 2020 13:15:05 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id x8so5996026plm.10 for ; Mon, 13 Jul 2020 13:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FrBgPrgTeBiJc90yEeremeQlH6Tb4/9Y0eWkSBJnlyc=; b=W/KC/3P+fyNwficSIm+l9Hmg8NVivaEb7530aUaJRrF8v0fvEMPNKHiWbAGoa6KHMv Yy3VZbnx0qMhKRaco32m/D78T2/lNs9fqEeLqHa87JFIJqRHP/pRIr2Hvsx6bAcykWYN 3w7pCjEJSCvkV2P1vU3UiyX5MGKC+dfNFQVvw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FrBgPrgTeBiJc90yEeremeQlH6Tb4/9Y0eWkSBJnlyc=; b=PGyMOYsHPphvPIvXC21Ca6MKpXUqDcvghSyzy9QxHml0+TTBjItxPd90ajRG1HMnJl +/UlodLvArM//zOsJWe1+efUdsIjfNOt5jbFzMmxtS2HmAGCIlnnanF0NIGhVq6mhmHI Iyi+A+15R5aNVVPV2z0vMSRg4RSZq1WoN4ozdUDlR+pS+NIDrnm6LS/a3OUWlWPrsRmB FYBrun9D8OTFK7JlKMSTVZ1yesYqas8ImnaiB2x1FDWzFMFj2PoRoRRkdrCsGSyi7XYU No0f9JTinEsVArtyPmnNoJwNY6lyanlEDFnYvlBV6g++CAQRwYrhY2rPMqWuJTNNJUYb AU/Q== X-Gm-Message-State: AOAM5317Rw0MVodZsax2ERkUs+F/s9iw1cx06QU7vQcKFYcXOqoGxQcB pgoJHeRHLsxZSXMXDZcL0XlRjiAJfEI= X-Google-Smtp-Source: ABdhPJyqtBpD62gnyd+/pHFGD0fZhhtKH2c4YaEVXRMjvzu5/fjGcdn+So9cmZgkufLOC/cFBnF4Iw== X-Received: by 2002:a17:90a:bc98:: with SMTP id x24mr966653pjr.63.1594671304665; Mon, 13 Jul 2020 13:15:04 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id h18sm7866135pfr.186.2020.07.13.13.15.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jul 2020 13:15:04 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth-@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Alain Michaud Subject: [PATCH BlueZ 2/3] device: Add "AllowInternalProfiles" property to org.bluez.Device1 Date: Mon, 13 Jul 2020 13:14:40 -0700 Message-Id: <20200713201441.235959-3-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200713201441.235959-1-sonnysasaka@chromium.org> References: <20200713201441.235959-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Some clients want to have full control over all profiles for specific peer devices, for example to handle the GATT Battery profile. This patch adds an option via a property in org.bluez.Device1 interface. Setting to true will let BlueZ take control over internal profiles (such as A2DP, HOG, Battery), and setting to false will prevent BlueZ from handling all internal profiles, allowing the client to handle them. Reviewed-by: Alain Michaud --- src/device.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/hcid.h | 2 ++ src/main.c | 10 ++++++ src/main.conf | 4 +++ 4 files changed, 112 insertions(+) diff --git a/src/device.c b/src/device.c index 0deee2707..bd8c80032 100644 --- a/src/device.c +++ b/src/device.c @@ -275,6 +275,7 @@ struct btd_device { gboolean auto_connect; gboolean disable_auto_connect; gboolean general_connect; + gboolean allow_internal_profiles; bool legacy; int8_t rssi; @@ -294,6 +295,10 @@ static const uint16_t uuid_list[] = { static int device_browse_gatt(struct btd_device *device, DBusMessage *msg); static int device_browse_sdp(struct btd_device *device, DBusMessage *msg); +static void gatt_service_added(struct gatt_db_attribute *attr, void *user_data); +static void gatt_service_removed(struct gatt_db_attribute *attr, + void *user_data); + static struct bearer_state *get_state(struct btd_device *dev, uint8_t bdaddr_type) { @@ -436,6 +441,9 @@ static gboolean store_device_info_cb(gpointer user_data) g_key_file_set_boolean(key_file, "General", "Blocked", device->blocked); + g_key_file_set_boolean(key_file, "General", "AllowInternalProfiles", + device->allow_internal_profiles); + if (device->wake_override != WAKE_FLAG_DEFAULT) { g_key_file_set_boolean(key_file, "General", "WakeAllowed", device->wake_override == @@ -1468,6 +1476,71 @@ static gboolean dev_property_wake_allowed_exist( return device_get_wake_support(device); } +static gboolean +dev_property_get_allow_internal_profiles(const GDBusPropertyTable *property, + DBusMessageIter *iter, + void *data) +{ + struct btd_device *device = data; + dbus_bool_t allow_internal_profiles = device->allow_internal_profiles; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, + &allow_internal_profiles); + + return TRUE; +} + +static void +dev_property_set_allow_internal_profiles(const GDBusPropertyTable *property, + DBusMessageIter *value, + GDBusPendingPropertySet id, + void *data) +{ + struct btd_device *device = data; + dbus_bool_t b; + + if (dbus_message_iter_get_arg_type(value) != DBUS_TYPE_BOOLEAN) { + g_dbus_pending_property_error( + id, ERROR_INTERFACE ".InvalidArguments", + "Invalid arguments in method call"); + return; + } + + if (device->le_state.connected || device->bredr_state.connected) { + g_dbus_pending_property_error(id, ERROR_INTERFACE ".Failed", + "Device is connected"); + return; + } + + dbus_message_iter_get_basic(value, &b); + + device->allow_internal_profiles = b; + + /* Remove GATT client cache */ + gatt_db_unregister(device->db, device->db_id); + btd_gatt_client_destroy(device->client_dbus); + gatt_db_unref(device->db); + + device->db = gatt_db_new(); + device->client_dbus = btd_gatt_client_new(device); + device->db_id = gatt_db_register(device->db, gatt_service_added, + gatt_service_removed, device, NULL); + + /* Re-probe all profiles */ + while (device->services != NULL) { + struct btd_service *service = device->services->data; + + device->services = g_slist_remove(device->services, service); + service_remove(service); + } + + device_probe_profiles(device, device->uuids); + + /* Update D-Bus property and reply client */ + g_dbus_emit_property_changed(dbus_conn, device->path, DEVICE_INTERFACE, + "AllowInternalProfiles"); + g_dbus_pending_property_success(id); +} static gboolean disconnect_all(gpointer user_data) { @@ -2944,6 +3017,9 @@ static const GDBusPropertyTable device_properties[] = { { "WakeAllowed", "b", dev_property_get_wake_allowed, dev_property_set_wake_allowed, dev_property_wake_allowed_exist }, + { "AllowInternalProfiles", "b", + dev_property_get_allow_internal_profiles, + dev_property_set_allow_internal_profiles }, { } }; @@ -3196,6 +3272,7 @@ static void load_info(struct btd_device *device, const char *local, char *str; gboolean store_needed = FALSE; gboolean blocked; + gboolean allow_internal_profiles; gboolean wake_allowed; char **uuids; int source, vendor, product, version; @@ -3283,6 +3360,20 @@ next: if (blocked) device_block(device, FALSE); + /* Load allow internal profiles */ + allow_internal_profiles = g_key_file_get_boolean( + key_file, "General", "AllowInternalProfiles", &gerr); + if (!gerr) { + device->allow_internal_profiles = allow_internal_profiles; + } else { + /* Old config doesn't contain this item, so set it to true to + * match the previous default behavior. + */ + device->allow_internal_profiles = true; + g_error_free(gerr); + gerr = NULL; + } + /* Load device profile list */ uuids = g_key_file_get_string_list(key_file, "General", "Services", NULL, NULL); @@ -3782,6 +3873,9 @@ static bool device_match_profile(struct btd_device *device, bt_uuid_strcmp) == NULL) return false; + if (!device->allow_internal_profiles && !profile->external) + return false; + return true; } @@ -4055,6 +4149,8 @@ static struct btd_device *device_new(struct btd_adapter *adapter, device->adapter = adapter; device->temporary = true; + device->allow_internal_profiles = + main_opts.default_allow_internal_profiles; device->db_id = gatt_db_register(device->db, gatt_service_added, gatt_service_removed, device, NULL); diff --git a/src/hcid.h b/src/hcid.h index c21ac9980..82ea0cb14 100644 --- a/src/hcid.h +++ b/src/hcid.h @@ -114,6 +114,8 @@ struct main_opts { uint8_t key_size; enum jw_repairing_t jw_repairing; + + gboolean default_allow_internal_profiles; }; extern struct main_opts main_opts; diff --git a/src/main.c b/src/main.c index bacb44197..30218f8d0 100644 --- a/src/main.c +++ b/src/main.c @@ -89,6 +89,7 @@ static const char *supported_options[] = { "FastConnectable", "Privacy", "JustWorksRepairing", + "DefaultAllowInternalProfiles", NULL }; @@ -615,6 +616,13 @@ static void parse_config(GKeyFile *config) else main_opts.fast_conn = boolean; + boolean = g_key_file_get_boolean(config, "General", + "DefaultAllowInternalProfiles", &err); + if (err) + g_clear_error(&err); + else + main_opts.default_allow_internal_profiles = boolean; + str = g_key_file_get_string(config, "GATT", "Cache", &err); if (err) { DBG("%s", err->message); @@ -691,6 +699,8 @@ static void init_defaults(void) main_opts.gatt_cache = BT_GATT_CACHE_ALWAYS; main_opts.gatt_mtu = BT_ATT_MAX_LE_MTU; main_opts.gatt_channels = 3; + + main_opts.default_allow_internal_profiles = true; } static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, diff --git a/src/main.conf b/src/main.conf index 6a6f7d4b4..497394395 100644 --- a/src/main.conf +++ b/src/main.conf @@ -77,6 +77,10 @@ # Defaults to "never" #JustWorksRepairing = never +# The default value of "AllowInternalProfiles" property in org.bluez.Device1 +# interface. Defaults to 'true'. +#DefaultAllowInternalProfiles = true + [Controller] # The following values are used to load default adapter parameters. BlueZ loads # the values into the kernel before the adapter is powered if the kernel From patchwork Mon Jul 13 20:14:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Sasaka X-Patchwork-Id: 11660999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 121AA13B1 for ; Mon, 13 Jul 2020 20:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBEF72075D for ; Mon, 13 Jul 2020 20:15:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="b/7kWF87" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726734AbgGMUPH (ORCPT ); Mon, 13 Jul 2020 16:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbgGMUPG (ORCPT ); Mon, 13 Jul 2020 16:15:06 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD936C061755 for ; Mon, 13 Jul 2020 13:15:06 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id x9so6011109plr.2 for ; Mon, 13 Jul 2020 13:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xuwheI+yFoySeDdqiX9Di5PWt7znOMhM8gXI0aBJuic=; b=b/7kWF87GiyV5+sodQkD2ZHy+FdJZqCkfuZaSd1uqlzgW7ml0CZ9XglUjlVXBnJMiK d0KFLvkPWxdD5R1SOQmMUisRAhke4dLNgeAvXeZgWDLV3NomZCsUB2hXNzruEvP7dpEa 9iPbpZCLzw9OxR8OrfL4ZKWxfPUgbWRPGmnLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xuwheI+yFoySeDdqiX9Di5PWt7znOMhM8gXI0aBJuic=; b=QimzKJ8tfkLkErcP0QVLk3PmrteXgKxJEmwt/D7sKUPI0c8HGo+yeBf0ECiY2S44+Y VGYIUL9U/Y+uRFF9VrXtkuCywfKQdEGXovzcepTaLEraZLctgzp+oVgG3mMMjdPivrx0 8soY+4PcmWiuY0M9rzuX9b2A33oKn6o27VFCvMcSpkxMDrmt3hluIo4H4grhru3gs07B iHbX+RKrzL1IdvQ6O7gFb+2JZwk5O1ChEi5VHvVroch8665VoYzI9qy1IfC8QFHtgyZg zltRsffTujcH3MkKKaeCEhtA1d49iQMvn+ZWK+ApGZVZB9WzCv6vy10EOeUfQlZBINCR A8xQ== X-Gm-Message-State: AOAM5308VlQj9O0Ar2hofcyxI1nlCuaGsL2LVSMtslz/J+Jp9zpNvrIY gcHho4HSPrUwJTTnqxaNhNaFXQ== X-Google-Smtp-Source: ABdhPJzFvaJiTeGC4CN3aVEEi1nv42e0gdZ8vE2aZ2MrS4fywWaBI9Oma5fj+MVBzF31gJIvfFVHLw== X-Received: by 2002:a17:90a:9d84:: with SMTP id k4mr1084380pjp.227.1594671306331; Mon, 13 Jul 2020 13:15:06 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id h18sm7866135pfr.186.2020.07.13.13.15.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jul 2020 13:15:05 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth-@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Alain Michaud Subject: [PATCH BlueZ 3/3] client: Add set-allow-internal-profiles command Date: Mon, 13 Jul 2020 13:14:41 -0700 Message-Id: <20200713201441.235959-4-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200713201441.235959-1-sonnysasaka@chromium.org> References: <20200713201441.235959-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Reviewed-by: Alain Michaud --- client/main.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/client/main.c b/client/main.c index 9abada69f..c2b6e21e4 100644 --- a/client/main.c +++ b/client/main.c @@ -1678,6 +1678,7 @@ static void cmd_info(int argc, char *argv[]) print_property(proxy, "Connected"); print_property(proxy, "WakeAllowed"); print_property(proxy, "LegacyPairing"); + print_property(proxy, "AllowInternalProfiles"); print_uuids(proxy); print_property(proxy, "Modalias"); print_property(proxy, "ManufacturerData"); @@ -1838,6 +1839,39 @@ static void cmd_unblock(int argc, char *argv[]) return bt_shell_noninteractive_quit(EXIT_FAILURE); } +static void cmd_set_allow_internal_profiles(int argc, char *argv[]) +{ + GDBusProxy *proxy; + dbus_bool_t allow_internal_profiles; + char *str; + + proxy = find_device(argc, argv); + if (!proxy) + return bt_shell_noninteractive_quit(EXIT_FAILURE); + + if (strcmp(argv[2], "true") != 0 && strcmp(argv[2], "false") != 0) { + bt_shell_printf("Invalid argument: %s\n", argv[2]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + allow_internal_profiles = strcmp(argv[2], "true") == 0 ? true : false; + + str = g_strdup_printf("%s allow internal profiles", + proxy_address(proxy)); + + if (g_dbus_proxy_set_property_basic(proxy, "AllowInternalProfiles", + DBUS_TYPE_BOOLEAN, + &allow_internal_profiles, + generic_callback, + str, + g_free) == TRUE) + return; + + g_free(str); + + return bt_shell_noninteractive_quit(EXIT_FAILURE); +} + static void remove_device_reply(DBusMessage *message, void *user_data) { DBusError error; @@ -2824,6 +2858,10 @@ static const struct bt_shell_menu main_menu = { dev_generator }, { "unblock", "[dev]", cmd_unblock, "Unblock device", dev_generator }, + { "set-allow-internal-profiles", " ", + cmd_set_allow_internal_profiles, + "Set allow internal profiles", + dev_generator }, { "remove", "", cmd_remove, "Remove device", dev_generator }, { "connect", "", cmd_connect, "Connect device",