Mesh: Implement Network Key operations
authorAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 11:15:45 +0000 (16:45 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 11:15:45 +0000 (16:45 +0530)
Ths patch major handles following
- Create/Update/Delete Network Key
- Create/Update/Delete Application Key
- Set Network Friendly Name

Change-Id: I3f9a3588f11ee735352788fb86c6ec81882fc626
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-api/bt-mesh.c
bt-service/services/bt-request-handler.c
bt-service/services/include/bt-service-mesh-network.h
bt-service/services/mesh/bt-service-mesh-network.c

index b04fb25..5963603 100644 (file)
@@ -232,3 +232,267 @@ BT_EXPORT_API int bluetooth_mesh_authentication_reply(int auth_type,
 
        return result;
 }
+
+BT_EXPORT_API int bluetooth_mesh_network_set_name(
+       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:Set Network Name");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_NAME,
+                       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_add_netkey(
+               bluetooth_mesh_network_t *network,
+                       uint16_t *netkey_idx)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(network, return);
+       BT_CHECK_PARAMETER(netkey_idx, 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: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) {
+               *netkey_idx = g_array_index(out_param, guint16, 0);
+       }
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
+       bluetooth_mesh_network_t *network,
+               uint16_t netkey_idx)
+{
+       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));
+       g_array_append_vals(in_param2, &netkey_idx,  sizeof(guint16));
+
+       BT_INFO("Mesh: Delete Subnetwork key");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
+                       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_update_netkey(
+       bluetooth_mesh_network_t *network,
+               uint16_t netkey_idx)
+{
+       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));
+       g_array_append_vals(in_param2, &netkey_idx,  sizeof(guint16));
+
+       BT_INFO("Mesh: Update Subnetwork key");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
+                       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_add_appkey(
+               bluetooth_mesh_network_t *network,
+                       uint16_t netkey_index,
+                               uint16_t *appkey_index)
+{
+       int result;
+
+       BT_CHECK_PARAMETER(network, return);
+       BT_CHECK_PARAMETER(appkey_index, 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, &netkey_index,  sizeof(guint16));
+
+       BT_INFO("Mesh: Create 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) {
+               *appkey_index = g_array_index(out_param, guint16, 0);
+       }
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
+               bluetooth_mesh_network_t *network,
+                       uint16_t netkey_index, uint16_t appkey_index)
+{
+       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));
+       g_array_append_vals(in_param2, &netkey_index,  sizeof(guint16));
+       g_array_append_vals(in_param3, &appkey_index,  sizeof(guint16));
+
+       BT_INFO("Mesh:BTAPI: Update AppKey");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
+                       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_delete_appkey(bluetooth_mesh_network_t *network,
+                       uint16_t netkey_index, uint16_t appkey_index)
+{
+       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));
+       g_array_append_vals(in_param2, &netkey_index,  sizeof(guint16));
+       g_array_append_vals(in_param3, &appkey_index,  sizeof(guint16));
+
+       BT_INFO("Mesh: Delete AppKey");
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
+                       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_get_all_netkey(
+       bluetooth_mesh_network_t *network,
+               GPtrArray **netkeys)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       guint size;
+       int i;
+
+       BT_CHECK_PARAMETER(network, return);
+       BT_CHECK_PARAMETER(netkeys, 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));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               if (out_param == NULL) {
+                       BT_ERR("Mesh: out_param is NULL");
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       size = (out_param->len) / sizeof(guint16);
+
+                       if (size == 0) {
+                               BT_ERR("Mesh: No netkeys created for the network");
+                               result = BLUETOOTH_ERROR_NOT_FOUND;
+                       }
+
+                       for (i = 0; i < size; i++) {
+                               uint16_t netkey_index;
+                               uint16_t *netkey_idx = NULL;
+
+                               netkey_index = g_array_index(out_param,
+                                               guint16, i);
+
+                               netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
+                               g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
+                       }
+               }
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
+               bluetooth_mesh_network_t *network,
+                       uint16_t netkey_idx,
+                               GPtrArray **appkeys)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       guint size;
+       int i;
+
+       BT_CHECK_PARAMETER(network, return);
+       BT_CHECK_PARAMETER(appkeys, 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, &netkey_idx,  sizeof(guint16));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               if (out_param == NULL) {
+                       BT_ERR("Mesh: out_param is NULL");
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       size = (out_param->len) / sizeof(guint16);
+
+                       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++) {
+                               uint16_t appkey_index;
+                               uint16_t *appkey_idx = NULL;
+
+                               appkey_index = g_array_index(out_param,
+                                               guint16, i);
+
+                               appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
+                               g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
+                       }
+               }
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
index 007a598..c61e140 100644 (file)
@@ -232,7 +232,13 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_AUDIO_SELECT_ROLE
                        /* Mesh API's */
                        || service_function == BT_MESH_NETWORK_CREATE
