MsgHndlrTask.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Brief: Receive message from Interface and send response to original interface.
  3. Process all IPMI standard command and oem command.
  4. * Author: Jimbo_Zhang@outlook.com
  5. * Date: 2019-9-13, the Mid-autumn Festival;
  6. */
  7. #include <stdio.h>
  8. #include <sys/stat.h>
  9. #include <sys/socket.h>
  10. #include <sys/un.h>
  11. #include <sys/prctl.h>
  12. #include <errno.h>
  13. #include <fcntl.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <unistd.h>
  17. #include <string.h>
  18. #include <pthread.h>
  19. #include "MsgHndlr.h"
  20. #include "PDKCmds.h"
  21. #include "App.h"
  22. #include "PICMG.h"
  23. #include "Bridge.h"
  24. #include "SensorEvent.h"
  25. #include "Chassis.h"
  26. #include "Storage.h"
  27. #include "cmdselect.h"
  28. #include "com_IPMI_App.h"
  29. #include "com_IPMI_Storage.h"
  30. #include "com_IPMI_SDR.h"
  31. //#include "main.h"
  32. #include <string.h>
  33. #include "main.h"
  34. static void ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes);
  35. MsgHndlrTbl_T m_MsgHndlrTbl [] = //notice!
  36. {
  37. { NETFN_APP, g_App_CmdHndlr },
  38. { NETFN_CHASSIS, g_Chassis_CmdHndlr },
  39. { NETFN_BRIDGE, g_Bridge_CmdHndlr },
  40. { NETFN_SENSOR, g_SensorEvent_CmdHndlr },
  41. { NETFN_STORAGE, g_Storage_CmdHndlr },
  42. // { NETFN_TRANSPORT, g_Config_CmdHndlr },
  43. // { NETFN_AMI, (CmdHndlrMap_T*)g_AMI_CmdHndlr },
  44. { 0, 0 },
  45. };
  46. GroupExtnMsgHndlrTbl_T m_GroupExtnMsgHndlrTbl [] = //jimbo add
  47. {
  48. {0, 0},
  49. };
  50. //PendingBridgedResTbl_T m_PendingBridgedResTbl[MAX_PENDING_BRIDGE_RES];
  51. int gFd_MsgHndlrIfc;
  52. /*!
  53. \brief Message handler Task. Process all standard and oem ipmi message form interface, and send response back.
  54. \param[in] none
  55. \param[out] none
  56. \retval none
  57. */
  58. void *MsgHndlrTask( void *pArg )
  59. {
  60. MsgPkt_T reqMsgPkt;
  61. MsgPkt_T resMsgPkt;
  62. printf("MsgHndlrTask start...\r\n");
  63. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  64. //create
  65. if(-1 != access(MSG_HNDLR_Q, F_OK))
  66. {
  67. remove(MSG_HNDLR_Q);
  68. }
  69. if(0 != mkfifo (MSG_HNDLR_Q, 0777))
  70. {
  71. printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, MSG_HNDLR_Q, strerror(errno));
  72. return (void*)-1;
  73. }
  74. gFd_MsgHndlrIfc = open (MSG_HNDLR_Q, O_RDWR);
  75. if(-1 == gFd_MsgHndlrIfc)
  76. {
  77. printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, MSG_HNDLR_Q, strerror(errno));
  78. return (void*)-1;
  79. }
  80. while(1)
  81. {
  82. while(GetMsg(gFd_MsgHndlrIfc, &reqMsgPkt, WAIT_INFINITE) != 0);
  83. // printf("MsgHndlrTask get message: \n");
  84. // int i;
  85. // for(i=0;i<reqMsgPkt.Size;i++)
  86. // printf("%#x ", reqMsgPkt.Data[i]);
  87. // printf("\n");
  88. ProcessIPMIReq(&reqMsgPkt, &resMsgPkt);
  89. //update checksum2
  90. resMsgPkt.Data[resMsgPkt.Size-1] = CalculateCheckSum2(resMsgPkt.Data, resMsgPkt.Size-1);
  91. //send response pkt to source queue.
  92. PostMsg(resMsgPkt.SrcQ, &resMsgPkt);
  93. // printf("MsgHndlrTask post message to socket %d:\n", resMsgPkt.SrcQ);
  94. // for(i=0;i<reqMsgPkt.Size;i++)
  95. // printf("%#x ", reqMsgPkt.Data[i]);
  96. // printf("\n");
  97. }
  98. }
  99. /**
  100. *@fn ProcessIPMIReq
  101. *@brief Processes the requested IPMI command
  102. *@param pReq Request of the command
  103. *@param pRes Response for the requested command
  104. *@return none
  105. */
  106. static void
  107. ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
  108. {
  109. CmdHndlrMap_T * pCmdHndlrMap;
  110. uint32_t HdrOffset = 0;
  111. uint8_t CmdOverride = 1;
  112. int8_t MsgHndlrMapGot=0;
  113. BMCInfo_t* pBMCInfo = &g_BMCInfo;
  114. // msgHndlr_dbg_printf ("Processing IPMI Packet.\r\n");
  115. /* Set the Cmd and Net function in response packet */
  116. pRes->Cmd = pReq->Cmd;
  117. pRes->NetFnLUN = pReq->NetFnLUN;
  118. pRes->Channel = pReq->Channel;
  119. pRes->SrcQ = pReq->SrcQ;
  120. /* Normal IPMI Command response */
  121. pRes->Param = PARAM_NORMAL_RESPONSE;
  122. HdrOffset = sizeof (IPMIMsgHdr_T);
  123. pReq->Size = pReq->Size - HdrOffset - 1;
  124. SwapIPMIMsgHdr((IPMIMsgHdr_T*)pReq->Data, (IPMIMsgHdr_T*)pRes->Data);
  125. pRes->Size = HdrOffset;
  126. if(IsCommandEnabled(NET_FN(pReq->NetFnLUN), &pReq->Data[HdrOffset], pReq->Cmd) != 0)
  127. {
  128. pRes->Data [HdrOffset] = CC_INV_CMD;
  129. printf ("Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
  130. pRes->Size += 2;
  131. return;
  132. }
  133. //Get oem command map
  134. MsgHndlrMapGot = PDKGetOEMMsgHndlrMap(NET_FN(pReq->NetFnLUN),&pCmdHndlrMap);
  135. if(MsgHndlrMapGot == 0)
  136. {
  137. CmdOverride = GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap);
  138. }
  139. //get standard ipmi command map
  140. if((CmdOverride == 0 || MsgHndlrMapGot == -1) ) //OEM commands have no command map.
  141. {
  142. if (0 != GetMsgHndlrMap (NET_FN (pReq->NetFnLUN), &pCmdHndlrMap))
  143. {
  144. // if(pBMCInfo->IpmiConfig.GrpExtnSupport == 1)
  145. // {
  146. if (0 != GroupExtnGetMsgHndlrMap (NET_FN (pReq->NetFnLUN), pReq->Data [HdrOffset], &pCmdHndlrMap) )
  147. {
  148. pRes->Data [HdrOffset] = CC_INV_CMD;
  149. printf ("MsgHndlr.c : Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
  150. pRes->Size += 2;
  151. return;
  152. }
  153. // }
  154. // else
  155. // {
  156. // pRes->Data [HdrOffset] = CC_INV_CMD;
  157. // printf ("MsgHndlr.c : Invalid Net Function 0x%x\n",NET_FN(pReq->NetFnLUN));
  158. // pRes->Size += 2;
  159. // return;
  160. // }
  161. }
  162. if(GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap) == FALSE)
  163. {
  164. pRes->Data [HdrOffset] = CC_INV_CMD;
  165. pRes->Size += 2;
  166. return;
  167. }
  168. }
  169. /* Check for the request size */
  170. if (0xff != pCmdHndlrMap->ReqLen)
  171. {
  172. /* Check for invalid request size */
  173. if (pCmdHndlrMap->ReqLen != pReq->Size)
  174. {
  175. printf("Warning: Request data len error, require %d\n", pCmdHndlrMap->ReqLen);
  176. pRes->Data [HdrOffset] = CC_REQ_INV_LEN;
  177. pRes->Size += 2;
  178. return;
  179. }
  180. }
  181. pRes->Size = pCmdHndlrMap->CmdHndlr (&pReq->Data [HdrOffset], pReq->Size, &pRes->Data [HdrOffset]) + HdrOffset + 1;
  182. //Patch for sensor Owner ID not equal IPMB address bug.
  183. if((NET_FN(pReq->NetFnLUN) == NETFN_STORAGE) && (pReq->Cmd == CMD_GET_SDR)
  184. && (((GetSDRReq_T*)&pReq->Data[6])->Offset == 5) && (pRes->Data [HdrOffset] == CC_NORMAL))
  185. {
  186. pRes->Data [HdrOffset+3] = ((IPMIMsgHdr_T*)(pReq->Data))->ResAddr; //modify sensor owner id
  187. }
  188. // //send message command
  189. // if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
  190. // {
  191. // int Offset = 0;
  192. // uint8_t SeqNum = pBMCInfo->SendMsgSeqNum;
  193. // if ((0 == pRes->Size) &&
  194. // ((pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 0x01 && pBMCInfo->PrimaryIPMBCh == pRes->Channel) ||
  195. // (pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 0x01 && pBMCInfo->SecondaryIPMBCh == pRes->Channel)) )
  196. // {
  197. // pRes->Param = PARAM_NO_RESPONSE;
  198. // Offset = HdrOffset + 2;
  199. // }
  200. // else if (HdrOffset == pRes->Size)
  201. // {
  202. // Offset = HdrOffset + 1;
  203. // }
  204. //
  205. // while(TRUE)
  206. // {
  207. // if ( (TRUE == m_PendingBridgedResTbl[SeqNum].Used) &&
  208. // (0 == memcmp (&m_PendingBridgedResTbl[SeqNum].ReqMsgHdr, &pReq->Data[Offset], sizeof (IPMIMsgHdr_T))) )
  209. // {
  210. // memcpy (&m_PendingBridgedResTbl[SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
  211. // break;
  212. // }
  213. // else
  214. // {
  215. // SeqNum = (SeqNum - 1) & 0x3F;
  216. // if(SeqNum == pBMCInfo->SendMsgSeqNum)
  217. // {
  218. // break;
  219. // }
  220. // }
  221. // }
  222. // }
  223. return;
  224. }
  225. /**
  226. *@fn CalculateChecksum2
  227. *@brief Calculates the checksum
  228. *@param Pkt Pointer to the data for the checksum to be calculated
  229. *@param Len Size of data for checksum calculation
  230. *@return Returns the checksum value
  231. */
  232. uint8_t CalculateCheckSum2 (uint8_t* Pkt, uint32_t Len)
  233. {
  234. uint8_t Sum;
  235. uint32_t i;
  236. /* Get Checksum 2 */
  237. Sum = 0;
  238. for (i = 3; i < Len; i++)
  239. {
  240. Sum += Pkt [i];
  241. }
  242. return (uint8_t)(0xFF & (0x100 - Sum));
  243. }
  244. /**
  245. *@fn GetMsgHndlrMap
  246. *@brief Gets the exact command Handler by comparing NetFn
  247. *@param Netfn -NetFunction of the Cmd to execute
  248. *@param pCmdHndlrMap Pointer to the Command Handler
  249. *@return Returns 0 on success
  250. * Returns -1 on failure
  251. */
  252. int
  253. GetMsgHndlrMap (uint8_t NetFn, CmdHndlrMap_T ** pCmdHndlrMap)
  254. {
  255. int i;
  256. /* Get the command handler corresponding to the net function */
  257. for (i = 0; i < sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]); i++) //pBMCInfo->MsgHndlrTblSize
  258. {
  259. if (m_MsgHndlrTbl [i].NetFn == NetFn) { break; }
  260. }
  261. /* Check if we have not found our net function */
  262. if (i == sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]) )
  263. {
  264. return -1;
  265. }
  266. /* Get the handler corresponding to the command */
  267. *pCmdHndlrMap = (CmdHndlrMap_T*)m_MsgHndlrTbl [i].CmdHndlrMap;
  268. return 0;
  269. }
  270. /**
  271. *@fn GetCmdHndlr
  272. *@brief Picks up the exact command to execute by comparing Cmd no.
  273. *@param pReq Request buffer for the command
  274. *@param pRes Response buffer for the command
  275. *@param pCmdHndlrMap
  276. *@param HdrOffset
  277. *@param CmdOverride
  278. *@param CmdHndlr
  279. *@return Returns TRUE on success
  280. * Returns FALSE on failure
  281. */
  282. int GetCmdHndlr(MsgPkt_T* pReq,MsgPkt_T* pRes,CmdHndlrMap_T* pCmdHndlrMap,
  283. uint32_t HdrOffset,uint8_t CmdOverride,CmdHndlrMap_T** CmdHndrl )
  284. {
  285. int i=0;
  286. while (1)
  287. {
  288. /**
  289. * If we reached the end of the Command Handler map - invalid command
  290. **/
  291. if (0 == pCmdHndlrMap->CmdHndlr)
  292. {
  293. if(CmdOverride == FALSE)
  294. {
  295. pRes->Data [HdrOffset] = CC_INV_CMD;
  296. printf( "Warning: MsgHndlr.c : Invalid Command %#x\r\n", pReq->Cmd );
  297. }
  298. return FALSE;
  299. }
  300. if (pCmdHndlrMap->Cmd == pReq->Cmd)
  301. {
  302. break;
  303. }
  304. i++;
  305. pCmdHndlrMap++;
  306. }
  307. *CmdHndrl = pCmdHndlrMap;
  308. return TRUE;
  309. }
  310. /**
  311. *@fn GroupExtnGetMsgHndlrMap
  312. *@brief Gets the exact command Handler by comparing NetFn
  313. *@param Netfn -NetFunction of the Cmd to execute
  314. *@GroupExtnCode - Group Extension code
  315. *@param pCmdHndlrMap Pointer to the Command Handler
  316. *@return Returns 0 on success
  317. * Returns -1 on failure
  318. */
  319. int
  320. GroupExtnGetMsgHndlrMap (uint8_t NetFn, uint8_t GroupExtnCode, CmdHndlrMap_T ** pCmdHndlrMap)
  321. {
  322. int i;
  323. /* Get the command handler corresponding to the net function */
  324. for (i = 0; i < sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl [0]); i++)
  325. {
  326. if ((m_GroupExtnMsgHndlrTbl [i].NetFn == NetFn) && (m_GroupExtnMsgHndlrTbl [i].GroupExtnCode == GroupExtnCode))
  327. {
  328. break;
  329. }
  330. }
  331. /* Check if we have not found our net function */
  332. if (i == sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl[0]))
  333. {
  334. return -1;
  335. }
  336. // printf("---> GroupExtnGetMsgHndlrMap successful, i=%d\n",i);
  337. /* Get the handler corresponding to the command */
  338. *pCmdHndlrMap = (CmdHndlrMap_T*)m_GroupExtnMsgHndlrTbl [i].CmdHndlrMap;
  339. return 0;
  340. }
  341. /*------------------------------------------------------------------
  342. *@fn RespondSendMessage
  343. *@brief Frames the Response packet when a IPMB destination is
  344. * unavialable
  345. *
  346. *@param pReq: Request Message Packet address
  347. *@param Status Status of SendIPMBPkt method
  348. *@param BMCInst: BMC Instance Number
  349. *
  350. *@return none
  351. *-----------------------------------------------------------------*/
  352. void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status)
  353. {
  354. // uint8_t PBTbl = PRIMARY_PB_TBL;
  355. // BMCInfo_t* pBMCInfo = &g_BMCInfo;
  356. // MsgPkt_T ResPkt;
  357. // IPMIMsgHdr_T* pIPMIResHdr = (_NEAR_ IPMIMsgHdr_T*)ResPkt.Data;
  358. // IPMIMsgHdr_T* pIPMIReqHdr = (_NEAR_ IPMIMsgHdr_T*)pReq->Data;
  359. // uint8_t SeqNum = NET_FN(pIPMIReqHdr->RqSeqLUN);
  360. //
  361. // /* Check for pending responses */
  362. // if ( (TRUE == m_PendingBridgedResTbl[SeqNum].Used) &&
  363. // (NET_FN(pIPMIReqHdr->RqSeqLUN) == SeqNum) &&
  364. // (NET_FN(pIPMIReqHdr->NetFnLUN) == NET_FN(m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.NetFnLUN )) &&
  365. // (pIPMIReqHdr->Cmd == m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.Cmd) &&
  366. // (pIPMIReqHdr->ResAddr == m_PendingBridgedResTbl[SeqNum].ReqMsgHdr.ResAddr) )
  367. // {
  368. //
  369. // memcpy (pIPMIResHdr, &m_PendingBridgedResTbl[SeqNum].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  370. //
  371. //
  372. // if (STATUS_OK == Status)
  373. // {
  374. // if ( (0 == strcmp ((char *)m_PendingBridgedResTbl[SeqNum].DestQ, PrimaryIPMBQueueName)) ||
  375. // (0 == strcmp ((char *)m_PendingBridgedResTbl[SeqNum].DestQ, SecondaryIPMBQueueName)) ||
  376. // (ORIGIN_SENDMSG != m_PendingBridgedResTbl[SeqNum].OriginSrc) )
  377. // {
  378. // return;
  379. // }
  380. //
  381. // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NORMAL;
  382. // }
  383. // else if (STATUS_FAIL == Status)
  384. // {
  385. // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NO_ACK_FROM_SLAVE;
  386. // }
  387. // else
  388. // {
  389. // ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_UNSPECIFIED_ERR;
  390. // }
  391. // ResPkt.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
  392. // ResPkt.Cmd = pIPMIResHdr->Cmd;
  393. // ResPkt.NetFnLUN = pIPMIReqHdr->NetFnLUN;
  394. // ResPkt.Channel = pReq->Channel;
  395. // /* Calculate the Second CheckSum */
  396. // ResPkt.Data[ResPkt.Size - 1] = CalculateCheckSum2 (ResPkt.Data, ResPkt.Size-1);
  397. // ResPkt.Param = BRIDGING_REQUEST;
  398. // if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, LANQueueName))
  399. // {
  400. // strcpy (QueueName, LAN_RES_Q);
  401. // }
  402. // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, SerialQueueName))
  403. // {
  404. // //ResPkt.SessionID = m_PendingBridgedResTbl[i].ResMsgHdr.RqSeqLUN;
  405. // strcpy (QueueName, SERIAL_RES_Q);
  406. // }
  407. // else if ( (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, PrimaryIPMBQueueName)) ||
  408. // (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, SecondaryIPMBQueueName)) )
  409. // {
  410. // strcpy (QueueName, (char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ);
  411. // }
  412. // else
  413. // {
  414. // /* PDK Hook to format Pending Bridge Response Packet for other destinations */
  415. // if(g_PDKHandle[PDK_FORMATBRIDGERESPKT] != NULL)
  416. // {
  417. // SwapIPMIMsgHdr ( pIPMIReqHdr, pIPMIResHdr);
  418. //
  419. // ( (void (*)(MsgPkt_T *, int) ) g_PDKHandle[PDK_FORMATBRIDGERESPKT]) ( &ResPkt, BMCInst);
  420. // }
  421. //
  422. // strcpy (QueueName, (char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ);
  423. // }
  424. // if (STATUS_OK != Status)
  425. // {
  426. // m_PendingBridgedResTbl[PBTbl][SeqNum].Used = FALSE;
  427. // }
  428. //
  429. // /* Post the data to Destination Interface queue */
  430. // PostMsg (&ResPkt, QueueName, BMCInst);
  431. // }
  432. }
  433. ///**
  434. //*@fn PendingBridgeResTimerTask
  435. //*@brief Sends the timeout message to response queue
  436. //* if the message does not turn out within send message timeout
  437. //*@return none
  438. //*/
  439. //static void
  440. //PendingBridgeResTimerTask (int BMCInst)
  441. //{
  442. // uint8_t i;
  443. // BMCInfo_t* pBMCInfo = &g_BMCInfo;
  444. // char IPMBQueueName[MAX_STR_LENGTH];
  445. // //LANQueueName[MAX_STR_LENGTH],PrimarySecondaryIPMBQueueName[MAX_STR_LENGTH],QueueName[MAX_STR_LENGTH];
  446. // //,SerialQueueName[MAX_STR_LENGTH];
  447. //
  448. // //memset(LANQueueName,0,sizeof(LANQueueName));
  449. // //memset(PrimaryIPMBQueueName,0,sizeof(PrimaryIPMBQueueName));
  450. // //memset(SecondaryIPMBQueueName,0,sizeof(SecondaryIPMBQueueName));
  451. // //memset(SerialQueueName,0,sizeof(SerialQueueName));
  452. // memset(QueueName,0,sizeof(QueueName));
  453. //
  454. // /* Check for any pending responses */
  455. // for( PBTbl=0; PBTbl < MAX_PENDING_BRIDGE_TBL; PBTbl++)
  456. // {
  457. // for (i = 0; i < sizeof (m_PendingBridgedResTbl[0])/sizeof (m_PendingBridgedResTbl[0][0]); i++)
  458. // {
  459. // if (TRUE == m_PendingBridgedResTbl[PBTbl][i].Used)
  460. // {
  461. // m_PendingBridgedResTbl[PBTbl][i].TimeOut--;
  462. // if (0 == m_PendingBridgedResTbl[PBTbl][i].TimeOut)
  463. // {
  464. // MsgPkt_T Timeout;
  465. // IPMIMsgHdr_T* pIPMIMsgHdr = (_NEAR_ IPMIMsgHdr_T*) Timeout.Data;
  466. // /* Fill the response packet */
  467. // SwapIPMIMsgHdr (&m_PendingBridgedResTbl[PBTbl][i].ReqMsgHdr, pIPMIMsgHdr);
  468. // slog(LANQueueName,"%s%d",LAN_IFC_Q,BMCInst);
  469. // sprintf(PrimaryIPMBQueueName,"%s%d",IPMB_PRIMARY_IFC_Q,BMCInst);
  470. // sprintf(SecondaryIPMBQueueName,"%s%d",IPMB_SECONDARY_IFC_Q,BMCInst);
  471. // sprintf(SerialQueueName,"%s%d",SERIAL_IFC_Q,BMCInst);
  472. // if(PBTbl == PRIMARY_PB_TBL)
  473. // {
  474. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.PrimaryIPMBAddr;
  475. // }
  476. // else if(PBTbl == SECONDARY_PB_TBL)
  477. // {
  478. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.SecondaryIPMBAddr;
  479. // }
  480. // else
  481. // {
  482. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  483. // }
  484. // Timeout.Data [sizeof(IPMIMsgHdr_T)] = CC_TIMEOUT;
  485. // Timeout.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
  486. // /* Calculate the Second CheckSum */
  487. // Timeout.Data[Timeout.Size - 1] = CalculateCheckSum2 (Timeout.Data, Timeout.Size-1);
  488. // Timeout.Param = BRIDGING_REQUEST;
  489. // if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, LANQueueName))
  490. // {
  491. // int j;
  492. // for (j = Timeout.Size - 1; j >= 0; --j)
  493. // {
  494. // Timeout.Data [j+1] = Timeout.Data [j];
  495. // }
  496. // Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
  497. // Timeout.Size++;
  498. // Timeout.Cmd = PAYLOAD_IPMI_MSG;
  499. // strcpy(QueueName, LAN_IFC_Q);
  500. // }
  501. // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, SerialQueueName))
  502. // {
  503. // int j;
  504. // for (j = Timeout.Size - 1; j >= 0; --j)
  505. // {
  506. // Timeout.Data [j+1] = Timeout.Data [j];
  507. // }
  508. // Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
  509. // Timeout.Size++;
  510. // Timeout.Cmd = PAYLOAD_IPMI_MSG;
  511. // strcpy(QueueName, SERIAL_IFC_Q);
  512. // }
  513. // else if (pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 1 && 0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, PrimaryIPMBQueueName))
  514. // {
  515. // int j;
  516. // for (j = Timeout.Size - 1; j >= 0; --j)
  517. // {
  518. // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  519. // }
  520. // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr, sizeof (IPMIMsgHdr_T));
  521. // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
  522. // Timeout.Size++;
  523. // strcpy(QueueName, IPMB_PRIMARY_IFC_Q);
  524. // }
  525. // else if (pBMCInfo->IpmiConfig.SecondaryIPMBSupport == 1 && 0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, SecondaryIPMBQueueName))
  526. // {
  527. // int j;
  528. // for (j = Timeout.Size - 1; j >= 0; --j)
  529. // {
  530. // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  531. // }
  532. // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  533. // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
  534. // Timeout.Size++;
  535. // strcpy(QueueName, IPMB_SECONDARY_IFC_Q);
  536. // }
  537. // else if (0 == strncmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, UDS_RES_Q,strlen(UDS_RES_Q)))
  538. // {
  539. // int j;
  540. // UDSSessionTbl_T *pUDSSessionInfo = NULL;
  541. // for (j = sizeof (IPMIMsgHdr_T); j < Timeout.Size ;j++)
  542. // {
  543. // Timeout.Data [j + sizeof (IPMIUDSMsg_T)-sizeof (IPMIMsgHdr_T)] = Timeout.Data [j];
  544. // }
  545. // Timeout.Size = Timeout.Size + sizeof (IPMIUDSMsg_T)- sizeof (IPMIMsgHdr_T);
  546. //
  547. // m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.IPMIMsgLen = Timeout.Size;
  548. // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr, sizeof (IPMIUDSMsg_T));
  549. // Timeout.NetFnLUN = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.NetFnLUN;
  550. // Timeout.SessionID = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.SessionID;
  551. // Timeout.Cmd = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.Cmd;
  552. //
  553. // pUDSSessionInfo = GetUDSSessionInfo (UDS_SESSION_ID_INFO,&Timeout.SessionID, BMCInst);
  554. // if(pUDSSessionInfo != NULL)
  555. // {
  556. // Timeout.Socket = pUDSSessionInfo->UDSSocket;
  557. // }
  558. // sprintf (QueueName,"%s",m_PendingBridgedResTbl[PBTbl][i].DestQ);
  559. // }
  560. // else
  561. // {
  562. // int j;
  563. // for (j = Timeout.Size - 1; j >= 0; --j)
  564. // {
  565. // Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  566. // }
  567. // _fmemcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  568. // Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_TIMEOUT;
  569. // sprintf (QueueName,"%s",m_PendingBridgedResTbl[PBTbl][i].DestQ);
  570. // }
  571. // /* Post the data to Destination Interface queue */
  572. // PostMsg (&Timeout,QueueName,BMCInst);
  573. // m_PendingBridgedResTbl[PBTbl][i].Used = FALSE;
  574. // IPMI_DBG_PRINT_1( "MsgHndlr: clean pending index = %d.\n", i );
  575. // }
  576. // }
  577. // }
  578. // }
  579. //}
  580. /**
  581. *@fn SwapIPMIMsgHdr
  582. *@brief Swaps the header and copies into response
  583. *@param pIPMIMsgReq Header of the Request
  584. *@param pIPMIMsgRes Header of the response
  585. *@return none
  586. */
  587. void
  588. SwapIPMIMsgHdr (IPMIMsgHdr_T* pIPMIMsgReq, IPMIMsgHdr_T* pIPMIMsgRes)
  589. {
  590. pIPMIMsgRes->ResAddr = pIPMIMsgReq->ReqAddr;
  591. pIPMIMsgRes->NetFnLUN = (pIPMIMsgReq->NetFnLUN & 0xFC) + 0x04;
  592. pIPMIMsgRes->NetFnLUN |= pIPMIMsgReq->RqSeqLUN & 0x03;
  593. /* Calculate the Checksum for above two bytes */
  594. pIPMIMsgRes->ChkSum = (~(pIPMIMsgRes->ResAddr + pIPMIMsgRes->NetFnLUN) + 1);
  595. pIPMIMsgRes->ReqAddr = pIPMIMsgReq->ResAddr;
  596. pIPMIMsgRes->RqSeqLUN = (pIPMIMsgReq->RqSeqLUN & 0xFC);
  597. pIPMIMsgRes->RqSeqLUN |= (pIPMIMsgReq->NetFnLUN & 0x03);
  598. pIPMIMsgRes->Cmd = pIPMIMsgReq->Cmd;
  599. return;
  600. }