Beispiel #1
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;
}
Beispiel #2
0
/****************************************************************************
  Name          : cpa_mds_dec

  Description   : This function decodes an events sent to CPA.

  Arguments     : cb    : CPA control Block.
                  info  : Info for decoding

  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE

  Notes         : None.
******************************************************************************/
static uns32 cpa_mds_dec(CPA_CB *cb, MDS_CALLBACK_DEC_INFO *dec_info)
{
	CPSV_EVT *msg_ptr = NULL;
	EDU_ERR ederror = 0;
	uns32 rc = NCSCC_RC_SUCCESS;
	uns8 local_data[20];
	uns8 *pstream;
	NCS_BOOL is_valid_msg_fmt = FALSE;

	if (dec_info->i_fr_svc_id == NCSMDS_SVC_ID_CPND) {
		is_valid_msg_fmt = m_NCS_MSG_FORMAT_IS_VALID(dec_info->i_msg_fmt_ver,
							     CPA_WRT_CPND_SUBPART_VER_MIN,
							     CPA_WRT_CPND_SUBPART_VER_MAX, cpa_cpnd_msg_fmt_table);
	} else if (dec_info->i_fr_svc_id == NCSMDS_SVC_ID_CPD) {
		is_valid_msg_fmt = m_NCS_MSG_FORMAT_IS_VALID(dec_info->i_msg_fmt_ver,
							     CPA_WRT_CPD_SUBPART_VER_MIN,
							     CPA_WRT_CPD_SUBPART_VER_MAX, cpa_cpd_msg_fmt_table);
	}

	if (is_valid_msg_fmt) {

		msg_ptr = m_MMGR_ALLOC_CPSV_EVT(NCS_SERVICE_ID_CPA);
		if (!msg_ptr)
			return NCSCC_RC_FAILURE;

		memset(msg_ptr, 0, sizeof(CPSV_EVT));
		dec_info->o_msg = (NCSCONTEXT)msg_ptr;
		pstream = ncs_dec_flatten_space(dec_info->io_uba, local_data, 8);
		msg_ptr->type = ncs_decode_32bit(&pstream);
		if (msg_ptr->type == CPSV_EVT_TYPE_CPA) {
			msg_ptr->info.cpa.type = ncs_decode_32bit(&pstream);
			if (msg_ptr->info.cpa.type == CPA_EVT_ND2A_CKPT_DATA_RSP) {
				ncs_dec_skip_space(dec_info->io_uba, 8);
				rc = cpsv_data_access_rsp_decode(&msg_ptr->info.cpa.info.sec_data_rsp,
								 dec_info->io_uba);
				goto free;

			}
			/* if(msg_ptr->info.cpa.type == CPA_EVT_ND2A_CKPT_DATA_RSP) */
		}
		/* if( msg_ptr->type == CPSV_EVT_TYPE_CPA) */
		/* For all Other Cases Other Than CPA( Read / Write Rsp Follow EDU rules */
		rc = m_NCS_EDU_EXEC(&cb->edu_hdl, FUNC_NAME(CPSV_EVT),
				    dec_info->io_uba, EDP_OP_TYPE_DEC, (CPSV_EVT **)&dec_info->o_msg, &ederror);
 free:
		if (rc != NCSCC_RC_SUCCESS) {
			m_MMGR_FREE_CPSV_EVT(dec_info->o_msg, NCS_SERVICE_ID_CPA);
		}
		return rc;
	} else {
		m_LOG_CPA_CCL(CPA_PROC_FAILED, NCSFL_LC_CKPT_MGMT, NCSFL_SEV_INFO, "mds_dec", __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}
}
Beispiel #3
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;
}
Beispiel #4
0
uns32 ncs_decode_key(uns8 **stream, NCS_KEY *key)
{
	uns8 len;

	key->svc = *(*stream)++;
	key->fmat = *(*stream)++;
	key->type = *(*stream)++;

	switch (key->fmat) {
	case NCS_FMT_NUM:
		key->val.num = ncs_decode_32bit(stream);
		return 7;
		break;
	case NCS_FMT_STR:
		len = *(*stream)++;
		m_KEY_CHK_LEN(key->val.oct.len);
		strncpy((char *)key->val.str, (char *)(*stream), len);
		*stream = *stream + len;	/* move pointer beyond what was consumed */
		return (3 + len + 1);
		break;

	case NCS_FMT_OCT:
		len = *(*stream)++;
		m_KEY_CHK_LEN(key->val.oct.len);
		key->val.oct.len = len;
		memcpy(key->val.oct.data, *stream, len);
		*stream = *stream + len;	/* move pointer beyond what was consumed */
		return (3 + len + 1);
		break;
	}
	return m_LEAP_DBG_SINK(0);
}
Beispiel #5
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;
}
Beispiel #6
0
/*********************************************************************************
 * Name          :glsv_gld_mbcsv_dec_warm_sync_resp 
 *
 * Description   : To decode the message at the warm sync at the standby

 * Arguments     : NCS_MBCSV_CB_ARG - MBCSv callback argument
 * 
 * Return Values : Success / Error
*********************************************************************************/
static uint32_t glsv_gld_mbcsv_dec_warm_sync_resp(GLSV_GLD_CB *gld_cb, NCS_MBCSV_CB_ARG *arg)
{
	uint32_t num_of_async_upd, rc = NCSCC_RC_SUCCESS;
	uint8_t data[16], *ptr;
	NCS_MBCSV_ARG ncs_arg;
	TRACE_ENTER();

	/*TBD check for the validity of gld_cb arg */

	memset(&ncs_arg, '\0', sizeof(NCS_MBCSV_ARG));

	ptr = ncs_dec_flatten_space(&arg->info.decode.i_uba, data, sizeof(int32_t));
	num_of_async_upd = ncs_decode_32bit(&ptr);
	ncs_dec_skip_space(&arg->info.decode.i_uba, 4);

	if (gld_cb->gld_async_cnt == num_of_async_upd) {
		goto end;
	} else {
		gld_cb_destroy(gld_cb);
		ncs_arg.i_op = NCS_MBCSV_OP_SEND_DATA_REQ;
		ncs_arg.i_mbcsv_hdl = gld_cb->mbcsv_handle;
		ncs_arg.info.send_data_req.i_ckpt_hdl = gld_cb->o_ckpt_hdl;
		rc = ncs_mbcsv_svc(&ncs_arg);
		if (rc != NCSCC_RC_SUCCESS) {
			/* Log */
			/* TBD */
			goto end;
		}
	}
 end:
	TRACE_LEAVE();
	return rc;
}
Beispiel #7
0
/****************************************************************************
  Name          : lga_dec_lstr_close_rsp_msg
 
  Description   : This routine decodes a close response message
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_dec_lstr_close_rsp_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_stream_close_rsp_t *param = &msg->info.api_resp_info.param.close_rsp;
	uint8_t local_data[100];

	osafassert(uba != NULL);

	p8 = ncs_dec_flatten_space(uba, local_data, 8);
	param->client_id = ncs_decode_32bit(&p8);
	param->lstr_id = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 8);
	total_bytes += 8;

	return total_bytes;
}
Beispiel #8
0
static uns32 msg_decode(MDS_CALLBACK_DEC_INFO *dec_info)
{
	uns32 rc = NCSCC_RC_SUCCESS;
	struct rde_msg *msg;
	NCS_UBAID *uba;
	uns8 *data;
	uns8 data_buff[256];

	if (dec_info->i_fr_svc_id != NCSMDS_SVC_ID_RDE) {
			rc = NCSCC_RC_FAILURE;
			goto done;
	}

	if (dec_info->i_msg_fmt_ver != 1) {
			rc = NCSCC_RC_FAILURE;
			goto done;
	}

	msg = malloc(sizeof(*msg));
	assert(msg);

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

	data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
	assert(data);
	msg->type = ncs_decode_32bit(&data);
	ncs_dec_skip_space(uba, sizeof(uns32));

	switch (msg->type) {
	case RDE_MSG_PEER_INFO_REQ:
	case RDE_MSG_PEER_INFO_RESP:
		data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
		assert(data);
		msg->info.peer_info.ha_role = ncs_decode_32bit(&data);
		ncs_dec_skip_space(uba, sizeof(uns32));
		break;

	default:
		assert(0);
		break;
	}

done:
	return rc;
}
Beispiel #9
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;
}
Beispiel #10
0
/****************************************************************************
  Name          : cpa_mds_dec

  Description   : This function decodes an events sent to CPA.

  Arguments     : cb    : CPA control Block.
                  info  : Info for decoding

  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE

  Notes         : None.
******************************************************************************/
static uint32_t cpa_mds_dec(CPA_CB *cb, MDS_CALLBACK_DEC_INFO *dec_info)
{
	CPSV_EVT *msg_ptr = NULL;
	EDU_ERR ederror = 0;
	uint32_t rc = NCSCC_RC_SUCCESS;
	uint8_t local_data[20];
	uint8_t *pstream;
	bool is_valid_msg_fmt = false;
	
	TRACE_ENTER();

	if (dec_info->i_fr_svc_id == NCSMDS_SVC_ID_CPND) {
		is_valid_msg_fmt = m_NCS_MSG_FORMAT_IS_VALID(dec_info->i_msg_fmt_ver,
							     CPA_WRT_CPND_SUBPART_VER_MIN,
							     CPA_WRT_CPND_SUBPART_VER_MAX, cpa_cpnd_msg_fmt_table);
	} else if (dec_info->i_fr_svc_id == NCSMDS_SVC_ID_CPD) {
		is_valid_msg_fmt = m_NCS_MSG_FORMAT_IS_VALID(dec_info->i_msg_fmt_ver,
							     CPA_WRT_CPD_SUBPART_VER_MIN,
							     CPA_WRT_CPD_SUBPART_VER_MAX, cpa_cpd_msg_fmt_table);
	}

	if (is_valid_msg_fmt) {

		msg_ptr = m_MMGR_ALLOC_CPSV_EVT(NCS_SERVICE_ID_CPA);
		if (!msg_ptr)
			return NCSCC_RC_FAILURE;

		memset(msg_ptr, 0, sizeof(CPSV_EVT));
		dec_info->o_msg = (NCSCONTEXT)msg_ptr;
		pstream = ncs_dec_flatten_space(dec_info->io_uba, local_data, 8);
		msg_ptr->type = ncs_decode_32bit(&pstream);
		if (msg_ptr->type == CPSV_EVT_TYPE_CPA) {
			/* For Events  Write/Read Call EDU VER_EXEC*/
			rc = m_NCS_EDU_VER_EXEC(&cb->edu_hdl, FUNC_NAME(CPSV_EVT),
					dec_info->io_uba, EDP_OP_TYPE_DEC,
					(CPSV_EVT **)&dec_info->o_msg, &ederror, dec_info->i_msg_fmt_ver);
			goto free;

			/* if(msg_ptr->info.cpa.type == CPA_EVT_ND2A_CKPT_DATA_RSP) */
		}
		/* if( msg_ptr->type == CPSV_EVT_TYPE_CPA) */
		/* For all Other Cases Other Than CPA( Read / Write Rsp Follow EDU rules */
		rc = m_NCS_EDU_EXEC(&cb->edu_hdl, FUNC_NAME(CPSV_EVT),
				    dec_info->io_uba, EDP_OP_TYPE_DEC, (CPSV_EVT **)&dec_info->o_msg, &ederror);
 free:
		if (rc != NCSCC_RC_SUCCESS) {
			m_MMGR_FREE_CPSV_EVT(dec_info->o_msg, NCS_SERVICE_ID_CPA);
		}
		TRACE_LEAVE();
		return rc;
	} else {
		TRACE_4("CPA:Processing failed for mds_dec ");
		TRACE_LEAVE();
		return NCSCC_RC_FAILURE;
	}
}
Beispiel #11
0
/**
 * Sends and receives an unregister message using osaf_secutil
 * @param evt_type
 * @param mds_dest
 * @param version
 * @param out_evt
 * @param timeout max time to wait for a response in ms unit
 * @return 0 - OK, negated errno otherwise
 */
