/**
 * Function to send message to all nodes
 *
 * @param buffer len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uns32 dtm_internode_snd_msg_to_all_nodes(uns8 *buffer, uns16 len)
{
	/* Get each node and send message */
	NODE_ID node_id = 0;
	DTM_NODE_DB *node = NULL;
	TRACE_ENTER();

	/* while (NULL != (node = (DTM_NODE_DB *) ncs_patricia_tree_getnext(&dtms_gl_cb->nodeid_tree, (uns8 *)&node_id)))  */
	while (NULL != (node = dtm_node_getnext_by_id(node_id))) {
		node_id = node->node_id;
		if (node_id != dtms_gl_cb->node_id) {
			uns8 *buf_send = NULL;
			if (NULL == (buf_send = calloc(1, len))) {
				TRACE("DTM :calloc failed for snd_msg_to_all_nodes");
				free(buffer);
				return NCSCC_RC_FAILURE;
			}
			memcpy(buf_send, buffer, len);	
			dtm_internode_snd_msg_common(node, buf_send, len);
		}
	}
	free(buffer);
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
/**
 * Function to send message to all nodes
 *
 * @param buffer len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_internode_snd_msg_to_all_nodes(uint8_t *buffer, uint16_t len)
{
	/* Get each node and send message */
	NODE_ID node_id = 0;
	DTM_NODE_DB *node = NULL;
	TRACE_ENTER();

	while (NULL != (node = dtm_node_getnext_by_id(node_id))) {
		node_id = node->node_id;
		/* send only to fully connected peers */
		if ((node_id != dtms_gl_cb->node_id) &&	node->comm_status) {
			uint8_t *buf_send = NULL;
			if (NULL == (buf_send = calloc(1, len))) {
				TRACE("DTM :calloc failed for snd_msg_to_all_nodes");
				free(buffer);
				return NCSCC_RC_FAILURE;
			}
			memcpy(buf_send, buffer, len);	
			dtm_internode_snd_msg_common(node, buf_send, len);
		}
	}
	free(buffer);
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}