/**************************************************************************** Name : ntfa_dec_send_not_rsp_msg Description : This routine decodes a notification send response message Arguments : NCS_UBAID *msg, NTFSV_MSG *msg Return Values : uns32 Notes : None. ******************************************************************************/ static uns32 ntfa_dec_send_not_rsp_msg(NCS_UBAID *uba, ntfsv_msg_t *msg) { uns8 *p8; uns32 total_bytes = 0; ntfsv_send_not_rsp_t *param = &msg->info.api_resp_info.param.send_not_rsp; uns8 local_data[8]; assert(uba != NULL); /* chan_id */ p8 = ncs_dec_flatten_space(uba, local_data, 8); param->notificationId = ncs_decode_64bit(&p8); ncs_dec_skip_space(uba, 8); total_bytes += 8; return total_bytes; }
/**************************************************************************** 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; }
/** * 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(); }
/**************************************************************************** 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; }