int mds_auth_server_disconnect(const char *name, MDS_DEST mds_dest, int svc_id, int timeout)
{
	uint32_t rc;
	uint8_t msg[32];
	uint8_t *p = msg;
	uint32_t sz;
	int n;

	sz = ncs_encode_32bit(&p, MDS_UNREGISTER_REQ);
	sz += ncs_encode_32bit(&p, svc_id);
	sz += ncs_encode_64bit(&p, mds_dest);

	n = osaf_auth_server_connect(name, msg, sz, msg,
			sizeof(msg), timeout);

	if (n < 0) {
		TRACE_3("err n:%d", n);
		rc = NCSCC_RC_FAILURE;
		goto fail;
	} else if (n == 0) {
		TRACE_3("tmo");
		rc = NCSCC_RC_REQ_TIMOUT;
		goto fail;
	} else if (n == 8) {
		p = msg;
		int type = ncs_decode_32bit(&p);
		if (type != MDS_UNREGISTER_RESP) {
			TRACE_3("wrong type %d", type);
			rc = NCSCC_RC_FAILURE;
			goto fail;
		}
		int status = ncs_decode_32bit(&p);
		TRACE("received type:%d, status:%d", type, status);
		status == 0 ? (rc = NCSCC_RC_SUCCESS) : (rc = NCSCC_RC_FAILURE);
	} else {
		TRACE_3("err n:%d", n);
		rc = NCSCC_RC_FAILURE;
		goto fail;
	}

fail:
	return rc;
 }
