Mesh: Add support for Node Reset in OAL & HAL
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-mesh.c
index 63eeb5b..0e47904 100644 (file)
@@ -45,6 +45,8 @@ static const btmesh_interface_t *mesh_api;
 /* Forward declaration: Callbacks from HAL */
 static void mesh_network_attached_callback(bt_status_t status,
                bt_mesh_token_t *token, bt_uuid_t *uuid);
+static void mesh_network_destroyed_callback(bt_status_t status,
+               bt_mesh_token_t *token, bt_uuid_t *uuid);
 static void mesh_network_scan_status_callback(bt_mesh_scan_state_t scan_state,
                bt_status_t status, bt_uuid_t *net_uuid);
 static void mesh_network_scan_result_callback(bt_status_t status,
@@ -75,6 +77,7 @@ static void mesh_message_received_callback(bt_uuid_t *net_uuid,
 static btmesh_callbacks_t sBluetoothMeshCallbacks = {
        .size = sizeof(sBluetoothMeshCallbacks),
        .network_attached_cb = mesh_network_attached_callback,
+       .network_destroyed_cb = mesh_network_destroyed_callback,
        .scan_status_cb = mesh_network_scan_status_callback,
        .scan_result_cb = mesh_network_scan_result_callback,
        .provisioning_status_cb = mesh_network_provisioning_status_callback,
@@ -104,6 +107,22 @@ static void mesh_network_attached_callback(bt_status_t status,
                event, sizeof(event_mesh_network_attached_t), NULL);
 }
 
+static void mesh_network_destroyed_callback(bt_status_t status,
+               bt_mesh_token_t *token, bt_uuid_t *uuid)
+{
+       event_mesh_network_attached_t *event = g_new0(event_mesh_network_attached_t, 1);
+
+       event->status = convert_to_oal_status(status);
+       BT_INFO("Mesh Event: Network Destroyed, status: [%s]",
+                       status2string(status));
+
+       memcpy(event->token, token->token, sizeof(bt_mesh_token_t));
+       memcpy(event->uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
+
+       send_event_bda_trace(OAL_EVENT_MESH_NETWORK_DESTROYED,
+                       event, sizeof(event_mesh_network_destroyed_t), NULL);
+}
+
 static void mesh_network_scan_status_callback(bt_mesh_scan_state_t scan_state,
                bt_status_t status, bt_uuid_t *net_uuid)
 {
@@ -348,6 +367,37 @@ oal_status_t mesh_register_node(oal_mesh_node_t *node,
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid)
+{
+       int ret = BT_STATUS_SUCCESS;
+       API_TRACE();
+       CHECK_OAL_MESH_ENABLED();
+
+       ret = mesh_api->destroy((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_delete_remote_node(oal_uuid_t* network_uuid,
+               uint16_t unicast, uint16_t num_elements)
+{
+       int ret = BT_STATUS_SUCCESS;
+       API_TRACE();
+       CHECK_OAL_MESH_ENABLED();
+
+       ret = mesh_api->delete_node((bt_uuid_t*)network_uuid, unicast, num_elements);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("Mesh: Remote Node Deletion failed: %s", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t mesh_network_start_scan(oal_uuid_t* network_uuid,
                oal_mesh_scan_params_t *params)
 {