Mesh: Add support for Node Reset in OAL & HAL
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-mesh.c
index c3cffc3..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,
@@ -67,11 +69,15 @@ static void mesh_network_appkey_execute_callback(bt_status_t status,
 static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid,
                uint16_t source_addr, bool is_remote_devkey,
                        uint16_t netkey_idx, uint16_t ata_len, uint8_t *data);
+static void mesh_message_received_callback(bt_uuid_t *net_uuid,
+               uint16_t source_addr, uint16_t dest_addr,
+               uint16_t key_idx, uint16_t data_len, uint8_t *data);
 
 
 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,
@@ -81,6 +87,7 @@ static btmesh_callbacks_t sBluetoothMeshCallbacks = {
        .netkey_execute_cb = mesh_network_netkey_execute_callback,
        .appkey_execute_cb = mesh_network_appkey_execute_callback,
        .devkey_msg_cb = mesh_devkey_message_received_callback,
+       .msg_cb = mesh_message_received_callback,
 };
 
 /* Mesh HAL event handlers */
@@ -100,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)
 {
@@ -262,6 +285,24 @@ static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid,
                sizeof(event_mesh_devkey_message_t), NULL);
 }
 
+static void mesh_message_received_callback(bt_uuid_t *net_uuid,
+               uint16_t source_addr, uint16_t dest_addr, uint16_t key_idx,
+                               uint16_t data_len, uint8_t *data)
+{
+       event_mesh_message_t *event = g_new0(event_mesh_message_t, 1);
+
+       BT_INFO("Mesh Event: Model Message Received");
+       event->source = source_addr;
+       event->dest = dest_addr;
+       event->key_idx = key_idx;
+       event->data_len = data_len;
+       memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
+       memcpy(event->data, data, data_len);
+
+       send_event_bda_trace(OAL_EVENT_MESH_MODEL_MESSAGE_RECEIVED, event,
+               sizeof(event_mesh_message_t), NULL);
+}
+
 oal_status_t mesh_enable(void)
 {
        int ret;
@@ -326,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)
 {
@@ -415,6 +487,25 @@ oal_status_t mesh_conf_send_key_message(oal_uuid_t *network_uuid,
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t mesh_model_send_message(oal_uuid_t *network_uuid,
+               uint16_t dest, uint16_t appkey_idx,
+               uint8_t *buf, int len)
+{
+       int ret = BT_STATUS_SUCCESS;
+       API_TRACE();
+       CHECK_OAL_MESH_ENABLED();
+
+       ret = mesh_api->msg_execute((bt_uuid_t*)network_uuid,
+                       dest, appkey_idx, buf, len);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("MESH: Model Message sending failed: %s",
+                       status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t mesh_network_provision_device(oal_uuid_t* network_uuid,
                oal_uuid_t *dev_uuid)
 {