Mesh: Release Network DBUS resources during deinit 98/241898/1 accepted/tizen/unified/20200825.142907 submit/tizen/20200821.002054
authorAnupam Roy <anupam.r@samsung.com>
Thu, 20 Aug 2020 15:55:01 +0000 (21:25 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 20 Aug 2020 16:16:50 +0000 (21:46 +0530)
When application wants to deinitialize mesh,
Network resources of that application shall be
released by stack. Currently, those resouces
are not released. Also, HAL retains the dynamic
resouces of the Networks, which should be cleaned.

This patch requests release of resources
by calling 'Release' API of stack, which
is introduced in Tizen. When dbus resouces
are cleaned, HAL will automatically release dynamic
resources of networks, upon removal of proxies.

After release, at any point of time, application
can again initialize mesh and 'Attach' the Networks,
that it had created before, with the help of
token, which was aquired during network creation.

Change-Id: I617110d10fdb6d9eaa711f77dcd5a92e6b93a55f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h
bt-oal/bluez_hal/src/bt-hal-mesh.c
bt-oal/hardware/bt_mesh.h
bt-oal/include/oal-mesh.h
bt-oal/oal-mesh.c
bt-service/services/mesh/bt-service-mesh-network.c

index a548554fbafbcd6b937abca1675b8d023f8c4081..5c49b592177ad6a3ac561df07fe9592c3b076f13 100644 (file)
@@ -397,17 +397,12 @@ static gint __compare_proxy_path(gconstpointer data, gconstpointer user_data)
        char *app_uuid_path;
        const meshcfg_app *app = (meshcfg_app*) data;
        char *path = (char *) user_data;
-       INFO("Mesh: proxy path compare: path [%s]", path);
-       INFO("Mesh: App Path  path [%s]", app->path);
        if (!path)
                return -1;
 
        app_uuid_path = l_util_hexstring(app->uuid, 16);
-       INFO("Mesh:App UUID string [%s]", app_uuid_path);
        char **strings =  g_strsplit(path, "node", 2);
 
-       INFO("Mesh:String 0 [%s]", strings[0]);
-       INFO("Mesh:String 1 [%s]", strings[1]);
        ret = g_strcmp0(strings[1], app_uuid_path);
        g_free(strings[0]);
        g_free(strings[1]);
@@ -610,6 +605,8 @@ void _bt_hal_mesh_stack_deinit(void)
                l_dbus_destroy(dbus);
                dbus = NULL;
        }
+       INFO("Mesh: Number of meshapps present in memory [%d]",
+                       g_slist_length(mesh_apps));
 }
 
 /* To send stack event to hal-mesh handler */
@@ -1719,6 +1716,34 @@ static void __bt_hal_mesh_leave_net_setup(struct l_dbus_message *msg,
        INFO("Mesh: Leave Network Setup app path [%s]", app->path);
 }
 
+static void __bt_hal_mesh_release_net_reply(
+               struct l_dbus_proxy *proxy,
+                       struct l_dbus_message *msg, void *user_data)
+{
+       meshcfg_app *app;
+       app = (meshcfg_app*) user_data;
+
+       INFO("Mesh:Release Network Reply from Meshd: app path [%s]", app->path);
+       if (l_dbus_message_is_error(msg)) {
+               const char *name;
+
+               l_dbus_message_get_error(msg, &name, NULL);
+               ERR("Mesh: Failed to Release network: %s", name);
+
+       } else {
+               INFO("Mesh: Release Network: Success, cleanup app after proxy removed");
+       }
+}
+
+static void __bt_hal_mesh_release_net_setup(struct l_dbus_message *msg,
+               void *user_data)
+{
+       meshcfg_app *app = (meshcfg_app*) user_data;
+
+       l_dbus_message_set_arguments(msg, "t", l_get_be64(app->token.u8));
+       INFO("Mesh: Release Network Setup app path [%s]", app->path);
+}
+
 static void __bt_hal_mesh_create_net_reply(
                struct l_dbus_proxy *proxy,
                        struct l_dbus_message *msg, void *user_data)
@@ -2362,6 +2387,35 @@ bt_status_t _bt_hal_mesh_node_delete(bt_uuid_t *network,
        return BT_STATUS_SUCCESS;
 }
 