Beispiel #12
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;
}
Beispiel #13
0
/****************************************************************************
  Name          : ntfa_dec_reader_finalize_rsp_msg
 
  Description   : This routine decodes an reader_finalize sync response message
 
  Arguments     : NCS_UBAID *msg,
                  NTFSV_MSG *msg
                  
  Return Values : uns32
 
  Notes         : None.
******************************************************************************/
static uns32 ntfa_dec_reader_finalize_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
{
	uns8 *p8;
	uns32 total_bytes = 0;
	ntfsv_reader_finalize_rsp_t *param = &msg->info.api_resp_info.param.reader_finalize_rsp;
	uns8 local_data[4];

	assert(uba != NULL);

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	param->reader_id = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	return total_bytes;
}
Beispiel #14
0
/****************************************************************************
  Name          : lga_dec_write_ckb_msg
 
  Description   : This routine decodes an initialize sync response message
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_dec_write_cbk_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_write_log_callback_ind_t *param = &msg->info.cbk_info.write_cbk;
	uint8_t local_data[100];

	osafassert(uba != NULL);

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	param->error = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	return total_bytes;
}
Beispiel #15
0
/****************************************************************************
 * Function Name: dts_log_str_decode
 * Purpose:        Decodes the flexlog string.
 *****************************************************************************/
