Esempio n. 1
0
/****************************************************************************
  Name          : ntfa_enc_reader_initialize_msg
 
  Description   : This routine encodes an reader_initialize API msg
 
  Arguments     : NCS_UBAID *msg,
                  NTFSV_MSG *msg
                  
  Return Values : uns32
 
  Notes         : None.
******************************************************************************/
static uns32 ntfa_enc_reader_initialize_msg(NCS_UBAID *uba, ntfsv_msg_t *msg)
{
	uns8 *p8;
	uns32 total_bytes = 0;
	ntfsv_reader_init_req_t *param = &msg->info.api_info.param.reader_init;

	TRACE_ENTER();
	assert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 22);
	if (!p8) {
		TRACE("NULL pointer");
		return 0;
	}
	ncs_encode_32bit(&p8, param->client_id);
	ncs_encode_16bit(&p8, param->searchCriteria.searchMode);
	ncs_encode_64bit(&p8, param->searchCriteria.eventTime);
	ncs_encode_64bit(&p8, param->searchCriteria.notificationId);
	ncs_enc_claim_space(uba, 22);
	total_bytes += 22;

	TRACE_LEAVE();
	return total_bytes;
}
Esempio n. 2
0
/****************************************************************************
  Name          : eda_enc_subscribe_msg
 
  Description   : This routine encodes a subscribe API msg
 
  Arguments     : NCS_UBAID *msg,
                  EDSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_enc_subscribe_msg(NCS_UBAID *uba, EDSV_MSG *msg)
{
	uint8_t *p8;
	uint32_t x;
	uint32_t total_bytes = 0;
	SaEvtEventFilterT *filter_ptr;
	EDSV_EDA_SUBSCRIBE_PARAM *param = &msg->info.api_info.param.subscribe;

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

   /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 24);
	if (!p8) {
		TRACE_4("reserve space failed");
	}
	ncs_encode_32bit(&p8, param->reg_id);
	ncs_encode_32bit(&p8, param->chan_id);
	ncs_encode_32bit(&p8, param->chan_open_id);
	ncs_encode_32bit(&p8, param->sub_id);
	ncs_encode_64bit(&p8, param->filter_array->filtersNumber);
	ncs_enc_claim_space(uba, 24);
	total_bytes += 24;

	/* Encode the filters */
	filter_ptr = param->filter_array->filters;
	for (x = 0; x < (uint32_t)param->filter_array->filtersNumber; x++) {
		/* Save room for the filterType(4 bytes), patternSize(8 bytes)
		 */
		p8 = ncs_enc_reserve_space(uba, 12);
		if (!p8) {
			TRACE_4("reserve space failed");
		}
		ncs_encode_32bit(&p8, filter_ptr->filterType);
		ncs_encode_64bit(&p8, filter_ptr->filter.patternSize);
		ncs_enc_claim_space(uba, 12);
		total_bytes = 12;

		/* For zero length filters, fake encode zero */
		if ((uint32_t)filter_ptr->filter.patternSize == 0) {
			p8 = ncs_enc_reserve_space(uba, 4);
			if (!p8) {
				TRACE_4("reserve space failed");
			}
			ncs_encode_32bit(&p8, 0);
			ncs_enc_claim_space(uba, 4);
			total_bytes += 4;
		} else {
			ncs_encode_n_octets_in_uba(uba, filter_ptr->filter.pattern,
						   (uint32_t)filter_ptr->filter.patternSize);
			total_bytes += (uint32_t)filter_ptr->filter.patternSize;
		}
		filter_ptr++;
	}

	return total_bytes;
}
Esempio n. 3
0
/****************************************************************************
  Name          : eda_enc_chan_open_async_msg
 
  Description   : This routine encodes a chan open async API msg
 
  Arguments     : NCS_UBAID *msg,
                  EDSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_enc_chan_open_async_msg(NCS_UBAID *uba, EDSV_MSG *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	EDSV_EDA_CHAN_OPEN_ASYNC_PARAM *param = &msg->info.api_info.param.chan_open_async;

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

   /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 15);
	if (!p8) {
		TRACE_4("reserve space failed");
	}
	ncs_encode_64bit(&p8, param->inv);
	ncs_encode_32bit(&p8, param->reg_id);
	ncs_encode_8bit(&p8, param->chan_open_flags);
	ncs_encode_16bit(&p8, param->chan_name.length);
	ncs_enc_claim_space(uba, 15);
	total_bytes += 15;

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

	return total_bytes;
}
Esempio n. 4
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;
 }
Esempio n. 5
0
/****************************************************************************\
 * Name          : ncs_logmsg_int
 *
 * Description   : This function is use for Message Logging.
 *
 * Arguments     : svc_id       : Service ID.
 *                 fmat_id      : Format ID.
 *                 str_table_id : String tabel ID.
 *                 category     : Message category.
 *                 severity     : Message Severity.
 *                 fmat_type    : Format type to be used for logging.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
\*****************************************************************************/
uns32 ncs_logmsg_int(SS_SVC_ID svc_id,
		     uns32 inst_id,
		     uns8 fmat_id, uns8 str_table_id, uns32 category, uns8 severity, char *fmat_type, va_list argp)
{
	uns32 i = 0, length = 0;
	DTA_CB *inst = &dta_cb;
	DTSV_MSG *msg;
	NCSFL_HDR *hdr;
	REG_TBL_ENTRY *svc;
	NCS_UBAID *uba = NULL;
	uns8 *data;
	uns32 send_pri;
	int warning_rmval = 0;

    /*************************************************************************\
    * As different fields of the log-message are encoded, the minimum DTS     
    * required to understand the message may change.
    \*************************************************************************/
	uns32 act_dts_ver;	/* Active dts's version. */
	uns32 min_dts_ver;	/* Minimum DTS version that understands message */

	DTA_LOG_BUFFER *list = &inst->log_buffer;
	DTA_BUFFERED_LOG *buf = NULL;

	/* Check if DTA is created. Continue logging if DTA is created */
	if (inst->created == FALSE) {
		return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE,
					  "ncs_logmsg: DTA does not exist. First create DTA before logging.", svc_id);
	}

	m_DTA_LK(&inst->lock);

	/* 
	 * Check whether DTS exist. If DTS does not exist then there is no 
	 * point in logging message. Return failure.
	 * Changed as of 15th June 2006. 
	 * If FLS doesn't exist & number of buffer msgs is more than DTA_BUF_LIMIT
	 * then drop the message and return failure.
	 */
	if ((inst->dts_exist == FALSE) && (list->num_of_logs >= DTA_BUF_LIMIT)) {
		m_DTA_UNLK(&inst->lock);
		return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE,
					  "ncs_logmsg: DTS does not exist & DTA log buffer is full. Log message is dropped.",
					  svc_id);
	}

	/*
	 * Check whether the Sevice is registered with the DTSv. If not already
	 * bound return failure.
	 */
	if (((svc = (REG_TBL_ENTRY *)ncs_patricia_tree_get(&inst->reg_tbl, (const uns8 *)&svc_id)) == NULL)) {
		m_DTA_UNLK(&inst->lock);
		return NCSCC_RC_FAILURE;
	}
