From patchwork Tue Apr 14 08:55:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 11487115 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 25C86174A for ; Tue, 14 Apr 2020 08:55:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D5F22072D for ; Tue, 14 Apr 2020 08:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="t4Ef3Yel" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437244AbgDNIzv (ORCPT ); Tue, 14 Apr 2020 04:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2437239AbgDNIzp (ORCPT ); Tue, 14 Apr 2020 04:55:45 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB00EC0A3BE2 for ; Tue, 14 Apr 2020 01:55:43 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id u13so12886035wrp.3 for ; Tue, 14 Apr 2020 01:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=L5GiMjQby01dqR0vl4XnhvCIDDKqRZfrlvKJr6NqcmM=; b=t4Ef3YelFAJV5/TnpyUnDWfuYqHKEs1fQpYeBuqubEmt/hZUBNurIPyHgjqYC0UuBg RA6W2XSJ7uAsdWIwXFEdPxcNPPV5bBfkuXlnQYeGC58lAjVw4IoeavuMQl5rJtwlpY2X sGvACcL3iM2X1PJg+5JjXR4j5a6iFvb8LwK5GTnlxxftXPY2BThRw8TQrIxTR/Re6soD W5ZIt18Wu/0x3kVkPgfY3ShG0gI3D9ojxZo5ofQFWZh6rX5JcPqxFjZSbenyegmJ9Fgk r/LsRd7lBMQBdybvvlfRkLUak59YqNVWPWWJI719Ko/ZfAiDRLQQE/+L2QrcWyGOay+3 mMcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L5GiMjQby01dqR0vl4XnhvCIDDKqRZfrlvKJr6NqcmM=; b=LWbsIdg+y5qchor1U+B+zGFNxBj58ugm40p/xe1qhL8YTBTcqbpPe7tOYcJP8AlS/H +PdYkb2FAE5gya+bWHpaKlQMHi6bQehX0e7C1vbIcbcU8wNfqRMxtIZzz7ms2xLG7mnz wInxUcDiZBgWUeu3aaMv/xKbE7gflLwB122Uc9ZG+huk1Mzv80ZiNuVjCN3h0Zqh7Auc rUmpQwrwkvWn5uf7jwZDdlL/qSPrqXEt8QUjXmB383aB5rPlVjKIH1K/cmJp2aSISFrI aaSFaFIsQyZQecNuv20GZtW2qQOtskHPp9ZFQy72epNEVMTGOM3OPX0wuRGJsddaQwpD qQfA== X-Gm-Message-State: AGi0Pub9G2fDv2WwE8Jagp+4nEIcBVbisZfyUPryxEAnZkZWWP2U7f5W 4bYg+X6LGmlGGUGiVo9Oeo9Qnl9olzs= X-Google-Smtp-Source: APiQypLY2OKsIsQnfQ+AGLf2idVF+j/ClFBvbFqutNUMy27dGMatF7hP4v9CyX68JELjrhjpmRjEEA== X-Received: by 2002:adf:cd8c:: with SMTP id q12mr24009725wrj.419.1586854542119; Tue, 14 Apr 2020 01:55:42 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id w83sm18361553wmb.37.2020.04.14.01.55.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 01:55:41 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v5 1/4] doc/mesh: Change API to deliver tokens via JoinComplete Date: Tue, 14 Apr 2020 10:55:54 +0200 Message-Id: <20200414085557.23464-2-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> References: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If Application is not be able to reliably store the token, the daemon will end up with a uncontrollable node in its database. Let's fix the issue by always delivering tokens using JoinComplete call, and expecting a reply - if the application return an error, daemon will get rid of the node. --- doc/mesh-api.txt | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt index c7374703b..e38b8d1eb 100644 --- a/doc/mesh-api.txt +++ b/doc/mesh-api.txt @@ -29,6 +29,10 @@ Methods: therefore attempting to call this function using already registered UUID results in an error. + When provisioning finishes, the daemon will call either + JoinComplete or JoinFailed method on object implementing + org.bluez.mesh.Application1 interface. + PossibleErrors: org.bluez.mesh.Error.InvalidArguments org.bluez.mesh.Error.AlreadyExists, @@ -123,7 +127,7 @@ Methods: PossibleErrors: org.bluez.mesh.Error.InvalidArguments - uint64 token CreateNetwork(object app_root, array{byte}[16] uuid) + void CreateNetwork(object app_root, array{byte}[16] uuid) This is the first method that an application calls to become a Provisioner node, and a Configuration Client on a newly @@ -144,22 +148,20 @@ Methods: therefore attempting to call this function using already registered UUID results in an error. - The returned token must be preserved by the application in - order to authenticate itself to the mesh daemon and attach to - the network as a mesh node by calling Attach() method or - permanently remove the identity of the mesh node by calling - Leave() method. - The other information the bluetooth-meshd daemon will preserve about the initial node, is to give it the initial primary unicast address (0x0001), and create and assign a net_key as the primary network net_index (0x000). + Upon successful processing of Create() method, the daemon + will call JoinComplete method on object implementing + org.bluez.mesh.Application1. + PossibleErrors: org.bluez.mesh.Error.InvalidArguments org.bluez.mesh.Error.AlreadyExists, - uint64 token Import(object app_root, array{byte}[16] uuid, + void Import(object app_root, array{byte}[16] uuid, array{byte}[16] dev_key, array{byte}[16] net_key, uint16 net_index, dict flags, uint32 iv_index, uint16 unicast) @@ -204,11 +206,9 @@ Methods: The unicast parameter is the primary unicast address of the imported node. - The returned token must be preserved by the application in - order to authenticate itself to the mesh daemon and attach to - the network as a mesh node by calling Attach() method or - permanently remove the identity of the mesh node by calling - Leave() method. + Upon successful processing of Import() method, the daemon will + call JoinComplete method on object implementing + org.bluez.mesh.Application1 interface. PossibleErrors: org.bluez.mesh.Error.InvalidArguments, @@ -770,6 +770,10 @@ Methods: permanently remove the identity of the mesh node by calling Leave() method. + If this method returns an error, the daemon will assume that the + application failed to preserve the token, and will remove the + freshly created node. + void JoinFailed(string reason) This method is called when the node provisioning initiated by From patchwork Tue Apr 14 08:55:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 11487113 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 748DD174A for ; Tue, 14 Apr 2020 08:55:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C5E02072D for ; Tue, 14 Apr 2020 08:55:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="Vv8//iXZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437245AbgDNIzu (ORCPT ); Tue, 14 Apr 2020 04:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2437240AbgDNIzq (ORCPT ); Tue, 14 Apr 2020 04:55:46 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD26DC008748 for ; Tue, 14 Apr 2020 01:55:44 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e26so12110029wmk.5 for ; Tue, 14 Apr 2020 01:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o+E8MAsU/VToF7MpC+vzMgQnq8ejVDOjf7uiE778Eyo=; b=Vv8//iXZb1dTLP7nhR8g73eLsbEC3YSbXIO0aizialkvv+12RGJpAc8NGuI2g11C7A 9NgWbxWh8QB45ife7hOl6PC+e10yycFMChb1Vv4gYEP7DJdnBFmteqXhc0QY6LbMnUHe IflJULVsuxAVeQWJUoCdzW6wU+yoDWIjOKh0e4GMnjq5ZNBlMBUXsL7bGLf7Wy1guKWk wJn3fvdQO8Gxx6Io2EjNLSCsLKKLZd+QNwZl6SQZ+7DmLRKCLvjUe5WCOOtlrzD9E4HS 3zVwIAbEJiN5rcHN+ZjXimgODnJPsJL3FT/k0+wNVBB97WDm8ihzS+drMqdb9moNbpv9 5RBA== 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=o+E8MAsU/VToF7MpC+vzMgQnq8ejVDOjf7uiE778Eyo=; b=UPhFdH9nmp3C+rBZofZJE/qE2rpks7yAX8E5tXeFFfTHKcqWL1haQtEVigcjq5Oqaq M8r5iDGxWpGGcIBH50psZmHz27OOUGE+Iw6HaP/gnF73mqy5jY6kbnI6Wtg/LDIO5sjM +tlasG2qmmz3hhrSSgiEpBXWaIzvCduFK8kdIeN/c68bEJn+X1RhwmzG1tAjPAFYxcbI rpWa5dS7PRLO8cSIZuZWWYC7j4FsvZeMHcDVHfIrGninYiPV2+NeVpxaFCXdrWCjeVTo aNzRXcTzG78/sVz/FPlPrH+bFbedRV6whsrM0/QWYcIsekgI8/VrgERHUXHCYFhqI6Z0 gkgQ== X-Gm-Message-State: AGi0Pubp3UhRVl1g2R+jbdDygXUpSu1pWdi6vp04djuns4xDY+1xgz6T a3OriRKmvFbA36GyzEJm8VMX1aRCbSk= X-Google-Smtp-Source: APiQypKUM3hfqc+1Oh3thbNMM4ySEAQSXWXWOeji+r15Znnw0JnNcsltUfZJBRfWAIyJNNweacTJbw== X-Received: by 2002:a1c:8106:: with SMTP id c6mr22272032wmd.88.1586854543200; Tue, 14 Apr 2020 01:55:43 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id w83sm18361553wmb.37.2020.04.14.01.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 01:55:42 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: =?utf-8?q?Przemys=C5=82aw_Fierek?= Subject: [PATCH BlueZ v5 2/4] mesh: Change API to deliver tokens via JoinComplete Date: Tue, 14 Apr 2020 10:55:55 +0200 Message-Id: <20200414085557.23464-3-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> References: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Przemysław Fierek This patch changes Import and CreateNetwork API to deliver tokens via the JoinComplete method call. When application doesn't raise any error during handling JoinComplete then it is assumed that the token has been saved, otherwise when application replies with an error message then the node is removed. --- mesh/mesh.c | 68 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/mesh/mesh.c b/mesh/mesh.c index 9b3768b69..01e39e916 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -430,6 +430,20 @@ 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, + void *user_data) +{ + bool failed = false; + + if (!message || l_dbus_message_is_error(message)) + failed = true; + + if (!failed) + node_attach_io(join_pending->node, mesh.io); + + free_pending_join_call(failed); +} + static bool prov_complete_cb(void *user_data, uint8_t status, struct mesh_prov_node_info *info) { @@ -456,18 +470,16 @@ static bool prov_complete_cb(void *user_data, uint8_t status, return false; } - node_attach_io(join_pending->node, mesh.io); token = node_get_token(join_pending->node); + l_debug("Calling JoinComplete (prov)"); msg = l_dbus_message_new_method_call(dbus, owner, path, MESH_APPLICATION_INTERFACE, "JoinComplete"); l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); - - l_dbus_send(dbus, msg); - - free_pending_join_call(false); + l_dbus_send_with_reply(dbus, msg, + prov_join_complete_reply_cb, NULL, NULL); return true; } @@ -662,11 +674,28 @@ 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, + void *user_data) +{ + struct mesh_node *node = user_data; + + if (!message || l_dbus_message_is_error(message)) { + node_remove(node); + return; + } + + node_attach_io(node, mesh.io); +} + static void create_node_ready_cb(void *user_data, int status, struct mesh_node *node) { + struct l_dbus *dbus = dbus_get_bus(); struct l_dbus_message *reply; struct l_dbus_message *pending_msg; + struct l_dbus_message *msg; + const char *owner; + const char *path; const uint8_t *token; pending_msg = l_queue_find(pending_queue, simple_match, user_data); @@ -675,20 +704,29 @@ static void create_node_ready_cb(void *user_data, int status, if (status != MESH_ERROR_NONE) { reply = dbus_error(pending_msg, status, NULL); - goto done; - } - node_attach_io(node, mesh.io); + l_dbus_send(dbus_get_bus(), reply); + l_queue_remove(pending_queue, pending_msg); + return; + } reply = l_dbus_message_new_method_return(pending_msg); + + l_dbus_send(dbus, reply); + l_queue_remove(pending_queue, pending_msg); + + owner = l_dbus_message_get_sender(pending_msg); + path = node_get_app_path(node); token = node_get_token(node); - l_debug(); - l_dbus_message_set_arguments(reply, "t", l_get_be64(token)); + l_debug("Calling JoinComplete (create)"); + msg = l_dbus_message_new_method_call(dbus, owner, path, + MESH_APPLICATION_INTERFACE, + "JoinComplete"); -done: - l_dbus_send(dbus_get_bus(), reply); - l_queue_remove(pending_queue, pending_msg); + l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); + l_dbus_send_with_reply(dbus, msg, + create_join_complete_reply_cb, node, NULL); } static struct l_dbus_message *create_network_call(struct l_dbus *dbus, @@ -842,11 +880,11 @@ static void setup_network_interface(struct l_dbus_interface *iface) "token"); l_dbus_interface_method(iface, "CreateNetwork", 0, create_network_call, - "t", "oay", "token", "app", "uuid"); + "", "oay", "app", "uuid"); l_dbus_interface_method(iface, "Import", 0, import_call, - "t", "oayayayqa{sv}uq", "token", + "", "oayayayqa{sv}uq", "app", "uuid", "dev_key", "net_key", "net_index", "flags", "iv_index", "unicast"); From patchwork Tue Apr 14 08:55:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 11487117 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 1B631112C for ; Tue, 14 Apr 2020 08:55:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02C3C2074D for ; Tue, 14 Apr 2020 08:55:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="g5CdbYab" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437246AbgDNIzw (ORCPT ); Tue, 14 Apr 2020 04:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2437241AbgDNIzq (ORCPT ); Tue, 14 Apr 2020 04:55:46 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120F6C008749 for ; Tue, 14 Apr 2020 01:55:46 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id x4so12119169wmj.1 for ; Tue, 14 Apr 2020 01:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WYw83xQZWPThAtROU1oga8r97ZB97JOahIrkX+lwcrw=; b=g5CdbYabWHDPDzbLX/KIqGC+4iWYugLaR0E+5no8fMdeCHL9UfOHPqBv8ZFVPP6UD2 POo5AdlmmaTqNioQ5KFQhiK+S246EVrPLQb1IPuRRVzkbvYOJe1F2A8V6uXK6XI6IYe4 v3Tl5HKWtOaGRuxDilTFRM4xYedOvFHBRfVbYcuMNzvIJ5NFtcd7p3J6FsnghrYVX5CG c8cyFK+oARpU1RzCAI0TIajc63PVhJtn/FPvcki9OWm7/uKatnRxvDBaEZ2RoSOewu9f j7XN6GGNRy/CE76o8dvLIr7fUtGWnocYbg6rtD0GSxApi8/UN8Ahjbqv/T08YWdCUV5O Tumw== 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=WYw83xQZWPThAtROU1oga8r97ZB97JOahIrkX+lwcrw=; b=WLWh/qA+txalY5f2xIBVg0nxaMgSeAKyLa5RnJAZH4b9XQ1ZnBvXUbvawIIwvYcyNr 8aDMzRg5UbJI19cl5CnPKh0h/OAPTHCa21nngKNfudCn4UTvXlHBaGYhT/2ue504Bv9l yhaKpD84I1UPYqEILGGdjqx5PnGHjMbxS8o352FuhYEJ8Gwfu2AUiTbLZQ1kfdxDhFSC NZrjDGWPbG4WzALF8E6KnbT8speKoCQXd/PXVpFr5HTzP2Pa6TUVjzfvCOYEdtlFvaLs eMhYs9obMzGWVUzeGVxH/U1WK/reaOStba6bNzL8DHs54FElonGJ5sQlvbrxX/hA6Gez +QZQ== X-Gm-Message-State: AGi0Pua/NB1KuLeKgwN56IVwTVKb8NLo25EpU6wzhF8pDv3s+K0T8jfj o8kLAytfl07Zez2yJAbqa31baiiQJO8= X-Google-Smtp-Source: APiQypIQ3mpGTqvECB3o5fJni4zf8cMrn2iwHMNdYPVXbpdrqPpK9qfQgwmIE/wRNra9m6mEscDWsQ== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr21383196wmj.125.1586854544349; Tue, 14 Apr 2020 01:55:44 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id w83sm18361553wmb.37.2020.04.14.01.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 01:55:43 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: =?utf-8?q?Przemys=C5=82aw_Fierek?= Subject: [PATCH BlueZ v5 3/4] tools/mesh-cfgclient: Add waiting for 'JoinComplete' Date: Tue, 14 Apr 2020 10:55:56 +0200 Message-Id: <20200414085557.23464-4-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> References: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Przemysław Fierek --- tools/mesh-cfgclient.c | 78 +++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c index 5b018eb4a..6db65cd49 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -707,44 +707,13 @@ static void attach_node_setup(struct l_dbus_message *msg, void *user_data) static void create_net_reply(struct l_dbus_proxy *proxy, struct l_dbus_message *msg, void *user_data) { - char *str; - uint64_t tmp; - if (l_dbus_message_is_error(msg)) { const char *name; l_dbus_message_get_error(msg, &name, NULL); l_error("Failed to create network: %s", name); return; - - } - - if (!l_dbus_message_get_arguments(msg, "t", &tmp)) - return; - - local = l_new(struct meshcfg_node, 1); - local->token.u64 = l_get_be64(&tmp); - str = l_util_hexstring(&local->token.u8[0], 8); - bt_shell_printf("Created new node with token %s\n", str); - l_free(str); - - if (!mesh_db_create(cfg_fname, local->token.u8, - "Mesh Config Client Network")) { - l_free(local); - local = NULL; - return; } - - mesh_db_set_addr_range(low_addr, high_addr); - keys_add_net_key(PRIMARY_NET_IDX); - mesh_db_net_key_add(PRIMARY_NET_IDX); - - remote_add_node(app.uuid, 0x0001, 1, PRIMARY_NET_IDX); - mesh_db_add_node(app.uuid, 0x0001, 1, PRIMARY_NET_IDX); - - l_dbus_proxy_method_call(net_proxy, "Attach", attach_node_setup, - attach_node_reply, NULL, - NULL); } static void create_net_setup(struct l_dbus_message *msg, void *user_data) @@ -1727,7 +1696,7 @@ static struct l_dbus_message *add_node_fail_call(struct l_dbus *dbus, static void setup_prov_iface(struct l_dbus_interface *iface) { l_dbus_interface_method(iface, "ScanResult", 0, scan_result_call, "", - "naya{sv}", "rssi", "data", "options"); + "naya{sv}", "rssi", "data", "options"); l_dbus_interface_method(iface, "RequestProvData", 0, req_prov_call, "qq", "y", "net_index", "unicast", "count"); @@ -1779,6 +1748,48 @@ static bool crpl_getter(struct l_dbus *dbus, return true; } +static void attach_node(void *user_data) +{ + l_dbus_proxy_method_call(net_proxy, "Attach", attach_node_setup, + attach_node_reply, NULL, + NULL); +} + +static struct l_dbus_message *join_complete(struct l_dbus *dbus, + struct l_dbus_message *message, + void *user_data) +{ + char *str; + uint64_t tmp; + + if (!l_dbus_message_get_arguments(message, "t", &tmp)) + return l_dbus_message_new_error(message, dbus_err_args, NULL); + + local = l_new(struct meshcfg_node, 1); + local->token.u64 = l_get_be64(&tmp); + str = l_util_hexstring(&local->token.u8[0], 8); + bt_shell_printf("Created new node with token %s\n", str); + l_free(str); + + if (!mesh_db_create(cfg_fname, local->token.u8, + "Mesh Config Client Network")) { + l_free(local); + local = NULL; + return l_dbus_message_new_error(message, dbus_err_fail, NULL); + } + + mesh_db_set_addr_range(low_addr, high_addr); + keys_add_net_key(PRIMARY_NET_IDX); + mesh_db_net_key_add(PRIMARY_NET_IDX); + + remote_add_node(app.uuid, 0x0001, 1, PRIMARY_NET_IDX); + mesh_db_add_node(app.uuid, 0x0001, 1, PRIMARY_NET_IDX); + + l_idle_oneshot(attach_node, NULL, NULL); + + return l_dbus_message_new_method_return(message); +} + static void setup_app_iface(struct l_dbus_interface *iface) { l_dbus_interface_property(iface, "CompanyID", 0, "q", cid_getter, @@ -1789,6 +1800,9 @@ static void setup_app_iface(struct l_dbus_interface *iface) NULL); l_dbus_interface_property(iface, "CRPL", 0, "q", crpl_getter, NULL); + l_dbus_interface_method(iface, "JoinComplete", 0, join_complete, + "", "t", "token"); + /* TODO: Methods */ } From patchwork Tue Apr 14 08:55:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 11487119 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 B1625186E for ; Tue, 14 Apr 2020 08:55:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A0802074D for ; Tue, 14 Apr 2020 08:55:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="IzhGtzvb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437247AbgDNIzw (ORCPT ); Tue, 14 Apr 2020 04:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2437242AbgDNIzr (ORCPT ); Tue, 14 Apr 2020 04:55:47 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFCFFC008769 for ; Tue, 14 Apr 2020 01:55:46 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id x18so9079834wrq.2 for ; Tue, 14 Apr 2020 01:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1vJvsZdK9Zte0jn8KQyvh97y2PKBP0yP5HpQaCPeJ7g=; b=IzhGtzvb+v5xTtbf2GhcWg73YVCvNaiQQJ4rPxfZW+1TMBsNA+casulg/kUJzzqrTi aeSdZIjd4gZF59w4R+5gpt5Lc5hDBB7kCfQaU7IF0y1gwyu3PJTrEtKaXAslV1V0NKkz /0Sc9APzYgjCKVNQ7j/y5OLlcvuhoCgnkcsjpLPzS645LIwQMyerhyifRDY0l92CB2os m4bUTBKm4Vjv++OVfeK37PlLh9k2548huKjJgYY8RL9Jjk7fI8C5prWjE+JWLZJtez6i u7sjcCzR4Ou5DYNC9TB1s9o1Z00kzBC6w117GLAHv2HeqCd8Yxcy5rC3lLL/Op4T86fc dZ3Q== 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=1vJvsZdK9Zte0jn8KQyvh97y2PKBP0yP5HpQaCPeJ7g=; b=ewpKNUhOGlCibMGesXHJ6aMm1nTx7Ke2zzuU6Ym3//2Y8VylQ585OtD5V4zjW3gzZ4 l55mgDrJQawWOR7wJ398mpwmBv2YgoSN/Jbd/c/1D6XYllYqazELQe9IBMxeMnBXh5TD ZATC+f6ZSnwVJCzG6Q1tXhkMgJ4pHqn+wOnisrEg/YENC6OeSEOLsYDaqOa9Rwpxk9cs 4k9eGsEeolNLBmOkLOKs9U9k0BgagWoY/Dr4fy+MBK2xhiFirJXwuG2mHZtIdUsviED6 wGvGFRgrEJE+AzA58wR99G3zK4ksr5nwosO7WDr4MNVbQeWUs6VYu/9ILLFE7srSqisl lIlw== X-Gm-Message-State: AGi0Pua3VnrhZKB4nBApvixwKk7KkTQfc6r5qiE9VxMfUMoAJBawCvS4 Nl1UY4gfk3VbYPjZ6JrP9aUKJjMeQno= X-Google-Smtp-Source: APiQypIi/d1Ny+uaF2GVoosCR+5a0xmFlmljyKWuUHetngZzDRNdRMNHEfkcBe9v5l2RofkG+Qo7pQ== X-Received: by 2002:a05:6000:8f:: with SMTP id m15mr19574914wrx.19.1586854545363; Tue, 14 Apr 2020 01:55:45 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id w83sm18361553wmb.37.2020.04.14.01.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 01:55:44 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: Brian Gix Subject: [PATCH BlueZ v5 4/4] mesh: Add Time-outs to critical dbus send-with-replies Date: Tue, 14 Apr 2020 10:55:57 +0200 Message-Id: <20200414085557.23464-5-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> References: <20200414085557.23464-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Brian Gix JoinComplete() dbus method calls are the only time that node tokens are delivered to client Applications, so if the call fails for any reason (including time-outs) the daemon has a way to clean-up the stale unused node data. --- mesh/dbus.c | 40 ++++++++++++++++++++++++++++++++++++++++ mesh/dbus.h | 6 ++++++ mesh/mesh.c | 8 ++++---- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mesh/dbus.c b/mesh/dbus.c index 6b9694ab7..bf0f73bd9 100644 --- a/mesh/dbus.c +++ b/mesh/dbus.c @@ -37,6 +37,14 @@ struct error_entry { const char *default_desc; }; +struct send_info { + struct l_dbus *dbus; + struct l_timeout *timeout; + l_dbus_message_func_t cb; + void *user_data; + uint32_t serial; +}; + /* * Important: The entries in this table follow the order of * enumerated values in mesh_error (file error.h) @@ -143,3 +151,35 @@ void dbus_append_dict_entry_basic(struct l_dbus_message_builder *builder, l_dbus_message_builder_leave_variant(builder); l_dbus_message_builder_leave_dict(builder); } + +static void send_reply(struct l_dbus_message *message, void *user_data) +{ + struct send_info *info = user_data; + + l_timeout_remove(info->timeout); + info->cb(message, info->user_data); + l_free(info); +} + +static void send_timeout(struct l_timeout *timeout, void *user_data) +{ + struct send_info *info = user_data; + + l_dbus_cancel(info->dbus, info->serial); + send_reply(NULL, info); +} + +void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, + l_dbus_message_func_t cb, + void *user_data, + unsigned int seconds) +{ + struct send_info *info = l_new(struct send_info, 1); + + info->dbus = dbus; + info->cb = cb; + info->user_data = user_data; + 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 e7643a59d..aafb85f6b 100644 --- a/mesh/dbus.h +++ b/mesh/dbus.h @@ -20,6 +20,8 @@ #define BLUEZ_MESH_PATH "/org/bluez/mesh" #define BLUEZ_MESH_SERVICE "org.bluez.mesh" +#define DEFAULT_DBUS_TIMEOUT 30 + bool dbus_init(struct l_dbus *dbus); struct l_dbus *dbus_get_bus(void); void dbus_append_byte_array(struct l_dbus_message_builder *builder, @@ -31,3 +33,7 @@ bool dbus_match_interface(struct l_dbus_message_iter *interfaces, const char *match); struct l_dbus_message *dbus_error(struct l_dbus_message *msg, int err, const char *description); +void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, + l_dbus_message_func_t cb, + void *user_data, + unsigned int seconds); diff --git a/mesh/mesh.c b/mesh/mesh.c index 01e39e916..21e1517db 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -478,8 +478,8 @@ static bool prov_complete_cb(void *user_data, uint8_t status, "JoinComplete"); l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); - l_dbus_send_with_reply(dbus, msg, - prov_join_complete_reply_cb, NULL, NULL); + dbus_send_with_timeout(dbus, msg, prov_join_complete_reply_cb, + NULL, DEFAULT_DBUS_TIMEOUT); return true; } @@ -725,8 +725,8 @@ static void create_node_ready_cb(void *user_data, int status, "JoinComplete"); l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); - l_dbus_send_with_reply(dbus, msg, - create_join_complete_reply_cb, node, NULL); + dbus_send_with_timeout(dbus, msg, create_join_complete_reply_cb, + node, DEFAULT_DBUS_TIMEOUT); } static struct l_dbus_message *create_network_call(struct l_dbus *dbus,