RMCP.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  1. /****************************************************************
  2. ****************************************************************
  3. ** **
  4. ** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. ** **
  6. ** All Rights Reserved. **
  7. ** **
  8. ** 6145-F, Northbelt Parkway, Norcross, **
  9. ** **
  10. ** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. ** **
  12. ****************************************************************
  13. ****************************************************************/
  14. /*****************************************************************
  15. *
  16. * RMCP.c
  17. * RMCP Message Handler
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * : Bakka Ravinder Reddy <bakkar@ami.com>
  21. *
  22. *****************************************************************/
  23. #include "com_Message.h"
  24. #include "com_IPMIDefs.h"
  25. #include "Session.h"
  26. #include "LANIfc.h"
  27. #include "MD.h"
  28. #include "RMCP.h"
  29. #include "RMCP+.h"
  30. #include "main.h"
  31. #include "MD5_128.h"
  32. #include <string.h>
  33. #include "BmcType.h"
  34. #include "AuthCode.h"
  35. /*** Local definitions ***/
  36. #define RMCP_VERSION 6
  37. #define IPMI_MESSAGE_CLASS 7
  38. #define PRESENCE_PING_MSGTYPE 0x80
  39. #define RMCP_VERSION 6
  40. #define AMI_CMD_NETFN_LUN (((0x2E | 1) << 2) | 0x00)
  41. #define AMI_CMD_12 0x12
  42. #define PING_IPMI_15_SUPPORT 1
  43. #define PING_IPMI_20_SUPPORT 2
  44. #define MAX_AUTH_CODE_SIZE 12
  45. #define INIT_VECTOR_SIZE 16
  46. #define INTEGRITY_MASK BIT6
  47. #define CONFIDENT_MASK BIT7
  48. #define PAYLOAD_RSSP_OS_REQ 0x10
  49. #define PAYLOAD_RSSP_OS_RES 0x11
  50. #define PAYLOAD_RAKP_MSG1 0x12
  51. #define PAYLOAD_RAKP_MSG2 0x13
  52. #define PAYLOAD_RAKP_MSG3 0x14
  53. #define PAYLOAD_RAKP_MSG4 0x15
  54. // /*** Prototype Declaration ***/
  55. static int ProcIPMIReq ( SessionInfo_T* pSessionInfo, uint8_t Payload, MsgPkt_T *pReq, MsgPkt_T *pRes);
  56. static uint8_t ValidateRMCPHdr ( RMCPHdr_T* pRMCPHdr);
  57. // static bool ValidateSessionHdr (uint32_t SessionID, uint32_t SeqNo );
  58. static uint8_t ProcessPingMsg ( RMCPHdr_T* pRMCPReq,
  59. RMCPHdr_T* pRMCPRes );
  60. static uint8_t ValidateAuthCode ( uint8_t* pAuthCode, uint8_t* pPassword,
  61. SessionHdr_T* pSessionHdr,
  62. IPMIMsgHdr_T* pIPMIMsg);
  63. // static int Proc20Payload ( RMCPHdr_T* pRMCPReq,
  64. // RMCPHdr_T* pRMCPRes, MiscParams_T *pParams, uint8_t Channel );
  65. /*** Local typedefs ***/
  66. /**
  67. * @struct PreSessionCmd_T
  68. * @brief Pre-session command entry.
  69. **/
  70. typedef struct
  71. {
  72. uint8_t NetFn;
  73. uint8_t Cmd;
  74. } PreSessionCmd_T;
  75. /**
  76. * @brief Message Payload Handler function.
  77. * @param pReq - Request message.
  78. * @param ReqLen - Request length.
  79. * @param pRes - Response message.
  80. * @return 0 if success, -1 if error.
  81. **/
  82. typedef int (*pPayloadHndlr_T) ( uint8_t* pReq, uint8_t ReqLen,
  83. uint8_t* pRes, uint8_t Channel );
  84. /**
  85. * @struct PayloadTbl_T;
  86. * @brief Payload Table structure.
  87. **/
  88. typedef struct
  89. {
  90. uint8_t Payload;
  91. pPayloadHndlr_T PayloadHndlr;
  92. } PayloadTbl_T;
  93. // static const PayloadTbl_T m_PayloadTbl [] =
  94. // {
  95. // /* Payload Handler */
  96. // {PAYLOAD_RSSP_OS_REQ, RSSPOpenSessionReq },
  97. // {PAYLOAD_RAKP_MSG1, RAKPMsg1 },
  98. // {PAYLOAD_RAKP_MSG3, RAKPMsg3 },
  99. // };
  100. // /* Pre-Session establishment commands */
  101. // static const PreSessionCmd_T m_PreSessionCmdsTbl[] =
  102. // {
  103. // { NETFN_APP, CMD_GET_CH_AUTH_CAP },
  104. // { NETFN_APP, CMD_GET_SESSION_CHALLENGE },
  105. // { NETFN_APP, CMD_GET_DEV_GUID },
  106. // { NETFN_APP, CMD_GET_CH_CIPHER_SUITES },
  107. // { NETFN_APP, CMD_GET_SYSTEM_GUID },
  108. // { NETFN_SENSOR, CMD_PET_ACKNOWLEDGE},
  109. // };
  110. // /**
  111. // * @struct IPMIAuditMaskTbl_T;
  112. // * @brief Maps Audit Event types to their bitmask in configuration.
  113. // **/
  114. // typedef struct
  115. // {
  116. // uint8_t EventType;
  117. // uint8_t EventMask;
  118. // }IPMIAuditMaskTbl_T;
  119. // static const IPMIAuditMaskTbl_T m_IPMIAuditMaskMap[] =
  120. // {
  121. // { EVENT_LOGIN, 0x0 },
  122. // { EVENT_LOGOUT, 0x1 },
  123. // { EVENT_AUTO_LOGOUT, 0x2 },
  124. // { EVENT_LOGIN_FAILURE, 0x3 },
  125. // };
  126. // int RmcpSeqNumValidation(SessionInfo_T* pSessionInfo, uint32_t SessionSeqNum, IPMIMsgHdr_T* pIPMIMsgReq)
  127. // {
  128. // uint32_t SeqTrac[SIXTEEN_COUNT_WINDOW_LEN];
  129. // bool TrackRollOver = FALSE;
  130. // uint32_t TrackRollOverSeq = SEQNUM_ROLLOVER;
  131. // int i;
  132. // if((pIPMIMsgReq->Cmd != CMD_ACTIVATE_SESSION) ||
  133. // ((pIPMIMsgReq->Cmd == CMD_ACTIVATE_SESSION) &&
  134. // (SessionSeqNum != 0)))
  135. // {
  136. // if( pSessionInfo->InboundSeq == SessionSeqNum)
  137. // return -1;
  138. // if((pSessionInfo->InboundSeq < (SEQNUM_ROLLOVER - EIGHT_COUNT_WINDOW_LEN)) && (pSessionInfo->InboundSeq > EIGHT_COUNT_WINDOW_LEN))
  139. // {
  140. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  141. // {
  142. // if((pSessionInfo->InboundSeq -SessionSeqNum) > EIGHT_COUNT_WINDOW_LEN)
  143. // {
  144. // return -1;
  145. // }
  146. // else
  147. // {
  148. // for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
  149. // {
  150. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  151. // {
  152. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  153. // {
  154. // return -1;
  155. // }
  156. // else
  157. // {
  158. // pSessionInfo->InboundRecv |= (1<<i);
  159. // }
  160. // }
  161. // }
  162. // }
  163. // }
  164. // else
  165. // {
  166. // if((SessionSeqNum - pSessionInfo->InboundSeq) > EIGHT_COUNT_WINDOW_LEN)
  167. // {
  168. // return -1;
  169. // }
  170. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
  171. // for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq); i++)
  172. // {
  173. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  174. // }
  175. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  176. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq)-1));
  177. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  178. // (uint8_t *)&SeqTrac[0],
  179. // (sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  180. // pSessionInfo->InboundSeq = SessionSeqNum;
  181. // }
  182. // }
  183. // else if((pSessionInfo->InboundSeq < EIGHT_COUNT_WINDOW_LEN)
  184. // || (pSessionInfo->InboundSeq > (SEQNUM_ROLLOVER -EIGHT_COUNT_WINDOW_LEN))) /* Checking for Roll over condition */
  185. // {
  186. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  187. // {
  188. // if(!((((pSessionInfo->InboundSeq -SessionSeqNum) <= EIGHT_COUNT_WINDOW_LEN) &&
  189. // (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) >= EIGHT_COUNT_WINDOW_LEN )) ||
  190. // ((((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= EIGHT_COUNT_WINDOW_LEN ) &&
  191. // (pSessionInfo->InboundSeq -SessionSeqNum) >= EIGHT_COUNT_WINDOW_LEN)))
  192. // {
  193. // return -1;
  194. // }
  195. // else
  196. // {
  197. // if((pSessionInfo->InboundSeq -SessionSeqNum) <= EIGHT_COUNT_WINDOW_LEN)
  198. // {
  199. // for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
  200. // {
  201. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  202. // {
  203. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  204. // {
  205. // return -1;
  206. // }
  207. // else
  208. // {
  209. // pSessionInfo->InboundRecv |= (1<<i);
  210. // }
  211. // }
  212. // }
  213. // }
  214. // else if(((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= EIGHT_COUNT_WINDOW_LEN )
  215. // {
  216. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
  217. // for(i=0; i < ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1); i++)
  218. // {
  219. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  220. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  221. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  222. // {
  223. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  224. // TrackRollOver = TRUE;
  225. // }
  226. // else if(TrackRollOver == TRUE)
  227. // {
  228. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  229. // TrackRollOverSeq--;
  230. // }
  231. // }
  232. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  233. // TrackRollOver = FALSE;
  234. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1);
  235. // pSessionInfo->InboundRecv |= (1 << (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) -1));
  236. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[(SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1],
  237. // (uint8_t *)&SeqTrac[0],
  238. // (sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1))));
  239. // pSessionInfo->InboundSeq = SessionSeqNum;
  240. // }
  241. // }
  242. // }
  243. // else if(SessionSeqNum > pSessionInfo->InboundSeq)
  244. // {
  245. // if(!((((SessionSeqNum -pSessionInfo->InboundSeq) <= EIGHT_COUNT_WINDOW_LEN) &&
  246. // (((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) >= EIGHT_COUNT_WINDOW_LEN )) ||
  247. // ((((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) <= EIGHT_COUNT_WINDOW_LEN ) &&
  248. // (SessionSeqNum-pSessionInfo->InboundSeq) >= EIGHT_COUNT_WINDOW_LEN)))
  249. // {
  250. // return -1;
  251. // }
  252. // else
  253. // {
  254. // if((SessionSeqNum - pSessionInfo->InboundSeq) <= EIGHT_COUNT_WINDOW_LEN)
  255. // {
  256. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * EIGHT_COUNT_WINDOW_LEN));
  257. // for(i=0;i<(SessionSeqNum - pSessionInfo->InboundSeq) ;i++)
  258. // {
  259. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  260. // {
  261. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  262. // }
  263. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  264. // {
  265. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  266. // TrackRollOver = TRUE;
  267. // }
  268. // else if(TrackRollOver == TRUE)
  269. // {
  270. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  271. // TrackRollOverSeq--;
  272. // }
  273. // }
  274. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  275. // TrackRollOver = FALSE;
  276. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  277. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq) -1));
  278. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  279. // (uint8_t *)&SeqTrac[0],
  280. // (sizeof(uint32_t) *(EIGHT_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  281. // pSessionInfo->InboundSeq = SessionSeqNum;
  282. // }
  283. // else if(((SEQNUM_ROLLOVER -SessionSeqNum) + pSessionInfo->InboundSeq+1) <= EIGHT_COUNT_WINDOW_LEN)
  284. // {
  285. // for(i=0;i<EIGHT_COUNT_WINDOW_LEN;i++)
  286. // {
  287. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  288. // {
  289. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  290. // {
  291. // return -1;
  292. // }
  293. // else
  294. // {
  295. // pSessionInfo->InboundRecv |= (1<<i);
  296. // }
  297. // }
  298. // }
  299. // }
  300. // }
  301. // }
  302. // }
  303. // }
  304. // return 0;
  305. // }
  306. /*-------------------------------------------
  307. * ProcessRMCPReq
  308. *-------------------------------------------*/
  309. uint32_t
  310. ProcessRMCPReq( RMCPHdr_T* pRMCPReq, RMCPHdr_T* pRMCPRes)
  311. {
  312. SessionInfo_T* pSessionInfo = NULL;
  313. IPMIMsgHdr_T* pIPMIMsgReq;
  314. IPMIMsgHdr_T* pIPMIMsgRes;
  315. uint8_t* pReqMsgAuthCode;
  316. uint8_t* pResMsgAuthCode;
  317. SessionHdr_T* pReqSessionHdr = ( SessionHdr_T*)(pRMCPReq + 1);
  318. SessionHdr_T* pResSessionHdr = ( SessionHdr_T*)(pRMCPRes + 1);
  319. uint8_t IPMIMsgLen;
  320. uint32_t SessionID;
  321. uint32_t ResLen, IPMIMsgResLen;
  322. MsgPkt_T Req,Res;
  323. /* Validate RMCP Header */
  324. if (TRUE != ValidateRMCPHdr(pRMCPReq))
  325. {
  326. printf ("RMCP.c : RMCP header validation failed\r\n");
  327. return 0;
  328. }
  329. /* If RMCP Ping, process it seperately */
  330. if (pRMCPReq->MsgClass == 0x06)
  331. {
  332. return ProcessPingMsg (pRMCPReq, pRMCPRes);
  333. }
  334. /* Process IPMI 2.0 Separately */
  335. #if IPMI20_SUPPORT == 1
  336. // if (RMCP_PLUS_FORMAT == pReqSessionHdr->AuthType)
  337. // {
  338. // ResLen = Proc20Payload (pRMCPReq, pRMCPRes);
  339. // }
  340. // else
  341. #endif
  342. {
  343. SessionID = pReqSessionHdr->SessionID;
  344. /* Get Session Information */
  345. pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
  346. if (0 == pReqSessionHdr->AuthType)
  347. {
  348. IPMIMsgLen = (uint8_t) (*(( uint8_t*)(pReqSessionHdr + 1)));
  349. pIPMIMsgReq = ( IPMIMsgHdr_T*) ((( uint8_t*)(pReqSessionHdr + 1)) +
  350. sizeof (IPMIMsgLen));
  351. pIPMIMsgRes = ( IPMIMsgHdr_T*) ((( uint8_t*)(pResSessionHdr + 1)) +
  352. sizeof (IPMIMsgLen));
  353. }
  354. else
  355. {
  356. pReqMsgAuthCode = (( uint8_t*)(pReqSessionHdr + 1));
  357. pResMsgAuthCode = (( uint8_t*)(pResSessionHdr + 1));
  358. IPMIMsgLen = *(pReqMsgAuthCode + AUTH_CODE_LEN);
  359. pIPMIMsgReq = ( IPMIMsgHdr_T*) (pReqMsgAuthCode + AUTH_CODE_LEN +
  360. sizeof (IPMIMsgLen));
  361. pIPMIMsgRes = ( IPMIMsgHdr_T*) (pResMsgAuthCode + AUTH_CODE_LEN +
  362. sizeof (IPMIMsgLen));
  363. if (TRUE != ValidateAuthCode (pReqMsgAuthCode, g_BMCInfo.pUserInfo->UserPassword,
  364. pReqSessionHdr, pIPMIMsgReq))
  365. {
  366. printf("Password error!\n");
  367. return 0;
  368. }
  369. //TODO:pSessionInfo->Password到底是在哪里赋值的?在这里可以吗?
  370. //memcpy(pSessionInfo->Password,g_BMCInfo.pUserInfo->UserPassword,MAX_PASSWORD_LEN);
  371. }
  372. /* Frame the Message Packet for Message Handler */
  373. Req.Param = PARAM_IFC;
  374. Req.Cmd = pIPMIMsgReq->Cmd;
  375. Req.NetFnLUN = pIPMIMsgReq->NetFnLUN;
  376. Req.SessionID = SessionID;
  377. Req.SessionType = LAN_SESSION_TYPE;
  378. Req.Channel = LAN_RMCP_CHANNEL;
  379. //UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
  380. Req.Size = IPMIMsgLen;
  381. memcpy(Req.Data, ( uint8_t*) pIPMIMsgReq, Req.Size);
  382. /* Post Msg to MsgHndlr and Get Res */
  383. if (0 != ProcIPMIReq (pSessionInfo, PAYLOAD_IPMI_MSG, &Req, &Res))
  384. {
  385. return 0;
  386. }
  387. /* Fill Response data */
  388. memcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
  389. /* Fill Authentication Code */
  390. if (0 != pReqSessionHdr->AuthType)
  391. {
  392. pResMsgAuthCode = ( uint8_t*)(pResSessionHdr + 1);
  393. pIPMIMsgRes = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
  394. AUTH_CODE_LEN + sizeof (IPMIMsgLen));
  395. IPMIMsgResLen = AUTH_CODE_LEN + sizeof (IPMIMsgLen) + Res.Size;
  396. /* Fill IPMI Message */
  397. memcpy (pIPMIMsgRes, Res.Data, Res.Size);
  398. *(pResMsgAuthCode + AUTH_CODE_LEN) = Res.Size;
  399. // ComputeAuthCode ((uint8_t*)g_BMCInfo.pUserInfo->UserPassword, pResSessionHdr, pIPMIMsgRes,
  400. // pResMsgAuthCode, MULTI_SESSION_CHANNEL);
  401. }
  402. else
  403. {
  404. pIPMIMsgRes = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
  405. sizeof (IPMIMsgLen));
  406. IPMIMsgResLen = Res.Size + sizeof (IPMIMsgLen);
  407. /* Fill IPMI Message */
  408. memcpy (pIPMIMsgRes, Res.Data, Res.Size);
  409. *(( uint8_t*) (pResSessionHdr + 1)) = Res.Size;
  410. }
  411. // if( (NETFN_APP == (pIPMIMsgReq->NetFnLUN >> 2)) && (CMD_GET_SESSION_CHALLENGE == pIPMIMsgReq->Cmd) &&
  412. // (CC_GET_SESSION_INVALID_USER == Res.Data[sizeof(IPMIMsgHdr_T)]) && (NULL == pSessionInfo) )
  413. // {
  414. // if ( 0 != AddLoginEvent( 0xFF, &pBMCInfo->LANConfig.MsgReq.Data[7], EVENT_LOGIN_FAILURE, BMCInst ))
  415. // {
  416. // TCRIT("Problem while adding Log record \n");
  417. // }
  418. // }
  419. ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr_T) + IPMIMsgResLen;
  420. }
  421. return ResLen;
  422. }
  423. /**
  424. * @brief Process the IPMI request and prepare response.
  425. * @param pSessionInfo - Session information.
  426. * @param Payload - Payload type.
  427. * @return 0 if success, -1 if error.
  428. **/
  429. int ProcIPMIReq ( SessionInfo_T* pSessionInfo, uint8_t Payload, MsgPkt_T *pReq, MsgPkt_T *pRes)
  430. {
  431. // ChannelInfo_T* pChannelInfo;
  432. // int RetVal = 0;
  433. //printf("ProcIPMIReq\n");
  434. /* Frame the Message Packet for Message Handler */
  435. pReq->Param = PARAM_IFC;
  436. pReq->SrcQ = gFd_LanResQ;
  437. if (PAYLOAD_IPMI_MSG == Payload)
  438. {
  439. // printf("\n\n===> Post to MsgHndlr\n");
  440. PostMsg (gFd_MsgHndlrIfc, pReq);
  441. }
  442. if ( GetMsg (gFd_LanResQ, pRes, DEFAULT_TIMEOUT) != 0)
  443. {
  444. //FillIPMIResFailure (pReq, pRes);
  445. printf("Warning: RMCP get message error!\n");
  446. }
  447. // printf("===> gFd_LanResQ Recv: ");
  448. // int i;
  449. // for(i=0;i<pRes->Size;i++)
  450. // printf("%#x ", pRes->Data[i]);
  451. // printf("\n");
  452. if (PARAM_NO_RESPONSE == pRes->Param)
  453. {
  454. printf ("RMCP.c : No response from message handler\n");
  455. return -1;
  456. }
  457. //printf("ProcIPMIReq get response: Param %#x, netfn %#x, cmd %#x, len %#x\n", pRes->Param, pRes->NetFnLUN, pRes->Cmd, pRes->Size);
  458. if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd == 0x3A) && //Active Session , ipmi2.0 page 613
  459. (PAYLOAD_IPMI_MSG == Payload))
  460. {
  461. //TODO:
  462. }
  463. /* If Request IPMI Message is Close Session */
  464. if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd == 0x3C) && //close session
  465. (PAYLOAD_IPMI_MSG == Payload))
  466. {
  467. //TODO:
  468. }
  469. return 0;
  470. }
  471. /**
  472. * @brief Validate RMCP Header
  473. * @param pRMCPHdr - RMCP header.
  474. * @return TRUE if valid, FALSE if invalid.
  475. **/
  476. static uint8_t
  477. ValidateRMCPHdr ( RMCPHdr_T* pRMCPHdr)
  478. {
  479. /* If RMCP Packet is NULL */
  480. if (pRMCPHdr == NULL)
  481. {
  482. printf ("RMCP.c : RMCP Packet is NULL\n");
  483. return FALSE;
  484. }
  485. /* Verify RMCP Version */
  486. if (pRMCPHdr->Version != RMCP_VERSION)
  487. {
  488. printf ("RMCP.c : Invalid RMCP Version\n");
  489. return FALSE;
  490. }
  491. /* LOOK for RMCP MessageClass */
  492. if ((pRMCPHdr->MsgClass != IPMI_MESSAGE_CLASS) &&
  493. (pRMCPHdr->MsgClass != 0x06))
  494. {
  495. printf ("RMCP.c : Invalid Message Class\n");
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. // /**
  501. // * @brief Validate session header.
  502. // * @param SessionID - Session ID.
  503. // * @param SeqNo - Session Sequence Number.
  504. // * @return TRUE if valid, FALSE if invalid.
  505. // **/
  506. // static bool
  507. // ValidateSessionHdr (uint32_t SessionID, uint32_t SeqNo )
  508. // {
  509. // SessionInfo_T* pSessionInfo;
  510. // /* if its Pre Session commands */
  511. // if (0 == SessionID)
  512. // {
  513. // return TRUE;
  514. // }
  515. // pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
  516. // if ( pSessionInfo == NULL)
  517. // {
  518. // return FALSE;
  519. // }
  520. // /* If packet is already received - drop the packet */
  521. // /* if (ntohs(SeqNo) <= ntohs (CAST_32 (&pSessionInfo->InboundSeq)))
  522. // {
  523. // IPMI_DBG_PRINT ("RMCP: Duplicate Seq No - Packet dropped\n");
  524. // return FALSE;
  525. // }
  526. // */
  527. // /* inc the Sequence No */
  528. // return TRUE;
  529. // }
  530. /**
  531. * @brief Process RMCP Ping Message.
  532. * @param pRMCPReq - Request RMCP message.
  533. * @param pRMCPRes - Response RMCP message.
  534. * @return the response length.
  535. **/
  536. static uint8_t
  537. ProcessPingMsg ( RMCPHdr_T* pRMCPReq, RMCPHdr_T* pRMCPRes )
  538. {
  539. RMCPPingHdr_T* pReqPingHdr = ( RMCPPingHdr_T*)(pRMCPReq + 1);
  540. RMCPPingHdr_T* pResPingHdr = ( RMCPPingHdr_T*)(pRMCPRes + 1);
  541. if (PRESENCE_PING_MSGTYPE != pReqPingHdr->MsgType) { return 0; }
  542. if((pReqPingHdr->IANANum[0]!=0x00)||(pReqPingHdr->IANANum[1]!=0x00)||
  543. (pReqPingHdr->IANANum[2]!=0x11)||(pReqPingHdr->IANANum[3]!=0xBE))
  544. { return 0; }
  545. /* Construct Response Header */
  546. memcpy (pResPingHdr, pReqPingHdr, sizeof (RMCPPingHdr_T));
  547. pResPingHdr->MsgType = 0x40;
  548. pResPingHdr->DataLen = 0x10;
  549. /* Fill Response Data */
  550. memset (pResPingHdr + 1, 0, pResPingHdr->DataLen);
  551. *(( uint8_t*)(pResPingHdr + 1) + 8) = 0x81;
  552. *(( uint8_t*)(pResPingHdr + 1) + 4) = PING_IPMI_15_SUPPORT;
  553. #if IPMI20_SUPPORT == 1
  554. // *(( uint8_t*)(pResPingHdr + 1) + 4) |= PING_IPMI_20_SUPPORT;
  555. #endif
  556. // /*Update the OEM IANA Number for DCMI Discovery (36465 = Data Center Manageability Forum,Spec .1.5)*/
  557. // if(g_corefeatures.dcmi_1_5_support == ENABLED)
  558. // {
  559. // if(pBMCInfo->IpmiConfig.DCMISupport == 1)
  560. // {
  561. // *(( uint8_t*)(pResPingHdr + 1) + 2) = 0x8E;
  562. // *(( uint8_t*)(pResPingHdr + 1) + 3) = 0x71;
  563. // }
  564. // }
  565. return (sizeof (RMCPHdr_T) + sizeof (RMCPPingHdr_T) + pResPingHdr->DataLen);
  566. }
  567. /**
  568. * @brief Validate Authentication Code
  569. * @param pAuthCode - Request authentication code.
  570. * @param pPassword - Password string.
  571. * @param pSessionHdr - Request Session header.
  572. * @param pIPMIMsg - Request IPMI message.
  573. * @return TRUE if valid, FALSE if invalid.
  574. **/
  575. static uint8_t
  576. ValidateAuthCode ( uint8_t* pAuthCode, uint8_t* pPassword,
  577. SessionHdr_T* pSessionHdr, IPMIMsgHdr_T* pIPMIMsg)
  578. {
  579. uint8_t ComputedAuthCode [AUTH_CODE_LEN];
  580. memset(ComputedAuthCode, 0, sizeof (ComputedAuthCode));
  581. ComputeAuthCode (pPassword, pSessionHdr, pIPMIMsg,
  582. ComputedAuthCode, MULTI_SESSION_CHANNEL);
  583. // int i;
  584. // printf("pAuthCode: ");
  585. // for(i=0;i<AUTH_CODE_LEN;i++)
  586. // printf("%#x ", pAuthCode[i]);
  587. // printf("\n");
  588. // printf("pPassword: %s\n", pPassword);
  589. // printf("pComputeAuthCode: ");
  590. // for(i=0;i<AUTH_CODE_LEN;i++)
  591. // printf("%#x ", ComputedAuthCode[i]);
  592. // printf("\n");
  593. return (0 == memcmp (pAuthCode, ComputedAuthCode, AUTH_CODE_LEN));
  594. }
  595. #if IPMI20_SUPPORT
  596. // /*-------------------------------------------
  597. // * Frame20Payload
  598. // *-------------------------------------------*/
  599. // int
  600. // Frame20Payload (uint8_t PayloadType, RMCPHdr_T* pRMCPPkt,
  601. // uint8_t* pPayload, uint32_t PayloadLen,
  602. // SessionInfo_T* pSessionInfo )
  603. // {
  604. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  605. // SessionHdr2_T* pResSessionHdr = ( SessionHdr2_T*)(pRMCPPkt + 1);
  606. // uint8_t* pRes = ( uint8_t*)(pResSessionHdr + 1);
  607. // uint8_t* pConfHdr;
  608. // uint8_t* pConfPayld;
  609. // uint8_t* pIntPad;
  610. // uint8_t* pResMsgAuthCode;
  611. // uint8_t ConfPadLen, IntPadLen;
  612. // INT16U ConfPayldLen, AuthCodeLen;
  613. // int i, ResLen;
  614. // unsigned int seed = 1;
  615. // /* Fill Session Hdr */
  616. // pResSessionHdr->AuthType = RMCP_PLUS_FORMAT;
  617. // pResSessionHdr->PayloadType = PayloadType;
  618. // if (NULL == pSessionInfo)
  619. // {
  620. // pResSessionHdr->SessionID = 0;
  621. // pResSessionHdr->SessionSeqNum = 0;
  622. // }
  623. // else
  624. // {
  625. // /* Response packets should send the Remote Console
  626. // * Session ID so the remote console can correctly
  627. // * match up the session with its own table of active
  628. // * session IDs. */
  629. // pResSessionHdr->SessionID = pSessionInfo->RemConSessionID;
  630. // /* Increment session sequence number */
  631. // /* During RMCP Opensession , OutboundSeq initialized to 0 and but 0 is reserved */
  632. // /* and also When It reach 0xffffffff then It become zero */
  633. // if(0==pSessionInfo->OutboundSeq)
  634. // {
  635. // pSessionInfo->OutboundSeq=1;
  636. // }
  637. // pResSessionHdr->SessionSeqNum = htoipmi_u32(pSessionInfo->OutboundSeq++);
  638. // }
  639. // /* Fill Payload and Do Encryption if needed */
  640. // if ((NULL != pSessionInfo) &&
  641. // (0 != (pResSessionHdr->PayloadType & CONFIDENT_MASK)))
  642. // {
  643. // pConfHdr = ( uint8_t*)(pResSessionHdr + 1);
  644. // switch (pSessionInfo->ConfidentialityAlgorithm)
  645. // {
  646. // case CONF_AES_CBC_128:
  647. // /* Fill Init Vector */
  648. // for (i =0; i < CONF_AES_CBC_128_HDR_LEN; i++)
  649. // {
  650. // pConfHdr [i] = (uint8_t)rand_r (&seed);
  651. // }
  652. // pConfPayld = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
  653. // /* Add Padding; include size of confpadlen */
  654. // ConfPadLen = (PayloadLen + 1) % CONF_BLOCK_SIZE;
  655. // if (0 != ConfPadLen)
  656. // {
  657. // ConfPadLen = CONF_BLOCK_SIZE - ConfPadLen;
  658. // }
  659. // for (i = 0; i < ConfPadLen; i++)
  660. // {
  661. // *(pPayload + PayloadLen + i) = i + 1;
  662. // }
  663. // *(pPayload + PayloadLen + ConfPadLen) = ConfPadLen;
  664. // ConfPayldLen = PayloadLen + ConfPadLen + 1;
  665. // aesEncrypt (( uint8_t*)pPayload, ConfPayldLen,
  666. // ( uint8_t*)pConfHdr, pSessionInfo->Key2,
  667. // ( uint8_t*)pConfPayld);
  668. // IPMI_DBG_PRINT_BUF (( uint8_t*)pConfPayld, ConfPayldLen);
  669. // PayloadLen = ConfPayldLen + CONF_AES_CBC_128_HDR_LEN;
  670. // pBMCInfo->LANConfig.MsgReq.Size = PayloadLen;
  671. // break;
  672. // case CONF_xCR4_128:
  673. // case CONF_xCR4_40:
  674. // default:
  675. // IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
  676. // return 0;
  677. // }
  678. // }
  679. // else
  680. // {
  681. // _fmemcpy (pRes, pPayload, PayloadLen);
  682. // }
  683. // /* Fill Payload Length */
  684. // pResSessionHdr->IPMIMsgLen = htoipmi_u16 (PayloadLen);
  685. // ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T) + PayloadLen;
  686. // /* Add Integrity Check Value */
  687. // if ((NULL != pSessionInfo) &&
  688. // (0 != (pResSessionHdr->PayloadType & INTEGRITY_MASK)))
  689. // {
  690. // /* Add Integrity Pad */
  691. // pIntPad = ( uint8_t*)(pResSessionHdr + 1) + PayloadLen;
  692. // IntPadLen = (sizeof (SessionHdr2_T) + PayloadLen + 2) % sizeof (uint32_t);
  693. // if (0 != IntPadLen)
  694. // {
  695. // IntPadLen = sizeof(uint32_t) - IntPadLen;
  696. // }
  697. // _fmemset (pIntPad, 0xFF, IntPadLen);
  698. // *(pIntPad + IntPadLen) = IntPadLen; /* Integrity Pad Len */
  699. // *(pIntPad + IntPadLen + 1) = 0x07; /* Next Header */
  700. // pResMsgAuthCode = pIntPad + IntPadLen + 2;
  701. // AuthCodeLen = sizeof (SessionHdr2_T) + PayloadLen + IntPadLen + 2;
  702. // ResLen += IntPadLen + 2;
  703. // switch (pSessionInfo->IntegrityAlgorithm)
  704. // {
  705. // case AUTH_HMAC_SHA1_96:
  706. // hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
  707. // ( uint8_t*)pResSessionHdr, AuthCodeLen,
  708. // (uint8_t *)pResMsgAuthCode, MAX_INTEGRITY_LEN);
  709. // ResLen += HMAC_SHA1_96_LEN;
  710. // break;
  711. // case AUTH_HMAC_MD5_128:
  712. // hmac_md5(pSessionInfo->Key1,HASH_KEY1_SIZE,( uint8_t*)pResSessionHdr, AuthCodeLen,
  713. // pResMsgAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
  714. // ResLen += HMAC_MD5_LEN;
  715. // break;
  716. // case AUTH_MD5_128:
  717. // MD5_128((char *)pSessionInfo->Password,MAX_PASSWORD_LEN,( INT8S*)pResSessionHdr, AuthCodeLen,
  718. // (char *)pResMsgAuthCode, MAX_MD5_INTEGRITY_LEN);
  719. // ResLen += MD5_LEN;
  720. // break;
  721. // case AUTH_HMAC_SHA256_128:
  722. // hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pResSessionHdr,
  723. // AuthCodeLen, (unsigned char *)pResMsgAuthCode, HMAC_SHA256_128_LEN);
  724. // ResLen += HMAC_SHA256_128_LEN;
  725. // break;
  726. // default:
  727. // IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
  728. // return 0;
  729. // }
  730. // }
  731. // return ResLen;
  732. // }
  733. // int RMCPplusSeqNumValidation(SessionInfo_T * pSessionInfo,uint32_t SessionSeqNum)
  734. // {
  735. // uint32_t SeqTrac[SIXTEEN_COUNT_WINDOW_LEN];
  736. // bool TrackRollOver = FALSE;
  737. // uint32_t TrackRollOverSeq = SEQNUM_ROLLOVER;
  738. // int i=0;
  739. // if( pSessionInfo->InboundSeq == SessionSeqNum)
  740. // return -1;
  741. // if((pSessionInfo->InboundSeq < (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT)) && (pSessionInfo->InboundSeq > RMCPPLUS_SEQLOWLIMIT))
  742. // {
  743. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  744. // {
  745. // if((pSessionInfo->InboundSeq -SessionSeqNum) > RMCPPLUS_SEQLOWLIMIT)
  746. // return -1;
  747. // else
  748. // {
  749. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  750. // {
  751. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  752. // {
  753. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  754. // return -1;
  755. // else
  756. // pSessionInfo->InboundRecv |= (1<<i);
  757. // }
  758. // }
  759. // }
  760. // }
  761. // else
  762. // {
  763. // if((SessionSeqNum - pSessionInfo->InboundSeq) > RMCPPLUS_SEQUPLIMIT)
  764. // return -1;
  765. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  766. // for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq); i++)
  767. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  768. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  769. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq)-1));
  770. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  771. // (uint8_t *)&SeqTrac[0],
  772. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  773. // pSessionInfo->InboundSeq = SessionSeqNum;
  774. // }
  775. // }
  776. // else if((pSessionInfo->InboundSeq < RMCPPLUS_SEQLOWLIMIT)
  777. // || (pSessionInfo->InboundSeq > (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT))) /* Checking condition for rollover */
  778. // {
  779. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  780. // {
  781. // if(!((((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT) &&
  782. // (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) >= RMCPPLUS_SEQLOWLIMIT )) ||
  783. // ((((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
  784. // (pSessionInfo->InboundSeq -SessionSeqNum) >= RMCPPLUS_SEQLOWLIMIT)))
  785. // {
  786. // return -1;
  787. // }
  788. // else
  789. // {
  790. // if((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT)
  791. // {
  792. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  793. // {
  794. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  795. // {
  796. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  797. // return -1;
  798. // else
  799. // pSessionInfo->InboundRecv |= (1<<i);
  800. // }
  801. // }
  802. // }
  803. // else if(((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQUPLIMIT )
  804. // {
  805. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  806. // for(i=0; i < ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) ; i++)
  807. // {
  808. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  809. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  810. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  811. // {
  812. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  813. // TrackRollOver = TRUE;
  814. // }
  815. // else if(TrackRollOver == TRUE)
  816. // {
  817. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  818. // TrackRollOverSeq--;
  819. // }
  820. // }
  821. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  822. // TrackRollOver = FALSE;
  823. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1);
  824. // pSessionInfo->InboundRecv |= (1 << (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) -1));
  825. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[(SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1],
  826. // (uint8_t *)&SeqTrac[0],
  827. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1))));
  828. // pSessionInfo->InboundSeq = SessionSeqNum;
  829. // }
  830. // }
  831. // }
  832. // else if(SessionSeqNum > pSessionInfo->InboundSeq)
  833. // {
  834. // if(!((((SessionSeqNum -pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT) &&
  835. // (((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) >= RMCPPLUS_SEQUPLIMIT )) ||
  836. // ((((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
  837. // (SessionSeqNum-pSessionInfo->InboundSeq) >= RMCPPLUS_SEQLOWLIMIT)))
  838. // {
  839. // return -1;
  840. // }
  841. // else
  842. // {
  843. // if((SessionSeqNum - pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT)
  844. // {
  845. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  846. // for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq) ; i++)
  847. // {
  848. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  849. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  850. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  851. // {
  852. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  853. // TrackRollOver = TRUE;
  854. // }
  855. // else if(TrackRollOver == TRUE)
  856. // {
  857. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  858. // TrackRollOverSeq--;
  859. // }
  860. // }
  861. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  862. // TrackRollOver = FALSE;
  863. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  864. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq) -1));
  865. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  866. // (uint8_t *)&SeqTrac[0],
  867. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  868. // pSessionInfo->InboundSeq = SessionSeqNum;
  869. // }
  870. // else if(((SEQNUM_ROLLOVER -SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT)
  871. // {
  872. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  873. // {
  874. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  875. // {
  876. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  877. // return -1;
  878. // else
  879. // pSessionInfo->InboundRecv |= (1<<i);
  880. // }
  881. // }
  882. // }
  883. // }
  884. // }
  885. // }
  886. // return 0;
  887. // }
  888. // /**
  889. // * @brief Process IPMI 2.0 Payload.
  890. // * @param pRMCPReq - RMCP request message.
  891. // * @param pRMCPRes _ RMCP response message.
  892. // * @return 0 if success, -1 if error.
  893. // **/
  894. // static int
  895. // Proc20Payload ( RMCPHdr_T* pRMCPReq, RMCPHdr_T* pRMCPRes, MiscParams_T *pParams,uint8_t Channel )
  896. // {
  897. // SessionHdr2_T* pReqSession2Hdr = ( SessionHdr2_T*)(pRMCPReq + 1);
  898. // SessionHdr2_T* pResSession2Hdr = ( SessionHdr2_T*)(pRMCPRes + 1);
  899. // uint8_t* pReq = ( uint8_t *)(pReqSession2Hdr + 1);
  900. // uint8_t* pRes = ( uint8_t *)(pResSession2Hdr + 1);
  901. // SessionInfo_T* pSessionInfo = NULL;
  902. // uint8_t* pIntPad;
  903. // uint8_t* pConfHdr;
  904. // uint8_t* pConfPayld;
  905. // uint8_t* pReqMsgAuthCode;
  906. // UserInfo_T* pUserInfo;
  907. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  908. // uint8_t Payload, IntPadLen, ComputedAuthCode [25];
  909. // INT16U IPMIMsgLen, AuthCodeLen, ConfPayldLen;
  910. // uint32_t SessionID;
  911. // uint32_t SessionSeqNum;
  912. // int len, i;
  913. // uint8_t UserPswd [MAX_PASSWORD_LEN];
  914. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  915. // /* Get SessionID & Session Seq */
  916. // SessionID = pReqSession2Hdr->SessionID;
  917. // SessionSeqNum = pReqSession2Hdr->SessionSeqNum;
  918. // /* Validate IPMI Session Header */
  919. // if (TRUE != ValidateSessionHdr (SessionID, SessionSeqNum, BMCInst))
  920. // {
  921. // // IPMI_WARNING ("RMCP.c : IPMI Session header validation failed\n");
  922. // return 0;
  923. // }
  924. // IPMIMsgLen = ipmitoh_u16 (pReqSession2Hdr->IPMIMsgLen);
  925. // Payload = pReqSession2Hdr->PayloadType & 0x3F;
  926. // /* Process PreSession Payloads */
  927. // for (i = 0; i < sizeof (m_PayloadTbl) / sizeof (m_PayloadTbl [0]); i++)
  928. // {
  929. // if (m_PayloadTbl [i].Payload == Payload)
  930. // {
  931. // /* Copy RMCP & Session Hdr */
  932. // _fmemcpy (( uint8_t*)pRMCPRes, ( uint8_t*)pRMCPReq,
  933. // sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T));
  934. // /* For response the type is type + 1 */
  935. // pResSession2Hdr->PayloadType++;
  936. // /* Copy message tag from request */
  937. // *pRes = *pReq;
  938. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  939. // /* Call the function and pass the data after message tag */
  940. // len = m_PayloadTbl [i].PayloadHndlr ((pReq),
  941. // (uint8_t)(IPMIMsgLen - sizeof (uint8_t)), (pRes), pParams,Channel,BMCInst);
  942. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
  943. // /* Copy the message length */
  944. // pResSession2Hdr->IPMIMsgLen = htoipmi_u16 ((len));
  945. // if(len!=0)
  946. // len += sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T);
  947. // return len;
  948. // }
  949. // }
  950. // /* Check for Invalid Payload Type */
  951. // if ((PAYLOAD_IPMI_MSG != Payload) && (PAYLOAD_SOL != Payload))
  952. // {
  953. // IPMI_WARNING ("RMCP.c : Invalid payload\n");
  954. // return 0;
  955. // }
  956. // /* check for the pre-session commands */
  957. // if (0 == SessionID)
  958. // {
  959. // int i;
  960. // IPMIMsgHdr_T* pIPMIMsg = ( IPMIMsgHdr_T*) pReq;
  961. // for (i=0; i < sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T); i++)
  962. // {
  963. // if ((m_PreSessionCmdsTbl[i].NetFn == (pIPMIMsg->NetFnLUN >> 2)) &&
  964. // (m_PreSessionCmdsTbl[i].Cmd == pIPMIMsg->Cmd))
  965. // {
  966. // pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
  967. // _fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
  968. // break;
  969. // }
  970. // }
  971. // if (i >= (sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T)))
  972. // {
  973. // IPMI_WARNING ("RMCP.c : Presession command not found\n");
  974. // return 0;
  975. // }
  976. // }
  977. // else
  978. // {
  979. // /* Get Session Information */
  980. // pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
  981. // if (NULL == pSessionInfo)
  982. // {
  983. // IPMI_WARNING ("RMCP.c : Proc20Payload - Invalid Session Id\n");
  984. // return 0;
  985. // }
  986. // /* Check if session is activated */
  987. // if (TRUE != pSessionInfo->Activated)
  988. // {
  989. // IPMI_WARNING ("RMCP.c : Session not activated with session id %lx\n", SessionID);
  990. // return 0;
  991. // }
  992. // if(pBMCInfo->IpmiConfig.LinkDownResilentSupport == 1)
  993. // {
  994. // if(pSessionInfo->Linkstat == TRUE)
  995. // {
  996. // pSessionInfo->Linkstat = FALSE;
  997. // memset(pSessionInfo->InboundTrac,0,SIXTEEN_COUNT_WINDOW_LEN);
  998. // }
  999. // }
  1000. // if( (((( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN)>>2==NETFN_APP) &&
  1001. // (((( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd)==CMD_SET_SESSION_PRIV_LEVEL) &&
  1002. // ((pSessionInfo->EventFlag)== 1) )
  1003. // {
  1004. // pSessionInfo->EventFlag=0;
  1005. // if ( 0 != AddLoginEvent ( pSessionInfo->UserId, NULL, EVENT_LOGIN, BMCInst ))
  1006. // {
  1007. // TCRIT("Problem while adding Log record \n");
  1008. // }
  1009. // }
  1010. // if(RMCPplusSeqNumValidation(pSessionInfo,ipmitoh_u32(SessionSeqNum)) != 0)
  1011. // {
  1012. // return 0;
  1013. // }
  1014. // if (0 != (pReqSession2Hdr->PayloadType & INTEGRITY_MASK))
  1015. // {
  1016. // uint8_t Len;
  1017. // /* check Integrity pad which starts from auth type till auth code */
  1018. // pIntPad = ( uint8_t*)(pReqSession2Hdr + 1) + IPMIMsgLen;
  1019. // IntPadLen = (sizeof (SessionHdr2_T) + IPMIMsgLen + 2) % sizeof (uint32_t);
  1020. // if (0 != IntPadLen)
  1021. // {
  1022. // IntPadLen = sizeof(uint32_t) - IntPadLen;
  1023. // }
  1024. // if (pIntPad [IntPadLen] != IntPadLen)
  1025. // {
  1026. // IPMI_WARNING ("RMCP.c : Invalid Padlength\n");
  1027. // return 0;
  1028. // }
  1029. // /* Check auth code */
  1030. // pReqMsgAuthCode = pIntPad + IntPadLen + 2;
  1031. // AuthCodeLen = sizeof (SessionHdr2_T) + IPMIMsgLen + IntPadLen + 2;
  1032. // switch (pSessionInfo->IntegrityAlgorithm)
  1033. // {
  1034. // case AUTH_HMAC_SHA1_96:
  1035. // hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
  1036. // ( uint8_t*)pReqSession2Hdr, AuthCodeLen,
  1037. // ( uint8_t*)ComputedAuthCode, MAX_INTEGRITY_LEN);
  1038. // Len = HMAC_SHA1_96_LEN;
  1039. // break;
  1040. // case AUTH_HMAC_MD5_128:
  1041. // hmac_md5 (pSessionInfo->Key1, HASH_KEY1_SIZE,
  1042. // ( uint8_t*)pReqSession2Hdr, AuthCodeLen,
  1043. // ( uint8_t*)ComputedAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
  1044. // Len = HMAC_MD5_LEN;
  1045. // break;
  1046. // case AUTH_MD5_128:
  1047. // /* Get User Info */
  1048. // pUserInfo = getUserIdInfo((uint8_t)pSessionInfo->UserId, BMCInst);
  1049. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1050. // {
  1051. // /* Get Encryption Key from the MBMCInfo_t structure */
  1052. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1053. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pSessionInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1054. // {
  1055. // TCRIT("Error in decrypting the user password for user ID:%d. .\n", pSessionInfo->UserId);
  1056. // return -1;
  1057. // }
  1058. // }
  1059. // else
  1060. // {
  1061. // _fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  1062. // }
  1063. // MD5_128((char *)pUserInfo->UserPassword, MAX_PASSWORD_LEN,
  1064. // ( INT8S*)pReqSession2Hdr, AuthCodeLen,
  1065. // ( INT8S*)ComputedAuthCode, MAX_MD5_INTEGRITY_LEN);
  1066. // Len= MD5_LEN;
  1067. // break;
  1068. // case AUTH_HMAC_SHA256_128:
  1069. // hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pReqSession2Hdr,
  1070. // AuthCodeLen, (unsigned char *)ComputedAuthCode, SHA2_HASH_KEY_SIZE);
  1071. // Len= HMAC_SHA256_128_LEN;
  1072. // break;
  1073. // default:
  1074. // IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
  1075. // return 0;
  1076. // }
  1077. // IPMI_DBG_PRINT_BUF (( uint8_t*)ComputedAuthCode, Len);
  1078. // if (0 != _fmemcmp (( uint8_t*)ComputedAuthCode, pReqMsgAuthCode, Len))
  1079. // {
  1080. // return 0;
  1081. // }
  1082. // }
  1083. // /* Decrypt the message if Encrypted */
  1084. // /* Verify confidentiality header and trailer */
  1085. // if (0 != (pReqSession2Hdr->PayloadType & CONFIDENT_MASK))
  1086. // {
  1087. // pConfHdr = ( uint8_t*)(pReqSession2Hdr + 1);
  1088. // switch (pSessionInfo->ConfidentialityAlgorithm)
  1089. // {
  1090. // case CONF_AES_CBC_128:
  1091. // pConfPayld = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
  1092. // ConfPayldLen = IPMIMsgLen - CONF_AES_CBC_128_HDR_LEN;
  1093. // aesDecrypt (( uint8_t*)pConfPayld, ConfPayldLen,
  1094. // ( uint8_t*)pConfHdr, pSessionInfo->Key2,
  1095. // ( uint8_t*)pBMCInfo->LANConfig.MsgReq.Data);
  1096. // /* Remove pad length */
  1097. // if (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] > CONF_BLOCK_SIZE)
  1098. // {
  1099. // IPMI_WARNING ("Invalid Conf Blocke size %d\n", pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1]);
  1100. // return 0;
  1101. // }
  1102. // ConfPayldLen -= (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] + 1);
  1103. // break;
  1104. // case CONF_xCR4_128:
  1105. // case CONF_xCR4_40:
  1106. // default:
  1107. // IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
  1108. // return 0;
  1109. // }
  1110. // pBMCInfo->LANConfig.MsgReq.Size = ConfPayldLen;
  1111. // }
  1112. // else
  1113. // {
  1114. // pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
  1115. // _fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
  1116. // }
  1117. // }
  1118. // /* Fill IPMI MsgPkt Request */
  1119. // pBMCInfo->LANConfig.MsgReq.Cmd = (( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd;
  1120. // pBMCInfo->LANConfig.MsgReq.NetFnLUN = (( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN;
  1121. // pBMCInfo->LANConfig.MsgReq.SessionID = SessionID;
  1122. // pBMCInfo->LANConfig.MsgReq.SessionType = LAN_SESSION_TYPE;
  1123. // pBMCInfo->LANConfig.MsgReq.Channel =Channel;
  1124. // UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
  1125. // // Moved to line 966
  1126. // // Bug : if SessionID is 0 this Unlock will be called without a Lock
  1127. // //UNLOCK_BMC_SHARED_MEM();
  1128. // /* Process IPMI Request */
  1129. // if (0 != ProcIPMIReq (pSessionInfo, Payload, pParams,Channel, BMCInst))
  1130. // {
  1131. // return 0;
  1132. // }
  1133. // /* Fill Response data */
  1134. // _fmemcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
  1135. // return Frame20Payload (pReqSession2Hdr->PayloadType, pRMCPRes,
  1136. // pBMCInfo->LANConfig.MsgRes.Data, pBMCInfo->LANConfig.MsgRes.Size, pSessionInfo, BMCInst);
  1137. // }
  1138. // /****************************************************************************
  1139. // * fn AddLoginEvent
  1140. // * params:
  1141. // * pRMCPSession pointer to RMCP Session information
  1142. // * EvtType 0x9 - login, 0xa - logout, 0xb - autologout, 0xc - connection lost
  1143. // *
  1144. // * return 0 - success, -1 - failure
  1145. // ***************************************************************************/
  1146. // int AddLoginEvent ( uint8_t UserID, uint8_t* UserName, uint8_t EvtType )
  1147. // {
  1148. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1149. // int reslen = 0, ret = -1;
  1150. // int i = 0;
  1151. // AddSELRes_T AddSelRes;
  1152. // uint8_t IPAddr[IP_ADDR_LEN];
  1153. // SELOEM1Record_T OEMSELRec;
  1154. // #ifdef CONFIG_SPX_FEATURE_IANA_0
  1155. // uint8_t MfgID[] = { CONFIG_SPX_FEATURE_IANA_2,
  1156. // CONFIG_SPX_FEATURE_IANA_1,
  1157. // CONFIG_SPX_FEATURE_IANA_0 };
  1158. // #else
  1159. // uint8_t MfgID[] = { 0, 0, 0 };
  1160. // #endif
  1161. // /* Hook for RMCP Login Audit */
  1162. // if (g_PDKHandle[PDK_RMCPLOGINAUDIT] != NULL)
  1163. // {
  1164. // /* Return if event type bit is not set in event mask */
  1165. // for (i = 0; i < sizeof(m_IPMIAuditMaskMap)/sizeof(IPMIAuditMaskTbl_T); i++)
  1166. // {
  1167. // if ((EvtType == m_IPMIAuditMaskMap[i].EventType) &&
  1168. // (!(pBMCInfo->LoginAuditCfg.IPMIEventMask >> m_IPMIAuditMaskMap[i].EventMask) & 0x01))
  1169. // {
  1170. // return reslen;
  1171. // }
  1172. // }
  1173. // ret = ((int(*)(uint8_t , uint8_t, uint8_t*, uint8_t*,int))(g_PDKHandle[PDK_RMCPLOGINAUDIT]))(EvtType, UserID, UserName, pBMCInfo->LANConfig.MsgReq.IPAddr, BMCInst);
  1174. // if (ret != -1)
  1175. // {
  1176. // return 0;
  1177. // }
  1178. // if(g_corefeatures.global_ipv6 == ENABLED)
  1179. // {
  1180. // if(IN6_IS_ADDR_V4MAPPED(pBMCInfo->LANConfig.MsgReq.IPAddr))
  1181. // {
  1182. // /* The last bytes of IP6 contains IP4 address */
  1183. // _fmemcpy(IPAddr, &pBMCInfo->LANConfig.MsgReq.IPAddr[IP6_ADDR_LEN - IP_ADDR_LEN], sizeof (struct in_addr));
  1184. // }
  1185. // else
  1186. // {
  1187. // /*
  1188. // * IPV6 address so it will be filled with 0xff.
  1189. // */
  1190. // memset(IPAddr, 0xFF, sizeof (struct in_addr));
  1191. // }
  1192. // }
  1193. // else
  1194. // {
  1195. // _fmemcpy(IPAddr, pBMCInfo->LANConfig.MsgReq.IPAddr, sizeof (struct in_addr));
  1196. // }
  1197. // /* This structure values are AMI specific SEL Record data */
  1198. // OEMSELRec.ID = 0x00;
  1199. // OEMSELRec.Type = 0xc1;
  1200. // OEMSELRec.TimeStamp = 0x00;
  1201. // memcpy(OEMSELRec.MftrID, MfgID, sizeof(MfgID));
  1202. // OEMSELRec.OEMData[0] = EvtType;
  1203. // OEMSELRec.OEMData[1] = UserID;
  1204. // memcpy (&OEMSELRec.OEMData[2], IPAddr, IP_ADDR_LEN);
  1205. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SELConfig.SELMutex, WAIT_INFINITE);
  1206. // /*we are not posting login/logout audit logs to PEF*/
  1207. // reslen = LockedAddSELEntry((uint8_t *)&OEMSELRec, sizeof(SELOEM1Record_T), (uint8_t *)&AddSelRes, FALSE,POST_ONLY_SEL, BMCInst);
  1208. // /* Enable Reservation ID which was cancelled by this event */
  1209. // pBMCInfo->SELConfig.RsrvIDCancelled = FALSE;
  1210. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SELConfig.SELMutex);
  1211. // return ( (sizeof(uint8_t) == reslen) ? -1 : 0 ); //reslen is only Completion code size if error
  1212. // }
  1213. // return 0;
  1214. // }
  1215. #endif /*#if IPMI20_SUPPORT*/