예제 #1
0
/****************************************************************************
 * Function Name: dts_ipaddr_decode
 * Purpose:        Decodes the IP address.
 *****************************************************************************/
uns32 decode_ip_address(NCS_UBAID *uba, NCS_IP_ADDR *ipa)
{
	uns8 *data = NULL;
	uns8 data_buff[sizeof(NCS_IP_ADDR)];

	data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns8));
	if (data == NULL) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "decode_ip_address: Decode flatten space failed");
	}
	ipa->type = ncs_decode_8bit(&data);
	ncs_dec_skip_space(uba, sizeof(uns8));

	if (ipa->type == NCS_IP_ADDR_TYPE_IPV4) {
		data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
		ipa->info.v4 = ncs_decode_32bit(&data);
		ncs_dec_skip_space(uba, sizeof(uns32));
	}
#if (NCS_IPV6 == 1)
	else if (ipa->type == NCS_IP_ADDR_TYPE_IPV6) {
		data = ncs_dec_flatten_space(uba, data_buff, NCS_IPV6_ADDR_UNS8_CNT);
		if (data == NULL) {
			return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "decode_ip_address: Decode flatten space failed");
		}
		memcpy((uns8 *)&ipa->info.v6, data, NCS_IPV6_ADDR_UNS8_CNT);
		ncs_dec_skip_space(uba, NCS_IPV6_ADDR_UNS8_CNT);
	}
#endif
	else {
		return NCSCC_RC_FAILURE;
	}

	return NCSCC_RC_SUCCESS;
}
예제 #2
0
/****************************************************************************
  Name          : eda_dec_chan_open_cbk_msg
 
  Description   : This routine decodes a channel open callback message
 
  Arguments     : NCS_UBAID *msg,
                  EDSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_dec_chan_open_cbk_msg(NCS_UBAID *uba, EDSV_MSG *msg)
{
	uint8_t *p8;
	int32_t total_bytes = 0;
	EDSV_EDA_CHAN_OPEN_CBK_PARAM *param = &msg->info.cbk_info.param.chan_open_cbk;
	uint8_t local_data[256];

	if (uba == NULL) {
		TRACE_4("uba is NULL");
		return 0;
	}

	/* chan_name_len */
	p8 = ncs_dec_flatten_space(uba, local_data, 2);
	param->chan_name.length = ncs_decode_16bit(&p8);
	ncs_dec_skip_space(uba, 2);
	total_bytes += 2;

	/* chan_name */
	ncs_decode_n_octets_from_uba(uba, param->chan_name.value, (uint32_t)param->chan_name.length);
	total_bytes += (uint32_t)param->chan_name.length;

	/* chan_id, chan_open_id, chan_open_flags, eda_chan_hdl, error */
	p8 = ncs_dec_flatten_space(uba, local_data, 17);
	param->chan_id = ncs_decode_32bit(&p8);
	param->chan_open_id = ncs_decode_32bit(&p8);
	param->chan_open_flags = ncs_decode_8bit(&p8);
	param->eda_chan_hdl = ncs_decode_32bit(&p8);
	param->error = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 17);
	total_bytes += 17;

	return total_bytes;
}
예제 #3
0
/************************************************************************************
 * Name           :glsv_gld_mbcsv_dec_sync_resp 
 *
 * Description    : Decode the message at Standby for cold sync and update the database

 * Arguments      : NCS_MBCSV_CB_ARG - MBCSv callback argument
 *
 * Return Values  : Success / Error
*************************************************************************************/
static uint32_t glsv_gld_mbcsv_dec_sync_resp(GLSV_GLD_CB *gld_cb, NCS_MBCSV_CB_ARG *arg)
{
	uint8_t *ptr, num_of_ckpts, data[16];
	GLSV_GLD_A2S_RSC_DETAILS *rsc_info;
	uint32_t count = 0, rc = NCSCC_RC_SUCCESS, num_of_async_upd;
	EDU_ERR ederror = 0;
	GLSV_A2S_NODE_LIST *node_list, *tmp1_node_list;
	TRACE_ENTER();

	if (arg->info.decode.i_uba.ub == NULL) {	/* There is no data */
		goto end;
	}

	/* Allocate memory */
	rsc_info = m_MMGR_ALLOC_GLSV_GLD_A2S_RSC_DETAILS;
	if (rsc_info == NULL) {
		LOG_CR("Rsc info alloc failed: Error %s", strerror(errno));
		assert(0);
	}

	memset(rsc_info, 0, sizeof(GLSV_GLD_A2S_RSC_DETAILS));

	/* 1. Decode the 1st uint8_t region ,  we will get the num of ckpts */
	ptr = ncs_dec_flatten_space(&arg->info.decode.i_uba, data, sizeof(uint8_t));
	num_of_ckpts = ncs_decode_8bit(&ptr);
	ncs_dec_skip_space(&arg->info.decode.i_uba, sizeof(uint8_t));

	/* Decode the data */

	while (count < num_of_ckpts) {
		rc = m_NCS_EDU_EXEC(&gld_cb->edu_hdl, glsv_edp_gld_evt_a2s_rsc_details, &arg->info.decode.i_uba,
				    EDP_OP_TYPE_DEC, &rsc_info, &ederror);
		if (rc != NCSCC_RC_SUCCESS) {
			goto end;
		}
		rc = gld_sb_proc_data_rsp(gld_cb, rsc_info);
		count++;
		memset(rsc_info, 0, sizeof(GLSV_GLD_A2S_RSC_DETAILS));
	}

	/* Get the async update count */
	ptr = ncs_dec_flatten_space(&arg->info.decode.i_uba, data, sizeof(uint32_t));
	num_of_async_upd = ncs_decode_32bit(&ptr);
	gld_cb->gld_async_cnt = num_of_async_upd;

	/* New code */
	node_list = rsc_info->node_list;
	while (node_list != NULL) {
		tmp1_node_list = node_list;
		node_list = node_list->next;
		m_MMGR_FREE_GLSV_NODE_LIST(tmp1_node_list);
	}
	m_MMGR_FREE_GLSV_GLD_A2S_RSC_DETAILS(rsc_info);
 end:
	TRACE_LEAVE();
	return rc;
}
예제 #4
0
/*****************************************************************************
 * Function Name: dts_log_msg_decode
 * Purpose:       decodes a NCSDTS_FLTR from a ubaid
 ****************************************************************************/
uns32 dts_log_msg_decode(NCSFL_NORMAL *logmsg, NCS_UBAID *uba)
{
	uns8 *data = NULL;
	uns8 data_buff[DTS_MAX_SIZE_DATA];

	if (uba == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_log_msg_decode: User buffer is NULL");

	if (logmsg == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_log_msg_decode: Message to be decoded is NULL");

	data = ncs_dec_flatten_space(uba, data_buff, DTS_LOG_MSG_HDR_SIZE);
	if (data == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_log_msg_decode: ncs_dec_flatten_space returns NULL");

	logmsg->hdr.time.seconds = ncs_decode_32bit(&data);
	logmsg->hdr.time.millisecs = ncs_decode_32bit(&data);

	logmsg->hdr.vr_id = ncs_decode_16bit(&data);
	logmsg->hdr.ss_id = ncs_decode_32bit(&data);
	logmsg->hdr.inst_id = ncs_decode_32bit(&data);
	logmsg->hdr.severity = ncs_decode_8bit(&data);
	logmsg->hdr.category = ncs_decode_32bit(&data);

	logmsg->hdr.fmat_id = ncs_decode_8bit(&data);

	ncs_dec_skip_space(uba, DTS_LOG_MSG_HDR_SIZE);

	/* Check for any mem failure in dts_log_str_decode */
	if (dts_log_str_decode(uba, &logmsg->hdr.fmat_type) == NCSCC_RC_FAILURE)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
				      "dts_log_msg_decode: dts_log_str_decode returned memory alloc failure");

	memcpy(&logmsg->uba, uba, sizeof(NCS_UBAID));

	return NCSCC_RC_SUCCESS;
}
예제 #5
0
/***************************************************************************
* Name          : fm_fm_mds_dec
*                                                                           
* Description   : To decode GFM related messages                                                      
*                                                                        
* Arguments     : Ptr to the MDS callback info struct MDS_CALLBACK_DEC_INFO
*                                                                           
* Return Values : NCSCC_RC_FAILURE/NCSCC_RC_SUCCESS                        
*                                                                           
* Notes         : None.
***************************************************************************/
static uint32_t fm_fm_mds_dec(MDS_CALLBACK_DEC_INFO *dec_info)
{
	GFM_GFM_MSG *msg;
	NCS_UBAID *uba;
	uint8_t *data;
	uint8_t data_buff[256];

	if (NULL == dec_info->io_uba) {
		return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
	}

	msg = m_MMGR_ALLOC_FM_FM_MSG;
	if (NULL == msg)
		return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);

	memset(msg, 0, sizeof(GFM_GFM_MSG));

	dec_info->o_msg = msg;
	uba = dec_info->io_uba;

	data = ncs_dec_flatten_space(uba, data_buff, sizeof(uint8_t));
	if (NULL == data)
		return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);

	msg->msg_type = (GFM_GFM_MSG_TYPE)ncs_decode_8bit(&data);
	ncs_dec_skip_space(uba, sizeof(uint8_t));

	switch (msg->msg_type) {
	case GFM_GFM_EVT_NODE_INFO_EXCHANGE:
		data = ncs_dec_flatten_space(uba, data_buff, 2 * sizeof(uint32_t));
		if (data == NULL) {
			return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
		}

		msg->info.node_info.node_id = (uint32_t)ncs_decode_32bit(&data);
		msg->info.node_info.node_name.length = (uint32_t)ncs_decode_32bit(&data);
		ncs_dec_skip_space(uba, 2 * sizeof(uint32_t));

		ncs_decode_n_octets_from_uba(uba, msg->info.node_info.node_name.value,
					     msg->info.node_info.node_name.length);
		break;
	default:
		syslog(LOG_INFO, "fm_fm_mds_dec: Invalid msg for decoding.");
		return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
		break;
	}

	return NCSCC_RC_SUCCESS;
}
예제 #6
0
/****************************************************************************
 * Function Name: dts_mds_dec
 * Purpose:        decode a DTS message coming in
 ****************************************************************************/
uns32 dts_mds_dec(MDS_CLIENT_HDL yr_svc_hdl, NCSCONTEXT *msg,
		  SS_SVC_ID to_svc, NCS_UBAID *uba, MDS_CLIENT_MSG_FORMAT_VER msg_fmat_ver)
{
	uns8 *data = NULL;
	DTSV_MSG *mm;
	uns8 data_buff[DTSV_DTA_DTS_HDR_SIZE];
	uns32 lenn = 0;

	if ((msg_fmat_ver < DTS_MDS_MIN_MSG_FMAT_VER_SUPPORT) || (msg_fmat_ver > DTS_MDS_MAX_MSG_FMAT_VER_SUPPORT))
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
				      "dts_mds_dec: Message format version is not within acceptable range");

	if (uba == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_mds_dec: DTS decode: user buffer is NULL");

	if (msg == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_mds_dec: DTS decode: Message is NULL");

	mm = m_MMGR_ALLOC_DTSV_MSG;

	if (mm == NULL) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_mds_dec: DTS decode: Failed to allocate DTSV message");
	}

	memset(mm, '\0', sizeof(DTSV_MSG));

	*msg = mm;

	data = ncs_dec_flatten_space(uba, data_buff, DTSV_DTA_DTS_HDR_SIZE);
	if (data == NULL) {
		m_MMGR_FREE_DTSV_MSG(mm);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
	}

	mm->vrid = ncs_decode_16bit(&data);

	mm->msg_type = ncs_decode_8bit(&data);

	ncs_dec_skip_space(uba, DTSV_DTA_DTS_HDR_SIZE);

	switch (mm->msg_type) {
	case DTA_REGISTER_SVC:
		{
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(SS_SVC_ID));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			mm->data.data.reg.svc_id = ncs_decode_32bit(&data);
			ncs_dec_skip_space(uba, sizeof(SS_SVC_ID));

			/* Decode the version no. */
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns16));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			mm->data.data.reg.version = ncs_decode_16bit(&data);
			ncs_dec_skip_space(uba, sizeof(uns16));

			/* Decode the service name */
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			lenn = ncs_decode_32bit(&data);
			ncs_dec_skip_space(uba, sizeof(uns32));
			if (lenn == 0) {
				/* No need to decode any further. no service name specified */
			} else if (lenn < DTSV_SVC_NAME_MAX) {	/* Check valid len of svc_name */
				ncs_decode_n_octets_from_uba(uba, (uns8 *)mm->data.data.reg.svc_name, lenn);
			} else {	/* Discard this message */

				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: Length of service name decoded in register message exceeds limits");
			}
			break;
		}
	case DTA_UNREGISTER_SVC:
		{
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(SS_SVC_ID));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			mm->data.data.unreg.svc_id = ncs_decode_32bit(&data);
			ncs_dec_skip_space(uba, sizeof(SS_SVC_ID));

			/* Decode the version no. */
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns16));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			mm->data.data.unreg.version = ncs_decode_16bit(&data);
			ncs_dec_skip_space(uba, sizeof(uns16));

			/* Decode the service name */
			data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
			if (data == NULL) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: DTS decode: ncs_dec_flatten_space returns NULL");
			}
			lenn = ncs_decode_32bit(&data);
			ncs_dec_skip_space(uba, sizeof(uns32));
			if (lenn == 0) {
				/* No need to decode any further. no service name specified */
			}
			if (lenn < DTSV_SVC_NAME_MAX) {	/* Check valid len of svc_name */
				ncs_decode_n_octets_from_uba(uba, (uns8 *)mm->data.data.unreg.svc_name, lenn);
			} else {	/* Discard this message */

				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: Length of service name decoded in unregister msg exceeds limits");
			}
			break;
		}
	case DTA_LOG_DATA:
		{
			/* Versioning changes : Set the msg_fmat_ver field of DTA_LOG_MSG 
			 * according to the message format version from MDS callback. 
			 */
			mm->data.data.msg.msg_fmat_ver = msg_fmat_ver;

			/* Check for any mem failure in dts_log_str_decode */
			if (dts_log_msg_decode(&mm->data.data.msg.log_msg, uba) == NCSCC_RC_FAILURE) {
				m_MMGR_FREE_DTSV_MSG(mm);
				return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
						      "dts_mds_dec: dts_log_msg_decode returned failure");
			}
			break;
		}

