MsgHndlrTask.c 23 KB

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