#if (DTA_FLOW == 1)
	/* Check whether logging is enabled beyond default level for this service 
	 * i.e. INFO or DEBUG levels are enabled or not. 
	 * If logging levels are increased to INFO/DEBUG, don't apply DTA message
	 * thresholding. Otherwise DTA defines MAX threshold of 2000 messages after
	 * which all messages will be dropped. In such cases, check the rate of 
	 * logging for such processes.
	 */
	if (svc->severity_bit_map > 0xFC) {
		/* Don't apply thresholding of messages here */
	} else {
		/* Else apply thresholding */
		if (inst->msg_count > DTA_MAX_THRESHOLD) {
			m_DTA_UNLK(&inst->lock);
			warning_rmval =
			    m_DTA_DBG_SINK(NCSCC_RC_FAILURE,
					   "ncs_logmsg: DTA queued msgs exceeds 2000. Message will be dropped.");
			return NCSCC_RC_FAILURE;
		}
	}

	/* Drop INFO/DEBUG messages at source during congestion */
	if ((inst->dts_congested == TRUE) && (severity < NCSFL_SEV_NOTICE)) {
		m_DTA_UNLK(&inst->lock);
		return NCSCC_RC_FAILURE;
	}
#endif

	msg = m_MMGR_ALLOC_DTSV_MSG;
	if (msg == NULL) {
		m_DTA_UNLK(&inst->lock);
		return m_DTA_DBG_SINK(NCSCC_RC_FAILURE, "ncs_logmsg: Memory allocation failer for DTSV_MSG");
	}
	memset(msg, '\0', sizeof(DTSV_MSG));

	hdr = &msg->data.data.msg.log_msg.hdr;

	hdr->category = category;
	hdr->severity = severity;
	hdr->fmat_id = fmat_id;
	hdr->ss_id = svc_id;
	hdr->inst_id = inst_id;
	hdr->str_table_id = str_table_id;

	/* Apply the filter Policies. If the logging is disabled
	 * then return success. We are returning success here since it may 
	 * possible that logging is disabled by user.
	 */
	if (dta_svc_reg_log_en(svc, &msg->data.data.msg.log_msg) == NCSCC_RC_FAILURE) {
		m_DTA_UNLK(&inst->lock);
		m_MMGR_FREE_DTSV_MSG(msg);
		return NCSCC_RC_SUCCESS;
	}

	if (NCSCC_RC_SUCCESS != dta_copy_octets(&hdr->fmat_type, fmat_type, (uns16)(1 + strlen(fmat_type)))) {
		m_DTA_UNLK(&inst->lock);
		m_MMGR_FREE_DTSV_MSG(msg);
		return m_DTA_DBG_SINK(NCSCC_RC_FAILURE, "ncs_logmsg_int: Copy octet failed.");
	}

	/* Flexlog Agent fills in the TIME STAMP value */
	m_GET_MSEC_TIME_STAMP(&hdr->time.seconds, &hdr->time.millisecs);

	msg->vrid = inst->vrid;
	msg->msg_type = DTA_LOG_DATA;
	uba = &msg->data.data.msg.log_msg.uba;

	/* act_dts_ver needs to be recorded before inst->lock is unlocked  */
	act_dts_ver = inst->act_dts_ver;
	min_dts_ver = 1;	/* DTS should be at least this version to interpret the
				   encoded message. This directly determines the
				   message format vesion */

	m_DTA_UNLK(&inst->lock);

	memset(uba, '\0', sizeof(NCS_UBAID));

	if (ncs_enc_init_space(uba) != NCSCC_RC_SUCCESS) {
		m_MMGR_FREE_OCT(hdr->fmat_type);
		m_MMGR_FREE_DTSV_MSG(msg);
		return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE, "ncs_logmsg: Unable to init user buff", svc_id);
	}

	while (fmat_type[i] != '\0') {
		switch (fmat_type[i]) {
		case 'T':
			{
				break;
			}
		case 'I':
			{
				uns32 idx;
				idx = m_NCSFL_MAKE_IDX((uns32)str_table_id, (uns32)va_arg(argp, uns32));
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, idx);
				ncs_enc_claim_space(uba, sizeof(uns32));
				break;
			}
		case 'L':
			{
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, va_arg(argp, uns32));
				ncs_enc_claim_space(uba, sizeof(uns32));
				break;
			}

		case 'C':
			{
				char *str = va_arg(argp, char *);

				if (NULL == str) {
					if (uba->start != NULL)
						m_MMGR_FREE_BUFR_LIST(uba->start);
					m_MMGR_FREE_OCT(hdr->fmat_type);
					m_MMGR_FREE_DTSV_MSG(msg);
					return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE,
								  "ncs_logmsg: NULL string passed for format type 'C'",
								  svc_id);
				}

				length = strlen(str) + 1;

				if (length > (DTS_MAX_SIZE_DATA * 3)) {
					if (uba->start != NULL)
						m_MMGR_FREE_BUFR_LIST(uba->start);
					m_MMGR_FREE_OCT(hdr->fmat_type);
					m_MMGR_FREE_DTSV_MSG(msg);
					return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE,
								  "ncs_logmsg: Can not log string with more than 1536 characters",
								  svc_id);
				}

				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, length);
				ncs_enc_claim_space(uba, sizeof(uns32));

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

				break;
			}
		case 'M':
			{
				data = ncs_enc_reserve_space(uba, sizeof(uns16));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_16bit(&data, (uns16)va_arg(argp, uns32));
				ncs_enc_claim_space(uba, sizeof(uns16));
				break;
			}
		case 'D':
			{
				NCSFL_MEM mem_d = va_arg(argp, NCSFL_MEM);

				if (mem_d.len > DTS_MAX_SIZE_DATA)
					mem_d.len = DTS_MAX_SIZE_DATA;

				/* Versioning & 64-bit compatibility changes - Encode the msg 
				 * for format 'D' after checking the version of the current 
				 * Active DTS.
				 * If Active DTS has MDS version 1 and DTA arch 64-bit then, 
				 * encode 32 bits with reserved bit-pattern 0x6464. 
				 * Else, if DTS has MDS version 2, then encode 64-bits of the 
				 * address.
				 * Also fill DTA_LOG_MSG structure with the DTS version as seen
				 * while encoding.
				 */

				/* The 'D' message is encoded at version 1 or 2 based on 
				   whether DTS is at version 1 or higher respectively. 

				 */
				/* Check for compatibility with receiving DTS version
				   and set the minimum DTS version required */
				if (act_dts_ver == 1) {
					/* Compatible DTS. Update minimum DTS version required */
					if (min_dts_ver < 1)
						min_dts_ver = 1;

					data = ncs_enc_reserve_space(uba, (sizeof(uns16) + sizeof(uns32)));
					if (data == NULL)
						goto reserve_error;
					ncs_encode_16bit(&data, mem_d.len);

					if (sizeof(inst) == 8) {
						/* Attempt to print 64-bit address on 32-bit DTS. 
						 * Print pre-defined bit pattern to indicate error. 
						 */
						ncs_encode_32bit(&data, (uns32)0x6464);
					} else if (sizeof(inst) == 4) {
						/* Do it the old way */
						ncs_encode_32bit(&data, NCS_PTR_TO_UNS32_CAST(mem_d.addr));
					}
					ncs_enc_claim_space(uba, (sizeof(uns16) + sizeof(uns32)));
				}
				/* Act DTS on version 2 or higher , then encode all 64-bits */
				else {
					/* Compatible DTS. Update minimum DTS version required */
					if (min_dts_ver < 2)
						min_dts_ver = 2;

					data = ncs_enc_reserve_space(uba, (sizeof(uns16) + sizeof(uns64)));
					if (data == NULL)
						goto reserve_error;
					ncs_encode_16bit(&data, mem_d.len);
					ncs_encode_64bit(&data, (uns64)(long)mem_d.addr);
					ncs_enc_claim_space(uba, (sizeof(uns16) + sizeof(uns64)));
				}

				ncs_encode_n_octets_in_uba(uba, (uns8 *)mem_d.dump, (uns32)mem_d.len);

				break;
			}
		case 'P':
			{
				NCSFL_PDU pdu = va_arg(argp, NCSFL_PDU);

				if (pdu.len > DTS_MAX_SIZE_DATA)
					pdu.len = DTS_MAX_SIZE_DATA;

				data = ncs_enc_reserve_space(uba, sizeof(uns16));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_16bit(&data, pdu.len);
				ncs_enc_claim_space(uba, sizeof(uns16));

				ncs_encode_n_octets_in_uba(uba, (uns8 *)pdu.dump, (uns32)pdu.len);

				break;
			}
		case 'A':
			{
				encode_ip_address(uba, va_arg(argp, NCS_IP_ADDR));
				break;
			}
		case 'S':
			{
				data = ncs_enc_reserve_space(uba, sizeof(uns8));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_8bit(&data, (uns8)va_arg(argp, uns32));
				ncs_enc_claim_space(uba, sizeof(uns8));

				break;
			}
			/* Added code for handling float values */
		case 'F':
			{
				char str[DTS_MAX_DBL_DIGITS] = "";
				int num_chars = sprintf(str, "%f", va_arg(argp, double));
				if (num_chars == 0) {
					warning_rmval =
					    m_DTA_DBG_SINK(NCSCC_RC_FAILURE,
							   "ncs_logmsg: Float to string conversion gives NULL");
					goto reserve_error;
				}
				length = strlen(str) + 1;
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, length);
				ncs_enc_claim_space(uba, sizeof(uns32));

				ncs_encode_n_octets_in_uba(uba, (uns8 *)str, length);
				break;
			}
		case 'N':
			{
				char str[DTS_MAX_DBL_DIGITS] = "";
				int num_chars = 0;

				/* Check for compatibility with receiving DTS version
				   and set the minimum DTS version required */
				if (act_dts_ver == 1) {
					/* Incompatible DTS */
					goto reserve_error;
				} else {
					/* Compatible DTS. Update minimum DTS version required */
					if (min_dts_ver < 2)
						min_dts_ver = 2;
				}

				num_chars = sprintf(str, "%lld", va_arg(argp, long long));

                                if (num_chars == 0) {
					warning_rmval =
					    m_DTA_DBG_SINK(NCSCC_RC_FAILURE,
							   "ncs_logmsg: long long to string conversion gives NULL");
					goto reserve_error;
				}

				length = strlen(str) + 1;
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, length);
				ncs_enc_claim_space(uba, sizeof(uns32));

				ncs_encode_n_octets_in_uba(uba, (uns8 *)str, length);
				break;
			}
		case 'U':
			{
				char str[DTS_MAX_DBL_DIGITS] = "";
				int num_chars = 0;

				/* Check for compatibility with receiving DTS version
				   and set the minimum DTS version required */
				if (act_dts_ver == 1) {
					/* Incompatible DTS */
					goto reserve_error;
				} else {
					/* Compatible DTS. Update minimum DTS version required */
					if (min_dts_ver < 2)
						min_dts_ver = 2;
				}

				num_chars = sprintf(str, "%llu", va_arg(argp, unsigned long long));
                                if (num_chars == 0) {
					warning_rmval =
					    m_DTA_DBG_SINK(NCSCC_RC_FAILURE,
							   "ncs_logmsg: unsigned long long to string conversion gives NULL");
					goto reserve_error;
				}

				length = strlen(str) + 1;
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, length);
				ncs_enc_claim_space(uba, sizeof(uns32));

				ncs_encode_n_octets_in_uba(uba, (uns8 *)str, length);
				break;
			}
		case 'X':
			{
				char str[DTS_MAX_DBL_DIGITS] = "";
				int num_chars = 0;

				/* Check for compatibility with receiving DTS version
				   and set the minimum DTS version required */
				if (act_dts_ver == 1) {
					/* Incompatible DTS */
					goto reserve_error;
				} else {
					/* Compatible DTS. Update minimum DTS version required */
					if (min_dts_ver < 2)
						min_dts_ver = 2;
				}

				num_chars = sprintf(str, "Ox%016llx", va_arg(argp, long long));

                                if (num_chars == 0) {
					warning_rmval =
					    m_DTA_DBG_SINK(NCSCC_RC_FAILURE,
							   "ncs_logmsg: 64bit hex to string conversion gives NULL");
					goto reserve_error;
				}

				length = strlen(str) + 1;
				data = ncs_enc_reserve_space(uba, sizeof(uns32));
				if (data == NULL)
					goto reserve_error;
				ncs_encode_32bit(&data, length);
				ncs_enc_claim_space(uba, sizeof(uns32));

				ncs_encode_n_octets_in_uba(uba, (uns8 *)str, length);
				break;
			}
		default:
			{
				if (uba->start != NULL)
					m_MMGR_FREE_BUFR_LIST(uba->start);
				m_MMGR_FREE_OCT(hdr->fmat_type);
				m_MMGR_FREE_DTSV_MSG(msg);
				return m_DTA_DBG_SINK_SVC(NCSCC_RC_FAILURE,
							  "ncs_logmsg: Format Type Not accounted for", svc_id);
			}

		}

		i++;
	}

	/* Buffer log messgages if DTS is not up _or_ registration is not confirmed */
	if ((inst->dts_exist == FALSE) || (svc->log_msg == FALSE)) {
		m_DTA_LK(&inst->lock);
		buf = m_MMGR_ALLOC_DTA_BUFFERED_LOG;
		if (!buf) {
			if (msg->data.data.msg.log_msg.uba.start != NULL)
				m_MMGR_FREE_BUFR_LIST(msg->data.data.msg.log_msg.uba.start);
			m_MMGR_FREE_OCT(msg->data.data.msg.log_msg.hdr.fmat_type);
			if (0 != msg)
				m_MMGR_FREE_DTSV_MSG(msg);
			m_DTA_UNLK(&inst->lock);
			return m_DTA_DBG_SINK(NCSCC_RC_FAILURE, "Failed to allocate memory for log buffering");
		}

		/* Set the msg format version based on how it is encoded above. 
		   Usually it will be 1, because during DTS initialization, until
		   active DTS shows up (i.e until inst->dts_exist becomes TRUE)
		   active DTS version is assumed to be 1.
		 */
		msg->data.data.msg.msg_fmat_ver = min_dts_ver;

		memset(buf, '\0', sizeof(DTA_BUFFERED_LOG));
		buf->buf_msg = msg;
		buf->next = NULL;

		if (!list->head)
			list->head = buf;
		else
			list->tail->next = buf;

		list->tail = buf;
		list->num_of_logs++;
		m_DTA_UNLK(&inst->lock);
	} else {
		send_pri = NCS_IPC_PRIORITY_LOW;

		/* Set the msg format version to final value of min_dts_ver */
		msg->data.data.msg.msg_fmat_ver = min_dts_ver;

		/* Smik - We don't send the msg to MDS but to DTA's msgbox */
		if (m_DTA_SND_MSG(&gl_dta_mbx, msg, send_pri) != NCSCC_RC_SUCCESS) {
			if (uba->start != NULL)
				m_MMGR_FREE_BUFR_LIST(uba->start);
			m_MMGR_FREE_OCT(hdr->fmat_type);
			m_MMGR_FREE_DTSV_MSG(msg);
			/*if (dta_mds_async_send(&msg, inst) != NCSCC_RC_SUCCESS) */
			return m_DTA_DBG_SINK(NCSCC_RC_FAILURE, "ncs_logmsg: send to DTA msgbox failed");
		}
	}

	return NCSCC_RC_SUCCESS;

 reserve_error:
	if (uba->start != NULL)
		m_MMGR_FREE_BUFR_LIST(uba->start);
	m_MMGR_FREE_OCT(hdr->fmat_type);
	m_MMGR_FREE_DTSV_MSG(msg);
	return m_DTA_DBG_SINK(NCSCC_RC_FAILURE, "ncs_logmsg: Unable to reserve space in encode");
}
Esempio n. 6
0
/****************************************************************************
  Name          : eda_enc_publish_msg
 
  Description   : This routine encodes a publish API msg
 
  Arguments     : NCS_UBAID *msg,
                  EDSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_enc_publish_msg(NCS_UBAID *uba, EDSV_MSG *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	uint32_t x;
	SaEvtEventPatternT *pattern_ptr;
	EDSV_EDA_PUBLISH_PARAM *param = &msg->info.api_info.param.publish;

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

   /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 20);
	if (!p8) {
		TRACE_4("reserve space failed");
	}
	ncs_encode_32bit(&p8, param->reg_id);
	ncs_encode_32bit(&p8, param->chan_id);
	ncs_encode_32bit(&p8, param->chan_open_id);
	ncs_encode_64bit(&p8, param->pattern_array->patternsNumber);
	ncs_enc_claim_space(uba, 20);
	total_bytes += 20;

	/* Encode the patterns */
	pattern_ptr = param->pattern_array->patterns;
	for (x = 0; x < (uint32_t)param->pattern_array->patternsNumber; x++) {
		/* Save room for the patternSize field (8 bytes) */
		p8 = ncs_enc_reserve_space(uba, 8);
		if (!p8) {
			TRACE_4("reserve space failed");
		}
		ncs_encode_64bit(&p8, pattern_ptr->patternSize);
		ncs_enc_claim_space(uba, 8);
		total_bytes += 8;

		/* For zero length patterns, fake encode zero */
		if (pattern_ptr->patternSize == 0) {
			p8 = ncs_enc_reserve_space(uba, 4);
			if (!p8) {
				TRACE_4("reserve space failed");
			}
			ncs_encode_32bit(&p8, 0);
			ncs_enc_claim_space(uba, 4);
			total_bytes += 4;
		} else {
			ncs_encode_n_octets_in_uba(uba, pattern_ptr->pattern, (uint32_t)pattern_ptr->patternSize);
			total_bytes += (uint32_t)pattern_ptr->patternSize;
		}
		pattern_ptr++;
	}

	p8 = ncs_enc_reserve_space(uba, 11);
	if (!p8) {
		TRACE_4("reserve space failed");
	}
	ncs_encode_8bit(&p8, param->priority);
	ncs_encode_64bit(&p8, param->retention_time);
	ncs_encode_16bit(&p8, param->publisher_name.length);
	ncs_enc_claim_space(uba, 11);
	total_bytes += 11;

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

	p8 = ncs_enc_reserve_space(uba, 12);
	if (!p8) {
		TRACE_4("reserve space failed");
	}
	ncs_encode_32bit(&p8, param->event_id);
	ncs_encode_64bit(&p8, param->data_len);
	ncs_enc_claim_space(uba, 12);
	total_bytes += 12;

	ncs_encode_n_octets_in_uba(uba, param->data, (uint32_t)param->data_len);
	total_bytes += (uint32_t)param->data_len;

	return total_bytes;
}
Esempio n. 7
0
/****************************************************************************
  Name          : lga_enc_write_log_async_msg
 
  Description   : This routine encodes a write log async API msg
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_enc_write_log_async_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_write_log_async_req_t *param = &msg->info.api_info.param.write_log_async;
	const SaLogNtfLogHeaderT *ntfLogH;
	const SaLogGenericLogHeaderT *genLogH;

	osafassert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 20);
	if (!p8) {
		TRACE("Could not reserve space");
		return 0;
	}
	ncs_encode_64bit(&p8, param->invocation);
	ncs_encode_32bit(&p8, param->ack_flags);
	ncs_encode_32bit(&p8, param->client_id);
	ncs_encode_32bit(&p8, param->lstr_id);
	ncs_enc_claim_space(uba, 20);
	total_bytes += 20;

	p8 = ncs_enc_reserve_space(uba, 12);
	if (!p8) {
		TRACE("Could not reserve space");
		return 0;
	}
	ncs_encode_64bit(&p8, *param->logTimeStamp);
	ncs_encode_32bit(&p8, (uint32_t)param->logRecord->logHdrType);
	ncs_enc_claim_space(uba, 12);
	total_bytes += 12;

	/* Alarm and application streams so far. */

	switch (param->logRecord->logHdrType) {
	case SA_LOG_NTF_HEADER:
		ntfLogH = &param->logRecord->logHeader.ntfHdr;
		p8 = ncs_enc_reserve_space(uba, 14);
		if (!p8) {
			TRACE("Could not reserve space");
			return 0;
		}
		ncs_encode_64bit(&p8, ntfLogH->notificationId);
		ncs_encode_32bit(&p8, (uint32_t)ntfLogH->eventType);
		ncs_encode_16bit(&p8, ntfLogH->notificationObject->length);
		ncs_enc_claim_space(uba, 14);
		total_bytes += 14;

		ncs_encode_n_octets_in_uba(uba,
					   ntfLogH->notificationObject->value,
					   (uint32_t)ntfLogH->notificationObject->length);
		total_bytes += ntfLogH->notificationObject->length;

		p8 = ncs_enc_reserve_space(uba, 2);
		if (!p8) {
			TRACE("Could not reserve space");
			return 0;
		}
		ncs_encode_16bit(&p8, ntfLogH->notifyingObject->length);
		ncs_enc_claim_space(uba, 2);
		total_bytes += 2;

		ncs_encode_n_octets_in_uba(uba, ntfLogH->notifyingObject->value, ntfLogH->notifyingObject->length);
		total_bytes += ntfLogH->notifyingObject->length;

		p8 = ncs_enc_reserve_space(uba, 16);
		if (!p8) {
			TRACE("Could not reserve space");
			return 0;
		}
		ncs_encode_32bit(&p8, ntfLogH->notificationClassId->vendorId);
		ncs_encode_16bit(&p8, ntfLogH->notificationClassId->majorId);
		ncs_encode_16bit(&p8, ntfLogH->notificationClassId->minorId);
		ncs_encode_64bit(&p8, ntfLogH->eventTime);
		ncs_enc_claim_space(uba, 16);
		total_bytes += 16;
		break;

	case SA_LOG_GENERIC_HEADER:
		genLogH = &param->logRecord->logHeader.genericHdr;
		p8 = ncs_enc_reserve_space(uba, 10);
		if (!p8) {
			TRACE("Could not reserve space");
			return 0;
		}
		ncs_encode_32bit(&p8, 0);
		ncs_encode_16bit(&p8, 0);
		ncs_encode_16bit(&p8, 0);
		ncs_encode_16bit(&p8, param->logSvcUsrName->length);
		ncs_enc_claim_space(uba, 10);
		total_bytes += 10;

		ncs_encode_n_octets_in_uba(uba,
					   (uint8_t *)param->logSvcUsrName->value, (uint32_t)param->logSvcUsrName->length);
		total_bytes += param->logSvcUsrName->length;

		p8 = ncs_enc_reserve_space(uba, 2);
		if (!p8) {
			TRACE("Could not reserve space");
			return 0;
		}
		ncs_encode_16bit(&p8, genLogH->logSeverity);
		total_bytes += 2;

		break;

	default:
		TRACE("ERROR IN logHdrType in logRecord!!!");
		break;
	}

	p8 = ncs_enc_reserve_space(uba, 4);
	if (!p8) {
		TRACE("Could not reserve space");
		return 0;
	}

	if (param->logRecord->logBuffer == NULL) {
		ncs_encode_32bit(&p8, (uint32_t)0);
	} else {
		ncs_encode_32bit(&p8, (uint32_t)param->logRecord->logBuffer->logBufSize);
	}
	ncs_enc_claim_space(uba, 4);
	total_bytes += 4;

	if ((param->logRecord->logBuffer != NULL) && (param->logRecord->logBuffer->logBuf != NULL)) {
		ncs_encode_n_octets_in_uba(uba,
					   param->logRecord->logBuffer->logBuf,
					   (uint32_t)param->logRecord->logBuffer->logBufSize);
		total_bytes += (uint32_t)param->logRecord->logBuffer->logBufSize;
	}
	return total_bytes;
}
Esempio n. 8
0
/****************************************************************************
  Name          : lga_enc_lstr_open_sync_msg
 
  Description   : This routine encodes a log stream open sync API msg
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_enc_lstr_open_sync_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	int len;
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_stream_open_req_t *param = &msg->info.api_info.param.lstr_open_sync;

	TRACE_ENTER();
	osafassert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 6);
	if (!p8) {
		TRACE("p8 NULL!!!");
		return 0;
	}
	ncs_encode_32bit(&p8, param->client_id);
	ncs_encode_16bit(&p8, param->lstr_name.length);
	ncs_enc_claim_space(uba, 6);
	total_bytes += 6;

	/* Encode log stream name */
	ncs_encode_n_octets_in_uba(uba, param->lstr_name.value, (uint32_t)param->lstr_name.length);
	total_bytes += (uint32_t)param->lstr_name.length;

	/* Encode logFileName if initiated */
	p8 = ncs_enc_reserve_space(uba, 2);
	if (!p8) {
		TRACE("p8 NULL!!!");
		goto done;
	}
	if (param->logFileName != NULL)
		len = strlen(param->logFileName) + 1;
	else
		len = 0;
	ncs_encode_16bit(&p8, len);
	ncs_enc_claim_space(uba, 2);
	total_bytes += 2;

	if (param->logFileName != NULL) {
		ncs_encode_n_octets_in_uba(uba, (uint8_t *)param->logFileName, len);
		total_bytes += len;
	}

	/* Encode logFilePathName if initiated */
	p8 = ncs_enc_reserve_space(uba, 2);
	if (!p8) {
		TRACE("p8 NULL!!!");
		goto done;
	}
	if (param->logFilePathName)
		len = strlen(param->logFilePathName) + 1;
	else
		len = 0;
	ncs_encode_16bit(&p8, len);
	ncs_enc_claim_space(uba, 2);
	total_bytes += 2;

	if (param->logFilePathName != NULL) {
		ncs_encode_n_octets_in_uba(uba, (uint8_t *)param->logFilePathName, len);
		total_bytes += len;
	}

	/* Encode format string if initiated */
	p8 = ncs_enc_reserve_space(uba, 24);
	if (!p8) {
		TRACE("p8 NULL!!!");
		goto done;
	}
	if (param->logFileFmt != NULL)
		len = strlen(param->logFileFmt) + 1;
	else
		len = 0;
	ncs_encode_64bit(&p8, param->maxLogFileSize);
	ncs_encode_32bit(&p8, param->maxLogRecordSize);
	ncs_encode_32bit(&p8, (uint32_t)param->haProperty);
	ncs_encode_32bit(&p8, (uint32_t)param->logFileFullAction);
	ncs_encode_16bit(&p8, param->maxFilesRotated);
	ncs_encode_16bit(&p8, len);
	ncs_enc_claim_space(uba, 24);
	total_bytes += 24;

	if (len > 0) {
		ncs_encode_n_octets_in_uba(uba, (uint8_t *)param->logFileFmt, len);
		total_bytes += len;
	}

	/* Encode last item in struct => open flags!!!! */
	p8 = ncs_enc_reserve_space(uba, 1);
	if (!p8) {
		TRACE("p8 NULL!!!");
		goto done;
	}

	ncs_encode_8bit(&p8, param->lstr_open_flags);
	ncs_enc_claim_space(uba, 1);
	total_bytes += 1;

 done:
	TRACE_LEAVE();
	return total_bytes;
}