From 5fc1dfcdd76b2d5d6c3bd5b3adc95a6ad58fb47a Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Fri, 19 Jun 2020 14:26:54 -0700 Subject: [PATCH] tools/mesh-cfgclient: get/set IV index 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 Change-Id: I40996e727f9f638e384a7c64d4a9cd606e00511c Signed-off-by: anuj.bhumiya --- 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 84d85f1..28506de 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -146,6 +146,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; @@ -666,6 +667,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; @@ -695,6 +697,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: @@ -1794,6 +1802,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, @@ -1976,6 +2011,8 @@ static bool read_mesh_config(void) high_addr = range_h; } + iv_index = mesh_db_get_iv_index(); + return true; } @@ -2042,7 +2079,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 f63eb6f..93a896c 100644 --- a/tools/mesh/mesh-db.c +++ b/tools/mesh/mesh-db.c @@ -1234,6 +1234,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) { @@ -1284,6 +1307,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 89c6444..83fcfbe 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.7.4