+bt_status_t _bt_hal_mesh_network_release(bt_uuid_t *net_uuid)
+{
+       GSList *l;
+       meshcfg_app *app;
+       INFO("Mesh: Release Network");
+       l = g_slist_find_custom(mesh_apps, net_uuid->uu, __mesh_compare_network_uuid);
+       if (l) {
+               app = l->data;
+               if (!__bt_mesh_proxy_check(app)) {
+                       ERR("Mesh: Proxy check failed!!");
+                       return BT_STATUS_FAIL;
+               }
+               INFO("Mesh: Release Network");
+               /* Create CFG Network */
+               if (!l_dbus_proxy_method_call(net_proxy, "Release",
+                                       __bt_hal_mesh_release_net_setup,
+                                       __bt_hal_mesh_release_net_reply, app,
+                                       NULL)) {
+                       ERR("Mesh: Network Release failed!!");
+                       return BT_STATUS_FAIL;
+               }
+       } else {
+               ERR("Mesh: App not found!!");
+               return BT_STATUS_PARM_INVALID;
+       }
+       INFO("Mesh: Network Release Call issued successfully!!");
+       return BT_STATUS_SUCCESS;
+}
+
 bt_status_t _bt_hal_mesh_network_destroy(bt_uuid_t *net_uuid)
 {
        GSList *l;
index 2f27671935a95bd6a63af1873385fe5dd90d4ed4..b22bf40b949b838ca54ea7e46041e08df2b9741a 100644 (file)
@@ -49,6 +49,8 @@ bt_status_t _bt_hal_mesh_create_network(bt_hal_mesh_node_t *node,
 
 bt_status_t _bt_hal_mesh_network_destroy(bt_uuid_t *net_uuid);
 
+bt_status_t _bt_hal_mesh_network_release(bt_uuid_t *net_uuid);
+
 bt_status_t _bt_hal_mesh_node_delete(bt_uuid_t *network,
                uint16_t unicast, uint16_t num_elements);
 
index 0bac7ade9a557360cfc0349be83d3dd2e3e7b706..54d4937ba7b5d372e14327b1f0e7afbe6e851e6b 100644 (file)
@@ -240,6 +240,12 @@ static bt_status_t mesh_create_network(bt_hal_mesh_node_t *node,
        return _bt_hal_mesh_create_network(node, models, is_prov);
 }
 
+static bt_status_t mesh_release_network(bt_uuid_t *network)
+{
+       DBG("");
+       return _bt_hal_mesh_network_release(network);
+}
+
 static bt_status_t mesh_destroy_network(bt_uuid_t *network)
 {
        DBG("");
@@ -380,6 +386,7 @@ static btmesh_interface_t mesh_if = {
        .init = init,
        .create = mesh_create_network,
        .destroy = mesh_destroy_network,
+       .release = mesh_release_network,
        .delete_node = mesh_delete_node,
        .scan = mesh_scan,
        .scan_cancel = mesh_scan_cancel,
index a8b6d6247bddc5e2bfb6c50abf08d7e6dab2c406..bf64cda2b6bda3c296642a610501b6cfd92118dc 100644 (file)
@@ -204,6 +204,7 @@ typedef struct {
        bt_status_t (*create)(bt_hal_mesh_node_t *node,
                GSList *model_list, bool is_prov);
        bt_status_t (*destroy)(bt_uuid_t *network);
+       bt_status_t (*release)(bt_uuid_t *network);
        bt_status_t (*delete_node)(bt_uuid_t *network, uint16_t unicast,
                uint16_t elem_cnt);
        bt_status_t (*scan)(bt_uuid_t *network,
index eeeb2e2e4f8dda24633a5568c1c0a9f8547f01ed..f8bf7789988fc815b42ded5f123411a386b2a4d0 100644 (file)
@@ -271,6 +271,18 @@ oal_status_t mesh_register_node(oal_mesh_node_t *node,
  */
 oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid);
 
+/**
+ * @brief Request Stack to release Network resources
+ *
+ * @remarks Stack will remove only yhe DBUS resources of local node
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_register_node()
+ */
+oal_status_t mesh_network_release(oal_uuid_t* network_uuid);
+
 /**
  * @brief Delete Remote Node configuration
  *
index 0e47904b4c41b2334c127f472480289d4cc74922..ecb675c69ccd80ce7e4589774792725894fc4567 100644 (file)
@@ -367,6 +367,22 @@ oal_status_t mesh_register_node(oal_mesh_node_t *node,
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t mesh_network_release(oal_uuid_t* network_uuid)
+{
+       int ret = BT_STATUS_SUCCESS;
+       API_TRACE();
+       CHECK_OAL_MESH_ENABLED();
+
+       BT_INFO("Mesh: Send Release Network request to stack");
+       ret = mesh_api->release((bt_uuid_t*)network_uuid);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("MESH: Network Leave failed: %s", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid)
 {
        int ret = BT_STATUS_SUCCESS;
index 353e949032d89e93dd68b305dfc3a9219880ecf4..eddcc534420fea6dc84d891dbb47307a127065aa 100644 (file)
@@ -408,8 +408,9 @@ int _bt_mesh_network_unload(const char *app_cred,
                const char *sender, bluetooth_mesh_network_t *network)
 {
        GSList *l;
-       uint8_t net_uuid[16];
+       oal_uuid_t net_uuid;
        _bt_mesh_cdb_t *cdb_cfg;
+       int ret = OAL_STATUS_SUCCESS;
 
        BT_INFO("Mesh: Unload Network Configuration");
        /* If Scanning is going on */
@@ -420,10 +421,19 @@ int _bt_mesh_network_unload(const char *app_cred,
        }
 
        _bt_mesh_util_convert_string_to_hex(network->uuid,
-                       strlen(network->uuid), net_uuid, 16);
+                       strlen(network->uuid), net_uuid.uuid, 16);
+
+       /* Release Mesh Network */
+       ret = mesh_network_release(&net_uuid);
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_INFO("Mesh: Network released");
 
        /* Find CDB */
-       l = g_slist_find_custom(cdb_list, net_uuid,
+       l = g_slist_find_custom(cdb_list, net_uuid.uuid,
                        __mesh_compare_app_network_uuid);
        if (!l) {
                BT_ERR("Mesh: Could not find Network Entry: unexpected!!");