Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1017936ybt; Fri, 19 Jun 2020 21:46:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+q1mWGyhg1BKYqEMvbmSzoEmTkAmxmSCISRa8XrUM8yok0cPVX6Iq0O5tdkaTqcP1KRDx X-Received: by 2002:a50:a701:: with SMTP id h1mr6425941edc.170.1592628369797; Fri, 19 Jun 2020 21:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592628369; cv=none; d=google.com; s=arc-20160816; b=CkZAwOVuW97ARKj7dCBcxuZmbffA7tPbUCW8jhRB9n0Q5cmLO38Jcm1VR2AE5YuzHV EyBFlitpjaSAOAilDNx9yXAhE/wH5/fRD5XB4kdXSUDILIlqsAFy3BdZqqHbtTYXBIRN Xru6xYb5zRrNPtfbljukMm79xrRsKioiGaoHZirXZ+1ktG73aOu/pYHGHwYVopm2H9gr k2y1c1cIbfCaPyV8Kl/E0/PKwjbyQztXeev1xLywupHD/HBz/LH1J3fsZTG8IGRHSW0I ynWIzUspPUPTs9z6Jy4R3ZyQwDRUjsJBsyA4eR+xOkn5IQuRXWJObixoHB9HEsAtArxE 9IiQ== 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 :ironport-sdr:ironport-sdr; bh=/TUogP01Ly7BV848kvLwTOs2sXa22QFOm1Hsi5Dmkl4=; b=lRQ9dxbAsczIj6wtgsuwcY+Kk2tlz5b6ObmZCAQsz1dYf+kRqpbFmSwl1uWbH+w2pQ 4FflzV35vC6YeuQ3tbGekqoGiMZC1TpPb9ZFiuLUfGjJuKjPOJX0xXp9o9G1Yt7Z58tb S38P20UCtowBJMkIUgT5V0GS2xeb1qqsw/i5he+pqrS3zq6eJd8bTUNvO92H4O5cnd41 irte9zuX5EZg3USTgyTyozuOZxDHPeTEs7+wmkiGujSC9AsfPU6XnW8LIw0D4wCvhu2v 0mCV/vRLc/WcsBMAW84KOOV4vL1xAPBLyIgl8bUi9EAznLp+R4QFYGPg9CRzdLZqUkhf vUwA== 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 w4si5008176ejj.300.2020.06.19.21.45.46; Fri, 19 Jun 2020 21:46:09 -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 S1725320AbgFSV1B (ORCPT + 99 others); Fri, 19 Jun 2020 17:27:01 -0400 Received: from mga03.intel.com ([134.134.136.65]:21821 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbgFSV07 (ORCPT ); Fri, 19 Jun 2020 17:26:59 -0400 IronPort-SDR: 8LBm0Z0gMQF2AJO3YS9qWHFiud3jZW3mIdMAXssaQjQ09dxcb8q4Y+t4DM1eEZBoxdmvFCkKo6 dnxvndVdK9lA== X-IronPort-AV: E=McAfee;i="6000,8403,9657"; a="143045103" X-IronPort-AV: E=Sophos;i="5.75,256,1589266800"; d="scan'208";a="143045103" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2020 14:26:59 -0700 IronPort-SDR: 99eSHzOCTeeR59FlQjjGMWV8scU815X9yU1BMmEHClgtXCE5w8AnJbZSA2tH6/WKyH7qt8Im+V SwWxtareOpDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,256,1589266800"; d="scan'208";a="292246236" Received: from pafleisc-mobl.amr.corp.intel.com (HELO ingas-nuc1.sea.intel.com) ([10.254.109.121]) by orsmga002.jf.intel.com with ESMTP; 19 Jun 2020 14:26:59 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 2/3] tools/mesh-cfgclient: get/set IV index Date: Fri, 19 Jun 2020 14:26:54 -0700 Message-Id: <20200619212655.107839-3-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200619212655.107839-1-inga.stotland@intel.com> References: <20200619212655.107839-1-inga.stotland@intel.com> 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 This adds keeping track of IV index changes. The updates are detected by observing PropertiesChanged signal on local node's object path and reading "IvIndex" property --- tools/mesh-cfgclient.c | 39 ++++++++++++++++++++++++++++++++++++++- tools/mesh/mesh-db.c | 25 +++++++++++++++++++++++++ tools/mesh/mesh-db.h | 3 ++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c index fe82a8bbe..da9f83c29 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -144,6 +144,7 @@ static const char *range_opt; static const char *net_idx_opt; static const char *config_opt; +static uint32_t iv_index; static uint16_t low_addr; static uint16_t high_addr; static uint16_t prov_net_idx; @@ -664,6 +665,7 @@ static void attach_node_reply(struct l_dbus_proxy *proxy, { struct meshcfg_node *node = user_data; struct l_dbus_message_iter iter_cfg; + uint32_t ivi; if (l_dbus_message_is_error(msg)) { const char *name; @@ -693,6 +695,12 @@ static void attach_node_reply(struct l_dbus_proxy *proxy, /* Inititalize config client model */ client_init(); + if (l_dbus_proxy_get_property(local->proxy, "IvIndex", "u", &ivi) && + ivi != iv_index) { + iv_index = ivi; + mesh_db_set_iv_index(ivi); + } + return; fail: @@ -1792,6 +1800,33 @@ static struct l_dbus_message *join_complete(struct l_dbus *dbus, return l_dbus_message_new_method_return(message); } +static void property_changed(struct l_dbus_proxy *proxy, const char *name, + struct l_dbus_message *msg, void *user_data) +{ + const char *interface = l_dbus_proxy_get_interface(proxy); + const char *path = l_dbus_proxy_get_path(proxy); + + if (strcmp(path, local->path)) + return; + + bt_shell_printf("Property changed: %s %s %s\n", name, path, interface); + + if (!strcmp(interface, "org.bluez.mesh.Node1")) { + + if (!strcmp(name, "IvIndex")) { + uint32_t ivi; + + if (!l_dbus_message_get_arguments(msg, "u", &ivi)) + return; + + bt_shell_printf("New IV Index: %u\n", ivi); + + iv_index = ivi; + mesh_db_set_iv_index(ivi); + } + } +} + static void setup_app_iface(struct l_dbus_interface *iface) { l_dbus_interface_property(iface, "CompanyID", 0, "q", cid_getter, @@ -1974,6 +2009,8 @@ static bool read_mesh_config(void) high_addr = range_h; } + iv_index = mesh_db_get_iv_index(); + return true; } @@ -2040,7 +2077,7 @@ int main(int argc, char *argv[]) l_dbus_client_set_disconnect_handler(client, client_disconnected, NULL, NULL); l_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed, - NULL, NULL, NULL); + property_changed, NULL, NULL); l_dbus_client_set_ready_handler(client, client_ready, NULL, NULL); node_proxies = l_queue_new(); diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c index b789c3933..dbeed0214 100644 --- a/tools/mesh/mesh-db.c +++ b/tools/mesh/mesh-db.c @@ -1232,6 +1232,29 @@ bool mesh_db_set_addr_range(uint16_t low, uint16_t high) return save_config(); } +uint32_t mesh_db_get_iv_index(void) +{ + int ivi; + + if (!cfg || !cfg->jcfg) + return 0; + + if (!get_int(cfg->jcfg, "ivIndex", &ivi)) + return 0; + + return (uint32_t) ivi; +} + +bool mesh_db_set_iv_index(uint32_t ivi) +{ + if (!cfg || !cfg->jcfg) + return false; + + write_int(cfg->jcfg, "ivIndex", ivi); + + return save_config(); +} + bool mesh_db_create(const char *fname, const uint8_t token[8], const char *mesh_name) { @@ -1282,6 +1305,8 @@ bool mesh_db_create(const char *fname, const uint8_t token[8], json_object_object_add(jcfg, "appKeys", jarray); + write_int(jcfg, "ivIndex", 0); + if (!save_config()) goto fail; diff --git a/tools/mesh/mesh-db.h b/tools/mesh/mesh-db.h index 89c644400..83fcfbee7 100644 --- a/tools/mesh/mesh-db.h +++ b/tools/mesh/mesh-db.h @@ -26,7 +26,8 @@ bool mesh_db_create(const char *fname, const uint8_t token[8], bool mesh_db_load(const char *fname); bool mesh_db_get_token(uint8_t token[8]); - +bool mesh_db_set_iv_index(uint32_t ivi); +uint32_t mesh_db_get_iv_index(void); bool mesh_db_net_key_add(uint16_t idx); bool mesh_db_net_key_del(uint16_t idx); bool mesh_db_net_key_phase_set(uint16_t net_idx, uint8_t phase); -- 2.26.2