mesh: get/set IV index 57/250557/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 21 Dec 2020 10:44:44 +0000 (16:14 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 21 Dec 2020 11:02:12 +0000 (16:32 +0530)
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: I96d26f4aa6ba9bf2355fd6039b8b87ffaa30baad
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c

index 81d2d5a..be32a69 100644 (file)
@@ -63,7 +63,7 @@ static struct l_dbus_proxy *net_proxy = NULL;
 static struct l_dbus_message *agent_msg;
 
 static handle_stack_msg mesh_event_cb = NULL;
-
+static uint32_t iv_index;
 
 struct subnet_key_request {
        uint16_t idx;
@@ -546,6 +546,43 @@ static void __mesh_proxy_removed(struct l_dbus_proxy *proxy, void *user_data)
        }
 }
 
+static void __mesh_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);
+       GSList *l;
+       meshcfg_app *app = NULL;
+
+       l = g_slist_find_custom(mesh_apps, path, __compare_proxy_path);
+       if (l) {
+               app = l->data;
+       } else {
+               ERR("Mesh: app not found for Mgmt proxy");
+       }
+
+       INFO("Property changed: %s %s %s\n", name, path, interface);
+
+       if (!app)
+               return;
+
+       if (!strcmp(interface, BT_HAL_MESH_NODE_INTERFACE)) {
+
+               if (!strcmp(name, "IvIndex")) {
+                       uint32_t ivi;
+
+                       if (!l_dbus_message_get_arguments(msg, "u", &ivi))
+                               return;
+
+                       INFO("New IV Index: %u\n", ivi);
+
+                       iv_index = ivi;
+                       /*TODO: save iv index */
+               }
+       }
+}
+
+
 static void __mesh_dbus_client_ready(struct l_dbus_client *client_obj,
                void *user_data)
 {
@@ -600,7 +637,7 @@ bool _bt_hal_mesh_stack_init(void)
                return false;
        if (!l_dbus_client_set_proxy_handlers(client,
                                __mesh_proxy_added, __mesh_proxy_removed,
-                               NULL, NULL, NULL))
+                               __mesh_property_changed, NULL, NULL))
                return false;
        if (!l_dbus_client_set_ready_handler(client,
                                __mesh_dbus_client_ready, NULL, NULL))
@@ -717,6 +754,8 @@ static void __bt_hal_mesh_attach_node_reply(struct l_dbus_proxy *proxy,
        struct l_dbus_message_iter iter_cfg;
        char *path;
        meshcfg_app *app = (meshcfg_app*) user_data;
+       uint32_t ivi;
+
        INFO("Mesh: Attach Node Reply: App path [%s] Agent Path [%s]",
                app->path, app->agent_path);
 
@@ -734,6 +773,13 @@ static void __bt_hal_mesh_attach_node_reply(struct l_dbus_proxy *proxy,
 
        INFO("Mesh: Attached with path %s\n", app->path);
        __send_network_attach_event(app, BT_STATUS_SUCCESS);
+
+       if (l_dbus_proxy_get_property(app->proxy, "IvIndex", "u", &ivi) &&
+                                                       ivi != iv_index) {
+               iv_index = ivi;
+               /* TODO: Save IV index */
+       }
+
        return;
 failed:
        __send_network_attach_event(app, BT_STATUS_FAIL);
@@ -2014,7 +2060,7 @@ static void __bt_hal_mesh_add_node_setup(struct l_dbus_message *msg,
        l_dbus_message_builder_finalize(builder);
        l_dbus_message_builder_destroy(builder);
 
-       g_free(uuid);
+       l_free(uuid);
 }
 
 bt_status_t _bt_hal_mesh_provision_device(