GATT: Fix bug in GATT Send indication
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-mesh.c
index de10cc3..a1e2920 100644 (file)
@@ -47,7 +47,8 @@ BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb,
 
        BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE &&
+                       ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
                BT_ERR("Fail to init the mesh in bt-service");
                return ret;
        }
@@ -97,6 +98,63 @@ BT_EXPORT_API int bluetooth_mesh_deinit(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+BT_EXPORT_API int bluetooth_mesh_network_unload(bluetooth_mesh_network_t *network)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(network, return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, network,  sizeof(bluetooth_mesh_network_t));
+
+       BT_INFO("Mesh: Network Unload");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UNLOAD,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(network, return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, network,  sizeof(bluetooth_mesh_network_t));
+
+       BT_INFO("Mesh: Network Destroy");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DESTROY,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(node, return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_info_t));
+
+       BT_INFO("Mesh: Reset the Node");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_RESET,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_mesh_network_create(
        const char *net_name, bluetooth_mesh_node_t *node,
                uint16_t total_models, bluetooth_mesh_model_t **models,
@@ -118,7 +176,7 @@ BT_EXPORT_API int bluetooth_mesh_network_create(
        g_array_append_vals(in_param2, network_name,
                        BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX);
 
-       for(int i = 0; i < total_models; i++)
+       for (int i = 0; i < total_models; i++)
                g_array_append_vals(in_param3, models[i],
                                sizeof(bluetooth_mesh_model_t));
 
@@ -328,9 +386,8 @@ BT_EXPORT_API int bluetooth_mesh_network_add_netkey(
        BT_INFO("Mesh:Set Create Subnetwork key");
        result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_NETKEY,
                        in_param1, in_param2, in_param3, in_param4, &out_param);
-       if (result == BLUETOOTH_ERROR_NONE) {
+       if (result == BLUETOOTH_ERROR_NONE)
                *netkey_idx = g_array_index(out_param, guint16, 0);
-       }
        BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
        return result;
@@ -400,9 +457,8 @@ BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
        result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
                        in_param1, in_param2, in_param3, in_param4, &out_param);
 
-       if (result == BLUETOOTH_ERROR_NONE) {
+       if (result == BLUETOOTH_ERROR_NONE)
                *appkey_index = g_array_index(out_param, guint16, 0);
-       }
        BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
 
        return result;
@@ -488,7 +544,7 @@ BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
                                info = &g_array_index(out_param,
                                                bluetooth_mesh_node_info_t, i);
 
-                               data= g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
+                               data = g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
                                g_ptr_array_add(*nodes, (gpointer)data);
                        }
                }
@@ -526,7 +582,8 @@ BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
                        BT_ERR("Mesh: out_param is NULL");
                        result = BLUETOOTH_ERROR_INTERNAL;
                } else {
-                       size = (out_param->len) / sizeof(guint16);
+                       size = (out_param->len) / sizeof(guint32);
+                       BT_INFO("Mesh: Total Models found in Element [%d]", size);
 
                        for (i = 0; i < size; i++) {
                                uint32_t model_obj;
@@ -650,6 +707,32 @@ BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
        return result;
 }
 
+BT_EXPORT_API int bluetooth_mesh_model_send_msg(
+                       bluetooth_mesh_model_msg_t *req)
+{
+       int result;
+       bt_user_info_t *user_info;
+
+       BT_CHECK_PARAMETER(req, return);
+
+       user_info = _bt_get_user_data(BT_MESH);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, req,  sizeof(bluetooth_mesh_model_msg_t));
+
+       BT_INFO("Mesh: Node Model Send Msg");
+       result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_EXECUTE_MSG,
+                       in_param1, in_param2, in_param3, in_param4,
+                       user_info->cb, user_info->user_data);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
                        bluetooth_mesh_key_configure_t *req)
 {
@@ -681,6 +764,7 @@ BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
                        GPtrArray **groups)
 {
        int result = BLUETOOTH_ERROR_NONE;
+       bluetooth_mesh_network_group_info_t *info;
        guint size;
        int i;
 
@@ -700,21 +784,25 @@ BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
                        BT_ERR("Mesh: out_param is NULL");
                        result = BLUETOOTH_ERROR_INTERNAL;
                } else {
-                       size = (out_param->len) / sizeof(guint16);
+                       size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
 
-                       if (size == 0) {
+                       if (size == 0)
                                BT_INFO("Mesh: No Groups created for the network");
-                       }
 
+                       BT_INFO("Mesh: Total groups [%d]", size);
                        for (i = 0; i < size; i++) {
-                               uint16_t group_addr;
-                               uint16_t *group_ptr = NULL;
-
-                               group_addr = g_array_index(out_param,
-                                               guint16, i);
+                               bluetooth_mesh_network_group_info_t *grp_info = NULL;
 
-                               group_ptr = g_memdup(&group_addr, sizeof(guint16));
-                               g_ptr_array_add(*groups, (gpointer)group_ptr);
+                               info = &g_array_index(out_param,
+                                       bluetooth_mesh_network_group_info_t, i);
+                               BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
+                               BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual ? "YES" : "NO");
+                               BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
+                               if (info->is_virtual)
+                                       BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
+                               grp_info = g_memdup(info,
+                                       sizeof(bluetooth_mesh_network_group_info_t));
+                               g_ptr_array_add(*groups, (gpointer)grp_info);
                        }
                }
        }
@@ -801,9 +889,8 @@ BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
                } else {
                        size = (out_param->len) / sizeof(guint16);
 
-                       if (size == 0) {
+                       if (size == 0)
                                BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
-                       }
 
                        for (i = 0; i < size; i++) {
                                uint16_t appkey_index;
@@ -1010,6 +1097,30 @@ BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
        return result;
 }
 
+BT_EXPORT_API int bluetooth_mesh_network_remove_group(
+               bluetooth_mesh_network_t *network,
+                       bluetooth_mesh_network_group_info_t *req)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(network, return);
+       BT_CHECK_PARAMETER(req, return);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, network,  sizeof(bluetooth_mesh_network_t));
+       g_array_append_vals(in_param2, req,  sizeof(bluetooth_mesh_network_group_info_t));
+
+       BT_INFO("Mesh: Remove Group Request");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_mesh_network_create_group(
                bluetooth_mesh_network_t *network, bool is_virtual,
                        uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)