Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp208895pxb; Wed, 22 Sep 2021 20:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydKjhzUc+X0spZ8exNTsypLSIFQs3AlUKwUlaNI8IiKPK52G2a7G4heHXj4NWlNgtRI0xQ X-Received: by 2002:aa7:d598:: with SMTP id r24mr2980797edq.285.1632367793049; Wed, 22 Sep 2021 20:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632367793; cv=none; d=google.com; s=arc-20160816; b=Iifsvo6dK9Bgwgx4aQFxoNxcDdUNM1AAFb4UNONEZETvcR/3pV3kDHl415WCZKstwf n+rj/THsrTF9LlziipgP+VoUibWXFbi94UYDq1WhoF9ALnjnVvSZTooo9HvwAtwL7x1Y 6E2oN0/tJWxOfziKybD+RlxoZZuTZZJnK9BcMbf4Y8AxqzcYxk7wGKbzbEd/HUX5J/RO NxIIpGc2Ucd3UIc9wvqykF+gk64wr8FzJoRnjWyLBaA96aQEu5LcSTy5pwveKYjQd31s 79o7F2km2i4etqKD6i6trKTkXSfFj8Ouj4etx1A73iTaTYtcVCoNwWkTITUPOs6hnRaZ 9CwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Dzig1y9GQOxhH7aFg+aWfCkuKz6GfOy8j9oNbmdQyJI=; b=AcXyoYF1EfwCxnMiz3SedmS0IKwm6KWU2fq0sjH7uG3Z1fSNYPVTCAloTvigzMbOzB pVyw9vUFCc7GfStsyx1AjwI12tZtYqT2g3+u9J+ZacrlP6rGks+It0Jv3A1wYQGeRv06 0Iur43+5XV1ORRl7RZq1YL34E2O3SysQMDZEtkz6g0Xt9eEiJ/lL0XwLsbQPqu+clZu+ EjVqdxvNHP5yimudZPzFm7eL8VK215sOWM1RYqIAsmmiw+BzLABoLAVGnGnHwsKEpm9W Dj4F1qLavO3P/iX1mahjsN/8BH1Hpx8G9knobjafahpnUG7EdV+GLDhfDtGAIQBEPNPO vL6A== 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 l6si4482489ejq.366.2021.09.22.20.29.29; Wed, 22 Sep 2021 20:29:53 -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 S239050AbhIWD2y (ORCPT + 99 others); Wed, 22 Sep 2021 23:28:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:16377 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239062AbhIWD2p (ORCPT ); Wed, 22 Sep 2021 23:28:45 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10115"; a="220555926" X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="220555926" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 20:26:59 -0700 X-IronPort-AV: E=Sophos;i="5.85,315,1624345200"; d="scan'208";a="534072384" Received: from jdudwadk-mobl.amr.corp.intel.com (HELO istotlan-desk.intel.com) ([10.212.205.211]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 20:26:59 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 14/20] tools/mesh-cfgclient: Store remote's heartbeat sub/pub Date: Wed, 22 Sep 2021 20:25:57 -0700 Message-Id: <20210923032603.50536-15-inga.stotland@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210923032603.50536-1-inga.stotland@intel.com> References: <20210923032603.50536-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Store remote node's heartbeat publication or subscription info upon receiving CONFIG_HEARTBEAT_PUB_STATUS or CONFIG_HEARTBEAT_SUB_STATUS messages when the messages' status code is set to Success. --- tools/mesh/cfgcli.c | 30 +++++++++--- tools/mesh/mesh-db.c | 113 +++++++++++++++++++++++++++++++++++++++++-- tools/mesh/mesh-db.h | 4 ++ 3 files changed, 135 insertions(+), 12 deletions(-) diff --git a/tools/mesh/cfgcli.c b/tools/mesh/cfgcli.c index b5f39df18..2bf1a1503 100644 --- a/tools/mesh/cfgcli.c +++ b/tools/mesh/cfgcli.c @@ -400,7 +400,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, { uint32_t opcode, mod_id; const struct cfg_cmd *cmd; - uint16_t app_idx, net_idx, addr, ele_addr; + uint16_t app_idx, net_idx, addr, ele_addr, features; struct mesh_group *grp; struct model_pub pub; int n; @@ -813,13 +813,21 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("\nNode %4.4x Heartbeat publish status %s\n", src, mesh_status_str(data[0])); - bt_shell_printf("Destination\t%4.4x\n", get_le16(data + 1)); - bt_shell_printf("Count\t\t%2.2x\n", data[3]); - bt_shell_printf("Period\t\t%2.2x\n", data[4]); + if (data[0] != MESH_STATUS_SUCCESS) + return true; + + addr = get_le16(data + 1); + bt_shell_printf("Destination\t%4.4x\n", addr); + bt_shell_printf("CountLog\t\t%2.2x\n", data[3]); + bt_shell_printf("PeriodLog\t\t%2.2x\n", data[4]); bt_shell_printf("TTL\t\t%2.2x\n", data[5]); - bt_shell_printf("Features\t%4.4x\n", get_le16(data + 6)); + features = get_le16(data + 6); + bt_shell_printf("Features\t%4.4x\n", features); net_idx = get_le16(data + 8); bt_shell_printf("Net_Idx\t%u (0x%3.3x)\n", net_idx, net_idx); + + saved = mesh_db_node_set_hb_pub(src, addr, net_idx, data[4], + data[5], features); break; /* Per Mesh Profile 4.3.2.66 */ @@ -830,12 +838,20 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("\nNode %4.4x Heartbeat subscribe status %s\n", src, mesh_status_str(data[0])); - bt_shell_printf("Source\t\t%4.4x\n", get_le16(data + 1)); - bt_shell_printf("Destination\t%4.4x\n", get_le16(data + 3)); + if (data[0] != MESH_STATUS_SUCCESS) + return true; + + ele_addr = get_le16(data + 1); + bt_shell_printf("Source\t\t%4.4x\n", ele_addr); + addr = get_le16(data + 3); + bt_shell_printf("Destination\t%4.4x\n", addr); bt_shell_printf("Period\t\t%2.2x\n", data[5]); bt_shell_printf("Count\t\t%2.2x\n", data[6]); bt_shell_printf("Min Hops\t%2.2x\n", data[7]); bt_shell_printf("Max Hops\t%2.2x\n", data[8]); + + saved = mesh_db_node_set_hb_sub(src, ele_addr, addr); + break; /* Per Mesh Profile 4.3.2.71 */ diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c index 3290c5b8e..42ba831d4 100644 --- a/tools/mesh/mesh-db.c +++ b/tools/mesh/mesh-db.c @@ -963,12 +963,24 @@ static void jarray_string_del(json_object *jarray, const char *str, size_t len) } } +static bool add_array_string(json_object *jarray, const char *str) +{ + json_object *jstring; + + jstring = json_object_new_string(str); + if (!jstring) + return false; + + json_object_array_add(jarray, jstring); + return true; +} + static bool update_model_string_array(uint16_t unicast, uint16_t ele_addr, bool vendor, uint32_t mod_id, const char *str, uint32_t len, const char *keyword, bool add) { - json_object *jarray, *jmod, *jstring; + json_object *jarray, *jmod; if (!cfg || !cfg->jcfg) return false; @@ -988,12 +1000,9 @@ static bool update_model_string_array(uint16_t unicast, uint16_t ele_addr, if (!add) return true; - jstring = json_object_new_string(str); - if (!jstring) + if (!add_array_string(jarray, str)) return false; - json_object_array_add(jarray, jstring); - return save_config(); } @@ -1179,6 +1188,100 @@ fail: return false; } +bool mesh_db_node_set_hb_pub(uint16_t unicast, uint16_t dst, uint16_t net_idx, + uint8_t period_log, uint8_t ttl, + uint16_t features) +{ + json_object *jnode, *jpub, *jarray = NULL; + uint32_t period; + + if (!cfg || !cfg->jcfg) + return false; + + if (period_log > 0x12 || ttl > 0x7F) + return false; + + jnode = get_node_by_unicast(cfg->jcfg, unicast); + if (!jnode) + return false; + + jpub = json_object_new_object(); + + if (!write_uint16_hex(jpub, "address", dst)) + goto fail; + + period = period_log ? 1 << (period_log - 1) : 0; + + if (!write_int(jpub, "period", period)) + goto fail; + + if (!write_int(jpub, "ttl", ttl)) + goto fail; + + if (!write_int(jpub, "index", net_idx)) + goto fail; + + jarray = json_object_new_array(); + + if (features & FEATURE_PROXY) + if (!add_array_string(jarray, "proxy")) + goto fail; + + if (features & FEATURE_RELAY) + if (!add_array_string(jarray, "relay")) + goto fail; + + if (features & FEATURE_FRIEND) + if (!add_array_string(jarray, "friend")) + goto fail; + + if (features & FEATURE_LPN) + if (!add_array_string(jarray, "lowPower")) + goto fail; + + json_object_object_add(jpub, "features", jarray); + json_object_object_del(jnode, "heartbeatPub"); + json_object_object_add(jnode, "heartbeatPub", jpub); + + return save_config(); + +fail: + if (jarray) + json_object_put(jarray); + + json_object_put(jpub); + return false; +} + +bool mesh_db_node_set_hb_sub(uint16_t unicast, uint16_t src, uint16_t dst) +{ + json_object *jnode, *jsub; + + if (!cfg || !cfg->jcfg) + return false; + + jnode = get_node_by_unicast(cfg->jcfg, unicast); + if (!jnode) + return false; + + jsub = json_object_new_object(); + + if (!write_uint16_hex(jsub, "source", src)) + goto fail; + + if (!write_uint16_hex(jsub, "destination", dst)) + goto fail; + + json_object_object_del(jnode, "heartbeatSub"); + json_object_object_add(jnode, "heartbeatSub", jsub); + + return save_config(); + +fail: + json_object_put(jsub); + return false; +} + static void jarray_key_del(json_object *jarray, int16_t idx) { int i, sz = json_object_array_length(jarray); diff --git a/tools/mesh/mesh-db.h b/tools/mesh/mesh-db.h index b3b0bce79..16c46c046 100644 --- a/tools/mesh/mesh-db.h +++ b/tools/mesh/mesh-db.h @@ -74,6 +74,10 @@ bool mesh_db_node_model_del_sub_all(uint16_t unicast, uint16_t ele, bool vendor, bool mesh_db_node_model_set_pub(uint16_t unicast, uint16_t ele_addr, bool vendor, uint32_t mod_id, struct model_pub *pub, bool virt); +bool mesh_db_node_set_hb_pub(uint16_t unicast, uint16_t dst, uint16_t net_idx, + uint8_t period_log, uint8_t ttl, + uint16_t features); +bool mesh_db_node_set_hb_sub(uint16_t unicast, uint16_t src, uint16_t dst); struct l_queue *mesh_db_load_groups(void); bool mesh_db_add_group(struct mesh_group *grp); bool mesh_db_add_rejected_addr(uint16_t unicast, uint32_t iv_index); -- 2.31.1