Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SINT32 mmsclnTst_SmiClient_SendReceive(SMI_SERVER_INFO *pSrvInfo, VOID *pData, UINT32 DataLen, SMI_MSG *ReplyMsg, MMSCLNT_SERVICE SrvType) {
- SINT32 ret = 0; /* return value */
- SMI_MSG Msg; /* structure of SMI messages*/
- VOID *pCall = NULL;
- CHAR ntoaStr[INET_ADDR_LEN];
- struct in_addr IpAddr;
- SINT32 WaitForReply = 1;
- memset(&Msg, 0, sizeof(Msg)); //MODIFIED added
- printf("DEBUG: SmiClient_SendReceive() TYPE OF CALL: %s \n",SERVICETYPES[SrvType]);
- /*
- * If the RemoteModNb is zero (meaning invalid), the RemoteModNb has to
- * be requested from the remote target (ResourceManager on the remote
- * CPU), before a SMI-Call can be sent to the specific remote SW-Module.
- */
- if (!pSrvInfo->ModNb) {
- printf("%s_SMICLIENT_SEND: Cpu 0x%8x ModName %s ModNb 0x%08x\n", mmsclnTst_AppName, pSrvInfo->Cpu, pSrvInfo->ModName, pSrvInfo->ModNb);
- ret = GetRemoteModNumber(pSrvInfo); //moduleNumber is inserted into pSrvInfo
- //printf(" return GetRemoteModNumber %d \n",ret);
- //printdf("%s_SMICLIENT_SEND: Cpu 0x%8x ModName %s ModNb 0x%08x\n",
- // mmsclnTst_AppName, pSrvInfo->Cpu, pSrvInfo->ModName, pSrvInfo->ModNb);
- if (ret < 0)
- return -1;
- }
- /* __________SPECIAL case ? */
- if (pData == NULL || DataLen == 0) {
- printf("DEBUG: sendReceive special case... \n");
- DataLen = sizeof(MMSCLNT_CONN_INFO_C); /* ping the MMSCLNT SMI service at the remote server */
- pCall = smi_MemAlloc(DataLen);
- if (pCall == NULL) {
- printf("pCall is NULL \n");
- log_Err("%s no memory, line: %i", __FILE__, __LINE__);
- return -1;
- }
- if (pCall) {
- bzero((char*) pCall, DataLen);
- //printf(" pCall prepare info call \n");
- /* prepare info call */
- ((MMSCLNT_CONN_INFO_C*) pCall)->Hdr.SrvType = MMSCLNT_CONNINFO;
- ((MMSCLNT_CONN_INFO_C*) pCall)->Hdr.User = 0;
- ((MMSCLNT_CONN_INFO_C*) pCall)->Hdr.ConnId = 0;
- // printf(" pCall prepare info call \n");
- }
- /*________ DEFAULT case ! */
- } else {
- printf("DEBUG: sendReceive() NO special case... \n");
- pCall = smi_MemAlloc(DataLen); /* Allocate memory for SMI call */
- //no memory
- if (pCall == NULL) {
- log_Err("%s no memory, line: %i", __FILE__, __LINE__);
- smi_MemFreeDebug(pCall); //MODIFIED added free
- pCall = NULL; //MODIFIED added null assign
- return -1;
- }
- if (pCall) {
- memcpy(pCall, pData, DataLen); /* insert data */
- //printf("memcpy(pCall, pData, DataLen)\n");
- }
- }
- if (pCall == NULL) {
- log_Err("%s_SMICLIENT_SEND: Not enough memory!", mmsclnTst_AppName);
- return -1;
- }
- /* dispatch request to remote resource manager for module number */
- SmiClientInfo.XId++;
- printf("DEBUG: sendReceive() -> smi_SendCall(..) ... \n");
- /*______ SEND the call */
- if (smi_SendCall(SmiClientInfo.SmiId, pSrvInfo->Cpu, SmiClientInfo.XId, pSrvInfo->ModNb, SmiClientInfo.Protvers, MMSCLNT_PROC_MMSSRV, pCall, DataLen)) {
- IpAddr.s_addr = ntohl(pSrvInfo->Cpu);
- inet_ntoa_b(IpAddr, ntoaStr);
- log_Err("%s_SMICLIENT_SEND: Cannot send call to module '%s' on CPU %s!", mmsclnTst_AppName, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- smi_MemFreeDebug(pCall); //MODIFIED added this free
- pCall = NULL; //MODIFIED added this null asign
- return -1;
- } else {
- printf("DEBUG: sendReceive -> smi_SendCall(..): OK \n");
- }
- printf("DEBUG: sendReceive waiting for reply... \n");
- /*__________ receive reply from remote software module */
- while (WaitForReply) {
- /* fill &Msg with the received Msg.. */
- ret = smi_Receive(SmiClientInfo.SmiId, &Msg, WAIT_FOREVER); //SmiClientInfo.Timeout);
- WaitForReply = 0;
- /* _________REPLY RECEIVED (OK!) */
- if (ret == 0) {
- MMSCLNT_R_HDR *pReplyHdr = (MMSCLNT_R_HDR *) Msg.Data;
- /* Copy reply structure */
- if (ReplyMsg == NULL) {
- log_Err("%s_SMICLIENT_SEND: No reply structure available !", mmsclnTst_AppName);
- smi_FreeDataDebug(&Msg);
- memset(&Msg, 0, sizeof(Msg)); //MODIFIED added this nullassign
- smi_MemFreeDebug(pCall); //MODIFIED added this free
- pCall = NULL; //MODIFIED added this null asign
- return (-100);
- }
- if (pReplyHdr == NULL) {
- log_Err("pReplyHdr == NULL !");
- log_Err("ProcRetCode 0x%x, XId %u %u Type 0x%x DataLen %u", Msg.ProcRetCode, (Msg.XId & 0xffff), SmiClientInfo.XId, Msg.Type, Msg.DataLen);
- smi_FreeDataDebug(&Msg);
- memset(&Msg, 0, sizeof(Msg)); //MODIFIED added this nullassign
- // smi_MemFreeDebug(pCall); //MODIFIED added this free
- // pCall = NULL; //MODIFIED added this null asign
- return (-102);
- }
- /* Check, if it is the correct reply to the request */
- if (pReplyHdr->SrvType != SrvType) {
- printf("DEBUG: sendReceive waitForReply-Loop got wrong reply to request: \n request: %s \n reqReply: %s \n =>waitForReply=1; continue; \n", SERVICETYPES[SrvType],SERVICETYPES[pReplyHdr->SrvType]);
- WaitForReply = 1;
- continue;
- }
- memcpy(ReplyMsg, &Msg, sizeof(SMI_MSG));
- if (Msg.DataLen > 0) {
- ReplyMsg->Data = sys_MemPAlloc(mmsclnTst_MemPart, Msg.DataLen); //TODO FIXME
- if (ReplyMsg->Data == NULL) {
- log_Err("%s_SMICLIENT_SEND: No memory !", mmsclnTst_AppName);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- smi_FreeDataDebug(&Msg);
- memset(&Msg, 0, sizeof(Msg)); //MODIFIED added this nullassign
- smi_MemFreeDebug(pCall); //MODIFIED added this free
- pCall = NULL; //MODIFIED added this null asign
- return (-101);
- } else {
- memcpy(ReplyMsg->Data, Msg.Data, Msg.DataLen);
- }
- }
- /* Free SMI Data. */
- smi_FreeDataDebug(&Msg);
- memset(&Msg, 0, sizeof(Msg)); //MODIFIED added this nullassign
- /*____________ REPLY RECEIVED (ERROR = Timeout) */
- } else if (ret == -1) {
- SINT32 ErrorNo = errnoGet();
- IpAddr.s_addr = ntohl(pSrvInfo->Cpu);
- inet_ntoa_b(IpAddr, ntoaStr);
- if (ErrorNo == S_objLib_OBJ_TIMEOUT) {
- log_Err("%s_SMICLIENT_SEND: Timeout in smi_Receive() from %s:%s!", mmsclnTst_AppName, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- } else if (ErrorNo == S_objLib_OBJ_UNAVAILABLE) {
- log_Err("%s_SMICLIENT_SEND: Object unavailable in smi_Receive() from %s:%s!", mmsclnTst_AppName, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- } else {
- log_Err("%s_SMICLIENT_SEND: ErrorNo %ld in smi_Receive() from %s:%s!", mmsclnTst_AppName, ErrorNo, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- }
- pSrvInfo->ModNb = 0; /* reset module number */
- /*____________ REPLY RECEIVED (ERROR in Function) */
- } else if (ret == -2) {
- IpAddr.s_addr = ntohl(pSrvInfo->Cpu);
- inet_ntoa_b(IpAddr, ntoaStr);
- log_Err("%s_SMICLIENT_SEND: Queuing error in smi_Receive() from %s:%s!", mmsclnTst_AppName, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- /*____________ REPLY RECEIVED (ERROR unknown) */
- } else {
- IpAddr.s_addr = ntohl(pSrvInfo->Cpu);
- inet_ntoa_b(IpAddr, ntoaStr);
- log_Err("%s_SMICLIENT_SEND: unexpected error in smi_Receive()!", mmsclnTst_AppName, pSrvInfo->ModName, ntoaStr);
- if (mmsclnTst_Debug & APP_DBG_INFO1) {
- DEBUGPRINTL;
- }
- }
- }
- printf("DEBUG: sendReceive() free(&Msg) at %p.... \n", &Msg);
- smi_FreeDataDebug(&Msg); //MODIFIED commented this out...
- //memset(&Msg, 0, sizeof(Msg)); //MODIFIED added this nullassign
- // smi_MemFreeDebug(pCall); //MODIFIED added this free
- // pCall = NULL; //MODIFIED added this null asign
- printf("DEBUG: sendReceive() returns now \n");
- return (ret);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement