123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- /*
- * Brief: Receive message from Interface and send response to original interface.
- Process all IPMI standard command and oem command.
- * Author: Jimbo_Zhang@outlook.com
- * Date: 2019-9-13, the Mid-autumn Festival;
- */
- #include <stdio.h>
- #include <sys/stat.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <sys/prctl.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <pthread.h>
- #include "MsgHndlr.h"
- #include "PDKCmds.h"
- #include "App.h"
- #include "PICMG.h"
- #include "Bridge.h"
- #include "SensorEvent.h"
- #include "Chassis.h"
- #include "Storage.h"
- #include "cmdselect.h"
- #include "com_IPMI_App.h"
- #include "com_IPMI_Storage.h"
- #include "com_IPMI_SDR.h"
- //#include "main.h"
- #include <string.h>
- #include "main.h"
- static void ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes);
- MsgHndlrTbl_T m_MsgHndlrTbl [] = //notice!
- {
- { NETFN_APP, g_App_CmdHndlr },
- { NETFN_CHASSIS, g_Chassis_CmdHndlr },
- { NETFN_BRIDGE, g_Bridge_CmdHndlr },
- { NETFN_SENSOR, g_SensorEvent_CmdHndlr },
- { NETFN_STORAGE, g_Storage_CmdHndlr },
- // { NETFN_TRANSPORT, g_Config_CmdHndlr },
- // { NETFN_AMI, (CmdHndlrMap_T*)g_AMI_CmdHndlr },
- { 0, 0 },
- };
- GroupExtnMsgHndlrTbl_T m_GroupExtnMsgHndlrTbl [] = //jimbo add
- {
- {0, 0},
- };
- //PendingBridgedResTbl_T m_PendingBridgedResTbl[MAX_PENDING_BRIDGE_RES];
- int gFd_MsgHndlrIfc;
- /*!
- \brief Message handler Task. Process all standard and oem ipmi message form interface, and send response back.
- \param[in] none
- \param[out] none
- \retval none
- */
- void *MsgHndlrTask( void *pArg )
- {
- MsgPkt_T reqMsgPkt;
- MsgPkt_T resMsgPkt;
-
- printf("MsgHndlrTask start...\r\n");
- prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
- //create
- if(-1 != access(MSG_HNDLR_Q, F_OK))
- {
- remove(MSG_HNDLR_Q);
- }
- if(0 != mkfifo (MSG_HNDLR_Q, 0777))
- {
- printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, MSG_HNDLR_Q, strerror(errno));
- return (void*)-1;
- }
- gFd_MsgHndlrIfc = open (MSG_HNDLR_Q, O_RDWR);
- if(-1 == gFd_MsgHndlrIfc)
- {
- printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, MSG_HNDLR_Q, strerror(errno));
- return (void*)-1;
- }
-
- while(1)
- {
- while(GetMsg(gFd_MsgHndlrIfc, &reqMsgPkt, WAIT_INFINITE) != 0);
- // printf("MsgHndlrTask get message: \n");
- // int i;
- // for(i=0;i<reqMsgPkt.Size;i++)
- // printf("%#x ", reqMsgPkt.Data[i]);
- // printf("\n");
- ProcessIPMIReq(&reqMsgPkt, &resMsgPkt);
-
- //update checksum2
- resMsgPkt.Data[resMsgPkt.Size-1] = CalculateCheckSum2(resMsgPkt.Data, resMsgPkt.Size-1);
-
- //send response pkt to source queue.
- PostMsg(resMsgPkt.SrcQ, &resMsgPkt);
- // printf("MsgHndlrTask post message to socket %d:\n", resMsgPkt.SrcQ);
- // for(i=0;i<reqMsgPkt.Size;i++)
- // printf("%#x ", reqMsgPkt.Data[i]);
- // printf("\n");
- }
- }
- /**
- *@fn ProcessIPMIReq
- *@brief Processes the requested IPMI command
- *@param pReq Request of the command
- *@param pRes Response for the requested command
- *@return none
- */
- static void
- ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
- {
- CmdHndlrMap_T * pCmdHndlrMap;
- uint32_t HdrOffset = 0;
- uint8_t CmdOverride = 1;
- int8_t MsgHndlrMapGot=0;
- BMCInfo_t* pBMCInfo = &g_BMCInfo;
-
- // msgHndlr_dbg_printf ("Processing IPMI Packet.\r\n");
- /* Set the Cmd and Net function in response packet */
- pRes->Cmd = pReq->Cmd;
- pRes->NetFnLUN = pReq->NetFnLUN;
- pRes->Channel = pReq->Channel;
- pRes->SrcQ = pReq->SrcQ;
- /* Normal IPMI Command response */
- pRes->Param = PARAM_NORMAL_RESPONSE;
-
- HdrOffset = sizeof (IPMIMsgHdr_T);
- pReq->Size = pReq->Size - HdrOffset - 1;
-
- SwapIPMIMsgHdr((IPMIMsgHdr_T*)pReq->Data, (IPMIMsgHdr_T*)pRes->Data);
- pRes->Size = HdrOffset;
- if(IsCommandEnabled(NET_FN(pReq->NetFnLUN), &pReq->Data[HdrOffset], pReq->Cmd) != 0)
- {
- pRes->Data [HdrOffset] = CC_INV_CMD;
- printf ("Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
- pRes->Size += 2;
- return;
- }
-
- //Get oem command map
- MsgHndlrMapGot = PDKGetOEMMsgHndlrMap(NET_FN(pReq->NetFnLUN),&pCmdHndlrMap);
- if(MsgHndlrMapGot == 0)
- {
- CmdOverride = GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap);
- }
-
- //get standard ipmi command map
- if((CmdOverride == 0 || MsgHndlrMapGot == -1) ) //OEM commands have no command map.
- {
- if (0 != GetMsgHndlrMap (NET_FN (pReq->NetFnLUN), &pCmdHndlrMap))
- {
- // if(pBMCInfo->IpmiConfig.GrpExtnSupport == 1)
- // {
- if (0 != GroupExtnGetMsgHndlrMap (NET_FN (pReq->NetFnLUN), pReq->Data [HdrOffset], &pCmdHndlrMap) )
- {
- pRes->Data [HdrOffset] = CC_INV_CMD;
- printf ("MsgHndlr.c : Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
- pRes->Size += 2;
- return;
- }
- // }
- // else
- // {
- // pRes->Data [HdrOffset] = CC_INV_CMD;
- // printf ("MsgHndlr.c : Invalid Net Function 0x%x\n",NET_FN(pReq->NetFnLUN));
- // pRes->Size += 2;
- // return;
- // }
- }
- if(GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap) == FALSE)
- {
- pRes->Data [HdrOffset] = CC_INV_CMD;
- pRes->Size += 2;
- return;
- }
- }
-
- /* Check for the request size */
- if (0xff != pCmdHndlrMap->ReqLen)
- {
- /* Check for invalid request size */
- if (pCmdHndlrMap->ReqLen != pReq->Size)
- {
- printf("Warning: Request data len error, require %d\n", pCmdHndlrMap->ReqLen);
- pRes->Data [HdrOffset] = CC_REQ_INV_LEN;
- pRes->Size += 2;
- return;
- }
- }
-
- pRes->Size = pCmdHndlrMap->CmdHndlr (&pReq->Data [HdrOffset], pReq->Size, &pRes->Data [HdrOffset]) + HdrOffset + 1;
-
- //Patch for sensor Owner ID not equal IPMB address bug.
- if((NET_FN(pReq->NetFnLUN) == NETFN_STORAGE) && (pReq->Cmd == CMD_GET_SDR)
- && (((GetSDRReq_T*)&pReq->Data[6])->Offset == 5) && (pRes->Data [HdrOffset] == CC_NORMAL))
- {
- pRes->Data [HdrOffset+3] = ((IPMIMsgHdr_T*)(pReq->Data))->ResAddr; //modify sensor owner id
- }
-
- // //send message command
- // if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
- // {
- // int Offset = 0;
- // uint8_t SeqNum = pBMCInfo->SendMsgSeqNum;
- // if ((0 == pRes->Size) &&
- // ((pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 0x01 && pBMCInfo->PrimaryIPMBCh == pRes->Channel) ||
- // (pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01 && pBMCInfo->SecondaryIPMBCh == pRes->Channel)) )
- // {
- // pRes->Param = PARAM_NO_RESPONSE;
- // Offset = HdrOffset + 2;
- // }
- // else if (HdrOffset == pRes->Size)
- // {
- // Offset = HdrOffset + 1;
- // }
- //
- // while(TRUE)
- // {
- // if ( (TRUE == m_PendingBridgedResTbl[SeqNum].Used) &&
- // (0 == memcmp (&m_PendingBridgedResTbl[SeqNum].ReqMsgHdr, &pReq->Data[Offset], sizeof (IPMIMsgHdr_T))) )
- // {
- // memcpy (&m_PendingBridgedResTbl[SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
- // break;
- // }
- // else
- // {
- // SeqNum = (SeqNum - 1) & 0x3F;
- // if(SeqNum == pBMCInfo->SendMsgSeqNum)
- // {
- // break;
- // }
- // }
- // }
- // }
-
- return;
- }
- /**
- *@fn CalculateChecksum2
- *@brief Calculates the checksum
- *@param Pkt Pointer to the data for the checksum to be calculated
- *@param Len Size of data for checksum calculation
- *@return Returns the checksum value
- */
- uint8_t CalculateCheckSum2 (uint8_t* Pkt, uint32_t Len)
- {
- uint8_t Sum;
- uint32_t i;
- /* Get Checksum 2 */
- Sum = 0;
- for (i = 3; i < Len; i++)
- {
- Sum += Pkt [i];
- }
- return (uint8_t)(0xFF & (0x100 - Sum));
- }
- /**
- *@fn GetMsgHndlrMap
- *@brief Gets the exact command Handler by comparing NetFn
- *@param Netfn -NetFunction of the Cmd to execute
- *@param pCmdHndlrMap Pointer to the Command Handler
- *@return Returns 0 on success
- * Returns -1 on failure
- */
- int
- GetMsgHndlrMap (uint8_t NetFn, CmdHndlrMap_T ** pCmdHndlrMap)
- {
- int i;
- /* Get the command handler corresponding to the net function */
- for (i = 0; i < sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]); i++) //pBMCInfo->MsgHndlrTblSize
- {
- if (m_MsgHndlrTbl [i].NetFn == NetFn) { break; }
- }
- /* Check if we have not found our net function */
- if (i == sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]) )
- {
- return -1;
- }
- /* Get the handler corresponding to the command */
- *pCmdHndlrMap = (CmdHndlrMap_T*)m_MsgHndlrTbl [i].CmdHndlrMap;
- return 0;
- }
- /**
- *@fn GetCmdHndlr
- *@brief Picks up the exact command to execute by comparing Cmd no.
- *@param pReq Request buffer for the command
- *@param pRes Response buffer for the command
- *@param pCmdHndlrMap
- *@param HdrOffset
- *@param CmdOverride
- *@param CmdHndlr
- *@return Returns TRUE on success
- * Returns FALSE on failure
- */
- int GetCmdHndlr(MsgPkt_T* pReq,MsgPkt_T* pRes,CmdHndlrMap_T* pCmdHndlrMap,
- uint32_t HdrOffset,uint8_t CmdOverride,CmdHndlrMap_T** CmdHndrl )
- {
- int i=0;
- while (1)
- {
- /**
- * If we reached the end of the Command Handler map - invalid command
- **/
- if (0 == pCmdHndlrMap->CmdHndlr)
- {
- if(CmdOverride == FALSE)
- {
- pRes->Data [HdrOffset] = CC_INV_CMD;
- printf( "Warning: MsgHndlr.c : Invalid Command %#x\r\n", pReq->Cmd );
- }
- return FALSE;
- }
- if (pCmdHndlrMap->Cmd == pReq->Cmd)
- {
- break;
- }
-
- i++;
- pCmdHndlrMap++;
- }
- *CmdHndrl = pCmdHndlrMap;
- return TRUE;
- }
- /**
- *@fn GroupExtnGetMsgHndlrMap
- *@brief Gets the exact command Handler by comparing NetFn
- *@param Netfn -NetFunction of the Cmd to execute
- *@GroupExtnCode - Group Extension code
- *@param pCmdHndlrMap Pointer to the Command Handler
- *@return Returns 0 on success
- * Returns -1 on failure
- */
- int
- GroupExtnGetMsgHndlrMap (uint8_t NetFn, uint8_t GroupExtnCode, CmdHndlrMap_T ** pCmdHndlrMap)
- {
- int i;
- /* Get the command handler corresponding to the net function */
- for (i = 0; i < sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl [0]); i++)
- {
- if ((m_GroupExtnMsgHndlrTbl [i].NetFn == NetFn) && (m_GroupExtnMsgHndlrTbl [i].GroupExtnCode == GroupExtnCode))
- {
- break;
- }
- }
- /* Check if we have not found our net function */
- if (i == sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl[0]))
- {
- return -1;
- }
- // printf("---> GroupExtnGetMsgHndlrMap successful, i=%d\n",i);
- /* Get the handler corresponding to the command */
- *pCmdHndlrMap = (CmdHndlrMap_T*)m_GroupExtnMsgHndlrTbl [i].CmdHndlrMap;
- return 0;
- }
- /*------------------------------------------------------------------
- *@fn RespondSendMessage
- *@brief Frames the Response packet when a IPMB destination is
- * unavialable
- *
- *@param pReq: Request Message Packet address
- *@param Status Status of SendIPMBPkt method
- *@param BMCInst: BMC Instance Number
- *
- *@return none
- *-----------------------------------------------------------------*/
- void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status)
- {
- // uint8_t PBTbl = PRIMARY_PB_TBL;
- // BMCInfo_t* pBMCInfo = &g_BMCInfo;
- // MsgPkt_T ResPkt;
- // IPMIMsgHdr_T* pIPMIResHdr = (_NEAR_ IPMIMsgHdr_T*)ResPkt.Data;
- // IPMIMsgHdr_T* pIPMIReqHdr = (_NEAR_ IPMIMsgHdr_T*)pReq->Data;
- // uint8_t SeqNum = NET_FN(pIPMIReqHdr->RqSeqLUN);
- //
- // /* Check for pending responses */
- // if ( (TRUE == m_PendingBridgedResTbl[SeqNum].Used) &&
- // (NET_FN(pIPMIReqHdr->RqSeqLUN) == SeqNum) &&
- // (NET_FN(pIPMIReqHdr->NetFnLUN) == NET_FN(m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.NetFnLUN )) &&
- // (pIPMIReqHdr->Cmd == m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.Cmd) &&
- // (pIPMIReqHdr->ResAddr == m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.ResAddr) )
- // {
- //
- // memcpy (pIPMIResHdr, &m_PendingBridgedResTbl[SeqNum].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
- //
- //
- // if (STATUS_OK == Status)
- // {
- // if ( (0 == strcmp ((char *)m_PendingBridgedResTbl[SeqNum].DestQ, PrimaryIPMBQueueName)) ||
- // (0 == strcmp ((char *)m_PendingBridgedResTbl[SeqNum].DestQ, SecondaryIPMBQueueName)) ||
- // (ORIGIN_SENDMSG != m_PendingBridgedResTbl[SeqNum].OriginSrc) )
- // {
- // return;
- // }
- //
- // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NORMAL;
- // }
- // else if (STATUS_FAIL == Status)
- // {
- // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NO_ACK_FROM_SLAVE;
- // }
- // else
- // {
- // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_UNSPECIFIED_ERR;
- // }
- // ResPkt.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
- // ResPkt.Cmd = pIPMIResHdr->Cmd;
- // ResPkt.NetFnLUN = pIPMIReqHdr->NetFnLUN;
- // ResPkt.Channel = pReq->Channel;
- // /* Calculate the Second CheckSum */
- // ResPkt.Data[ResPkt.Size - 1] = CalculateCheckSum2 (ResPkt.Data, ResPkt.Size-1);
- // ResPkt.Param = BRIDGING_REQUEST;
- // if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, LANQueueName))
- // {
- // strcpy (QueueName, LAN_RES_Q);
- // }
- // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, SerialQueueName))
- // {
- // //ResPkt.SessionID = m_PendingBridgedResTbl[i].ResMsgHdr.RqSeqLUN;
- // strcpy (QueueName, SERIAL_RES_Q);
- // }
- // else if ( (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, PrimaryIPMBQueueName)) ||
- // (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, SecondaryIPMBQueueName)) )
- // {
- // strcpy (QueueName, (char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ);
- // }
- // else
- // {
- // /* PDK Hook to format Pending Bridge Response Packet for other destinations */
- // if(g_PDKHandle[PDK_FORMATBRIDGERESPKT] != NULL)
- // {
- // SwapIPMIMsgHdr ( pIPMIReqHdr, pIPMIResHdr);
- //
- // ( (void (*)(MsgPkt_T *, int) ) g_PDKHandle[PDK_FORMATBRIDGERESPKT]) ( &ResPkt, BMCInst);
- // }
- //
- // strcpy (QueueName, (char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ);
- // }
- // if (STATUS_OK != Status)
- // {
- // m_PendingBridgedResTbl[PBTbl][SeqNum].Used = FALSE;
- // }
- //
- // /* Post the data to Destination Interface queue */
- // PostMsg (&ResPkt, QueueName, BMCInst);
- // }
- }
- ///**
- //*@fn PendingBridgeResTimerTask
- //*@brief Sends the timeout message to response queue
- //* if the message does not turn out within send message timeout
- //*@return none
- //*/
- //static void
- //PendingBridgeResTimerTask (int BMCInst)
- //{
- // uint8_t i;
- // BMCInfo_t* pBMCInfo = &g_BMCInfo;
- // char IPMBQueueName[MAX_STR_LENGTH];
- // //LANQueueName[MAX_STR_LENGTH],PrimarySecondaryIPMBQueueName[MAX_STR_LENGTH],QueueName[MAX_STR_LENGTH];
- // //,SerialQueueName[MAX_STR_LENGTH];
- //
- // //memset(LANQueueName,0,sizeof(LANQueueName));
- // //memset(PrimaryIPMBQueueName,0,sizeof(PrimaryIPMBQueueName));
- // //memset(SecondaryIPMBQueueName,0,sizeof(SecondaryIPMBQueueName));
- // //memset(SerialQueueName,0,sizeof(SerialQueueName));
- // memset(QueueName,0,sizeof(QueueName));
- //
- // /* Check for any pending responses */
- // for( PBTbl=0; PBTbl < MAX_PENDING_BRIDGE_TBL; PBTbl++)
- // {
- // for (i = 0; i < sizeof (m_PendingBridgedResTbl[0])/sizeof (m_PendingBridgedResTbl[0][0]); i++)
- // {
- // if (TRUE == m_PendingBridgedResTbl[PBTbl][i].Used)
- // {
- // m_PendingBridgedResTbl[PBTbl][i].TimeOut--;
- // if (0 == m_PendingBridgedResTbl[PBTbl][i].TimeOut)
- // {
- // MsgPkt_T Timeout;
- // IPMIMsgHdr_T* pIPMIMsgHdr = (_NEAR_ IPMIMsgHdr_T*) Timeout.Data;
- // /* Fill the response packet */
- // SwapIPMIMsgHdr (&m_PendingBridgedResTbl[PBTbl][i].ReqMsgHdr, pIPMIMsgHdr);
- // slog(LANQueueName,"%s%d",LAN_IFC_Q,BMCInst);
- // sprintf(PrimaryIPMBQueueName,"%s%d",IPMB_PRIMARY_IFC_Q,BMCInst);
- // sprintf(SecondaryIPMBQueueName,"%s%d",IPMB_SECONDARY_IFC_Q,BMCInst);
- // sprintf(SerialQueueName,"%s%d",SERIAL_IFC_Q,BMCInst);
- // if(PBTbl == PRIMARY_PB_TBL)
- // {
- // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.PrimaryIPMBAddr;
- // }
- // else if(PBTbl == SECONDARY_PB_TBL)
- // {
- // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.SecondaryIPMBAddr;
- // }
- // else
- // {
- // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
- // }
- // Timeout.Data [sizeof(IPMIMsgHdr_T)] = CC_TIMEOUT;
- // Timeout.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
- // /* Calculate the Second CheckSum */
- // Timeout.Data[Timeout.Size - 1] = CalculateCheckSum2 (Timeout.Data, Timeout.Size-1);
- // Timeout.Param = BRIDGING_REQUEST;
- // if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, LANQueueName))
- // {
- // int j;
- // for (j = Timeout.Size - 1; j >= 0; --j)
- // {
- // Timeout.Data [j+1] = Timeout.Data [j];
- // }
- // Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
- // Timeout.Size++;
- // Timeout.Cmd = PAYLOAD_IPMI_MSG;
- // strcpy(QueueName, LAN_IFC_Q);
- // }
- // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, SerialQueueName))
- // {
- // int j;
- // for (j = Timeout.Size - 1; j >= 0; --j)
- // {
- // Timeout.Data [j+1] = Timeout.Data [j];
- // }
- // Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
- // Timeout.Size++;
- // Timeout.Cmd = PAYLOAD_IPMI_MSG;
- // strcpy(QueueName, SERIAL_IFC_Q);
- // }
- // else if (pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 1 && 0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, PrimaryIPMBQueueName))
- // {
- // int j;
- // for (j = Timeout.Size - 1; j >= 0; --j)
- // {
- // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
- // }
- // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr, sizeof (IPMIMsgHdr_T));
- // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
- // Timeout.Size++;
- // strcpy(QueueName, IPMB_PRIMARY_IFC_Q);
- // }
- // else if (pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 1 && 0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, SecondaryIPMBQueueName))
- // {
- // int j;
- // for (j = Timeout.Size - 1; j >= 0; --j)
- // {
- // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
- // }
- // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
- // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
- // Timeout.Size++;
- // strcpy(QueueName, IPMB_SECONDARY_IFC_Q);
- // }
- // else if (0 == strncmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, UDS_RES_Q,strlen(UDS_RES_Q)))
- // {
- // int j;
- // UDSSessionTbl_T *pUDSSessionInfo = NULL;
- // for (j = sizeof (IPMIMsgHdr_T); j < Timeout.Size ;j++)
- // {
- // Timeout.Data [j + sizeof (IPMIUDSMsg_T)-sizeof (IPMIMsgHdr_T)] = Timeout.Data [j];
- // }
- // Timeout.Size = Timeout.Size + sizeof (IPMIUDSMsg_T)- sizeof (IPMIMsgHdr_T);
- //
- // m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.IPMIMsgLen = Timeout.Size;
- // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr, sizeof (IPMIUDSMsg_T));
- // Timeout.NetFnLUN = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.NetFnLUN;
- // Timeout.SessionID = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.SessionID;
- // Timeout.Cmd = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.Cmd;
- //
- // pUDSSessionInfo = GetUDSSessionInfo (UDS_SESSION_ID_INFO,&Timeout.SessionID, BMCInst);
- // if(pUDSSessionInfo != NULL)
- // {
- // Timeout.Socket = pUDSSessionInfo->UDSSocket;
- // }
- // sprintf (QueueName,"%s",m_PendingBridgedResTbl[PBTbl][i].DestQ);
- // }
- // else
- // {
- // int j;
- // for (j = Timeout.Size - 1; j >= 0; --j)
- // {
- // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
- // }
- // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
- // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_TIMEOUT;
- // sprintf (QueueName,"%s",m_PendingBridgedResTbl[PBTbl][i].DestQ);
- // }
- // /* Post the data to Destination Interface queue */
- // PostMsg (&Timeout,QueueName,BMCInst);
- // m_PendingBridgedResTbl[PBTbl][i].Used = FALSE;
- // IPMI_DBG_PRINT_1( "MsgHndlr: clean pending index = %d.\n", i );
- // }
- // }
- // }
- // }
- //}
- /**
- *@fn SwapIPMIMsgHdr
- *@brief Swaps the header and copies into response
- *@param pIPMIMsgReq Header of the Request
- *@param pIPMIMsgRes Header of the response
- *@return none
- */
- void
- SwapIPMIMsgHdr (IPMIMsgHdr_T* pIPMIMsgReq, IPMIMsgHdr_T* pIPMIMsgRes)
- {
- pIPMIMsgRes->ResAddr = pIPMIMsgReq->ReqAddr;
- pIPMIMsgRes->NetFnLUN = (pIPMIMsgReq->NetFnLUN & 0xFC) + 0x04;
- pIPMIMsgRes->NetFnLUN |= pIPMIMsgReq->RqSeqLUN & 0x03;
- /* Calculate the Checksum for above two bytes */
- pIPMIMsgRes->ChkSum = (~(pIPMIMsgRes->ResAddr + pIPMIMsgRes->NetFnLUN) + 1);
- pIPMIMsgRes->ReqAddr = pIPMIMsgReq->ResAddr;
- pIPMIMsgRes->RqSeqLUN = (pIPMIMsgReq->RqSeqLUN & 0xFC);
- pIPMIMsgRes->RqSeqLUN |= (pIPMIMsgReq->NetFnLUN & 0x03);
- pIPMIMsgRes->Cmd = pIPMIMsgReq->Cmd;
- return;
- }
|