/**
 * @file get_input.c
 *
 * @brief This file contains functions that provides demonstration of
 *        usage of input collecting APIs
 *
 * The functions provided in the file provides demonstration on
 * usage of input collecting APIs
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *        usage of TC TM Library APIs
 */


/******************************************************************************/
/*                      Include headers of the component                      */
/******************************************************************************/

#include "ft_config.h"
#include "file_transfer.h"
#include "ftci.h"
#include "upload_def.h"
#include "suspend_resume.h"
#include "notify_apps.h"
#include "ftfci_decode.h"
#include "ftci_decode.h"
#include "segmentation.h"
#include "ft_timer.h"
#include "file_integrity_check.h"
#include "exo_types.h"
#include "logger.h"
#include "ft_sender.h"
#include "ft_receiver.h"

/******************************************************************************/
/*                  Definition of local function like macros                  */
/******************************************************************************/


#define MODE_FT 0
#define MODE_DT 1
#define INPUT_ARRAY_SIZE 50

/******************************************************************************/
/*                       Definition of local variables                        */
/******************************************************************************/

char 			*input_file_name;
char	 		output_file_path[INPUT_ARRAY_SIZE];
uint16_t 		get_mtu;
uint16_t 		ft_ftds_delay;



/******************************************************************************/
/*                      Definition of exported functions                      */
/******************************************************************************/


/*!
 * @brief This API configure the mode of FT operation
 * options: file mode or Bulk data mode
 *
 */
uint8_t ft_mode_select(uint8_t mode)
{
	uint8_t ret_sts = 1;
#ifndef FT_OBC
	if (mode < 2)
#else
	if (mode == 1)
#endif
	{
		tx_info.tx_mode = mode;
	}
	else
	{
		DEBUG_CPRINT(("Invalid mode, Enter again\r\n"));
		ret_sts = 0;
	}
	return ret_sts;
}


/*!
 * @brief This API configure input file name to be transfered
 */
uint8_t ft_config_sender_file_name_path(char name_and_path[])
{
	uint8_t ret_sts = 0;
	uint8_t len;

	FILE *fp = fopen(name_and_path, "r");

	// checking if the file exist or not
	if (fp == NULL)
	{
		DEBUG_CPRINT(("File %s Not Found! Enter again\n", name_and_path));
		ft_fsm_change_state(FT_Init);
	}
	else
	{
		fclose(fp);
		len = strlen(name_and_path);
		input_file_name = os_malloc(len+1);
		//memset(input_file_name,'\0',INPUT_ARRAY_SIZE);
		memcpy(input_file_name, name_and_path, len);
		input_file_name[len] = '\0';
		ret_sts = 1;
	}

	return ret_sts;
}



/*!
 * @brief This API configure receiver side storage address if bulk data transfer mode was chosen
 */
uint8_t ft_config_receiver_node_storage_address(ptr_typ mem_address)
{
	uint8_t ret_sts = 0;


	// checking if the file exist or not
	if (mem_address == 0)
	{
		DEBUG_CPRINT(("Bulk data buffer is Null \n"));
		ft_fsm_change_state(FT_Init);
	}
	else
	{
		DEBUG_CPRINT(("Bulk data buffer SIZE\n"));
		dwnld_rqst.mptr = (uint8_t*)mem_address;
		dwnld_rqst.obc_mem_addr = mem_address;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
		DEBUG_CPRINT(("Download Address %luX \n",dwnld_rqst.mptr));
	//	log_id_with_one_arg(LOG_INFO_L1, LOG_FTM, DOWNLOAD_ADDRESS_u8_,(uint32_t)dwnld_rqst.mptr);
#pragma GCC diagnostic pop

	}

	return ret_sts;
}

#ifndef FT_OBC


/*!
 * @brief This API configure receiver side folder path and file name
 *
 */
uint8_t ft_config_receiver_file_name_path(char name_and_path[])
{
	uint8_t ret_sts = 0;
	uint8_t len;

	FILE *fp = fopen(name_and_path, "r");

	// checking if the file exist or not
	if (fp == NULL)
	{
		DEBUG_CPRINT(("File %s Not Found! Enter again\n", name_and_path));
		ft_fsm_change_state(Input_State);
	}
	else
	{
		len = strlen(name_and_path);
		memcpy(output_file_path, name_and_path, len);
		ret_sts = 1;
		fclose(fp);
	}

	return ret_sts;
}
#endif



