Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1026942ybb; Wed, 8 Apr 2020 14:58:47 -0700 (PDT) X-Google-Smtp-Source: APiQypLpJHCJ60mQS6qqB5ieHJdAc+bdbw7l4ESfvrDiYLLbUTLcfzOuSmKxmuEOMkdHemm/bPPW X-Received: by 2002:aca:af4a:: with SMTP id y71mr755662oie.101.1586383126798; Wed, 08 Apr 2020 14:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586383126; cv=none; d=google.com; s=arc-20160816; b=eKgSZSfev+lyClzLwYMLVFr0WP+ale6dHS125t3OoYYMY5HQk2HfY5+jv+8N0xBw2P 3pbD5yOSUQQr2vD415Y/PUdGG/yRR4VveVKv1nR+GBxYb1ltxJmDfPU9j48oxnqc1GVA UkWU91zv6TxOmORW0ZUpX8yUgYJp8y9tg0Bn6HiO9KSkxUJnLcybEo/bTZXa6pMQx58x sX5CRIU12G9jnHnKcVB0bVYNOUI6C4zfuAEEbNGOtGRDOmlDnC6qeeLWLOI8IH3TgJhQ 5BCEx0VPkNSJ8qXja6v/CotmFtSBpVq6xB+olV0a/unjca6NjAumhggNgJimFlghxUUj ioPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dmoq1matlkF8+x8jlpWK2uxDi9B6sQ2NRp/AlEHi1sQ=; b=h1KamlHaThRWLeT4n5V35AglW7PJDZ9YtU+Nb/tULvXN7xML9Gl/OGdfDeMbqGV9Pm zq7UvgE32lP1d93Vdw9xtDRiIW/HU24uBXqK4XUBysr7bwNkLHL97a+uv8yck8FmOTWy cC0n1qis+/F0Qb4XHnA/QqDKQpxSpmATl3S9DUxhsECJfHK7vzEpClH7K2iNEqp3t+NM DJPMwJxj03GRDF4WCodmZ/6R1bhxy0lJtFwVBfaGtk3Fb5Vmiw4MzZLsV1+clOEDIyOw SzKt1XLf3M+6ilk7kzUCLXkzufP4kdMNrGQ84Yrpq7952nF6XZ/OdwoAC85UcRJ3KRGU Ie1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=UeC+3E6U; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si3144373otq.90.2020.04.08.14.58.35; Wed, 08 Apr 2020 14:58:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=UeC+3E6U; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729451AbgDHUxM (ORCPT + 99 others); Wed, 8 Apr 2020 16:53:12 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45823 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729388AbgDHUxL (ORCPT ); Wed, 8 Apr 2020 16:53:11 -0400 Received: by mail-lf1-f66.google.com with SMTP id f8so6202662lfe.12 for ; Wed, 08 Apr 2020 13:53:07 -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=UeC+3E6UBeXr3M9G+pHiYFpfGYAMkd5428xaJJHoxvwWAgMNZb2r4LHDQ+jdwve+97 DjJvb9C0PteWUOVG15exL/j1rgtaCeCLnj6Ts0OumitHzXKy+ptfOaaWjp/+f4woi1++ QxuwwQiXlCNKvj7BYpj+mr7SK0dljsg0U0qIkgkQkRfvJPl3oiUaAkvuifr4p/x3I6Di BTUyWPcQIM5xiaz6usXlUPlpyM0WL0APlaizGlk2UNSwtWNS/0yZ6PerLHg2YfSx2Igx KoLQtNf1B5MffwxbSfhI4YLFuAfwRxlppQo/dA/PC2eg5zkK6Vm2TjKO84tkqqFbQu4a vnTw== 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=DwcYe5diO870oJ8uLiUSFpkIiPo4ps1V7nmcs3Yx6Oa030Y494Vu0grYx0X9bl87hr D3HUQFZX5i83uhh2hlUypaLvU4G5twpxiQ8R82noEwoBj6+xhYlfnnsnTHsOywu67WsR 9ZebqcIygZ5ypbSPG4V7muNx2VrPBuSwf4vcTcQFXJAuqbiGR1tkucPMeDIyIa7fLGCp 2rStMUXpRfon/OnJUysPalb8R9r2H1xbWe+txGAM5nP/fsXeIBaD+XgYRpXJYfyNgarb YyFFYwAsvvGwhoR2SKJN4QpKmH6KLXNOIbl6y9FewJj8GA8mHjeNZGgSH7wR/1+Vf+XJ BrSA== X-Gm-Message-State: AGi0PuatF6N0dJuZqbTnqt0B0Isy0yHGcDntSaWcfxudUXjZDct9jkds NitCmAOlwZnRS0s5TsaIJ08pJ8K/SaY= X-Received: by 2002:ac2:58ee:: with SMTP id v14mr5320420lfo.25.1586379186802; Wed, 08 Apr 2020 13:53:06 -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 r24sm14168976ljn.25.2020.04.08.13.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 13:53:06 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: =?UTF-8?q?Przemys=C5=82aw=20Fierek?= Subject: [PATCH BlueZ 3/4] mesh: Change API to deliver tokens via JoinComplete Date: Wed, 8 Apr 2020 22:52:54 +0200 Message-Id: <20200408205255.45112-4-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200408205255.45112-1-michal.lowas-rzechonek@silvair.com> References: <20200408205255.45112-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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"); -- 2.26.0