uns32 dts_log_str_decode(NCS_UBAID *uba, char **str)
{
	uns32 length = 0;
	uns8 *data = NULL;
	uns8 data_buff[DTS_MAX_SIZE_DATA];

	data = ncs_dec_flatten_space(uba, data_buff, sizeof(uns32));
	if (data == NULL) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_log_str_decode: Decode flatten space failed");
	}
	length = ncs_decode_32bit(&data);
	ncs_dec_skip_space(uba, sizeof(uns32));

	*str = m_MMGR_ALLOC_OCT(length);
	if (*str == NULL)
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_log_str_decode: Memory allocation failed");

	memset(*str, '\0', length);

	ncs_decode_n_octets_from_uba(uba, (uns8 *)*str, length);

	return NCSCC_RC_SUCCESS;
}
Beispiel #16
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;
}
Beispiel #17
0
/**
 * Function to process the node info hdr
 *
 * @param dtms_cb stream_sock buffer node_info_hrd buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uns32 dtm_process_node_info(DTM_INTERNODE_CB * dtms_cb, int stream_sock, uns8 *buffer, uns8 *node_info_hrd,
			    int buffer_len)
{
	uns32 node_id;
	DTM_NODE_DB *node;
	uns32 nodename_len;
	char nodename[MAX_NAME_LENGTH];
	int rc = 0;
	uns8 *data = buffer;
	TRACE_ENTER();

	node_id = ncs_decode_32bit(&data);
	nodename_len = ncs_decode_32bit(&data);
	strncpy((char *)nodename, (char *)data, nodename_len);

	node = dtm_node_get_by_comm_socket(stream_sock);

	if (node == NULL) {
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	if (!node->comm_status) {

		/*****************************************************/
		/* nodeinfo data back to the client  NODE is still */
		/*****************************************************/

		if (node->node_id == 0) {
			node->node_id = node_id;
			strncpy((char *)&node->node_name, nodename, nodename_len);
			node->comm_status = TRUE;
			if (dtm_node_add(node, 0) != NCSCC_RC_SUCCESS) {
				assert(0);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}

		} else if (node->node_id == node_id) {
			strncpy((char *)&node->node_name, nodename, nodename_len);
			rc = dtm_comm_socket_send(stream_sock, node_info_hrd, buffer_len);
			if (rc != NCSCC_RC_SUCCESS) {

				LOG_ER("DTM: dtm_comm_socket_send() failed rc : %d", rc);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}
			node->comm_status = TRUE;

		} else
			assert(0);

		rc = dtm_process_node_up_down(node->node_id, node->node_name, node->comm_status);

		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("DTM: dtm_process_node_up_down() failed rc : %d ", rc);
			rc = NCSCC_RC_FAILURE;
		}
	} else {
		LOG_ER(" conn details msg recd when conn_status is true");
		assert(0);
	}

 done:
	TRACE_LEAVE();
	return rc;
}
Beispiel #18
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;
}
Beispiel #19
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;
}
Beispiel #20
0
/****************************************************************************
  Name          : ntfa_mds_dec
 
  Description   : This is a callback routine that is invoked to decode NTFS
                  messages.
 
  Arguments     : pointer to struct ncsmds_callback_info
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None.
******************************************************************************/
static uns32 ntfa_mds_dec(struct ncsmds_callback_info *info)
{
	uns8 *p8;
	ntfsv_msg_t *msg;
	NCS_UBAID *uba = info->info.dec.io_uba;
	uns8 local_data[12];
	uns32 total_bytes = 0;
	TRACE_ENTER();

	if (0 == m_NCS_MSG_FORMAT_IS_VALID(info->info.dec.i_msg_fmt_ver,
					   NTFA_WRT_NTFS_SUBPART_VER_AT_MIN_MSG_FMT,
					   NTFA_WRT_NTFS_SUBPART_VER_AT_MAX_MSG_FMT, NTFA_WRT_NTFS_MSG_FMT_ARRAY)) {
		TRACE("Invalid message format!!!\n");
		TRACE_LEAVE();
		return NCSCC_RC_FAILURE;
	}

    /** Allocate a new msg in both sync/async cases 
     **/
	if (NULL == (msg = calloc(1, sizeof(ntfsv_msg_t)))) {
		TRACE("calloc failed\n");
		return NCSCC_RC_FAILURE;
	}

	info->info.dec.o_msg = (uns8 *)msg;

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	msg->type = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	switch (msg->type) {
	case NTFSV_NTFA_API_RESP_MSG:
		{
			p8 = ncs_dec_flatten_space(uba, local_data, 8);
			msg->info.api_resp_info.type = ncs_decode_32bit(&p8);
			msg->info.api_resp_info.rc = ncs_decode_32bit(&p8);
			ncs_dec_skip_space(uba, 8);
			total_bytes += 8;
			TRACE_2("NTFSV_NTFA_API_RESP_MSG rc = %d", (int)msg->info.api_resp_info.rc);

			switch (msg->info.api_resp_info.type) {
			case NTFSV_INITIALIZE_RSP:
				total_bytes += ntfa_dec_initialize_rsp_msg(uba, msg);
				break;
			case NTFSV_SUBSCRIBE_RSP:
				total_bytes += ntfa_dec_subscribe_rsp_msg(uba, msg);
				break;
			case NTFSV_UNSUBSCRIBE_RSP:	/* Only header sent from server */
				break;
			case NTFSV_SEND_NOT_RSP:
				total_bytes += ntfa_dec_send_not_rsp_msg(uba, msg);
				break;
			case NTFSV_READER_INITIALIZE_RSP:
				total_bytes += ntfa_dec_reader_initialize_rsp_msg(uba, msg);
				break;
			case NTFSV_READER_FINALIZE_RSP:
				total_bytes += ntfa_dec_reader_finalize_rsp_msg(uba, msg);
				break;
			case NTFSV_READ_NEXT_RSP:
				total_bytes += ntfa_dec_read_next_rsp_msg(uba, msg);
				break;
			case NTFSV_FINALIZE_RSP:
				break;
			default:
				TRACE_2("Unknown API RSP type %d", msg->info.api_resp_info.type);
				break;
			}
		}
		break;
	case NTFSV_NTFS_CBK_MSG:
		{
			p8 = ncs_dec_flatten_space(uba, local_data, 12);
			msg->info.cbk_info.type = ncs_decode_32bit(&p8);
			msg->info.cbk_info.ntfs_client_id = ncs_decode_32bit(&p8);
			msg->info.cbk_info.subscriptionId = ncs_decode_32bit(&p8);
			ncs_dec_skip_space(uba, 12);
			total_bytes += 12;
			TRACE_2("NTFSV_NTFS_CBK_MSG");
			switch (msg->info.cbk_info.type) {
			case NTFSV_NOTIFICATION_CALLBACK:
				/* TODO: use notificationAlloc here? */
				msg->info.cbk_info.param.notification_cbk = calloc(1, sizeof(ntfsv_send_not_req_t));
				if (NULL == msg->info.cbk_info.param.notification_cbk) {
					TRACE_1("could not allocate memory");
					return 0;
				}
				TRACE_2("decode notification cbk message");
				total_bytes += ntfa_dec_not_send_cbk_msg(uba, msg);
				break;
			case NTFSV_DISCARDED_CALLBACK:
				TRACE_2("decode discarded cbk message");
				total_bytes += ntfa_dec_not_discard_cbk_msg(uba, msg);
				break;
			default:
				TRACE_2("Unknown callback type = %d!", msg->info.cbk_info.type);
				break;
			}
		}
		break;
	default:
		TRACE("Unknown MSG type %d", msg->type);
		break;
	}
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Beispiel #21
0
/****************************************************************************
  Name          : lga_mds_dec
 
  Description   : This is a callback routine that is invoked to decode LGS
                  messages.
 
  Arguments     : pointer to struct ncsmds_callback_info
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_mds_dec(struct ncsmds_callback_info *info)
{
	uint8_t *p8;
	lgsv_msg_t *msg;
	NCS_UBAID *uba = info->info.dec.io_uba;
	uint8_t local_data[20];
	uint32_t total_bytes = 0;
	TRACE_ENTER();

	if (0 == m_NCS_MSG_FORMAT_IS_VALID(info->info.dec.i_msg_fmt_ver,
					   LGA_WRT_LGS_SUBPART_VER_AT_MIN_MSG_FMT,
					   LGA_WRT_LGS_SUBPART_VER_AT_MAX_MSG_FMT, LGA_WRT_LGS_MSG_FMT_ARRAY)) {
		TRACE("Invalid message format!!!\n");
		TRACE_LEAVE();
		return NCSCC_RC_FAILURE;
	}

    /** Allocate a new msg in both sync/async cases 
     **/
	if (NULL == (msg = calloc(1, sizeof(lgsv_msg_t)))) {
		TRACE("calloc failed\n");
		return NCSCC_RC_FAILURE;
	}

	info->info.dec.o_msg = (uint8_t *)msg;

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	msg->type = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	switch (msg->type) {
	case LGSV_LGA_API_RESP_MSG:
		{
			p8 = ncs_dec_flatten_space(uba, local_data, 8);
			msg->info.api_resp_info.type = ncs_decode_32bit(&p8);
			msg->info.api_resp_info.rc = ncs_decode_32bit(&p8);
			ncs_dec_skip_space(uba, 8);
			total_bytes += 8;
			TRACE_2("LGSV_LGA_API_RESP_MSG");

			switch (msg->info.api_resp_info.type) {
			case LGSV_INITIALIZE_RSP:
				total_bytes += lga_dec_initialize_rsp_msg(uba, msg);
				break;
			case LGSV_FINALIZE_RSP:
				total_bytes += lga_dec_finalize_rsp_msg(uba, msg);
				break;
			case LGSV_STREAM_OPEN_RSP:
				total_bytes += lga_dec_lstr_open_sync_rsp_msg(uba, msg);
				break;
			case LGSV_STREAM_CLOSE_RSP:
				total_bytes += lga_dec_lstr_close_rsp_msg(uba, msg);
				break;
			default:
				TRACE_2("Unknown API RSP type %d", msg->info.api_resp_info.type);
				break;
			}
		}
		break;
	case LGSV_LGS_CBK_MSG:
		{
			p8 = ncs_dec_flatten_space(uba, local_data, 16);
			msg->info.cbk_info.type = ncs_decode_32bit(&p8);
			msg->info.cbk_info.lgs_client_id = ncs_decode_32bit(&p8);
			msg->info.cbk_info.inv = ncs_decode_64bit(&p8);
			ncs_dec_skip_space(uba, 16);
			total_bytes += 16;
			TRACE_2("LGSV_LGS_CBK_MSG");
			switch (msg->info.cbk_info.type) {
			case LGSV_WRITE_LOG_CALLBACK_IND:
				TRACE_2("decode writelog message");
				total_bytes += lga_dec_write_cbk_msg(uba, msg);
				break;
			default:
				TRACE_2("Unknown callback type = %d!", msg->info.cbk_info.type);
				break;
			}
		}
		break;
	default:
		TRACE("Unknown MSG type %d", msg->type);
		break;
	}
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Beispiel #22
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;
}
Beispiel #23
0
/**
 * Function to process the node info hdr
 *
 * @param dtms_cb stream_sock buffer node_info_hrd buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_process_node_info(DTM_INTERNODE_CB * dtms_cb, int stream_sock, uint8_t *buffer, uint8_t *node_info_hrd,
			    int buffer_len)
{
	uint32_t node_id;
	DTM_NODE_DB *node;
	uint32_t nodename_len;
	char nodename[MAX_NAME_LENGTH];
	int rc = 0;
	uint8_t *data = buffer;
	TRACE_ENTER();

	node_id = ncs_decode_32bit(&data);
	nodename_len = ncs_decode_32bit(&data);
	strncpy((char *)nodename, (char *)data, nodename_len);

	node = dtm_node_get_by_comm_socket(stream_sock);

	if (node == NULL) {
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	if (!node->comm_status) {

		/*****************************************************/
		/* nodeinfo data back to the client  NODE is still */
		/*****************************************************/

		if (node->node_id == 0) {
			node->node_id = node_id;
			strncpy((char *)&node->node_name, nodename, nodename_len);
			node->comm_status = true;
			if (dtm_node_add(node, 0) != NCSCC_RC_SUCCESS) {
				LOG_ER("DTM:  Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");				
				osafassert(0);
			
			}

		} else if (node->node_id == node_id) {
			strncpy((char *)&node->node_name, nodename, nodename_len);
			rc = dtm_comm_socket_send(stream_sock, node_info_hrd, buffer_len);
			if (rc != NCSCC_RC_SUCCESS) {

				LOG_ER("DTM: dtm_comm_socket_send() failed rc : %d", rc);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}
			node->comm_status = true;

		} else {
			LOG_ER("DTM: Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");
			osafassert(0);
		}

		TRACE("DTM: dtm_process_node_info node_ip:%s, node_id:%u i_addr_family:%d ", node->node_ip, node->node_id, node->i_addr_family);
		rc = dtm_process_node_up_down(node->node_id, node->node_name, node->node_ip , node->i_addr_family, node->comm_status);

		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("DTM: dtm_process_node_up_down() failed rc : %d ", rc);
			rc = NCSCC_RC_FAILURE;
		}
	} else {
		LOG_ER("DTM: Node down already  received  for this node ");
		osafassert(0);
	}

 done:
	TRACE_LEAVE();
	return rc;
}
Beispiel #24
0
/**
 * Handler for mds register requests
 * Note: executed by and in context of the auth thread!
 * Communicates with the main thread (where the
 * real work is done) to get outcome of initialization request which is then
 * sent back to the client.
 * @param fd
 * @param creds credentials for client
 */