/*!
 * @brief This API configure input bulk data buffer with length
 *
 */
uint8_t ft_config_bulk_data_input_buffer(uint8_t *buffer, uint32_t buf_length)
{
	uint8_t ret_sts = 0;


	// checking if the file exist or not
	if (buffer == NULL)
	{
		DEBUG_CPRINT(("Bulk data buffer is Null \n"));
		ft_fsm_change_state(FT_Init);
	}
	else
	{
		DEBUG_CPRINT(("Bulk data buffer SIZE ; %ld\n",(unsigned long)buf_length));
    	log_id_with_one_arg(LOG_INFO_L1, LOG_FTM, INPUT_BULK_DATA_BUFFER_SIZE_u16_,buf_length);
		tx_info.mptr = buffer;
		tx_info.size = buf_length;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
		DEBUG_CPRINT(("Buffer Address %luX \n",tx_info.mptr));
	    //log_id_with_one_arg(LOG_INFO_L1, LOG_FTM, INPUT_BUFFER_ADDRESS_u8_,(uint32_t)tx_info.mptr);
#pragma GCC diagnostic pop
	}

	return ret_sts;
}





/*
 *@brief API to get the MTU size
 *Function:  ft_get_mtu_size
 * --------------------
 * get the mtu size and check the range
 *
 * size: MTU size in bytes, Range 1 - 65535
 *
 * returns: returns zero on error
 */
uint8_t ft_config_mtu_size(uint16_t size)
{
	uint8_t u8ret_sts = 0;
	// checking if the size in range

	if (size < 16)
	{
		/*set default MTU size */
		DEBUG_CPRINT(("\r\nInvalid MTU, default value 16 Bytes assigned\r\n"));
		get_mtu = 16;
	//	sleep(2);
	}
	else if (size > 0xFFF)
	{
		/*set default MTU size */
		DEBUG_CPRINT(("\r\nInvalid MTU, default value 254 Bytes assigned\r\n"));
		get_mtu = 254;
	//	sleep(2);
	}
	else
	{
		get_mtu = size;
		u8ret_sts = 1;
	}

	return u8ret_sts;
}


/*!
 * @brief This API control all FT operation
 * 1. Start transmission
 * 2. Terminate transmission
 * 3. Resume transmission
 * 4. Suspend transmission - timeout mode
 * 5. Suspend transmission - save context mode
 * 6. Store context ack
 */
