From 430fe6971deca44cbbf9965219ec7852972f7af9 Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Thu, 13 Aug 2020 15:40:08 +0530 Subject: [PATCH] Mesh: Add support for Node Reset in OAL & HAL This patch adds HAL & OAL API's for remote node reset functionality. Change-Id: I6805c62e1edd1c3c1e9f1ec6c302df796a114986 Signed-off-by: Anupam Roy --- bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c | 62 +++++++++++++++++++++++++ bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h | 3 ++ bt-oal/bluez_hal/src/bt-hal-mesh.c | 8 ++++ bt-oal/hardware/bt_mesh.h | 2 + bt-oal/include/oal-mesh.h | 12 +++++ bt-oal/oal-mesh.c | 16 +++++++ 6 files changed, 103 insertions(+) diff --git a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c index 5f995b4..e1d12b0 100644 --- a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c @@ -99,6 +99,11 @@ struct mesh_provision_auth_action { bt_hal_mesh_auth_variant_e auth_type; }; +struct mesh_remote_node_info { + uint16_t unicast; + uint8_t num_elements; +}; + static struct mesh_provision_auth_action auth_table[] = { { "blink", BT_HAL_MESH_AUTH_REQ_BLINK_COUNT_INPUT}, { "beep", BT_HAL_MESH_AUTH_REQ_BEEP_COUNT_INPUT}, @@ -2295,6 +2300,63 @@ bt_status_t _bt_hal_mesh_network_scan(bt_uuid_t *net_uuid, return BT_STATUS_SUCCESS; } +static void __bt_hal_mesh_delete_node_setup(struct l_dbus_message *msg, + void *user_data) +{ + struct mesh_remote_node_info *node_info = \ + (struct mesh_remote_node_info*) user_data; + + l_dbus_message_set_arguments(msg, "qy", + node_info->unicast, node_info->num_elements); + INFO("Mesh: Delete Remote Node Setup params passed"); + g_free(node_info); +} + +static void __bt_hal_mesh_delete_node_reply( + struct l_dbus_proxy *proxy, + struct l_dbus_message *msg, void *user_data) +{ + INFO("Mesh: Delete Remote Node Reply from DBUS"); +} + +bt_status_t _bt_hal_mesh_node_delete(bt_uuid_t *network, + uint16_t unicast, uint16_t num_elements) +{ + GSList *l; + meshcfg_app *app; + struct mesh_remote_node_info *node_info; + INFO("Mesh: Delete Remote Node"); + l = g_slist_find_custom(mesh_apps, network->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: Delete Remote Node Unicast [0x%2.2x] Num els [%u]", + unicast, num_elements); + + /* Delete Remote Node Request */ + node_info = g_malloc0(sizeof(struct mesh_remote_node_info)); + node_info->unicast = unicast; + node_info->num_elements = num_elements; + + if (!l_dbus_proxy_method_call(app->mgmt_proxy, "DeleteRemoteNode", + __bt_hal_mesh_delete_node_setup, + __bt_hal_mesh_delete_node_reply, node_info, + l_free)) { + ERR("Mesh: Delete Remote Node Request failed!!"); + g_free(node_info); + return BT_STATUS_FAIL; + } + } else { + ERR("Mesh: App not found!!"); + return BT_STATUS_PARM_INVALID; + } + INFO("Mesh: Delete Remote Node Call issued successfully!!"); + return BT_STATUS_SUCCESS; +} + bt_status_t _bt_hal_mesh_network_destroy(bt_uuid_t *net_uuid) { GSList *l; diff --git a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h index 19d2cde..2f27671 100644 --- a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h +++ b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.h @@ -49,6 +49,9 @@ 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_node_delete(bt_uuid_t *network, + uint16_t unicast, uint16_t num_elements); + bt_status_t _bt_hal_mesh_network_scan(bt_uuid_t *net_uuid, bt_hal_mesh_scan_param_t *param); diff --git a/bt-oal/bluez_hal/src/bt-hal-mesh.c b/bt-oal/bluez_hal/src/bt-hal-mesh.c index a0e4467..0bac7ad 100644 --- a/bt-oal/bluez_hal/src/bt-hal-mesh.c +++ b/bt-oal/bluez_hal/src/bt-hal-mesh.c @@ -246,6 +246,13 @@ static bt_status_t mesh_destroy_network(bt_uuid_t *network) return _bt_hal_mesh_network_destroy(network); } +static bt_status_t mesh_delete_node(bt_uuid_t *network, uint16_t unicast, + uint16_t num_elements) +{ + DBG(""); + return _bt_hal_mesh_node_delete(network, unicast, num_elements); +} + static bt_status_t mesh_scan(bt_uuid_t *network, bt_hal_mesh_scan_param_t *param) { DBG(""); @@ -373,6 +380,7 @@ static btmesh_interface_t mesh_if = { .init = init, .create = mesh_create_network, .destroy = mesh_destroy_network, + .delete_node = mesh_delete_node, .scan = mesh_scan, .scan_cancel = mesh_scan_cancel, .capability = mesh_set_prov_caps, diff --git a/bt-oal/hardware/bt_mesh.h b/bt-oal/hardware/bt_mesh.h index a965f1b..a8b6d62 100644 --- a/bt-oal/hardware/bt_mesh.h +++ b/bt-oal/hardware/bt_mesh.h @@ -204,6 +204,8 @@ 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 (*delete_node)(bt_uuid_t *network, uint16_t unicast, + uint16_t elem_cnt); bt_status_t (*scan)(bt_uuid_t *network, bt_hal_mesh_scan_param_t *param); bt_status_t (*scan_cancel)(bt_uuid_t *network); diff --git a/bt-oal/include/oal-mesh.h b/bt-oal/include/oal-mesh.h index 1edbb35..eeeb2e2 100644 --- a/bt-oal/include/oal-mesh.h +++ b/bt-oal/include/oal-mesh.h @@ -272,6 +272,18 @@ oal_status_t mesh_register_node(oal_mesh_node_t *node, oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid); /** + * @brief Delete Remote Node configuration + * + * @remarks Stack will remove the Remote node entry + * + * @pre OAl API should be enabled with mesh_enable(). + * + * @see mesh_enable() + */ +oal_status_t mesh_delete_remote_node(oal_uuid_t* network_uuid, + uint16_t unicast, uint16_t num_elements); + +/** * @brief UnRegister the BLE Mesh Node * * @remarks Application will unregister the Mesh Provisioner diff --git a/bt-oal/oal-mesh.c b/bt-oal/oal-mesh.c index 1e476da..0e47904 100644 --- a/bt-oal/oal-mesh.c +++ b/bt-oal/oal-mesh.c @@ -382,6 +382,22 @@ oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid) 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) { -- 2.7.4