static void mds_register_callback(int fd, const struct ucred *creds)
{
	uint8_t buf[32];
	uint8_t *p = buf;

	TRACE_ENTER2("fd:%d, pid:%u", fd, creds->pid);

	int n = recv(fd, buf, sizeof(buf), 0);
	if (n == -1) {
		syslog(LOG_ERR, "%s: recv failed - %s", __FUNCTION__, strerror(errno));
		goto done;
	}

	if (n != 16) {
		syslog(LOG_ERR, "%s: recv failed - %d bytes", __FUNCTION__, n);
		goto done;
	}

	int type = ncs_decode_32bit(&p);

	NCSMDS_SVC_ID svc_id = ncs_decode_32bit(&p);
	MDS_DEST mds_dest = ncs_decode_64bit(&p);

	TRACE("mds: received %d from %"PRIx64", pid %d", type, mds_dest, creds->pid);

	if (type == MDS_REGISTER_REQ) {
		osaf_mutex_lock_ordie(&gl_mds_library_mutex);

		MDS_PROCESS_INFO *info = mds_process_info_get(mds_dest, svc_id);
		if (info == NULL) {
			MDS_PROCESS_INFO *info = calloc(1, sizeof(MDS_PROCESS_INFO));
			osafassert(info);
			info->mds_dest = mds_dest;
			info->svc_id = svc_id;
			info->uid = creds->uid;
			info->pid = creds->pid;
			info->gid = creds->gid;
			int rc = mds_process_info_add(info);
			osafassert(rc == NCSCC_RC_SUCCESS);
		} else {
			/* when can this happen? */
			LOG_NO("%s: dest %"PRIx64" already exist", __FUNCTION__, mds_dest);

			// just update credentials
			info->uid = creds->uid;
			info->pid = creds->pid;
			info->gid = creds->gid;
		}

		osaf_mutex_unlock_ordie(&gl_mds_library_mutex);

		p = buf;
		uint32_t sz = ncs_encode_32bit(&p, MDS_REGISTER_RESP);
		sz += ncs_encode_32bit(&p, 0); // result OK

		if ((n = send(fd, buf, sz, 0)) == -1)
			syslog(LOG_ERR, "%s: send to pid %d failed - %s",
					__FUNCTION__, creds->pid, strerror(errno));
	} else if (type == MDS_UNREGISTER_REQ) {
		osaf_mutex_lock_ordie(&gl_mds_library_mutex);

		MDS_PROCESS_INFO *info = mds_process_info_get(mds_dest, svc_id);
		if (info != NULL) {
			(void)mds_process_info_del(info);
		}
		osaf_mutex_unlock_ordie(&gl_mds_library_mutex);

		p = buf;
		uint32_t sz = ncs_encode_32bit(&p, MDS_UNREGISTER_RESP);
		sz += ncs_encode_32bit(&p, 0);  // result OK

		if ((n = send(fd, buf, sz, 0)) == -1)
			syslog(LOG_ERR, "%s: send to pid %d failed - %s",
					__FUNCTION__, creds->pid, strerror(errno));
	} else {
		syslog(LOG_ERR, "%s: recv failed - wrong type %d", __FUNCTION__, type);
		goto done;
	}

done:
	TRACE_LEAVE();
}