Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2648408ybt; Tue, 16 Jun 2020 11:15:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtB2aRTKNWw+melDbb1OSJqe0VId/IGs9JJA+Pfz8kKf+6ndnm2MRRvUhN8MaGpvfK1jbI X-Received: by 2002:a17:907:20cf:: with SMTP id qq15mr3901929ejb.238.1592331314934; Tue, 16 Jun 2020 11:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592331314; cv=none; d=google.com; s=arc-20160816; b=SYHBDVuN/rZe2DWbIUVhH6LJG/TSptiSxeONH+AGhl2GB/P8X0OoxUiTELTrI7nhVK le8CXdJNF4We6yaFiMbG8dDKDds+jt+Fx0aQIvmH5+OK+UqF+HE9LDPXg52c1u3tBs0h o0+zLXuytZduLC3X90eE9me2oN4hVliNi6Gi8o791dWS5r6OM2PfACZR5eO5ZCwFN+IE 9FtApXBrXl3TIFtu8FgmGRzmIz8IOEK4tOj4rf8z+Xpcy96N9ZJ5Qy+k+DeXeuY3EA4M r6tfP1ZDTnT2NI8W8msdxgVDBqtnviAcaRkP4ZQTAgWaA7uFupWQjGYDu+9d8NVugp2A eZtg== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=aJ5gsnboB7qX7aWF5PMpLS3/o+iLdxsFeyFOsoSYIYE=; b=o95K2hEr4BHfSpz7ax8DmCpW+xr/XkRgWCdquwWfXiHAsIg5tIeuik6Ph/trQ9O72r rISWBkYRIMVYlKHLPfVu1phdRA3QpiYyHqerllkEVOodi+JrXvwU1KB7pIS/11VL1jcO is+Ar/+cGq5xxzlSwgAOB9LatJxvsfKlL/BpAEeOFNumIOTESrsdVV3co49MdZj1JPuc 3az4g0HQGlKi3DWzLE9TnyX8/nzLD63+vXMdmBCRfYEgcodLpooBwwtFS0zuBapa8e7Z +dK6adMhmxZoC+WI2SdsN5xMicSPocI9OkADFDTpyAuIUU1HfvY2s8n08D84/S1jgCGH 66MQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d18si10716425edz.309.2020.06.16.11.14.50; Tue, 16 Jun 2020 11:15:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbgFPSOo (ORCPT + 99 others); Tue, 16 Jun 2020 14:14:44 -0400 Received: from mga07.intel.com ([134.134.136.100]:49322 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727083AbgFPSOn (ORCPT ); Tue, 16 Jun 2020 14:14:43 -0400 IronPort-SDR: moikEsVJ+Id1FeW4DCZxm0bGl9iFl/JWJKydLjbXgjdZMqHePT7CrkmjwZS6MQlWOPh+rnY5JC YhIhxHStYDAg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2020 11:14:43 -0700 IronPort-SDR: 0rVb+n2yF3XT03RMVfWj+j6u5GrdWdhJcNAswv0UEYie0zNh8/hNGjNay8lTxERtil5dTRhzq/ 6ha2Jhdl5rKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,519,1583222400"; d="scan'208";a="263085314" Received: from bgi1-mobl2.amr.corp.intel.com ([10.254.72.197]) by fmsmga008.fm.intel.com with ESMTP; 16 Jun 2020 11:14:42 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: inga.stotland@intel.com, brian.gix@intel.com, michal.lowas-rzechonek@silvair.com Subject: [PATCH BlueZ v2] mesh: Add deferral of Attach() and Leave() if busy Date: Tue, 16 Jun 2020 11:14:36 -0700 Message-Id: <20200616181436.50319-1-brian.gix@intel.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org We require the successful return of JoinComplete() method before handling subsequent Attach() or Leave() method calls. To simplify the construction of Applications, we will accept one of these calls up to 1 second prior to receiving the final return status of JoinComplete, which tells us that the Application is ready to use the node. If the node is still not ready after the deferral, Attach and/or Leave will fail. --- mesh/mesh.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/mesh/mesh.c b/mesh/mesh.c index ab2393deb..bc170371d 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -104,6 +104,10 @@ static struct l_queue *pending_queue; static const char *storage_dir; +/* Forward static decalrations */ +static void def_attach(struct l_timeout *timeout, void *user_data); +static void def_leave(struct l_timeout *timeout, void *user_data); + static bool simple_match(const void *a, const void *b) { return a == b; @@ -634,12 +638,26 @@ static struct l_dbus_message *attach_call(struct l_dbus *dbus, uint64_t token; const char *app_path, *sender; struct l_dbus_message *pending_msg; + struct mesh_node *node; l_debug("Attach"); if (!l_dbus_message_get_arguments(msg, "ot", &app_path, &token)) return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); + node = node_find_by_token(token); + if (!node) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, "Attach failed"); + + if (node_is_busy(node)) { + if (user_data) + return dbus_error(msg, MESH_ERROR_BUSY, NULL); + + /* Try once more in 1 second */ + l_timeout_create(1, def_attach, l_dbus_message_ref(msg), NULL); + return NULL; + } + sender = l_dbus_message_get_sender(msg); pending_msg = l_dbus_message_ref(msg); @@ -650,6 +668,19 @@ static struct l_dbus_message *attach_call(struct l_dbus *dbus, return NULL; } +static void def_attach(struct l_timeout *timeout, void *user_data) +{ + struct l_dbus *dbus = dbus_get_bus(); + struct l_dbus_message *msg = user_data; + struct l_dbus_message *reply; + + l_timeout_remove(timeout); + + reply = attach_call(dbus, msg, (void *) true); + l_dbus_send(dbus, reply); + l_dbus_message_unref(msg); +} + static struct l_dbus_message *leave_call(struct l_dbus *dbus, struct l_dbus_message *msg, void *user_data) @@ -666,14 +697,33 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, if (!node) return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL); - if (node_is_busy(node)) - return dbus_error(msg, MESH_ERROR_BUSY, NULL); + if (node_is_busy(node)) { + if (user_data) + return dbus_error(msg, MESH_ERROR_BUSY, NULL); + + /* Try once more in 1 second */ + l_timeout_create(1, def_leave, l_dbus_message_ref(msg), NULL); + return NULL; + } node_remove(node); return l_dbus_message_new_method_return(msg); } +static void def_leave(struct l_timeout *timeout, void *user_data) +{ + struct l_dbus *dbus = dbus_get_bus(); + struct l_dbus_message *msg = user_data; + struct l_dbus_message *reply; + + l_timeout_remove(timeout); + + reply = leave_call(dbus, msg, (void *) true); + l_dbus_send(dbus, reply); + l_dbus_message_unref(msg); +} + static void create_join_complete_reply_cb(struct l_dbus_message *msg, void *user_data) { -- 2.25.4