MsgHndlrTask.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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. if(g_BMCInfo.IpmiConfig.UDSIfcSupport == 0x01 && (reqMsgPkt.SrcQ == gFdUdsRes))
  131. {
  132. if (resMsgPkt.Size == sizeof(IPMIUDSMsg_T) && (NORMAL_RESPONSE == resMsgPkt.Param) )
  133. {
  134. continue;
  135. }
  136. resMsgPkt.Size = resMsgPkt.Size+1;
  137. SwapUDSIPMIMsg(&reqMsgPkt,&resMsgPkt);
  138. resMsgPkt.Data[resMsgPkt.Size] = 0;
  139. }
  140. if(SYS_IFC_CHANNEL == reqMsgPkt.Channel)
  141. {
  142. /* Skip current request if no response from Command Handler */
  143. if (!resMsgPkt.Size && (NO_RESPONSE == resMsgPkt.Param) )
  144. {
  145. continue;
  146. }
  147. resMsgPkt.SessionID = reqMsgPkt.SessionID;
  148. }
  149. // printf("Mtx: ");
  150. // for(i=0;i<resMsgPkt.Size;i++)
  151. // printf("%#x ", resMsgPkt.Data[i]);
  152. // printf("\n");
  153. //send response pkt to source queue.
  154. PostMsg(resMsgPkt.SrcQ, &resMsgPkt);
  155. }
  156. }
  157. /**
  158. *@fn ProcessIPMIReq
  159. *@brief Processes the requested IPMI command
  160. *@param pReq Request of the command
  161. *@param pRes Response for the requested command
  162. *@return none
  163. */
  164. static void
  165. ProcessIPMIReq (MsgPkt_T* pReq, MsgPkt_T* pRes)
  166. {
  167. CmdHndlrMap_T * pCmdHndlrMap;
  168. uint32_t HdrOffset = 0;
  169. uint8_t CmdOverride = 1;
  170. int8_t MsgHndlrMapGot=0;
  171. uint8_t PBTbl = PRIMARY_PB_TBL;
  172. // msgHndlr_dbg_printf ("Processing IPMI Packet.\r\n");
  173. /* Set the Cmd and Net function in response packet */
  174. pRes->Cmd = pReq->Cmd;
  175. pRes->NetFnLUN = pReq->NetFnLUN;
  176. pRes->Channel = pReq->Channel;
  177. pRes->SrcQ = pReq->SrcQ;
  178. /* Normal IPMI Command response */
  179. pRes->Param = PARAM_NORMAL_RESPONSE;
  180. if ((SYS_IFC_CHANNEL != pReq->Channel) && (USB_CHANNEL != pReq->Channel) && (UDS_CHANNEL != pReq->Channel))
  181. {
  182. //printf("log 1, pReq->Channel: %#x\n", pReq->Channel);
  183. HdrOffset = sizeof (IPMIMsgHdr_T);
  184. pReq->Size = pReq->Size - HdrOffset - 1;
  185. }
  186. if(UDS_CHANNEL == pReq->Channel)
  187. {
  188. //printf("log 2, pReq->Size: %d, HdrOffset: %d\n", pReq->Size, HdrOffset);
  189. HdrOffset = sizeof(IPMIUDSMsg_T);
  190. pReq->Size = pReq->Size -HdrOffset - 1;
  191. }
  192. SwapIPMIMsgHdr((IPMIMsgHdr_T*)pReq->Data, (IPMIMsgHdr_T*)pRes->Data);
  193. pRes->Size = HdrOffset + sizeof(uint8_t);
  194. pthread_setspecific(g_tls.CurSessionID,&pReq->SessionID);
  195. if(IsCommandEnabled(NET_FN(pReq->NetFnLUN), &pReq->Data[HdrOffset], pReq->Cmd) != 0)
  196. {
  197. pRes->Data [HdrOffset] = CC_INV_CMD;
  198. printf ("Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
  199. pRes->Size += 2;
  200. return;
  201. }
  202. //Get oem command map
  203. MsgHndlrMapGot = PDKGetOEMMsgHndlrMap(NET_FN(pReq->NetFnLUN),&pCmdHndlrMap);
  204. if(MsgHndlrMapGot == 0)
  205. {
  206. CmdOverride = GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap);
  207. }
  208. //get standard ipmi command map
  209. if((CmdOverride == 0 || MsgHndlrMapGot == -1) ) //OEM commands have no command map.
  210. {
  211. if (0 != GetMsgHndlrMap (NET_FN (pReq->NetFnLUN), &pCmdHndlrMap))
  212. {
  213. // if(pBMCInfo->IpmiConfig.GrpExtnSupport == 1)
  214. // {
  215. if (0 != GroupExtnGetMsgHndlrMap (NET_FN (pReq->NetFnLUN), pReq->Data [HdrOffset], &pCmdHndlrMap) )
  216. {
  217. pRes->Data [HdrOffset] = CC_INV_CMD;
  218. printf ("MsgHndlr.c : Invalid Net Function 0x%x or Invalid Command 0x%x\n",NET_FN(pReq->NetFnLUN), pReq->Cmd);
  219. pRes->Size += 2;
  220. return;
  221. }
  222. // }
  223. // else
  224. // {
  225. // pRes->Data [HdrOffset] = CC_INV_CMD;
  226. // printf ("MsgHndlr.c : Invalid Net Function 0x%x\n",NET_FN(pReq->NetFnLUN));
  227. // pRes->Size += 2;
  228. // return;
  229. // }
  230. }
  231. if(GetCmdHndlr(pReq,pRes,pCmdHndlrMap,HdrOffset,CmdOverride,&pCmdHndlrMap) == FALSE)
  232. {
  233. pRes->Data [HdrOffset] = CC_INV_CMD;
  234. pRes->Size += 2;
  235. //printf("log 3\n");
  236. return;
  237. }
  238. }
  239. /* Check for the request size */
  240. if (0xff != pCmdHndlrMap->ReqLen)
  241. {
  242. /* Check for invalid request size */
  243. if (pCmdHndlrMap->ReqLen != pReq->Size)
  244. {
  245. printf("Warning: Request data len error, require %d\n", pCmdHndlrMap->ReqLen);
  246. pRes->Data [HdrOffset] = CC_REQ_INV_LEN;
  247. pRes->Size += 2;
  248. return;
  249. }
  250. }
  251. pRes->Size = pCmdHndlrMap->CmdHndlr (&pReq->Data [HdrOffset], pReq->Size, &pRes->Data [HdrOffset]) + HdrOffset + 1;
  252. // //send message command
  253. // if( (CMD_SEND_MSG == pReq->Cmd) && (NETFN_APP == pReq->NetFnLUN >> 2))
  254. // {
  255. // printf("log 4\n");
  256. // int Offset = 0;
  257. // uint8_t SeqNum = g_BMCInfo.SendMsgSeqNum;
  258. // if ((0 == pRes->Size) &&
  259. // ((g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 0x01 && PRIMARY_IPMB_CHANNEL == pRes->Channel) ||
  260. // (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 0x01 && SECONDARY_IPMB_CHANNEL == pRes->Channel)) )
  261. // {
  262. // pRes->Param = PARAM_NO_RESPONSE;
  263. // Offset = HdrOffset + 2;
  264. // }
  265. // else if (HdrOffset == pRes->Size)
  266. // {
  267. // Offset = HdrOffset + 1;
  268. // }
  269. // PBTbl = ( ((pReq->Data[sizeof (IPMIMsgHdr_T)] & 0x0F) == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
  270. // while(TRUE)
  271. // {
  272. // if ( (TRUE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
  273. // (0 == memcmp (&m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr, &pReq->Data[Offset], sizeof (IPMIMsgHdr_T))) )
  274. // {
  275. // printf("---> log 4.1\n");
  276. // memcpy (&m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr, pRes->Data, sizeof (IPMIMsgHdr_T));
  277. // break;
  278. // }
  279. // else
  280. // {
  281. // SeqNum = (SeqNum - 1) & 0x3F;
  282. // if(SeqNum == g_BMCInfo.SendMsgSeqNum)
  283. // {
  284. // break;
  285. // }
  286. // }
  287. // }
  288. // }
  289. // printf("log 5\n");
  290. return;
  291. }
  292. /**
  293. *@fn CalculateChecksum2
  294. *@brief Calculates the checksum
  295. *@param Pkt Pointer to the data for the checksum to be calculated
  296. *@param Len Size of data for checksum calculation
  297. *@return Returns the checksum value
  298. */
  299. uint8_t CalculateCheckSum2 (uint8_t* Pkt, uint32_t Len)
  300. {
  301. uint8_t Sum;
  302. uint32_t i;
  303. /* Get Checksum 2 */
  304. Sum = 0;
  305. for (i = 3; i < Len; i++)
  306. {
  307. Sum += Pkt [i];
  308. }
  309. return (uint8_t)(0xFF & (0x100 - Sum));
  310. }
  311. /**
  312. *@fn GetMsgHndlrMap
  313. *@brief Gets the exact command Handler by comparing NetFn
  314. *@param Netfn -NetFunction of the Cmd to execute
  315. *@param pCmdHndlrMap Pointer to the Command Handler
  316. *@return Returns 0 on success
  317. * Returns -1 on failure
  318. */
  319. int
  320. GetMsgHndlrMap (uint8_t NetFn, CmdHndlrMap_T ** pCmdHndlrMap)
  321. {
  322. int i;
  323. /* Get the command handler corresponding to the net function */
  324. for (i = 0; i < sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]); i++) //pBMCInfo->MsgHndlrTblSize
  325. {
  326. if (m_MsgHndlrTbl [i].NetFn == NetFn) { break; }
  327. }
  328. /* Check if we have not found our net function */
  329. if (i == sizeof(m_MsgHndlrTbl)/sizeof(m_MsgHndlrTbl[0]) )
  330. {
  331. return -1;
  332. }
  333. /* Get the handler corresponding to the command */
  334. *pCmdHndlrMap = (CmdHndlrMap_T*)m_MsgHndlrTbl [i].CmdHndlrMap;
  335. return 0;
  336. }
  337. /**
  338. *@fn GetCmdHndlr
  339. *@brief Picks up the exact command to execute by comparing Cmd no.
  340. *@param pReq Request buffer for the command
  341. *@param pRes Response buffer for the command
  342. *@param pCmdHndlrMap
  343. *@param HdrOffset
  344. *@param CmdOverride
  345. *@param CmdHndlr
  346. *@return Returns TRUE on success
  347. * Returns FALSE on failure
  348. */
  349. int GetCmdHndlr(MsgPkt_T* pReq,MsgPkt_T* pRes,CmdHndlrMap_T* pCmdHndlrMap,
  350. uint32_t HdrOffset,uint8_t CmdOverride,CmdHndlrMap_T** CmdHndrl )
  351. {
  352. int i=0;
  353. while (1)
  354. {
  355. /**
  356. * If we reached the end of the Command Handler map - invalid command
  357. **/
  358. if (0 == pCmdHndlrMap->CmdHndlr)
  359. {
  360. if(CmdOverride == FALSE)
  361. {
  362. pRes->Data [HdrOffset] = CC_INV_CMD;
  363. printf( "Warning: MsgHndlr.c : Invalid Command %#x\r\n", pReq->Cmd );
  364. }
  365. return FALSE;
  366. }
  367. if (pCmdHndlrMap->Cmd == pReq->Cmd)
  368. {
  369. break;
  370. }
  371. i++;
  372. pCmdHndlrMap++;
  373. }
  374. *CmdHndrl = pCmdHndlrMap;
  375. return TRUE;
  376. }
  377. /**
  378. *@fn GroupExtnGetMsgHndlrMap
  379. *@brief Gets the exact command Handler by comparing NetFn
  380. *@param Netfn -NetFunction of the Cmd to execute
  381. *@GroupExtnCode - Group Extension code
  382. *@param pCmdHndlrMap Pointer to the Command Handler
  383. *@return Returns 0 on success
  384. * Returns -1 on failure
  385. */
  386. int
  387. GroupExtnGetMsgHndlrMap (uint8_t NetFn, uint8_t GroupExtnCode, CmdHndlrMap_T ** pCmdHndlrMap)
  388. {
  389. int i;
  390. /* Get the command handler corresponding to the net function */
  391. for (i = 0; i < sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl [0]); i++)
  392. {
  393. if ((m_GroupExtnMsgHndlrTbl [i].NetFn == NetFn) && (m_GroupExtnMsgHndlrTbl [i].GroupExtnCode == GroupExtnCode))
  394. {
  395. break;
  396. }
  397. }
  398. /* Check if we have not found our net function */
  399. if (i == sizeof (m_GroupExtnMsgHndlrTbl) / sizeof (m_GroupExtnMsgHndlrTbl[0]))
  400. {
  401. return -1;
  402. }
  403. // printf("---> GroupExtnGetMsgHndlrMap successful, i=%d\n",i);
  404. /* Get the handler corresponding to the command */
  405. *pCmdHndlrMap = (CmdHndlrMap_T*)m_GroupExtnMsgHndlrTbl [i].CmdHndlrMap;
  406. return 0;
  407. }
  408. /*------------------------------------------------------------------
  409. *@fn RespondSendMessage
  410. *@brief Frames the Response packet when a IPMB destination is
  411. * unavialable
  412. *
  413. *@param pReq: Request Message Packet address
  414. *@param Status Status of SendIPMBPkt method
  415. *@param BMCInst: BMC Instance Number
  416. *
  417. *@return none
  418. *-----------------------------------------------------------------*/
  419. void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status)
  420. {
  421. uint8_t PBTbl = PRIMARY_PB_TBL;
  422. MsgPkt_T ResPkt;
  423. IPMIMsgHdr_T* pIPMIResHdr = ( IPMIMsgHdr_T*)ResPkt.Data;
  424. IPMIMsgHdr_T* pIPMIReqHdr = ( IPMIMsgHdr_T*)pReq->Data;
  425. uint8_t SeqNum = NET_FN(pIPMIReqHdr->RqSeqLUN);
  426. int QueueFd;
  427. /* Check for pending responses */
  428. PBTbl = ( (pReq->Channel == SECONDARY_IPMB_CHANNEL) ? SECONDARY_PB_TBL : PRIMARY_PB_TBL );
  429. if ( (TRUE == m_PendingBridgedResTbl[PBTbl][SeqNum].Used) &&
  430. (NET_FN(pIPMIReqHdr->RqSeqLUN) == SeqNum) &&
  431. (NET_FN(pIPMIReqHdr->NetFnLUN) == NET_FN(m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.NetFnLUN )) &&
  432. (pIPMIReqHdr->Cmd == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.Cmd) &&
  433. (pIPMIReqHdr->ResAddr == m_PendingBridgedResTbl[PBTbl][SeqNum].ReqMsgHdr.ResAddr) )
  434. {
  435. memcpy (pIPMIResHdr, &m_PendingBridgedResTbl[PBTbl][SeqNum].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  436. if (STATUS_OK == Status)
  437. {
  438. if ( ( m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_PrimaryIpmbIfcQ) ||
  439. (m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_SecondaryIpmbIfcQ) ||
  440. (ORIGIN_SENDMSG != m_PendingBridgedResTbl[PBTbl][SeqNum].OriginSrc) )
  441. {
  442. return;
  443. }
  444. ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NORMAL;
  445. }
  446. else if (STATUS_FAIL == Status)
  447. {
  448. ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_NO_ACK_FROM_SLAVE;
  449. }
  450. else
  451. {
  452. ResPkt.Data [sizeof(IPMIMsgHdr_T)] = CC_UNSPECIFIED_ERR;
  453. }
  454. ResPkt.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
  455. ResPkt.Cmd = pIPMIResHdr->Cmd;
  456. ResPkt.NetFnLUN = pIPMIReqHdr->NetFnLUN;
  457. ResPkt.Channel = pReq->Channel;
  458. /* Calculate the Second CheckSum */
  459. ResPkt.Data[ResPkt.Size - 1] = CalculateCheckSum2 (ResPkt.Data, ResPkt.Size-1);
  460. ResPkt.Param = BRIDGING_REQUEST;
  461. if (m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_LanIfcQ)
  462. {
  463. QueueFd = gFd_LanResQ;
  464. }
  465. // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ, SerialQueueName))
  466. // {
  467. // //ResPkt.SessionID = m_PendingBridgedResTbl[i].ResMsgHdr.RqSeqLUN;
  468. // strcpy (QueueName, SERIAL_RES_Q);
  469. // }
  470. else if ( (m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_PrimaryIpmbIfcQ) ||
  471. (m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ == gFd_SecondaryIpmbIfcQ) )
  472. {
  473. QueueFd = m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ;
  474. }
  475. else
  476. {
  477. /* PDK Hook to format Pending Bridge Response Packet for other destinations */
  478. // if(g_PDKHandle[PDK_FORMATBRIDGERESPKT] != NULL)
  479. {
  480. SwapIPMIMsgHdr ( pIPMIReqHdr, pIPMIResHdr);
  481. // ( (void (*)(MsgPkt_T *, int) ) g_PDKHandle[PDK_FORMATBRIDGERESPKT]) ( &ResPkt, BMCInst);
  482. }
  483. QueueFd = m_PendingBridgedResTbl[PBTbl][SeqNum].DestQ;
  484. }
  485. if (STATUS_OK != Status)
  486. {
  487. m_PendingBridgedResTbl[PBTbl][SeqNum].Used = FALSE;
  488. }
  489. /* Post the data to Destination Interface queue */
  490. PostMsg (QueueFd, &ResPkt);
  491. }
  492. }
  493. /**
  494. *@fn PendingBridgeResTimerTask
  495. *@brief Sends the timeout message to response queue
  496. * if the message does not turn out within send message timeout
  497. *@return none
  498. */
  499. static void
  500. PendingBridgeResTimerTask (void)
  501. {
  502. uint8_t i;
  503. uint8_t PBTbl = PRIMARY_PB_TBL;
  504. int QueueFd = 0;
  505. printf("-> PendingBridgeResTimerTask\n");
  506. /* Check for any pending responses */
  507. for( PBTbl=0; PBTbl < MAX_PENDING_BRIDGE_TBL; PBTbl++)
  508. {
  509. for (i = 0; i < sizeof (m_PendingBridgedResTbl[0])/sizeof (m_PendingBridgedResTbl[0][0]); i++)
  510. {
  511. if (TRUE == m_PendingBridgedResTbl[PBTbl][i].Used)
  512. {
  513. m_PendingBridgedResTbl[PBTbl][i].TimeOut--;
  514. if (0 == m_PendingBridgedResTbl[PBTbl][i].TimeOut)
  515. {
  516. MsgPkt_T Timeout;
  517. IPMIMsgHdr_T* pIPMIMsgHdr = (IPMIMsgHdr_T*) Timeout.Data;
  518. /* Fill the response packet */
  519. SwapIPMIMsgHdr (&m_PendingBridgedResTbl[PBTbl][i].ReqMsgHdr, pIPMIMsgHdr);
  520. // slog(LANQueueName,"%s%d",LAN_IFC_Q,BMCInst);
  521. // sprintf(PrimaryIPMBQueueName,"%s%d",IPMB_PRIMARY_IFC_Q,BMCInst);
  522. // sprintf(SecondaryIPMBQueueName,"%s%d",IPMB_SECONDARY_IFC_Q,BMCInst);
  523. // sprintf(SerialQueueName,"%s%d",SERIAL_IFC_Q,BMCInst);
  524. if(PBTbl == PRIMARY_PB_TBL)
  525. {
  526. pIPMIMsgHdr->ReqAddr = g_BMCInfo.IpmiConfig.PrimaryIPMBAddr;
  527. }
  528. else if(PBTbl == SECONDARY_PB_TBL)
  529. {
  530. pIPMIMsgHdr->ReqAddr = g_BMCInfo.IpmiConfig.SecondaryIPMBAddr;
  531. }
  532. else
  533. {
  534. printf("Invalid PBTbl\n");;//pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  535. }
  536. Timeout.Data [sizeof(IPMIMsgHdr_T)] = CC_TIMEOUT;
  537. Timeout.Size = sizeof (IPMIMsgHdr_T) + 1 + 1; // IPMI Header + Completion Code + Second Checksum
  538. /* Calculate the Second CheckSum */
  539. Timeout.Data[Timeout.Size - 1] = CalculateCheckSum2 (Timeout.Data, Timeout.Size-1);
  540. Timeout.Param = BRIDGING_REQUEST;
  541. if (m_PendingBridgedResTbl[PBTbl][i].DestQ == gFd_LanIfcQ)
  542. {
  543. int j;
  544. for (j = Timeout.Size - 1; j >= 0; --j)
  545. {
  546. Timeout.Data [j+1] = Timeout.Data [j];
  547. }
  548. Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
  549. Timeout.Size++;
  550. Timeout.Cmd = PAYLOAD_IPMI_MSG;
  551. QueueFd = gFd_LanIfcQ;
  552. }
  553. // else if (0 == strcmp ((char *)m_PendingBridgedResTbl[PBTbl][i].DestQ, SerialQueueName))
  554. // {
  555. // int j;
  556. // for (j = Timeout.Size - 1; j >= 0; --j)
  557. // {
  558. // Timeout.Data [j+1] = Timeout.Data [j];
  559. // }
  560. // Timeout.Data[0] = m_PendingBridgedResTbl[PBTbl][i].SrcSessionHandle;
  561. // Timeout.Size++;
  562. // Timeout.Cmd = PAYLOAD_IPMI_MSG;
  563. // strcpy(QueueName, SERIAL_IFC_Q);
  564. // }
  565. else if (g_BMCInfo.IpmiConfig.PrimaryIPMBSupport == 1 && m_PendingBridgedResTbl[PBTbl][i].DestQ == gFd_PrimaryIpmbIfcQ)
  566. {
  567. int j;
  568. for (j = Timeout.Size - 1; j >= 0; --j)
  569. {
  570. Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  571. }
  572. memcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr, sizeof (IPMIMsgHdr_T));
  573. Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
  574. Timeout.Size++;
  575. QueueFd = gFd_PrimaryIpmbIfcQ;
  576. }
  577. else if (g_BMCInfo.IpmiConfig.SecondaryIPMBSupport == 1 && m_PendingBridgedResTbl[PBTbl][i].DestQ == gFd_SecondaryIpmbIfcQ)
  578. {
  579. int j;
  580. for (j = Timeout.Size - 1; j >= 0; --j)
  581. {
  582. Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  583. }
  584. memcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  585. Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_NORMAL;
  586. Timeout.Size++;
  587. QueueFd = gFd_SecondaryIpmbIfcQ;
  588. }
  589. else if (m_PendingBridgedResTbl[PBTbl][i].DestQ = gFdUdsIfc)
  590. {
  591. int j;
  592. UDSSessionTbl_T *pUDSSessionInfo = NULL;
  593. for (j = sizeof (IPMIMsgHdr_T); j < Timeout.Size ;j++)
  594. {
  595. Timeout.Data [j + sizeof (IPMIUDSMsg_T)-sizeof (IPMIMsgHdr_T)] = Timeout.Data [j];
  596. }
  597. Timeout.Size = Timeout.Size + sizeof (IPMIUDSMsg_T)- sizeof (IPMIMsgHdr_T);
  598. m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.IPMIMsgLen = Timeout.Size;
  599. memcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr, sizeof (IPMIUDSMsg_T));
  600. Timeout.NetFnLUN = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.NetFnLUN;
  601. Timeout.SessionID = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.SessionID;
  602. Timeout.Cmd = m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.UDSMsgHdr.Cmd;
  603. pUDSSessionInfo = GetUDSSessionInfo (UDS_SESSION_ID_INFO,&Timeout.SessionID);
  604. if(pUDSSessionInfo != NULL)
  605. {
  606. Timeout.Socket = pUDSSessionInfo->UDSSocket;
  607. }
  608. QueueFd = m_PendingBridgedResTbl[PBTbl][i].DestQ;
  609. }
  610. else
  611. {
  612. int j;
  613. for (j = Timeout.Size - 1; j >= 0; --j)
  614. {
  615. Timeout.Data [j + sizeof (IPMIMsgHdr_T) + 1] = Timeout.Data [j];
  616. }
  617. memcpy (Timeout.Data, &m_PendingBridgedResTbl[PBTbl][i].ResMsgHdr.IPMIMsgHdr, sizeof (IPMIMsgHdr_T));
  618. Timeout.Data[sizeof (IPMIMsgHdr_T)] = CC_TIMEOUT;
  619. QueueFd = m_PendingBridgedResTbl[PBTbl][i].DestQ;
  620. }
  621. /* Post the data to Destination Interface queue */
  622. PostMsg (QueueFd, &Timeout);
  623. m_PendingBridgedResTbl[PBTbl][i].Used = FALSE;
  624. printf( "MsgHndlr: clean pending index = %d.\n", i );
  625. }
  626. }
  627. }
  628. }
  629. }
  630. /**
  631. *@fn PendingSeqNoTimerTask
  632. *@brief Timertask which helpful in IPMB sequence number validation
  633. *@return none
  634. */
  635. static void
  636. PendingSeqNoTimerTask (void)
  637. {
  638. uint8_t i,j;
  639. printf("-> PendingSeqNoTimerTask\n");
  640. /* Check for any Sequence Number expiraied */
  641. for (i = 0; i < sizeof (m_PendingSeqNoTbl)/sizeof (m_PendingSeqNoTbl[0]); i++)
  642. {
  643. for (j = 0; j < sizeof (m_PendingSeqNoTbl[0])/sizeof (m_PendingSeqNoTbl[0][0]); j++)
  644. {
  645. if (TRUE == m_PendingSeqNoTbl[i][j].Used)
  646. {
  647. m_PendingSeqNoTbl[i][j].TimeOut--;
  648. if (0 == m_PendingSeqNoTbl[i][j].TimeOut)
  649. {
  650. m_PendingSeqNoTbl[i][j].Used = FALSE;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. /**
  657. *@fn SwapIPMIMsgHdr
  658. *@brief Swaps the header and copies into response
  659. *@param pIPMIMsgReq Header of the Request
  660. *@param pIPMIMsgRes Header of the response
  661. *@return none
  662. */
  663. void
  664. SwapIPMIMsgHdr (IPMIMsgHdr_T* pIPMIMsgReq, IPMIMsgHdr_T* pIPMIMsgRes)
  665. {
  666. pIPMIMsgRes->ResAddr = pIPMIMsgReq->ReqAddr;
  667. pIPMIMsgRes->NetFnLUN = (pIPMIMsgReq->NetFnLUN & 0xFC) + 0x04;
  668. pIPMIMsgRes->NetFnLUN |= pIPMIMsgReq->RqSeqLUN & 0x03;
  669. /* Calculate the Checksum for above two bytes */
  670. pIPMIMsgRes->ChkSum = (~(pIPMIMsgRes->ResAddr + pIPMIMsgRes->NetFnLUN) + 1);
  671. pIPMIMsgRes->ReqAddr = pIPMIMsgReq->ResAddr;
  672. pIPMIMsgRes->RqSeqLUN = (pIPMIMsgReq->RqSeqLUN & 0xFC);
  673. pIPMIMsgRes->RqSeqLUN |= (pIPMIMsgReq->NetFnLUN & 0x03);
  674. pIPMIMsgRes->Cmd = pIPMIMsgReq->Cmd;
  675. return;
  676. }
  677. /**
  678. * *@fn Swap UDSIPMIMsg
  679. * *@brief Swaps the header and copies into response
  680. * *@param pIPMIMsgReq Header of the Request
  681. * *@param pIPMIMsgRes Header of the response
  682. * *@return none
  683. * */
  684. void
  685. SwapUDSIPMIMsg ( MsgPkt_T* pIPMIMsgReq, MsgPkt_T* pIPMIMsgRes)
  686. {
  687. IPMIUDSMsg_T *pIPMIUDSMsgRes = (IPMIUDSMsg_T *)&pIPMIMsgRes->Data[0];
  688. IPMIUDSMsg_T *pIPMIUDSMsgReq = (IPMIUDSMsg_T *)&pIPMIMsgReq->Data[0];
  689. pIPMIMsgRes->NetFnLUN = pIPMIMsgReq->NetFnLUN;
  690. // pIPMIMsgRes->Privilege = pIPMIMsgReq->Privilege;
  691. pIPMIMsgRes->Cmd = pIPMIMsgReq->Cmd;
  692. pIPMIMsgRes->Channel = pIPMIMsgReq->Channel;
  693. pIPMIMsgRes->SessionID = pIPMIMsgReq->SessionID;
  694. pIPMIMsgRes->Socket = pIPMIMsgReq->Socket;
  695. pIPMIUDSMsgRes->NetFnLUN = pIPMIMsgReq->NetFnLUN;
  696. // pIPMIUDSMsgRes->Privilege = pIPMIMsgReq->Privilege;
  697. pIPMIUDSMsgRes->Cmd = pIPMIMsgReq->Cmd;
  698. pIPMIUDSMsgRes->ChannelNum = pIPMIMsgReq->Channel;
  699. pIPMIUDSMsgRes->SessionID = pIPMIMsgReq->SessionID;
  700. //pIPMIUDSMsgRes->AuthFlag = pIPMIUDSMsgReq->AuthFlag;
  701. pIPMIUDSMsgRes->IPMIMsgLen = pIPMIMsgRes->Size;
  702. // strcpy( (char *)pIPMIUDSMsgRes->UserName, (char *)pIPMIUDSMsgReq->UserName);
  703. // memcpy(pIPMIUDSMsgRes->IPAddr, pIPMIUDSMsgReq->IPAddr, 16);
  704. return;
  705. }