uint8_t ft_transfer_request(ft_request request, uint16 timeout)
{
	uint8_t ret_sts = 0;
	e_ft_current_process ft_state;
	switch(request)
	{
	case Start_Transmission_rqst:
		ft_state =  get_file_transfer_state();
		if(ft_state == ft_process_na)
		{
			ft_set_err_sts(ft_noerror);

			ret_sts = is_sender_app_resgistered(tx_info.app_id);
			if(ret_sts != 0)
			{
				ft_tx_session_id_update(FT_SESSION_ID_INC);
				ft_fsm_change_state(FT_Send_Upload_Request);
				set_file_transfer_state(ft_upload);
				ft_service_enable();
				ret_sts = 1;
			}
			else
			{
				ft_set_err_sts(ft_sender_app_not_reg_error);
				DEBUG_CPRINT(("Requesting Sender App not registered\n"));
			}

		}
		else
		{
			ft_set_err_sts(ft_framework_busy_error);
			DEBUG_CPRINT(("Error !!! FT busy\n"));
		}
		break;

	case Suspend_Timeout_Mode_rqst:
		ft_set_master_slave(sus_res_master);
		ft_suspend(Suspend_Timeout_Mode_rqst,timeout,0);
		ret_sts = 1;
		break;

	case Suspend_Savecontext_Mode_rqst:
		ft_state =  get_file_transfer_state();
		if(ft_state != ft_process_na)
		{
			ft_set_master_slave(sus_res_master);
			ft_suspend(Suspend_Savecontext_Mode_rqst,timeout,0);
			ret_sts = 1;
		}
		else
		{
			DEBUG_CPRINT(("Error, FTM service not available."));
			log_id(LOG_ERROR, LOG_FTM, ERROR_cm__FTM_SERVICE_NOT_AVAILABLE);
		}
		break;

	case Resume_Timeout_Mode_rqst:
		ft_set_master_slave(sus_res_master);
		ft_resume(Resume_Timeout_Mode_rqst,0);
		ret_sts = 1;
		break;

	case Suspend_Savecontext_ack_rqst:
//		ft_stop_timer();
//		ft_savecontext_ack(1);
//		ft_fsm_change_state(FT_Inactive);
//		set_file_transfer_state(ft_process_na);

		ft_savecontext_ack(1);
		break;

	case Suspend_Savecontext_nack_rqst:
		//ft_set_master_slave(sus_res_master);
		ft_state =  get_file_transfer_state();
		if(ft_state == ft_upload)
		{
			ft_file_reopen_upload();
		}
		else if(ft_state == ft_download)
		{
			ft_file_reopen_download();
		}
		restart_transmission();
		ft_savecontext_ack(0);
		break;

	case Resume_Savecontext_nack_rqst:
		ft_savecontext_ack(0);
		break;

	case Terminate_Transmission_rqst:
	case T_Txnode:
	case T_Rxnode:
	case T_SuspendTimeout:
		ft_terminate(request,1);
		break;

	default:
		break;
	}
	return ret_sts;
}




/*!
 * @brief This API configure APP id
 *
 */
uint8_t ft_config_app_id(uint16 app_id)
{
	uint8_t ret=0;
	if(app_id != 0)
		{
			tx_info.app_id = app_id;
			ret = 1;
		}
	return ret;
}



/*!
 * @brief This API used to read APP id
 *
 *
 */
uint16_t ft_read_app_id_tx(void)
{
	return tx_info.app_id;
}




/*!
 * @brief This API used to resume transmission by save context mode
 *
 *
 * return error code
 * 0x00 - no error
 * 0x01 - context data corrupted
 * 0x02 - input bulk data buffer corrupted
 * 0x03 - input file not available
 * 0x04 - downloading buffer data corrupted
 * 0x05 - downloading file not available
 * 0x06 - input context buffer null
 */
