From patchwork Thu Apr 9 19:47:30 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: 11482323 X-Patchwork-Delegate: brian.gix@gmail.com 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 19D5F81 for ; Thu, 9 Apr 2020 19:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE68F2082D for ; Thu, 9 Apr 2020 19:47:44 +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="uolOy8Fa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbgDITro (ORCPT ); Thu, 9 Apr 2020 15:47:44 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41218 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbgDITrn (ORCPT ); Thu, 9 Apr 2020 15:47:43 -0400 Received: by mail-lj1-f196.google.com with SMTP id n17so976082lji.8 for ; Thu, 09 Apr 2020 12:47:42 -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=bg5r2aE6Owh4lWMBQuidSHBU9dZmz8nf0T5rM6l2dLo=; b=uolOy8FakFx62tm/bMyKXYeALvKl8tiWRYlxoneVdebkqKa5wItoKQ0sGfhXFyplkW 1AD67AjDqmQR6J8O5Ox1HxvB/7UM05SNOqIezbrjDQv1scfGgBL1RrBNXGQyGaRVgfRh ylYQNBu4jqGA5Jm49MP902uJS1LywC+iVndgVYHSInphFmlISWijKJq7Z6NFgesdB7wP eDad2uIVsmfrxKmUS7ErYIAfu0iAG8c7x8z3oAf/waUeOL+BoZQSMCeDNqy1Wz/hGglS 6iwvPG9iajpyz/ISj5zNsCAy83zGQ4P//plHH61Y4DN5URAMhBtPMm1oqGlbL/SSkHxS Arkw== 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=bg5r2aE6Owh4lWMBQuidSHBU9dZmz8nf0T5rM6l2dLo=; b=RY2eoa7ZeJFDCk9R8OrWDDNiLIjKSa3jCaeJ+Uf4IVfer7jLInUMjRAxTIXn91Y1Pk xF8W1UsRbMAfGScwI4kAuRQ6dLvocdrv+DLb/dg+4PvlC2vX+TUNw0q4ZMV8L6/m/9hY 2trBMVIUYD/m3D6kg5aRjxzY+e38Q/3m7/RpIRlnPBjzWvdIqTgZnpDwMk8xtRgyon2F MFhjbGLsky2sFGC3+Ls7ZN4DS0eKeFA34EXsJ1AuQGPBy7cZt0TVmosp6vUsRzzd2cJE Pt3a5s6ovLMUsNho0iRj1z46FCp+fsGVLF+FqHrq954UI+mMmHm08xQTJD+LaqJsWEva VSaQ== X-Gm-Message-State: AGi0PuZ3+iXyUbu08vCgR/QQwYZufYEDF7EL0fWZmmzs9F8sSE890+bf 6b4FHCtpNoPEyUctzvxkm/nrwOgngbk= X-Google-Smtp-Source: APiQypJTVvEq+9+Ozy5iX4NdrRMAjTaV22mHb9lYB4ypH6FaV3/zA0saqWA3UNcNrCZhsdxU2AmdXg== X-Received: by 2002:a2e:9a87:: with SMTP id p7mr864312lji.61.1586461661748; Thu, 09 Apr 2020 12:47:41 -0700 (PDT) Received: from kynes.internet.domowy (apn-37-7-76-34.dynamic.gprs.plus.pl. [37.7.76.34]) by smtp.gmail.com with ESMTPSA id l13sm15915895ljc.84.2020.04.09.12.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 12:47:41 -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 v2 1/4] mesh: Fix invalid app_path on 'Join' Date: Thu, 9 Apr 2020 21:47:30 +0200 Message-Id: <20200409194733.18039-2-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200409194733.18039-1-michal.lowas-rzechonek@silvair.com> References: <20200409194733.18039-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 fixes invalid app_path on 'Join' method call - the daemon tried to use the value of app_root API argument, while it should use path discovered by scanning result of GetManagedObjects() call. --- mesh/mesh.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mesh/mesh.c b/mesh/mesh.c index 9b3768b69..a9d5d5dea 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -72,7 +72,6 @@ struct join_data{ struct l_dbus_message *msg; struct mesh_agent *agent; char *sender; - const char *app_path; struct mesh_node *node; uint32_t disc_watch; uint8_t *uuid; @@ -445,7 +444,7 @@ static bool prov_complete_cb(void *user_data, uint8_t status, return false; owner = join_pending->sender; - path = join_pending->app_path; + path = node_get_app_path(join_pending->node); if (status == PROV_ERR_SUCCESS && !node_add_pending_local(join_pending->node, info)) @@ -551,7 +550,6 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, join_pending->sender = l_strdup(sender); join_pending->msg = l_dbus_message_ref(msg); - join_pending->app_path = app_path; /* Try to create a temporary node */ node_join(app_path, sender, join_pending->uuid, node_init_cb); From patchwork Thu Apr 9 19:47:31 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: 11482325 X-Patchwork-Delegate: brian.gix@gmail.com 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 03C83912 for ; Thu, 9 Apr 2020 19:47:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8EC32084D for ; Thu, 9 Apr 2020 19:47:45 +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="vweZXeHI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726997AbgDITro (ORCPT ); Thu, 9 Apr 2020 15:47:44 -0400 Received: from mail-lf1-f48.google.com ([209.85.167.48]:37066 "EHLO mail-lf1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbgDITro (ORCPT ); Thu, 9 Apr 2020 15:47:44 -0400 Received: by mail-lf1-f48.google.com with SMTP id t11so589635lfe.4 for ; Thu, 09 Apr 2020 12:47:44 -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=wb2l5MlE5PDSa/vPETkuDpxKceTJxVH4B42sQMrryig=; b=vweZXeHIpH16A0A3BIkcv26TPnNQD0WY66G7gNruu2dJ1/NU8Ner7OAyUSbKQ8WebB cIg+KkF3z1nEVsYvekx5Mhyt+YVVGBJ56WQqLLOlq6iZU5hDIQujisv4hH/pbYO4MIeT luzV6vbVHYYw3LnPJlD90GEIXlp/ZjduaE2355C5936jQ7AB9PtNYbKNdjxJ30Swh83Q Lgd/EMFIv23nsjoLM+dMOOsFVjgxKoYocF+aiKpZ+irs08NZW3rI8EHsDfmiT9nbLCJh vBGtJa6Hdc4r5mw8qye66pUnDW8tBihBcSpKYmCLSqMRkEwpP8s05+pg4hmGf5Ms85/w MqSQ== 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=wb2l5MlE5PDSa/vPETkuDpxKceTJxVH4B42sQMrryig=; b=LOm6mwEO/V7wcLsdw0OblCc/PjExQfQit+LafvZeBJqBsJMJjh8b4e9Xihbhoxnsp2 9zsYsUXvYFLB6rUaz55LHxHW5oVPUyNFqYj5+rX5YNwbrDnKxGdyqzHnNgJpHipavgvZ TwUPETLXwnCtM8HlD8CYSoKZKAhSFBFGXywLAWT1Gr11SW6gzAyGbl3fbXv9DInzHTZy TlCbd6nUpE+BLFpIITiao2yQMHclb7CQ10iMPBEW205Hrp1/pVA0RFs9cq5MsH6M08h0 eydb7e2trRVFej10esBjachECkxExOL6LR4HvjU2HNNz78Vuvm+of2B3ph3dm4MOaTym /3vQ== X-Gm-Message-State: AGi0PubzlyjHXF1ve4bgPFkFoioRZpqDKErBMWLVBMj3UV1njTRMbwyS 300prWV31Mei70yFN1I8GWlGGd9dSE0= X-Google-Smtp-Source: APiQypKHmudys1OazyLaaEW+NTdfv/LtSESZhLo6dmqTG/RqyodXMj+WrWQdooYYZ9UcowINIsFzpw== X-Received: by 2002:a19:c64b:: with SMTP id w72mr549948lff.82.1586461663194; Thu, 09 Apr 2020 12:47:43 -0700 (PDT) Received: from kynes.internet.domowy (apn-37-7-76-34.dynamic.gprs.plus.pl. [37.7.76.34]) by smtp.gmail.com with ESMTPSA id l13sm15915895ljc.84.2020.04.09.12.47.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 12:47:42 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/4] doc/mesh: Change API to deliver tokens via JoinComplete Date: Thu, 9 Apr 2020 21:47:31 +0200 Message-Id: <20200409194733.18039-3-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200409194733.18039-1-michal.lowas-rzechonek@silvair.com> References: <20200409194733.18039-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 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt index c7374703b..08e34096d 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 @@ -155,11 +159,14 @@ Methods: unicast address (0x0001), and create and assign a net_key as the primary network net_index (0x000). + When creation finishes, the daemon will call JoinComplete method + on object implementing org.bluez.mesh.Application1 interface. + 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 +211,8 @@ 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. + When import finishes, the daemon will call JoinComplete method + on object implementing org.bluez.mesh.Application1 interface. PossibleErrors: org.bluez.mesh.Error.InvalidArguments, @@ -770,6 +774,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 Thu Apr 9 19:47:32 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: 11482327 X-Patchwork-Delegate: brian.gix@gmail.com 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 E1FD5912 for ; Thu, 9 Apr 2020 19:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C22B22082D for ; Thu, 9 Apr 2020 19:47:47 +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="J+BTQcLi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbgDITrq (ORCPT ); Thu, 9 Apr 2020 15:47:46 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46101 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725970AbgDITrq (ORCPT ); Thu, 9 Apr 2020 15:47:46 -0400 Received: by mail-lj1-f194.google.com with SMTP id r7so943761ljg.13 for ; Thu, 09 Apr 2020 12:47:45 -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=Dmoq1matlkF8+x8jlpWK2uxDi9B6sQ2NRp/AlEHi1sQ=; b=J+BTQcLihISDkbQJXV/aih0AEC/dMbJrjWejR5gdFSRXCZEs7WCgsuSQWth726uaF0 KAccMC5I1pquZgXBfjcbug0pRjLOXzPuNau30VsiByw/cD02CTLd2CGoNGKBfAohh8on twsmbYBnajOiRdkSLTCRrzvqtOxpHeNZb3zOkdxabJkqzpaKkfo6B8YqhdCP8ucz5wdC /tMz+U5PB5I17/fo8+so8llhhEvD3awzFmUAEIZ8/zH3sPSBNFuv8VXKOrpU3fDN65Er jPMR3OS4yrFTFpFlT5OMcKeB79cdXb+00gvpzgTc+2ESavEdEXkcvINW/bFhxFJEWIhR fQTA== 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=Dmoq1matlkF8+x8jlpWK2uxDi9B6sQ2NRp/AlEHi1sQ=; b=dPIKbRaEjpMZ3DsegIBmZkfGUylfW60uVXDX6ku1sAzvnrAdUnMe0deNKZ0sAtccil O9U2JfWim0pK/7t6o5cwickeh5Z65YaHpykT0EAv7Pd15GiWIM+JRJb43aATidSvYx5D j4YnYHAtA3wEd7fjLDO9E5VH566p2JR3Tafpx1dwCxE2bxVEGcFhDzdYiKsVuTV+XMpr jZzaiKTuN7zTCJWTr4ecAeCtR5ncp2Q4lSy4vj6ksBqNax+iU3eUprMtoQc+fnUjfXhI Kbkkvj1xheJt71zIT2Tt2D7KcsGM/xQPQ1qtY8CHN2ZlvJzWbSfu064wYhyxWygvR3pX srMw== X-Gm-Message-State: AGi0PuYIPyCon4by3ftfQzBdJk3tr05eSPlvCjYcn0S9g9t4GFpLVbQU nHQU07PegoR7a0kTQqUFrFEKuKUuLIg= X-Google-Smtp-Source: APiQypK16Rdx1flkdlpYpzrKdyGBRAV2GVqlpFI/KZqP3G7O6WXHKgHHm1AmvHU0FzmrG1updFKWdw== X-Received: by 2002:a2e:9e8f:: with SMTP id f15mr867028ljk.172.1586461664578; Thu, 09 Apr 2020 12:47:44 -0700 (PDT) Received: from kynes.internet.domowy (apn-37-7-76-34.dynamic.gprs.plus.pl. [37.7.76.34]) by smtp.gmail.com with ESMTPSA id l13sm15915895ljc.84.2020.04.09.12.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 12:47:44 -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 v2 3/4] mesh: Change API to deliver tokens via JoinComplete Date: Thu, 9 Apr 2020 21:47:32 +0200 Message-Id: <20200409194733.18039-4-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200409194733.18039-1-michal.lowas-rzechonek@silvair.com> References: <20200409194733.18039-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 | 63 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/mesh/mesh.c b/mesh/mesh.c index a9d5d5dea..6ffeb0c2b 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -429,6 +429,17 @@ 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 = l_dbus_message_is_error(message); + + 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) { @@ -455,7 +466,6 @@ 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); msg = l_dbus_message_new_method_call(dbus, owner, path, @@ -463,10 +473,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(dbus, msg); - - free_pending_join_call(false); + l_dbus_send_with_reply(dbus, msg, + prov_join_complete_reply_cb, NULL, NULL); return true; } @@ -660,11 +668,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 (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); @@ -673,20 +698,28 @@ 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)); + 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, @@ -840,11 +873,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 Thu Apr 9 19:47:33 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: 11482329 X-Patchwork-Delegate: brian.gix@gmail.com 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 6708F81 for ; Thu, 9 Apr 2020 19:47:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 467862074F for ; Thu, 9 Apr 2020 19:47:50 +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="ZHWxYUK3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726877AbgDITrt (ORCPT ); Thu, 9 Apr 2020 15:47:49 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:42438 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbgDITrt (ORCPT ); Thu, 9 Apr 2020 15:47:49 -0400 Received: by mail-lj1-f195.google.com with SMTP id q19so971836ljp.9 for ; Thu, 09 Apr 2020 12:47: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=f//NAxK7NVQLTDEd9r9V523X8NWIwjJbsxXRfwRbPxg=; b=ZHWxYUK39uU/dyfu/Z2V04FsoVQOI3NCWzyslqo3K9N5JFvbUPxqHD5ipq8yxXo/8M uwyCucbThnOaVYbV8Kv+7pSs7PG4r4PjMDtPcbIJYLOyZ3bi7aj56Vqs8N5dTCN9UKvB /HtCqODLBGmU9KKRG5Sq0CkBWWiR6tEARpjvvRoAvDdiMk1vd4HUUyQKQrPNw1LYfI7s x+PjyKSlxlGwPF6KesFHQkkNgdaPHHX4jdHQ9/3YPzuspwFL7N+SS3fVgFcnm+4BwIvl 2WqRWuRRF3lFmzNeWBScPg+51q7ci6i/ikC1GWXp5FrVVvAUyQEDmpq6czjMxje0NQ27 qCjw== 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=f//NAxK7NVQLTDEd9r9V523X8NWIwjJbsxXRfwRbPxg=; b=Mxv8jLUpTn1f1n9CoYyKo7BQ4WdF0Pyr7+YGy7HbL5AgCiGcb6fx+sCGQR/f5KukaV 3oHgjMcnYimr9HK5eXwUpPP3EP4RsfyvO4DJQm6kXwQLy5/l73OTKpjrAVjvzGxM3cwR QR8xEqcVgz0meLbSl8gnefJsqrhlGOtLX9xSZM0d2f6Ys+vUAvtD/dvACoBtrpXJxeSF l3d7rKPe4KOTMY+NYyYzTM8AgmGE9aESgxVty3P7okSaSxwxB+eaEApF4GJXzDhXr5yX eJ3lEHKGikJ9T1ciR9UFmfaKPKuDw5GWZXYYIOWj1LO97DMqix6KVAnTrAxCOXKdGmaa 3iEg== X-Gm-Message-State: AGi0PuaqEsJ/6dh0c/CnWYYWKaS5hEYPSJl8py2lXlwxB5u/8Tp+/r7f cKVUpCPg45OEFRFMQd6ctRJY8t+G0ko= X-Google-Smtp-Source: APiQypLvAYoKLJuxMYo6fQ4Qv4DuR/+5szCQyB5bMOsjbYcWMYc/pklpzHMq8HqYCPosH4aIj2xbgg== X-Received: by 2002:a2e:8195:: with SMTP id e21mr858581ljg.49.1586461665772; Thu, 09 Apr 2020 12:47:45 -0700 (PDT) Received: from kynes.internet.domowy (apn-37-7-76-34.dynamic.gprs.plus.pl. [37.7.76.34]) by smtp.gmail.com with ESMTPSA id l13sm15915895ljc.84.2020.04.09.12.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 12:47:45 -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 v2 4/4] tools/mesh-cfgclient: Add waiting for 'JoinComplete' Date: Thu, 9 Apr 2020 21:47:33 +0200 Message-Id: <20200409194733.18039-5-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200409194733.18039-1-michal.lowas-rzechonek@silvair.com> References: <20200409194733.18039-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 */ }