Handle bluetooth-meshd life cycle
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-mesh.c
index ea9d1ae..de10cc3 100644 (file)
@@ -38,6 +38,20 @@ BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb,
                BT_ERR("callback is NULL");
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_INIT,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to init the mesh in bt-service");
+               return ret;
+       }
+
        ret = _bt_init_event_handler();
 
        if (ret != BLUETOOTH_ERROR_NONE &&
@@ -62,9 +76,24 @@ BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb,
 
 BT_EXPORT_API int bluetooth_mesh_deinit(void)
 {
+       int ret;
+
        _bt_unregister_event(BT_MESH_EVENT);
        _bt_set_user_data(BT_MESH, NULL, NULL);
 
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_DEINIT,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to init the mesh in bt-service");
+               return ret;
+       }
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -108,6 +137,35 @@ BT_EXPORT_API int bluetooth_mesh_network_create(
        return result;
 }
 
+BT_EXPORT_API int bluetooth_mesh_network_load(
+               const char *token,
+                       bluetooth_mesh_network_t *network)
+{
+       int result;
+       char token_string[BLUETOOTH_MESH_TOKEN_STRING_MAX + 1];
+
+       BT_CHECK_PARAMETER(token, return);
+       BT_CHECK_PARAMETER(network, return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_strlcpy(token_string, token, sizeof(token_string));
+       g_array_append_vals(in_param1, token_string, BLUETOOTH_MESH_TOKEN_STRING_MAX);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_LOAD,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               *network = g_array_index(out_param,
+                               bluetooth_mesh_network_t, 0);
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_mesh_network_scan(
                        bluetooth_mesh_network_t *network,
                                bluetooth_mesh_scan_param_t *scan_param)
@@ -745,7 +803,6 @@ BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
 
                        if (size == 0) {
                                BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
-                               result = BLUETOOTH_ERROR_NOT_FOUND;
                        }
 
                        for (i = 0; i < size; i++) {