uint8_t ft_resume_context(uint8_t *save_info, uint16_t size)
{
	ft_contextsave_info* c_info_ptr = NULL;
	uint16_t calc_buf_size;
	//uint16_t u16cnt;
	uint8_t ret_sts = 0;
	uint32_t checksum;
	uint32_t *rx_checksum;
	ptr_typ mem_addrs_loc=0;
	uint8_t error_code = 0;

	static uint8_t test_var1 = 1;
	static uint8_t test_var2 = 1;


	if(size < 4 || size > 1024)
	{
		ft_savecontext_ack(0);
		return 0x01;
	}

	if(save_info != NULL)
	{

		checksum = calc_checksum_bulkdata(save_info, size-4);
		rx_checksum = (uint32_t*)&save_info[size-4];

		if(checksum != *rx_checksum)
		{
			DEBUG_CPRINT(("Error !!! Context data Checksum fail\n"));
			log_id(LOG_ERROR, LOG_FTM, ERROR__CONTEXT_DATA_CHECKSUM_FAIL);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
			DEBUG_CPRINT(("Calculated context checksum %luX failed against %luX\n",checksum,*rx_checksum));
	//		log_id_with_two_arg(LOG_INFO_L1, LOG_FTM, CALCULATED_CONTEXT_CHECKSUM_u32_FAILED_AGAINST_u32_,checksum,*rx_checksum);
#pragma GCC diagnostic pop
			error_code = 0x01;
			ft_set_err_sts(ft_rc_context_input_error);
			ft_savecontext_ack(0);
		}
		else
		{
			/* Context info integrity pass */

			c_info_ptr = (ft_contextsave_info*)save_info;

			DEBUG_CPRINT(("Read context info: "));
	//		for (u16cnt = 0; u16cnt < c_info_ptr->context_info_size; u16cnt++)
	//		{
	//			DEBUG_CPRINT(("%x ",save_info[u16cnt]));
	//		}
			DEBUG_CPRINT(("\n"));

			if(c_info_ptr->node_operation == ft_upload)
			{

				if(c_info_ptr->tx_mode == 1)
				{
					/* perform input data buffer integrity before restoring upload process
					 *
					 */
					DEBUG_CPRINT(("DATA mode \n"));
					checksum = calc_checksum_bulkdata(tx_info.mptr, c_info_ptr->bulkdata_len);
					if(checksum != c_info_ptr->bulkdata_checksum)
					{
						DEBUG_CPRINT(("Error !!! Input buffer data Checksum fail\n"));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
						DEBUG_CPRINT(("Calculated checksum %luX failed against %luX\n",checksum,c_info_ptr->bulkdata_checksum));
#pragma GCC diagnostic pop
						DEBUG_CPRINT(("Uploading buffer corrupted\n"));
						error_code = 0x02;
					}
					else
					{
						ret_sts = 1;
						mem_addrs_loc = (ptr_typ)tx_info.mptr;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
						DEBUG_CPRINT(("Success Calculated Upload buffer checksum %luX against %luX\n",checksum,c_info_ptr->bulkdata_checksum));
#pragma GCC diagnostic pop

					}
				}
				else
				{
					ret_sts = 1;
				}


				if(	test_var1 == 0)
				{
					error_code = 0xff;
					test_var1 = 1;
					ret_sts = 0;
				}


				if(ret_sts != 0)
				{

					/* read tx info */
					calc_buf_size = sizeof(ft_contextsave_info);
					memcpy(&tx_info,&save_info[calc_buf_size],sizeof(s_transfer_info));

					/* read sequence loss info */
					calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_transfer_info);
					memcpy(&seg_info,&save_info[calc_buf_size],sizeof(s_segment_info));
					input_file_name = NULL;
					if(c_info_ptr->tx_mode == 0)
					{
						/* read file name */
						input_file_name = os_malloc(c_info_ptr->file_name_size);
						calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_transfer_info) + sizeof(s_segment_info);
						memcpy(input_file_name,&save_info[calc_buf_size],c_info_ptr->file_name_size);
					}

					if(tx_info.tx_mode == 0)
					{
						ret_sts = ft_file_reopen_upload();
					}
					else
					{
						ret_sts = 1;
						tx_info.mptr = (uint8_t*)mem_addrs_loc;
					}

					if(ret_sts != 0)
					{
						ft_set_suspend_resume_sts(state_suspend);
						s_sus_res_info.fsm_state_save = c_info_ptr->fsm_state_save;
						set_file_transfer_state(ft_upload);
						ft_set_master_slave(c_info_ptr->mast_slave_sel);
						if(c_info_ptr->mast_slave_sel == sus_res_master)
						{
							DEBUG_CPRINT(("[Upload] Send Resume frame \n"));
							ft_resume(0xff,0);
							/* send FTCI frame again with flash resume context mode enabled */
							tx_info.resume_ctxt_mode =1;
							dest_path_name_info.str_ptr = (uint8_t*)input_file_name;
							dest_path_name_info.size = c_info_ptr->file_name_size;
							ftci_encode_ftciframe();
					#ifndef FT_SAT
							ft_send_tm_to_obc(FT_TC_FTCI,ftci_frame_info.str_ptr,ftci_frame_info.size);
					#else
							ft_send_tm_to_obc(FT_TM_FTCI,ftci_frame_info.str_ptr,ftci_frame_info.size);
					#endif
						}
						else if(c_info_ptr->mast_slave_sel == sus_res_slave)
						{
							DEBUG_CPRINT(("[Upload] Send Resume ACK \n"));
							s_sus_res_info.type = suspend_by_savecontext;
							ft_resume(0xff,1);
						}
						DEBUG_CPRINT(("[Upload] Resume-Store Context Success !!! \n"));
						log_id(LOG_INFO_L1, LOG_FTM, UPLOAD__RESUMW_STORE_CONTEXT_SUCCESS);

					}
					else
					{
						DEBUG_CPRINT(("[Upload] Resume-Store Context Fail !!! \n"));
						log_id(LOG_WARNING, LOG_FTM, UPLOAD__RESUMW_STORE_CONTEXT_FAIL);
						error_code = 0x03;
					}

				}
				else
				{
					DEBUG_CPRINT(("[Upload] Resume-Store Context Fail - Input buffer corrupted !!! \n"));
				}



			}
			else if(c_info_ptr->node_operation == ft_download)
			{


// NOR copy				if(c_info_ptr->tx_mode == 1)
				{
					DEBUG_CPRINT(("DATA mode \n"));
					checksum = calc_checksum_bulkdata(dwnld_rqst.mptr, c_info_ptr->bulkdata_len);
					if(checksum != c_info_ptr->bulkdata_checksum)
					{
						DEBUG_CPRINT(("Error !!! Input buffer data Checksum fail\n"));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
						DEBUG_CPRINT(("Calculated checksum %luX failed against %luX\n",checksum,c_info_ptr->bulkdata_checksum));
#pragma GCC diagnostic pop
						DEBUG_CPRINT(("Downloading buffer corrupted\n"));
						log_id(LOG_WARNING, LOG_FTM, DOWNLOADING_BUFFER_CORRUPTED);
						error_code = 0x04;
					}
					else
					{
						ret_sts = 1;
						mem_addrs_loc = (ptr_typ)dwnld_rqst.mptr;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
						DEBUG_CPRINT(("Success Calculated download buffer checksum %luX against %luX\n",checksum,c_info_ptr->bulkdata_checksum));
#pragma GCC diagnostic pop
					}
				}
//				else
//				{
//					ret_sts = 1;
//				}


				if(	test_var2 == 0)
				{
					error_code = 0xff;
					test_var2 = 1;
					ret_sts = 0;
				}


				if(ret_sts != 0)
				{

					/* read tx info */
					calc_buf_size = sizeof(ft_contextsave_info);
					memcpy(&dwnld_rqst,&save_info[calc_buf_size],sizeof(s_treceive_info));
					dwnld_rqst.file_name = NULL;
					if(c_info_ptr->tx_mode == 0)
					{
						/* read file name */
						dwnld_rqst.file_name = os_malloc(c_info_ptr->file_name_size+1);
						calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_treceive_info);
						memcpy(dwnld_rqst.file_name,&save_info[calc_buf_size],c_info_ptr->file_name_size);
						dwnld_rqst.file_name[c_info_ptr->file_name_size] = '\0';
					}

					if(dwnld_rqst.tx_mode == 0)
					{
#ifndef FT_OBC
						ret_sts = ft_file_reopen_download();
#else
						ret_sts = 1;
#endif
					}
					else
					{
						ret_sts = 1;
						dwnld_rqst.mptr = (uint8_t*)mem_addrs_loc;
					}

					if(ret_sts != 0)
					{
						if(c_info_ptr->mast_slave_sel == sus_res_master)
						{
							DEBUG_CPRINT(("[Download] Send Resume frame \n"));
							s_sus_res_info.state = state_suspend;
							s_sus_res_info.fsm_state_save = c_info_ptr->fsm_state_save;
							set_file_transfer_state(ft_download);
							ft_set_master_slave(c_info_ptr->mast_slave_sel);
							ft_service_enable();
							ft_resume(0xff,0);
							DEBUG_CPRINT(("[Download] Resume-Store Context Success !!! \n"));
						}
						else if(c_info_ptr->mast_slave_sel == sus_res_slave)
						{

							if(resume_ctxt_rqst.size != 0)
							{
								/* check resume context info is available*
								 *
								 */
								if(resume_ctxt_rqst.size == dwnld_rqst.size)
								{
									if(resume_ctxt_rqst.checksum == dwnld_rqst.checksum)
									{
										/* Resume context info matched with FTCI request */
										DEBUG_CPRINT(("[Download] Send Resume frame \n"));
										s_sus_res_info.state = state_suspend;
										s_sus_res_info.fsm_state_save = c_info_ptr->fsm_state_save;
										set_file_transfer_state(ft_download);
										ft_set_master_slave(c_info_ptr->mast_slave_sel);
										ft_service_enable();
										ft_resume(0xff,1);
										DEBUG_CPRINT(("[Download] Resume-Store Context Success !!! \n"));
									}
									else
									{
										/* no restore context available as requested from FTCI*/
										error_code = 0x0A;
										DEBUG_CPRINT(("[Download] Resume-Store Context Fail - No context Avail!!! \n"));
									}
								}
								else
								{
									/* no restore context available */
									error_code = 0x0A;
									DEBUG_CPRINT(("[Download] Resume-Store Context Fail - No context Avail!!! \n"));
								}
							}
							else
							{
								/* resume context enabled manually */
								DEBUG_CPRINT(("[Download] Send Resume frame \n"));
								s_sus_res_info.state = state_suspend;
								s_sus_res_info.fsm_state_save = c_info_ptr->fsm_state_save;
								set_file_transfer_state(ft_download);
								ft_set_master_slave(c_info_ptr->mast_slave_sel);
								ft_service_enable();
								ft_resume(0xff,1);
								DEBUG_CPRINT(("[Download] Resume-Store Context Success !!! \n"));
							}
						}
					}
					else
					{
						DEBUG_CPRINT(("[Download] Resume-Store Context Fail !!! \n"));
						error_code = 0x05;
					}

				}
				else
				{
					DEBUG_CPRINT(("[Download] Resume-Store Context Fail - Buffer corrupted !!! \n"));
				}



			}

		}


		if(c_info_ptr != NULL)
		{
			if(c_info_ptr->mast_slave_sel == sus_res_slave)
			{
				if(error_code != 0)
				{
					/* abort resume context */
					DEBUG_CPRINT(("Restore failed at Slave side ! NACK sent\n"));
					ft_savecontext_ack(0);
				}
			}
		}


	}
	else
	{
		DEBUG_CPRINT(("Restored failed - Null error\n"));
		error_code = 0x06;
		ft_set_err_sts(ft_rc_null_error);
		ft_savecontext_ack(0);

	}

	return error_code;
}

