Mesh: Maintain group subscription list in cdb
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / mesh / bt-service-mesh-config-client.c
index d1ca68c..5a7810b 100644 (file)
@@ -233,7 +233,7 @@ static void __bt_mesh_wait_response_timeout(
        /* TODO Reset the remote node, as no response is expected on reset command */
 
 
-       switch(req->cmd->opcode) {
+       switch (req->cmd->opcode) {
        case MESH_OPCODE_DEV_COMP_GET: {
                /* Send event with timeout for Vendor Features */
                bluetooth_mesh_node_features_t *vendor_event = \
@@ -261,6 +261,15 @@ static void __bt_mesh_wait_response_timeout(
                g_free(event);
                break;
        }
+       case MESH_OPCODE_CONFIG_MODEL_SUB_GET:
+       case MESH_OPCODE_CONFIG_VEND_MODEL_SUB_GET:
+               BT_INFO("Mesh: Command TimedOut: Model Subscription list get");
+               /* Send event with timeout */
+                __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_GET_SUBSCRIPTION_LIST, req->data,
+                                       sizeof(bluetooth_mesh_model_configure_t));
+       break;
        case MESH_OPCODE_NETKEY_ADD:
        case MESH_OPCODE_NETKEY_UPDATE:
        case MESH_OPCODE_NETKEY_DELETE:
@@ -283,7 +292,6 @@ static void __bt_mesh_wait_response_timeout(
                break;
        case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
        case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE:
-       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
        case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
                /* Send event with timeout */
                 __bt_mesh_handle_pending_dev_config_request_info(
@@ -300,6 +308,40 @@ static void __bt_mesh_wait_response_timeout(
                                BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, req->data,
                                        sizeof(bluetooth_mesh_model_configure_t));
                break;
+       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
+               /* Send event with timeout */
+                __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, req->data,
+                                       sizeof(bluetooth_mesh_model_configure_t));
+               /* Send event with timeout */
+                __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIG_GROUP_SUB, req->data,
+                                       sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_CONFIG_MODEL_PUB_GET:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_GET_PUBLICATION, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_CONFIG_MODEL_PUB_SET:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_SET_PUBLICATION, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
+       case MESH_OPCODE_MODEL_APP_BIND:
+       case MESH_OPCODE_MODEL_APP_UNBIND:
+               /* Send event with timeout */
+               __bt_mesh_handle_pending_dev_config_request_info(
+                       BLUETOOTH_ERROR_TIMEOUT,
+                               BT_MESH_MODEL_CONFIGURE_APPKEY, req->data,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
        default:
                break;
        }
@@ -321,7 +363,7 @@ static void __bt_mesh_add_request(uint32_t opcode, uint16_t dest,
                return;
        _bt_mesh_util_convert_hex_to_string((uint8_t *) net_uuid, 16, uuid_str,
                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
-       BT_INFO("Mesh: Net UUID[%s]",uuid_str);
+       BT_INFO("Mesh: Net UUID[%s]", uuid_str);
 
        BT_INFO("Mesh: Adding command opcode [0x%2.2x] response [0x%2.2x]",
                        cmd->opcode, cmd->response);
@@ -358,11 +400,11 @@ static struct mesh_pending_request *__bt_mesh_get_request_by_response(
                BT_INFO("Mesh: Current req addr [0x%2.2x] res [0x%2.2x]", addr, response);
                _bt_mesh_util_convert_hex_to_string((uint8_t *) net_uuid, 16, uuid_str,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
-               BT_INFO("Mesh: Net UUID[%s]",uuid_str);
+               BT_INFO("Mesh: Net UUID[%s]", uuid_str);
 
                _bt_mesh_util_convert_hex_to_string((uint8_t *) req->net_uuid, 16, uuid_str1,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
-               BT_INFO("Mesh: Net UUID1[%s]",uuid_str1);
+               BT_INFO("Mesh: Net UUID1[%s]", uuid_str1);
                if (!memcmp(net_uuid, req->net_uuid, 16) &&
                                req->addr == addr &&
                                req->cmd->response == response)
@@ -480,6 +522,8 @@ static void __bt_mesh_send_model_publication_status_event(
        GArray *info = NULL;
 
        if (BLUETOOTH_ERROR_NONE == result) {
+               BT_INFO("Mesh: Model ID [0x%4.4x]", evt->model);
+               BT_INFO("Mesh: Model Publication Address [0x%2.2x]", evt->pub_addr);
                /* Send event */
                info = g_array_new(FALSE, FALSE, sizeof(gchar));
                g_array_append_vals(info, evt,
@@ -524,19 +568,26 @@ static void __bt_mesh_send_model_get_subscription_list_event(
        GVariant  *param = NULL;
        GVariantBuilder *builder = NULL;
        int i;
+       char *net_uuid;
 
        if (BLUETOOTH_ERROR_NONE == result) {
-               if (evt->sublist_count) {
-                       builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
-                       for (i = 0; i < evt->sublist_count; i++)
-                               g_variant_builder_add(builder, "q", *evt->sub_list[i]);
+               BT_INFO("Mesh: Total Subscriptions bound to model [%d]",
+                               evt->sublist_count);
+               BT_INFO("Mesh: Network [%s]", evt->net_uuid);
+               builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
+               for (i = 0; i < evt->sublist_count; i++) {
+                       BT_INFO("Mesh: Subscription Address [0x%2.2x]",
+                               *evt->sub_list[i]);
+                       g_variant_builder_add(builder, "q", *evt->sub_list[i]);
+               }
 
-                       param = g_variant_new("(isqiui(aq))", result, evt->net_uuid,
-                                       evt->primary_unicast, evt->elem_index, evt->model,
-                                       evt->sublist_count, builder);
+               net_uuid = g_strdup(evt->net_uuid);
+               param = g_variant_new("(isqiui(aq))", result, net_uuid,
+                               evt->primary_unicast, evt->elem_index, evt->model,
+                               evt->sublist_count, builder);
+
+               g_variant_builder_unref(builder);
 
-                       g_variant_builder_unref(builder);
-               }
                /* Send event */
                _bt_send_event(BT_MESH_EVENT,
                                BLUETOOTH_EVENT_MESH_MODEL_SUBSCRIPTION_LIST,
@@ -548,6 +599,8 @@ static void __bt_mesh_send_model_get_subscription_list_event(
                                g_free(evt->sub_list[i]);
                        g_free(evt->sub_list);
                }
+               g_free(net_uuid);
+               BT_INFO("freed net uuid");
        }
 }
 
@@ -883,6 +936,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
                        bluetooth_mesh_model_configure_t *event;
                        bluetooth_mesh_model_configure_t *req;
 
+                       BT_INFO("Mesh: Handle event for BT_MESH_MODEL_GET_SUBSCRIPTION_LIST");
                        event = (bluetooth_mesh_model_configure_t*) param;
                        req = (bluetooth_mesh_model_configure_t*)req_info->user_data;
 
@@ -963,6 +1017,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
                        break;
                }
                case BT_MESH_MODEL_GET_PUBLICATION: {
+                       BT_INFO("Mesh: Event for Model Get Publication Request");
                        bluetooth_mesh_model_configure_t *event;
                        bluetooth_mesh_model_configure_t *req;
 
@@ -972,6 +1027,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
                        if (!g_strcmp0(req->net_uuid, event->net_uuid) &&
                                        req->primary_unicast == event->primary_unicast) {
                                /* Send Event */
+                               BT_INFO("Mesh: Send Model Publication status for Get Request");
                                __bt_mesh_send_model_publication_status_event( \
                                                BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS, \
                                                result, event);
@@ -987,6 +1043,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
                        break;
                }
                case BT_MESH_MODEL_SET_PUBLICATION: {
+                       BT_INFO("Mesh: Event for Model Set Publication Request");
                        bluetooth_mesh_model_configure_t *event;
                        bluetooth_mesh_model_configure_t *req;
 
@@ -996,6 +1053,7 @@ static void __bt_mesh_handle_pending_dev_config_request_info(int result,
                        if (!g_strcmp0(req->net_uuid, event->net_uuid) &&
                                req->primary_unicast == event->primary_unicast) {
                                /* Send Event */
+                               BT_INFO("Mesh: Send Model Publication status for Set Request");
                                __bt_mesh_send_model_publication_status_event( \
                                        BLUETOOTH_EVENT_MESH_MODEL_PUBLICATION_STATUS, \
                                                result, req);
@@ -1053,7 +1111,6 @@ static void __mesh_handle_model_subscription_event(int result,
        case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
        case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE:
        case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
-       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
                /* Model Bind/UnBind Event */
        BT_INFO("Mesh: Handle Event for Request: BT_MESH_MODEL_CONFIG_GROUP_SUB");
        __bt_mesh_handle_pending_dev_config_request_info(result,
@@ -1068,6 +1125,15 @@ static void __mesh_handle_model_subscription_event(int result,
                        BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, param,
                                sizeof(bluetooth_mesh_model_configure_t));
                break;
+       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
+       BT_INFO("Mesh: Handle Event for Request: MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL");
+       __bt_mesh_handle_pending_dev_config_request_info(result,
+                       BT_MESH_MODEL_CONFIG_GROUP_SUB, param,
+                               sizeof(bluetooth_mesh_model_configure_t));
+       __bt_mesh_handle_pending_dev_config_request_info(result,
+                       BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB, param,
+                               sizeof(bluetooth_mesh_model_configure_t));
+               break;
        default:
                break;
        }
@@ -1112,8 +1178,8 @@ void _bt_mesh_config_client_devkey_msg_handler(
 
 
        switch (opcode & ~MESH_OPCODE_UNRELIABLE) {
-               default:
-                       return;
+       default:
+               return;
        case MESH_OPCODE_CONFIG_MODEL_PUB_STATUS: {
                if (data_len != 12 && data_len != 14)
                        break;
@@ -1127,7 +1193,7 @@ void _bt_mesh_config_client_devkey_msg_handler(
                                event->source, __mesh_status_to_string(data[0]));
 
                if (data[0] != MESH_STATUS_SUCCESS)
-                       break;
+                       result = BLUETOOTH_ERROR_INTERNAL;
 
                /* Extract Element Address */
                ele_addr = l_get_le16(data + 1);
@@ -1143,16 +1209,22 @@ void _bt_mesh_config_client_devkey_msg_handler(
                        mod_id = MESH_VENDOR_ID_MASK | mod_id;
                }
 
+               param.model = mod_id;
+               BT_INFO("Model ID\t%4.4x\n", mod_id);
+
                param.primary_unicast = event->source;
                param.elem_index = ele_addr - event->source;
                /* Extract Publish Address */
                param.pub_addr = l_get_le16(data + 3);
+               BT_INFO("Mesh: Pub Address [0x%2.2x]", param.pub_addr);
 
                /* Extract Appkey Index */
                param.appkey_idx =  l_get_le16(data + 5);
+               BT_INFO("Mesh: AppKey Idx [0x%2.2x]", param.appkey_idx);
 
                /* Extract TTL */
                param.ttl = data[6];
+               BT_INFO("Mesh: TTL [0x%x]", param.ttl);
 
                /* Extract Period */
                param.period = data[7];
@@ -1213,6 +1285,43 @@ void _bt_mesh_config_client_devkey_msg_handler(
                BT_INFO("Subscr Addr\t%4.4x\n", addr);
                BT_INFO("Model ID\t%4.4x\n", mod_id);
 
+               if (data[0] == MESH_STATUS_SUCCESS) {
+                       /* Update cdb */
+                       switch (cmd->opcode) {
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_ADD:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_ADD:
+                               if (!_bt_mesh_network_add_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to add model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE:
+                               if (!_bt_mesh_network_delete_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to delete model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL:
+                               if (!_bt_mesh_network_delete_all_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id)) {
+                                       BT_INFO("Failed to delete all model subscription!");
+                               }
+                       break;
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_OVERWRITE:
+                       case MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE:
+                               if (!_bt_mesh_network_overwrite_model_subscription(
+                                       event->net_uuid.uuid, event->source,
+                                       ele_addr - event->source, mod_id, addr)) {
+                                       BT_INFO("Failed to overwrite model subscription!");
+                               }
+                       break;
+                       }
+               }
+
                if (cmd)
                        __mesh_handle_model_subscription_event(result, &param, cmd);
 
@@ -1372,19 +1481,23 @@ void _bt_mesh_config_client_devkey_msg_handler(
                param.primary_unicast = event->source;
                param.elem_index = elem_addr - event->source;
                param.model = mod_id;
-
-               total = data_len -  5;
+               BT_INFO("Mesh: Data length of All Models Together [%d]", data_len - 5);
+               total = (data_len -  5)/2;
                param.sublist_count = total;
+               BT_INFO("Mesh: Total Number of subscriptions [%d]", total);
                if (total) {
                        param.sub_list = (uint16_t **)g_malloc0(sizeof(uint16_t*) * total);
 
                        i = 5;
-                       for (; i < data_len; i += 2) {
-                               BT_INFO("Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i));
-                               param.sub_list[i] = g_malloc(sizeof(uint16_t));
-                               *param.sub_list[i] = l_get_le16(data + i);
+                       for (int k = 0; i < data_len; k++, i += 2) {
+                               BT_INFO("Mesh: Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i));
+                               param.sub_list[k] = g_malloc(sizeof(uint16_t));
+                               *param.sub_list[k] = l_get_le16(data + i);
                        }
                }
+
+               /* <TO-DO> Update model sub in cdb */
+
                __bt_mesh_handle_pending_dev_config_request_info(result,
                        BT_MESH_MODEL_GET_SUBSCRIPTION_LIST, &param,
                                sizeof(bluetooth_mesh_model_configure_t));
@@ -1402,7 +1515,7 @@ void _bt_mesh_config_client_devkey_msg_handler(
                        (uint8_t *) event->net_uuid.uuid, 16, param.net_uuid,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
 
-               BT_INFO("\nNode %4.4x BT SIG Model Subscription List status %s\n",
+               BT_INFO("\nNode %4.4x Vendor Model Subscription List status %s\n",
                                event->source, __mesh_status_to_string(data[0]));
 
                BT_INFO("Element Addr\t%4.4x\n", l_get_le16(data + 1));
@@ -1418,16 +1531,19 @@ void _bt_mesh_config_client_devkey_msg_handler(
                param.elem_index = elem_addr - event->source;
                param.model = mod_id;
 
-               total = data_len -  7;
+               BT_INFO("Mesh: Data length of All Models Together [%d]", data_len - 7);
+               total = (data_len -  7)/2;
                param.sublist_count = total;
+
+               BT_INFO("Mesh: Total Number of subscriptions [%d]", total);
                if (total) {
                        param.sub_list = (uint16_t **)g_malloc0(sizeof(uint16_t*) * total);
 
                        i = 7;
-                       for (; i < data_len; i += 2) {
-                               BT_INFO("Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i));
-                               param.sub_list[i] = g_malloc(sizeof(uint16_t));
-                               *param.sub_list[i] = l_get_le16(data + i);
+                       for (int k = 0; i < data_len; k++, i += 2) {
+                               BT_INFO("Mesh: Subscription Addr \t\t%4.4x\n ", l_get_le16(data + i));
+                               param.sub_list[k] = g_malloc(sizeof(uint16_t));
+                               *param.sub_list[k] = l_get_le16(data + i);
                        }
                }
                __bt_mesh_handle_pending_dev_config_request_info(result,
@@ -1457,9 +1573,19 @@ void _bt_mesh_config_client_devkey_msg_handler(
                        (uint8_t *) event->net_uuid.uuid, 16, features.net_uuid,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
                features.unicast = event->source;
-               _bt_mesh_node_get_vendor_features(event->net_uuid.uuid,
-                       event->source, &features);
-
+               BT_INFO("Mesh: Net UUID [%s]", features.net_uuid);
+
+               BT_INFO("Mesh: Composition status for node unicast [0x%2.2x]",
+                       event->source);
+               if (!_bt_mesh_node_get_vendor_features(event->net_uuid.uuid,
+                       event->source, &features)) {
+                       BT_ERR("Mesh: Failed to get Vendor Specific Infor for [0x%2.2x]",
+                               event->source);
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       BT_INFO("Mesh: Got Feature informations for [0x%2.2x]",
+                               event->source);
+               }
                __bt_mesh_handle_pending_dev_config_request_info(result,
                        BT_MESH_NODE_GET_VENDOR_FEATURES, &features,
                                sizeof(bluetooth_mesh_node_features_t));
@@ -1609,6 +1735,7 @@ int _bt_mesh_node_discover_vendor_features(const char *app_cred, const char *sen
        oal_uuid_t net_uuid;
        uint8_t buffer[MESH_CONFIG_BUFFER_MAX_LEN];
 
+       BT_INFO("Mesh: Vendor features for Network UUID [%s]", req->net_uuid);
        _bt_mesh_util_convert_string_to_hex(req->net_uuid,
                        strlen(req->net_uuid), net_uuid.uuid, 16);
        /* Check if Node's vendor features are already svaed or not */
@@ -1878,6 +2005,8 @@ int _bt_mesh_model_configure_virtual_group_subscription(
                opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_DELETE;
        else if (req->op == BLUETOOTH_MESH_MODEL_SUB_OVERWRITE)
                opcode = MESH_OPCODE_CONFIG_MODEL_SUB_VIRT_OVERWRITE;
+       else if (req->op == BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL)
+               opcode = MESH_OPCODE_CONFIG_MODEL_SUB_DELETE_ALL;
 
        /* Check pending request */
        if (_bt_mesh_check_pending_request(opcode,
@@ -2032,7 +2161,7 @@ int _bt_mesh_model_set_publication(const char *app_cred, const char *sender,
 
        if (req->pub_addr != MESH_UNASSIGNED_ADDRESS) {
                if (MESH_IS_VIRTUAL(req->pub_addr)) {
-                       if(!_bt_mesh_network_get_label_uuid_from_sub_addr(
+                       if (!_bt_mesh_network_get_label_uuid_from_sub_addr(
                                        net_uuid.uuid, req->pub_addr, label_uuid))
                                return BLUETOOTH_ERROR_INVALID_PARAM;
                        opcode = MESH_OPCODE_CONFIG_MODEL_PUB_VIRT_SET;
@@ -2153,13 +2282,14 @@ int _bt_mesh_node_model_get_subscription_list(const char *app_cred, const char *
        l_put_le16((req->primary_unicast + req->elem_index), buffer + data_len);
        data_len += 2;
 
-
        /* Insert Model ID */
        if (opcode == MESH_OPCODE_CONFIG_MODEL_SUB_GET) {
+               BT_INFO("Mesh: Get Subscription List for BT SIG Model");
                /* 1st 2 octet Company ID is 0xFFFF means, it is BT SIG Model*/
                l_put_le16(req->model & 0x0000FFFF, buffer + data_len);
                data_len += 2;
        } else {
+               BT_INFO("Mesh: Get Subscription List for Vendor Model");
                /* Vendor Model, 1st 2 octetes: Company ID, next 2 octets: Vendor Model ID */
                l_put_le16(req->model & 0xFFFF0000, buffer + data_len);
                data_len += 2;
@@ -2254,6 +2384,63 @@ int _bt_mesh_node_model_get_appkey_list(const char *app_cred, const char *sender
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_mesh_network_reset_node(const char *app_cred, const char *sender,
+               bluetooth_mesh_node_info_t *node)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       uint16_t netkey_idx;
+       oal_uuid_t net_uuid;
+       uint16_t data_len;
+       uint8_t buffer[MESH_CONFIG_BUFFER_MAX_LEN];
+
+       /* If Scanning is going on */
+       if (_bt_mesh_is_provisioning() ||
+                       _bt_mesh_is_scanning()) {
+               BT_ERR("Device is buzy..");
+               return BLUETOOTH_ERROR_DEVICE_BUSY;
+       }
+
+       _bt_mesh_util_convert_string_to_hex(node->net_uuid,
+                       strlen(node->net_uuid), net_uuid.uuid, 16);
+
+       /* Check pending request */
+       if (_bt_mesh_check_pending_request(MESH_OPCODE_NODE_RESET,
+                               node->primary_unicast, net_uuid.uuid)) {
+               BT_ERR("Device is buzy..");
+               return BLUETOOTH_ERROR_DEVICE_BUSY;
+       }
+       BT_INFO("Mesh: Reset a remote Node [0x%2.2x] Elem Cnt [0x%2.2x]",
+                       node->primary_unicast, node->num_elements);
+       /* Get Subnet index of the remote node for TX encryption */
+       netkey_idx = _bt_mesh_node_get_subnet_idx(net_uuid.uuid, node->primary_unicast);
+       if (netkey_idx == MESH_NET_IDX_INVALID)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       data_len = _bt_mesh_util_opcode_set(MESH_OPCODE_NODE_RESET, buffer);
+
+       /* Send Node Reset command 5 times to ensure reliability */
+       for (int i = 0; i < 5; i++)
+               ret = mesh_conf_send_message(&net_uuid, node->primary_unicast,
+                               true, netkey_idx, buffer, data_len);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("Mesh: Node Reset Failed!: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_INFO("Mesh: Node reset Done, Send Delete req: Unicast[0x%2.2x]",
+                       node->primary_unicast);
+
+       ret = mesh_delete_remote_node(&net_uuid, node->primary_unicast,
+                       node->num_elements);
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("Mesh: Remote Node Deletion Failed!: %d", ret);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return _bt_mesh_network_remove_node_configuration(node);
+}
+
 int _bt_mesh_node_model_appkey_execute(const char *app_cred, const char *sender,
                bluetooth_mesh_model_configure_t *req)
 {
@@ -2384,7 +2571,7 @@ static bool __bt_mesh_check_pending_key_cmd(uint16_t dest, bool is_netkey,
        const struct mesh_config_cmd *cmd;
 
        if (is_netkey) {
-               switch(op) {
+               switch (op) {
                case BLUETOOTH_MESH_NODE_KEY_ADD:
                        cmd = __mesh_get_command(MESH_OPCODE_NETKEY_ADD);
                        if (!cmd)
@@ -2417,7 +2604,7 @@ static bool __bt_mesh_check_pending_key_cmd(uint16_t dest, bool is_netkey,
                        return false;
                }
        } else {
-               switch(op) {
+               switch (op) {
                case BLUETOOTH_MESH_NODE_KEY_ADD:
                        cmd = __mesh_get_command(MESH_OPCODE_APPKEY_ADD);
                        if (!cmd)
@@ -2518,7 +2705,7 @@ int _bt_mesh_node_configure_key(const char *app_cred, const char *sender,
                /* Handle Key (App/Net) Update & Add Commands: Key Config message  */
                update = (opcode == MESH_OPCODE_NETKEY_UPDATE || opcode == MESH_OPCODE_APPKEY_UPDATE);
                ret = mesh_conf_send_key_message(&net_uuid, req->primary_unicast, req->is_netkey,
-                               update, req->is_netkey? req->netkey_idx: req->appkey_idx, netkey_idx);
+                               update, req->is_netkey ? req->netkey_idx : req->appkey_idx, netkey_idx);
        }
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("ret: %d", ret);