#if (DTA_FLOW == 1)
	case DTA_FLOW_CONTROL:
	case DTS_CONGESTION_HIT:
	case DTS_CONGESTION_CLEAR:
		/* Do Nothing */
		break;
#endif

	default:
		m_MMGR_FREE_DTSV_MSG(mm);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_mds_dec: Wrong message type is received");
	}

	return NCSCC_RC_SUCCESS;
}
예제 #7
0
/****************************************************************************
  Name          : eda_dec_delv_evt_cbk_msg
 
  Description   : This routine decodes a deliver event callback message
 
  Arguments     : NCS_UBAID *msg,
                  EDSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_dec_delv_evt_cbk_msg(NCS_UBAID *uba, EDSV_MSG *msg)
{
	uint8_t *p8;
	uint32_t x;
	uint32_t fake_value;
	uint64_t num_patterns;
	uint32_t total_bytes = 0;
	SaEvtEventPatternT *pattern_ptr;
	EDSV_EDA_EVT_DELIVER_CBK_PARAM *param = &msg->info.cbk_info.param.evt_deliver_cbk;
	uint8_t local_data[1024];

	if (uba == NULL) {
		TRACE_4("uba is NULL");
		return 0;
	}

	/* sub_id, chan_id, chan_open_id */
	p8 = ncs_dec_flatten_space(uba, local_data, 12);
	param->sub_id = ncs_decode_32bit(&p8);
	param->chan_id = ncs_decode_32bit(&p8);
	param->chan_open_id = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 12);
	total_bytes += 12;

	/* Decode the patterns.
	 * Must allocate space for these.
	 */

	/* patternsNumber */
	p8 = ncs_dec_flatten_space(uba, local_data, 8);
	num_patterns = ncs_decode_64bit(&p8);
	ncs_dec_skip_space(uba, 8);
	total_bytes += 8;

	param->pattern_array = m_MMGR_ALLOC_EVENT_PATTERN_ARRAY;
	if (!param->pattern_array) {
		TRACE_4("malloc failed for pattern array");
		return 0;
	}
	param->pattern_array->patternsNumber = num_patterns;
	if (num_patterns) {
		param->pattern_array->patterns = m_MMGR_ALLOC_EVENT_PATTERNS((uint32_t)num_patterns);
		if (!param->pattern_array->patterns) {
			TRACE_4("malloc failed for patternarray->patterns");
			return 0;
		}
	} else {
		param->pattern_array->patterns = NULL;
	}

	pattern_ptr = param->pattern_array->patterns;
	for (x = 0; x < param->pattern_array->patternsNumber; x++) {
		/* patternSize */
		p8 = ncs_dec_flatten_space(uba, local_data, 8);
		pattern_ptr->patternSize = ncs_decode_64bit(&p8);
		ncs_dec_skip_space(uba, 8);
		total_bytes += 8;

		/* For zero length patterns, fake decode zero */
		if (pattern_ptr->patternSize == 0) {
			p8 = ncs_dec_flatten_space(uba, local_data, 4);
			fake_value = ncs_decode_32bit(&p8);
			TRACE("pattern size: %u", fake_value);
			/* Do so the free routine is happy */
			pattern_ptr->pattern = m_MMGR_ALLOC_EDSV_EVENT_DATA(0);
			ncs_dec_skip_space(uba, 4);
			total_bytes += 4;
		} else {
			/* pattern */
			pattern_ptr->pattern = m_MMGR_ALLOC_EDSV_EVENT_DATA((uint32_t)pattern_ptr->patternSize);
			if (!pattern_ptr->pattern) {
				TRACE_4("malloc failed for event data");
				return 0;
			}
			ncs_decode_n_octets_from_uba(uba, pattern_ptr->pattern, (uint32_t)pattern_ptr->patternSize);
			total_bytes += (uint32_t)pattern_ptr->patternSize;
		}
		pattern_ptr++;
	}

	/* priority */
	p8 = ncs_dec_flatten_space(uba, local_data, 1);
	param->priority = ncs_decode_8bit(&p8);
	ncs_dec_skip_space(uba, 1);
	total_bytes += 1;

	/* publisher_name length */
	p8 = ncs_dec_flatten_space(uba, local_data, 2);
	param->publisher_name.length = ncs_decode_16bit(&p8);
	ncs_dec_skip_space(uba, 2);
	total_bytes += 2;

	/* publisher_name */
	ncs_decode_n_octets_from_uba(uba, param->publisher_name.value, (uint32_t)param->publisher_name.length);
	total_bytes += (uint32_t)param->publisher_name.length;

	/* publish_time, eda_event_id */
	p8 = ncs_dec_flatten_space(uba, local_data, 24);
	param->publish_time = ncs_decode_64bit(&p8);
	param->retention_time = ncs_decode_64bit(&p8);
	param->eda_event_id = ncs_decode_32bit(&p8);
	param->ret_evt_ch_oid = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 24);
	total_bytes += 24;

	/* data_len */
	p8 = ncs_dec_flatten_space(uba, local_data, 8);
	param->data_len = ncs_decode_64bit(&p8);
	ncs_dec_skip_space(uba, 8);
	total_bytes += 8;

	/* data */
	if ((uint32_t)param->data_len) {
		param->data = m_MMGR_ALLOC_EDSV_EVENT_DATA((uint32_t)param->data_len);
		if (!param->data) {
			TRACE_4("malloc failedi for event data");
			return 0;
		}
		ncs_decode_n_octets_from_uba(uba, param->data, (uint32_t)param->data_len);
	} else
		param->data = NULL;

	total_bytes += (uint32_t)param->data_len;

	return total_bytes;
}
예제 #8
0
/**
 * Function to process intranode poll rcv message common
 *
 *
 *
 */