/*
 * Sequence loss detection mode select
 * 1 >> sequence loss detection is enabled : it will word only on sband communication
 * 0 >> sequence loss detection is disabled : it can be enabled only for xband communication
 */
uint8_t ft_sequenceLoss_mode_select(uint8_t mode)
{
	uint8_t ret_sts = 1;
	if (mode < 2)
	{
		tx_info.seq_loss_detect_enable = mode;
	}
	else
	{
		DEBUG_CPRINT(("Invalid mode, Enter again\r\n"));
		ret_sts = 0;
	}
	return ret_sts;
}



void ft_config_ftds_delay(uint16_t set)
{
	if(set != 0 && set < 65535)
	{
		ft_ftds_delay = set;
	}
	else
	{
		ft_ftds_delay = 100;
	}

}


/*
 * This API is used to assign ID for each file transfered
 * this is useful to identify the multiple file sent to same app
 */
void ft_config_file_id(uint8_t f_id)
{
        if (f_id < 0x8)
        {
                tx_info.file_id = f_id;
        }
        else
        {
                tx_info.file_id = 0;
                DEBUG_CPRINT(("Invalid input file ID, Assigning default value 0\r\n"));
        }
}




/*
*   This API is used to configure timeout value for connection failure for receiver side.
*   Receiver node will terminate the transmission if communication with sender is not restored in timeout value
*   This timeout value should be greater than 44 seconds and multiples of 15 such as 45, 60, 75, 300 are some valid timeout value can be used.
*/

void ft_config_rx_node_conn_failure_time(uint16_t conn_fail_time)
{
        if (conn_fail_time >= 45 || conn_fail_time <= 1800)
        {
                tx_info.rx_node_conn_fail_timeout = conn_fail_time;
        }
        else
        {
                tx_info.rx_node_conn_fail_timeout = 45;
                DEBUG_CPRINT(("Invalid input file ID, Assigning default value 45\r\n"));
        }
}