-                       || service_function == BT_MESH_NETWORK_SCAN)
+                       || service_function == BT_MESH_NETWORK_SCAN
+                       || service_function == BT_MESH_NETWORK_ADD_NETKEY
+                       || service_function == BT_MESH_NETWORK_DELETE_NETKEY
+                       || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
+                       || service_function == BT_MESH_NETWORK_ADD_APPKEY
+                       || service_function == BT_MESH_NETWORK_DELETE_APPKEY
+                       || service_function == BT_MESH_NETWORK_UPDATE_APPKEY)
                return TRUE;
        else
                return FALSE;
@@ -3522,6 +3528,191 @@ normal:
                                auth_value, authentication_reply);
                break;
        }
+       case BT_MESH_NETWORK_SET_NAME: {
+               bluetooth_mesh_network_t network;
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+
+               result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
+
+               break;
+       }
+       case BT_MESH_NETWORK_ADD_NETKEY: {
+               bluetooth_mesh_network_t network;
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+
+               result = _bt_mesh_network_add_netkey(requester_unique_creds,
+                       sender, &network);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_DELETE_NETKEY: {
+               bluetooth_mesh_network_t network;
+               uint16_t index;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &index, sizeof(guint16));
+
+               result = _bt_mesh_network_delete_netkey(requester_unique_creds,
+                               sender, &network, index);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_UPDATE_NETKEY: {
+               bluetooth_mesh_network_t network;
+               uint16_t index;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &index, sizeof(guint16));
+
+               result = _bt_mesh_network_update_netkey(requester_unique_creds,
+                               sender, &network, index);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_ADD_APPKEY: {
+               bluetooth_mesh_network_t network;
+               uint16_t net_idx;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &net_idx, sizeof(guint16));
+
+               result = _bt_mesh_network_add_appkey(requester_unique_creds,
+                               sender, &network, net_idx);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_UPDATE_APPKEY: {
+               bluetooth_mesh_network_t network;
+               uint16_t net_idx;
+               uint16_t app_idx;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &net_idx, sizeof(guint16));
+               __bt_service_get_parameters(in_param3,
+                               &app_idx, sizeof(guint16));
+
+               result = _bt_mesh_network_update_appkey(requester_unique_creds,
+                               sender, &network, net_idx, app_idx);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_DELETE_APPKEY: {
+               bluetooth_mesh_network_t network;
+               uint16_t net_idx;
+               uint16_t app_idx;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &net_idx, sizeof(guint16));
+               __bt_service_get_parameters(in_param3,
+                               &app_idx, sizeof(guint16));
+
+               result = _bt_mesh_network_delete_appkey(requester_unique_creds,
+                               sender, &network, net_idx, app_idx);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
+               } else {
+                       bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)net);
+               }
+               break;
+       }
+       case BT_MESH_NETWORK_GET_NETKEYS: {
+               bluetooth_mesh_network_t network;
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               result = _bt_mesh_network_get_netkeys(requester_unique_creds,
+                               sender, &network, out_param1);
+               break;
+       }
+       case BT_MESH_NETWORK_GET_APPKEYS: {
+               bluetooth_mesh_network_t network;
+               uint16_t net_idx;
+
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param1,
+                               &network, sizeof(bluetooth_mesh_network_t));
+               __bt_service_get_parameters(in_param2,
+                               &net_idx, sizeof(guint16));
+               result = _bt_mesh_network_get_appkeys(requester_unique_creds,
+                               sender, &network, net_idx, out_param1);
+               break;
+       }
        default:
                BT_INFO("UnSupported function [%d]", function_name);
                result = BLUETOOTH_ERROR_NOT_SUPPORT;
@@ -4348,6 +4539,15 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_MESH_NETWORK_SET_CAPABILITIES:
        case BT_MESH_NETWORK_PROVISION_DEVICE:
        case BT_MESH_AUTHENTICATION_REPLY:
+       case BT_MESH_NETWORK_SET_NAME:
+       case BT_MESH_NETWORK_ADD_NETKEY:
+       case BT_MESH_NETWORK_DELETE_NETKEY:
+       case BT_MESH_NETWORK_UPDATE_NETKEY:
+       case BT_MESH_NETWORK_ADD_APPKEY:
+       case BT_MESH_NETWORK_DELETE_APPKEY:
+       case BT_MESH_NETWORK_UPDATE_APPKEY:
+       case BT_MESH_NETWORK_GET_NETKEYS:
+       case BT_MESH_NETWORK_GET_APPKEYS:
 
        ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
                                                BT_PRIVILEGE_PUBLIC);
index 322a7d7..32add7b 100644 (file)
@@ -69,6 +69,38 @@ int _bt_mesh_network_provision_device(const char *app_cred,
 int _bt_mesh_authentication_reply(int auth_type,
                const char *auth_value, gboolean reply);
 
+int _bt_mesh_network_add_netkey(const char *app_cred,
+               const char *sender, bluetooth_mesh_network_t *network);
+
+int _bt_mesh_network_delete_netkey(const char *app_cred,
+               const char *sender, bluetooth_mesh_network_t *network,
+                       uint16_t index);
+
+int _bt_mesh_network_update_netkey(const char *app_cred,
+               const char *sender, bluetooth_mesh_network_t *network,
+                       uint16_t index);
+
+int _bt_mesh_network_add_appkey(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network, uint16_t netkey_idx);
+
+int _bt_mesh_network_delete_appkey(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network, uint16_t netkey_idx,
+                       uint16_t appkey_idx);
+
+int _bt_mesh_network_update_appkey(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network, uint16_t netkey_idx,
+                       uint16_t appkey_idx);
+
+int _bt_mesh_network_set_name(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network);
+
+int _bt_mesh_network_get_netkeys(const char *app_cred, const char *sender,
+                bluetooth_mesh_network_t *network,  GArray **out_param);
+
+int _bt_mesh_network_get_appkeys(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network,  uint16_t net_idx,
+                       GArray **out_param);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index ed89107..ec032f5 100644 (file)
@@ -405,7 +405,49 @@ int _bt_mesh_authentication_reply(int auth_type,
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_mesh_eleiment_get_models(const char *app_cred, const char *sender,
+int _bt_mesh_network_get_netkeys(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network,  GArray **out_param)
+{
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       if (_bt_mesh_keys_get_netkey_list(cdb_cfg->uuid, out_param))
+               return BLUETOOTH_ERROR_NONE;
+       else
+               return BLUETOOTH_ERROR_INTERNAL;
+}
+
+int _bt_mesh_network_get_appkeys(const char *app_cred, const char *sender,
+               bluetooth_mesh_network_t *network,  uint16_t net_idx,
+                       GArray **out_param)
+{
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       if (_bt_mesh_keys_get_appkey_list(cdb_cfg->uuid,
+                               net_idx, out_param))
+               return BLUETOOTH_ERROR_NONE;
+       else
+               return BLUETOOTH_ERROR_INTERNAL;
+}
+
+int _bt_mesh_element_get_models(const char *app_cred, const char *sender,
                bluetooth_mesh_network_t *network,  uint16_t unicast,
                        int elem_idx, GArray **out_param)
 {
@@ -427,15 +469,261 @@ int _bt_mesh_eleiment_get_models(const char *app_cred, const char *sender,
                return BLUETOOTH_ERROR_INTERNAL;
 }
 
-int _bt_mesh_network_create(const char *app_cred,
-               const char *sender, const char *network_name,
-                       bluetooth_mesh_node_t *node, GSList *model_list)
+int _bt_mesh_network_set_name(const char *app_cred, const char *sender,
+       bluetooth_mesh_network_t *network)
+{
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list,
+               network->token.token, __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+       if (_bt_mesh_conf_set_network_friendly_name(cdb_cfg, network->name.name))
+               return BLUETOOTH_ERROR_NONE;
+
+       return BLUETOOTH_ERROR_INTERNAL;
+}
+
+int _bt_mesh_network_add_netkey(const char *app_cred,
+               const char *sender, bluetooth_mesh_network_t *network)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_ADD;
+       uint16_t idx;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list,
+               network->token.token, __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       if (!_bt_mesh_keys_get_new_netkey_index(cdb_cfg->uuid, &idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+               strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: netkey index to be created [%u]", idx);
+       ret = mesh_network_subnet_execute(&net_uuid, op, idx);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_delete_netkey(const char *app_cred,
+       const char *sender, bluetooth_mesh_network_t *network,
+               uint16_t index)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_DELETE;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       /* Check if NetKey entry is present in local Network */
+       if (!_bt_mesh_keys_is_netkey_present(cdb_cfg->uuid, index))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       /* Check if NetKey is already added to one of the provisioned nodes */
+       if (_bt_mesh_node_is_netkey_added(cdb_cfg->uuid, index))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+                       strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: netkey index to be deleted [%u]", index);
+       ret = mesh_network_subnet_execute(&net_uuid, op, index);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_update_netkey(const char *app_cred,
+       const char *sender, bluetooth_mesh_network_t *network,
+               uint16_t index)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_UPDATE;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       /* Check if NetKey entry is present in local Network */
+       if (!_bt_mesh_keys_is_netkey_present(cdb_cfg->uuid, index))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+                       strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: netkey index to be updated [%u]", index);
+       ret = mesh_network_subnet_execute(&net_uuid, op, index);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_add_appkey(const char *app_cred,
+       const char *sender, bluetooth_mesh_network_t *network,
+               uint16_t netkey_idx)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_ADD;
+       uint16_t idx;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+               __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       /* Check if NetKey entry is present in local Network */
+       if (!_bt_mesh_keys_is_netkey_present(cdb_cfg->uuid, netkey_idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       if (!_bt_mesh_keys_get_new_appkey_index(cdb_cfg->uuid, &idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+               strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: AppKey index to be created [%u]", idx);
+       ret = mesh_network_appkey_execute(&net_uuid, op, netkey_idx, idx);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_update_appkey(const char *app_cred,
+       const char *sender, bluetooth_mesh_network_t *network,
+               uint16_t netkey_idx, uint16_t appkey_idx)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_UPDATE;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       /* Check if NetKey entry is present in local Network */
+       if (!_bt_mesh_keys_is_netkey_present(cdb_cfg->uuid, netkey_idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+                       strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: AppKey index to be updated [%u]", appkey_idx);
+       ret = mesh_network_appkey_execute(&net_uuid, op, netkey_idx, appkey_idx);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_delete_appkey(const char *app_cred,
+       const char *sender, bluetooth_mesh_network_t *network,
+               uint16_t netkey_idx, uint16_t appkey_idx)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       GSList *l;
+       _bt_mesh_cdb_t *cdb_cfg = NULL;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op = OAL_MESH_KEY_DELETE;
+
+       /* Find CDB */
+       l = g_slist_find_custom(cdb_list, network->token.token,
+                       __mesh_compare_app_cdb_token);
+       if (!l)
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       cdb_cfg = (_bt_mesh_cdb_t*)l->data;
+
+       /* Check if NetKey entry is present in local Network */
+       if (!_bt_mesh_keys_is_netkey_present(cdb_cfg->uuid, netkey_idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       /* Check if AppKey is already added to one of the provisioned nodes */
+       if (_bt_mesh_node_is_appkey_added(cdb_cfg->uuid, appkey_idx))
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+
+       _bt_mesh_util_convert_string_to_hex(network->uuid,
+                       strlen(network->uuid), net_uuid.uuid, 16);
+
+       BT_INFO("Mesh: AppKey index to be deleted [%u]", appkey_idx);
+       ret = mesh_network_appkey_execute(&net_uuid, op, netkey_idx, appkey_idx);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_network_create(const char *app_cred, const char *sender,
+               const char *network_name, bluetooth_mesh_node_t *node,
+                       GSList *model_list)
 {
        int ret = OAL_STATUS_SUCCESS;
 
        BT_INFO("Mesh: App Cred [%s] sender [%s] network [%s]",
                        app_cred, sender, network_name);
 
+       /* TODO Handle Buzy status */
        /* Sanity Check: CDB directory creation */
        if (!_bt_mesh_util_is_directory_exists(MESH_CDB_DEFAULT_DIR_PATH)) {
                BT_INFO("MESH: CDB directory does not exist");