uint32_t dtm_intranode_process_poll_rcv_msg_common(DTM_INTRANODE_PID_INFO *pid_node)
{
	uint32_t identifier = 0;
	uint8_t version = 0 , *data = NULL; 
	DTM_INTRANODE_RCV_MSG_TYPES msg_type = 0;

	pid_node->buffer[pid_node->buff_total_len + 2] = '\0';
	data = &pid_node->buffer[2];

	/* Decode the message */
	identifier = ncs_decode_32bit(&data);
	version = ncs_decode_8bit(&data);

	if ((DTM_INTRANODE_RCV_MSG_IDENTIFIER != identifier)
			|| (DTM_INTRANODE_RCV_MSG_VER != version)) {
		TRACE("DTM_INTRA: Malformed packet recd, Ident = %d, ver = %d",identifier, version);
		free(pid_node->buffer);
		return NCSCC_RC_FAILURE;
	}

	msg_type = ncs_decode_8bit(&data);

	if (DTM_INTRANODE_RCV_PID_TYPE == msg_type) {
		dtm_intranode_process_pid_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_BIND_TYPE == msg_type) {
		dtm_intranode_process_bind_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_UNBIND_TYPE == msg_type) {
		dtm_intranode_process_unbind_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_SUBSCRIBE_TYPE == msg_type) {
		dtm_intranode_process_subscribe_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_UNSUBSCRIBE_TYPE == msg_type) {
		dtm_intranode_process_unsubscribe_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_NODE_SUBSCRIBE_TYPE == msg_type) {
		dtm_intranode_process_node_subscribe_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_NODE_UNSUBSCRIBE_TYPE == msg_type) {
		dtm_intranode_process_node_unsubscribe_msg(&pid_node->buffer[8], pid_node->accepted_fd);
		free(pid_node->buffer);
	} else if (DTM_INTRANODE_RCV_MESSAGE_TYPE == msg_type) {
		/* Get the Destination Node ID */
		NODE_ID dst_nodeid = 0;
		uint32_t dst_processid = 0;
		dst_nodeid = ncs_decode_32bit(&data);
		dst_processid = ncs_decode_32bit(&data);
		if (dtm_intranode_cb->nodeid == dst_nodeid) {
			/* local node message */
			dtm_intranode_process_rcv_data_msg(pid_node->buffer,
					dst_processid, (pid_node->buff_total_len +2));
		} else {
			/* remote node message */
			dtm_add_to_msg_dist_list(pid_node->buffer,
					(pid_node->buff_total_len +2), dst_nodeid);
		}
		pid_node->bytes_tb_read = 0;
		pid_node->buff_total_len = 0;
		pid_node->num_by_read_for_len_buff = 0;
		return NCSCC_RC_SUCCESS;
	} else {
		/* msg_type not supported, log error */
		TRACE("DTM_INTRA: Recd msg_type unknown, dropping the message");
	}

	pid_node->bytes_tb_read = 0;
	pid_node->buff_total_len = 0;
	pid_node->num_by_read_for_len_buff = 0;
	pid_node->buffer = NULL;
	return NCSCC_RC_SUCCESS;
}
예제 #9
0
/**
 * Function to process internode poll and rcv message
 *
 * @param node local_len_buf node_info_hrd node_info_buffer_len close_conn fd
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
void dtm_internode_process_poll_rcv_msg_common(DTM_NODE_DB * node, uint16_t local_len_buf, uint8_t *node_info_hrd,
					       uint16_t node_info_buffer_len, int fd, int *close_conn)
{
	DTM_MSG_TYPES pkt_type = 0;
	uint32_t identifier = 0;
	uint8_t version = 0;
	uint8_t *data = NULL;
	DTM_INTERNODE_CB *dtms_cb = dtms_gl_cb;

	node->buffer[local_len_buf + 2] = '\0';
	data = &node->buffer[2];
	/* Decode the message */
	identifier = ncs_decode_32bit(&data);
	version = ncs_decode_8bit(&data);

	if ((DTM_INTERNODE_RCV_MSG_IDENTIFIER != identifier) || (DTM_INTERNODE_RCV_MSG_VER != version)) {
		LOG_ER("DTM: Malformed packet recd, Ident : %d, ver : %d", identifier, version);
		goto done;
	}

	pkt_type = ncs_decode_8bit(&data);

	if (pkt_type == DTM_UP_MSG_TYPE) {
		uint8_t *alloc_buffer = NULL;

		if (NULL == (alloc_buffer = calloc(1, (local_len_buf - 6)))) {
			LOG_ER("\nMemory allocation failed in dtm_internode_processing");
			goto done;
		}
		memcpy(alloc_buffer, &node->buffer[8], (local_len_buf - 6));

		dtm_internode_process_rcv_up_msg(alloc_buffer, (local_len_buf - 6), node->node_id);
	} else if (pkt_type == DTM_CONN_DETAILS_MSG_TYPE) {
		if (dtm_process_node_info(dtms_cb, fd, &node->buffer[8], node_info_hrd, node_info_buffer_len) !=
		    NCSCC_RC_SUCCESS) {
			LOG_ER(" DTM : communication socket Connection closed\n");
			*close_conn = true;
		}
	} else if (pkt_type == DTM_DOWN_MSG_TYPE) {
		uint8_t *alloc_buffer = NULL;

		if (NULL == (alloc_buffer = calloc(1, (local_len_buf - 6)))) {
			LOG_ER("\nMemory allocation failed in dtm_internode_processing");
			goto done;
		}
		memcpy(alloc_buffer, &node->buffer[8], (local_len_buf - 6));
		dtm_internode_process_rcv_down_msg(alloc_buffer, (local_len_buf - 6), node->node_id);
	} else if (pkt_type == DTM_MESSAGE_MSG_TYPE) {
		NODE_ID dst_nodeid = 0;
		uint32_t dst_processid = 0;
		dst_nodeid = ncs_decode_32bit(&data);
		if (dtms_cb->node_id != dst_nodeid)
			LOG_ER("Invalid dest_nodeid: %u received in dtm_internode_processing", dst_nodeid);
		dst_processid = ncs_decode_32bit(&data);
		dtm_internode_process_rcv_data_msg(node->buffer, dst_processid, (local_len_buf + 2));
		node->bytes_tb_read = 0;
		node->buff_total_len = 0;
		node->num_by_read_for_len_buff = 0;
		return;
	}
 done:
	node->bytes_tb_read = 0;
	node->buff_total_len = 0;
	node->num_by_read_for_len_buff = 0;
	free(node->buffer);
	node->buffer = NULL;
	return;
}
예제 #10
0
/***********************************************************************************
 * Name        : glsv_gld_mbcsv_dec_async_update 
 *
 * Description : To decode the async update at the Standby, so the first field is decoded which will tell the type
                 and based on the event, a corresponding action will be taken

 * Arguments   : NCS_MBCSV_CB_ARG - MBCSv callback argument
 * 
 * Return Values : Success / Error
***********************************************************************************/
static uint32_t glsv_gld_mbcsv_dec_async_update(GLSV_GLD_CB *gld_cb, NCS_MBCSV_CB_ARG *arg)
{
	uint8_t *ptr, data[16];
	GLSV_GLD_A2S_CKPT_EVT *a2s_evt;
	uint32_t evt_type, rc = NCSCC_RC_SUCCESS;
	EDU_ERR ederror = 0;
	GLSV_A2S_RSC_OPEN_INFO *rsc_info = NULL;
	GLSV_A2S_RSC_DETAILS *rsc_details = NULL;
	GLSV_A2S_GLND_MDS_INFO *node_details = NULL;
	TRACE_ENTER();

	a2s_evt = m_MMGR_ALLOC_GLSV_GLD_A2S_EVT;
	if (a2s_evt == NULL) {
		LOG_CR("A2S event alloc failed: Error %s", strerror(errno));
		assert(0);
	}
	memset(a2s_evt, 0, sizeof(GLSV_GLD_A2S_CKPT_EVT));

	/* To store the value of Async Update received */
	gld_cb->gld_async_cnt++;

	/* in the decode.i_uba , the 1st parameter is the Type , so first decode only the first field and based on the type then decode the entire message */
	ptr = ncs_dec_flatten_space(&arg->info.decode.i_uba, data, sizeof(uint8_t));
	evt_type = ncs_decode_8bit(&ptr);
	a2s_evt->evt_type = evt_type;
	ncs_dec_skip_space(&arg->info.decode.i_uba, sizeof(uint8_t));

	switch (evt_type) {
	case GLSV_GLD_EVT_RSC_OPEN:
		rsc_info = &a2s_evt->info.rsc_open_info;
		/* The contents are decoded from i_uba a2s_evt */
		rc = m_NCS_EDU_EXEC(&gld_cb->edu_hdl, glsv_edp_gld_a2s_evt_rsc_open_info, &arg->info.decode.i_uba,
				    EDP_OP_TYPE_DEC, &rsc_info, &ederror);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("EDU exec async rsc open evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		rc = gld_process_standby_evt(gld_cb, a2s_evt);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("GLD standby rsc open evt failed");
			goto end;
		}
		break;

	case GLSV_GLD_EVT_RSC_CLOSE:
		rsc_details = &a2s_evt->info.rsc_details;
		/* The contents are decoded from i_uba to a2s_evt */
		rc = m_NCS_EDU_EXEC(&gld_cb->edu_hdl, glsv_edp_gld_a2s_evt_rsc_details,
				    &arg->info.decode.i_uba, EDP_OP_TYPE_DEC, &rsc_details, &ederror);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("EDU exec async rsc close evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		rc = gld_process_standby_evt(gld_cb, a2s_evt);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("GLD standby rsc close evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		break;

	case GLSV_GLD_EVT_SET_ORPHAN:
		rsc_details = &a2s_evt->info.rsc_details;
		/* The contents are decoded from i_uba to a2s_evt */
		rc = m_NCS_EDU_EXEC(&gld_cb->edu_hdl, glsv_edp_gld_a2s_evt_rsc_details, &arg->info.decode.i_uba,
				    EDP_OP_TYPE_DEC, &rsc_details, &ederror);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("EDU exec aysnc set orphan evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		rc = gld_process_standby_evt(gld_cb, a2s_evt);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("GLD standby rsc set orphan evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		break;

	case GLSV_GLD_EVT_GLND_DOWN:
	case GLSV_GLD_EVT_GLND_OPERATIONAL:
		node_details = &a2s_evt->info.glnd_mds_info;
		/* The contents are decoded from i_uba to a2s_evt */
		rc = m_NCS_EDU_EXEC(&gld_cb->edu_hdl, glsv_edp_gld_a2s_evt_glnd_mds_info, &arg->info.decode.i_uba,
				    EDP_OP_TYPE_DEC, &node_details, &ederror);
		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("EDU exec async glnd down evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		rc = gld_process_standby_evt(gld_cb, a2s_evt);
		if (rc != NCSCC_RC_SUCCESS) {
                          LOG_ER("GLD standby glnd down evt failed");
			rc = NCSCC_RC_FAILURE;
			goto end;
		}
		break;
	default:
		m_MMGR_FREE_GLSV_GLD_A2S_EVT(a2s_evt);
	 	rc = NCSCC_RC_FAILURE;
		goto end;

	}
 end:
	TRACE_LEAVE();
	return rc;

}