From patchwork Wed Jun 10 17:11:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 196904 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=-6.8 required=3.0 tests=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 B9CABC433E0 for ; Wed, 10 Jun 2020 17:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96C4E2072E for ; Wed, 10 Jun 2020 17:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729374AbgFJRLZ (ORCPT ); Wed, 10 Jun 2020 13:11:25 -0400 Received: from mga07.intel.com ([134.134.136.100]:8721 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgFJRLZ (ORCPT ); Wed, 10 Jun 2020 13:11:25 -0400 IronPort-SDR: r21OQpim6oAdAs3Nr2hNDTJ8GZM8dmWq9NDpc5QLQsUWBy2umvjs2DLE9+iIQBVEffmTXgFJYt vvreAO8KE7DQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 10:11:23 -0700 IronPort-SDR: viRrnd2uNKODHgkTOIAhImwEP8n3PvNoZ5N6NqfFUYBheml73SGjg8ugo6x6/5Q+DMRRZN4ylA mEY6uGenEyog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,496,1583222400"; d="scan'208";a="259340080" Received: from unknown (HELO ingas-nuc1.sea.intel.com) ([10.254.72.48]) by fmsmga007.fm.intel.com with ESMTP; 10 Jun 2020 10:11:23 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v3 1/5] mesh: Delete unused function Date: Wed, 10 Jun 2020 10:11:17 -0700 Message-Id: <20200610171121.46910-2-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610171121.46910-1-inga.stotland@intel.com> References: <20200610171121.46910-1-inga.stotland@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This deletes unused function node_is_provisioned() --- mesh/node.c | 5 ----- mesh/node.h | 1 - 2 files changed, 6 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index db888d27c..d1d4da23d 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -598,11 +598,6 @@ bool node_is_provisioner(struct mesh_node *node) return node->provisioner; } -bool node_is_provisioned(struct mesh_node *node) -{ - return (!IS_UNASSIGNED(node->primary)); -} - void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, uint16_t app_idx) { diff --git a/mesh/node.h b/mesh/node.h index 290681e28..e26d410c8 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -39,7 +39,6 @@ struct mesh_node *node_find_by_addr(uint16_t addr); struct mesh_node *node_find_by_uuid(uint8_t uuid[16]); struct mesh_node *node_find_by_token(uint64_t token); bool node_is_provisioner(struct mesh_node *node); -bool node_is_provisioned(struct mesh_node *node); void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, uint16_t app_idx); uint16_t node_get_primary(struct mesh_node *node); From patchwork Wed Jun 10 17:11:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 196903 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=-6.8 required=3.0 tests=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 351A3C433E1 for ; Wed, 10 Jun 2020 17:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F3B92070B for ; Wed, 10 Jun 2020 17:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729382AbgFJRL0 (ORCPT ); Wed, 10 Jun 2020 13:11:26 -0400 Received: from mga07.intel.com ([134.134.136.100]:8723 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgFJRLZ (ORCPT ); Wed, 10 Jun 2020 13:11:25 -0400 IronPort-SDR: sHSRkSjSFqYmLe8ES1bkhluyw8BYPaZbNNmPFFGVdN6uI1haSpFHeKRl22GbIZ0xJcSCz9G3xv Cbb9t0/JZAQA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 10:11:25 -0700 IronPort-SDR: wOdWSP3UMArk/PNUhPDZZQjF+dRu2vNeWU9dpGA1t+VfiUjKuBNCY1Q9jgz5ZqF+aPEKVCDyLk moP149IUME2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,496,1583222400"; d="scan'208";a="259340090" Received: from unknown (HELO ingas-nuc1.sea.intel.com) ([10.254.72.48]) by fmsmga007.fm.intel.com with ESMTP; 10 Jun 2020 10:11:24 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v3 3/5] mesh: Add destroy callback to dbus_send_with_timeout() Date: Wed, 10 Jun 2020 10:11:19 -0700 Message-Id: <20200610171121.46910-4-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610171121.46910-1-inga.stotland@intel.com> References: <20200610171121.46910-1-inga.stotland@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds a destroy callback as a function parameter to dbus_send_with_timeout() to allow automatic release of user data on either reply or timeout. --- mesh/dbus.c | 7 +++++++ mesh/dbus.h | 1 + mesh/mesh.c | 12 ++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mesh/dbus.c b/mesh/dbus.c index 83ae22c9f..63ea420ed 100644 --- a/mesh/dbus.c +++ b/mesh/dbus.c @@ -41,6 +41,7 @@ struct send_info { struct l_dbus *dbus; struct l_timeout *timeout; l_dbus_message_func_t cb; + l_dbus_destroy_func_t destroy; void *user_data; uint32_t serial; }; @@ -159,6 +160,10 @@ static void send_reply(struct l_dbus_message *message, void *user_data) l_timeout_remove(info->timeout); info->cb(message, info->user_data); + + if (info->destroy) + info->destroy(info->user_data); + l_free(info); } @@ -173,6 +178,7 @@ static void send_timeout(struct l_timeout *timeout, void *user_data) void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, l_dbus_message_func_t cb, void *user_data, + l_dbus_destroy_func_t destroy, unsigned int seconds) { struct send_info *info = l_new(struct send_info, 1); @@ -180,6 +186,7 @@ void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, info->dbus = dbus; info->cb = cb; info->user_data = user_data; + info->destroy = destroy; info->serial = l_dbus_send_with_reply(dbus, msg, send_reply, info, NULL); info->timeout = l_timeout_create(seconds, send_timeout, info, NULL); diff --git a/mesh/dbus.h b/mesh/dbus.h index aafb85f6b..89d6b1d31 100644 --- a/mesh/dbus.h +++ b/mesh/dbus.h @@ -36,4 +36,5 @@ struct l_dbus_message *dbus_error(struct l_dbus_message *msg, int err, void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, l_dbus_message_func_t cb, void *user_data, + l_dbus_destroy_func_t destroy, unsigned int seconds); diff --git a/mesh/mesh.c b/mesh/mesh.c index 24ea3afd6..a5935c216 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -439,12 +439,12 @@ static void send_join_failed(const char *owner, const char *path, free_pending_join_call(true); } -static void prov_join_complete_reply_cb(struct l_dbus_message *message, +static void prov_join_complete_reply_cb(struct l_dbus_message *msg, void *user_data) { bool failed = false; - if (!message || l_dbus_message_is_error(message)) + if (!msg || l_dbus_message_is_error(msg)) failed = true; if (!failed) @@ -488,7 +488,7 @@ static bool prov_complete_cb(void *user_data, uint8_t status, l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); dbus_send_with_timeout(dbus, msg, prov_join_complete_reply_cb, - NULL, DEFAULT_DBUS_TIMEOUT); + NULL, NULL, DEFAULT_DBUS_TIMEOUT); return true; } @@ -666,12 +666,12 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, return l_dbus_message_new_method_return(msg); } -static void create_join_complete_reply_cb(struct l_dbus_message *message, +static void create_join_complete_reply_cb(struct l_dbus_message *msg, void *user_data) { struct mesh_node *node = user_data; - if (!message || l_dbus_message_is_error(message)) { + if (!msg || l_dbus_message_is_error(msg)) { node_remove(node); return; } @@ -716,7 +716,7 @@ static void create_node_ready_cb(void *user_data, int status, l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); dbus_send_with_timeout(dbus, msg, create_join_complete_reply_cb, - node, DEFAULT_DBUS_TIMEOUT); + node, NULL, DEFAULT_DBUS_TIMEOUT); l_dbus_message_unref(pending_msg); } From patchwork Wed Jun 10 17:11:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 196902 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=-6.8 required=3.0 tests=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 462A3C433E0 for ; Wed, 10 Jun 2020 17:11:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F0C92072F for ; Wed, 10 Jun 2020 17:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729386AbgFJRL2 (ORCPT ); Wed, 10 Jun 2020 13:11:28 -0400 Received: from mga07.intel.com ([134.134.136.100]:8724 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgFJRL1 (ORCPT ); Wed, 10 Jun 2020 13:11:27 -0400 IronPort-SDR: k+5nyZ/qX5bvELHShrO1V6SCJAyTWisXINItqEzpVAikT70cwbgHcou2NXGNodgv9q8ICVQTvr mSLP2AI1R64w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2020 10:11:26 -0700 IronPort-SDR: Ezk+q8plssWNUv/u0qTTBUjHnpBD2fdzZvjYeWU9n0EPTBItXMHx0V28wE60pGqCdza8A853OJ R+m8W0oweJQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,496,1583222400"; d="scan'208";a="259340103" Received: from unknown (HELO ingas-nuc1.sea.intel.com) ([10.254.72.48]) by fmsmga007.fm.intel.com with ESMTP; 10 Jun 2020 10:11:26 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v3 5/5] mesh: Add "node is busy" check for Leave() & Attach() Date: Wed, 10 Jun 2020 10:11:21 -0700 Message-Id: <20200610171121.46910-6-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610171121.46910-1-inga.stotland@intel.com> References: <20200610171121.46910-1-inga.stotland@intel.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This introduces the following behavior change for those methods on Network interface that specify node token as an input parameter Leave() method: If Leave method is called for a node that is being processed as a result of a Create, Import, Join or Attach method calls in progress, node removal is not allowed and org.bluez.mesh.Error.Busy error is returned. Attach() method: If Attach method is called for a node that is being processed as a result of a Create, Import or Join method calls in progress, node attachment is not allowed and org.bluez.mesh.Error.Busy error is returned. --- doc/mesh-api.txt | 3 +++ mesh/mesh.c | 10 +++++++++- mesh/node.c | 21 +++++++++++++++++++++ mesh/node.h | 1 + test/test-mesh | 2 -- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt index e85f0bf52..4bef6174c 100644 --- a/doc/mesh-api.txt +++ b/doc/mesh-api.txt @@ -116,6 +116,7 @@ Methods: org.bluez.mesh.Error.InvalidArguments org.bluez.mesh.Error.NotFound, org.bluez.mesh.Error.AlreadyExists, + org.bluez.mesh.Error.Busy, org.bluez.mesh.Error.Failed void Leave(uint64 token) @@ -126,6 +127,8 @@ Methods: PossibleErrors: org.bluez.mesh.Error.InvalidArguments + org.bluez.mesh.Error.NotFound + org.bluez.mesh.Error.Busy void CreateNetwork(object app_root, array{byte}[16] uuid) diff --git a/mesh/mesh.c b/mesh/mesh.c index a5935c216..c8767ee7a 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -655,13 +655,21 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, void *user_data) { uint64_t token; + struct mesh_node *node; l_debug("Leave"); if (!l_dbus_message_get_arguments(msg, "t", &token)) return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); - node_remove(node_find_by_token(token)); + node = node_find_by_token(token); + if (!node) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL); + + if (node_is_busy(node)) + return dbus_error(msg, MESH_ERROR_BUSY, NULL); + + node_remove(node); return l_dbus_message_new_method_return(msg); } diff --git a/mesh/node.c b/mesh/node.c index 7ec06437b..567f2e6db 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -88,6 +88,7 @@ struct mesh_node { char *storage_dir; uint32_t disc_watch; uint32_t seq_number; + bool busy; bool provisioner; uint16_t primary; struct node_composition comp; @@ -598,6 +599,11 @@ bool node_is_provisioner(struct mesh_node *node) return node->provisioner; } +bool node_is_busy(struct mesh_node *node) +{ + return node->busy; +} + void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, uint16_t app_idx) { @@ -1352,6 +1358,8 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr, /* Initialize configuration server model */ cfgmod_server_init(node, PRIMARY_ELE_IDX); + node->busy = true; + return true; } @@ -1459,6 +1467,9 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) struct keyring_net_key net_key; uint8_t dev_key[16]; + if (req->type == REQUEST_TYPE_ATTACH) + req->attach->busy = false; + if (!msg || l_dbus_message_is_error(msg)) { l_error("Failed to get app's dbus objects"); goto fail; @@ -1654,6 +1665,12 @@ void node_attach(const char *app_root, const char *sender, uint64_t token, return; } + /* Check if there is a pending request associated with this node */ + if (node->busy) { + cb(user_data, MESH_ERROR_BUSY, NULL); + return; + } + /* Check if the node is already in use */ if (node->owner) { l_warn("The node is already in use"); @@ -1674,6 +1691,8 @@ void node_attach(const char *app_root, const char *sender, uint64_t token, req->attach = node; req->type = REQUEST_TYPE_ATTACH; + node->busy = true; + send_managed_objects_request(sender, app_root, req); } @@ -2347,6 +2366,8 @@ void node_finalize_new_node(struct mesh_node *node, struct mesh_io *io) free_node_dbus_resources(node); mesh_agent_remove(node->agent); + node->busy = false; + /* Register callback for the node's io */ attach_io(node, io); } diff --git a/mesh/node.h b/mesh/node.h index e26d410c8..b8b2b1b49 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -39,6 +39,7 @@ struct mesh_node *node_find_by_addr(uint16_t addr); struct mesh_node *node_find_by_uuid(uint8_t uuid[16]); struct mesh_node *node_find_by_token(uint64_t token); bool node_is_provisioner(struct mesh_node *node); +bool node_is_busy(struct mesh_node *node); void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, uint16_t app_idx); uint16_t node_get_primary(struct mesh_node *node); diff --git a/test/test-mesh b/test/test-mesh index 38f0c0a74..7c8a25482 100755 --- a/test/test-mesh +++ b/test/test-mesh @@ -412,8 +412,6 @@ class Application(dbus.service.Object): token = value have_token = True - if attached == False: - attach(token) @dbus.service.method(MESH_APPLICATION_IFACE, in_signature="s", out_signature="")