RMCP.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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. }
  370. /* Frame the Message Packet for Message Handler */
  371. Req.Param = PARAM_IFC;
  372. Req.Cmd = pIPMIMsgReq->Cmd;
  373. Req.NetFnLUN = pIPMIMsgReq->NetFnLUN;
  374. Req.SessionID = SessionID;
  375. Req.SessionType = LAN_SESSION_TYPE;
  376. Req.Channel = LAN_RMCP_CHANNEL;
  377. //UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
  378. Req.Size = IPMIMsgLen;
  379. memcpy(Req.Data, ( uint8_t*) pIPMIMsgReq, Req.Size);
  380. /* Post Msg to MsgHndlr and Get Res */
  381. if (0 != ProcIPMIReq (pSessionInfo, PAYLOAD_IPMI_MSG, &Req, &Res))
  382. {
  383. return 0;
  384. }
  385. /* Fill Response data */
  386. memcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
  387. /* Fill Authentication Code */
  388. if (0 != pReqSessionHdr->AuthType)
  389. {
  390. pResMsgAuthCode = ( uint8_t*)(pResSessionHdr + 1);
  391. pIPMIMsgRes = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
  392. AUTH_CODE_LEN + sizeof (IPMIMsgLen));
  393. IPMIMsgResLen = AUTH_CODE_LEN + sizeof (IPMIMsgLen) + Res.Size;
  394. /* Fill IPMI Message */
  395. memcpy (pIPMIMsgRes, Res.Data, Res.Size);
  396. *(pResMsgAuthCode + AUTH_CODE_LEN) = Res.Size;
  397. // ComputeAuthCode ((uint8_t*)g_BMCInfo.pUserInfo->UserPassword, pResSessionHdr, pIPMIMsgRes,
  398. // pResMsgAuthCode, MULTI_SESSION_CHANNEL);
  399. }
  400. else
  401. {
  402. pIPMIMsgRes = ( IPMIMsgHdr_T*)(( uint8_t*)(pResSessionHdr + 1) +
  403. sizeof (IPMIMsgLen));
  404. IPMIMsgResLen = Res.Size + sizeof (IPMIMsgLen);
  405. /* Fill IPMI Message */
  406. memcpy (pIPMIMsgRes, Res.Data, Res.Size);
  407. *(( uint8_t*) (pResSessionHdr + 1)) = Res.Size;
  408. }
  409. // if( (NETFN_APP == (pIPMIMsgReq->NetFnLUN >> 2)) && (CMD_GET_SESSION_CHALLENGE == pIPMIMsgReq->Cmd) &&
  410. // (CC_GET_SESSION_INVALID_USER == Res.Data[sizeof(IPMIMsgHdr_T)]) && (NULL == pSessionInfo) )
  411. // {
  412. // if ( 0 != AddLoginEvent( 0xFF, &pBMCInfo->LANConfig.MsgReq.Data[7], EVENT_LOGIN_FAILURE, BMCInst ))
  413. // {
  414. // TCRIT("Problem while adding Log record \n");
  415. // }
  416. // }
  417. ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr_T) + IPMIMsgResLen;
  418. }
  419. return ResLen;
  420. }
  421. /**
  422. * @brief Process the IPMI request and prepare response.
  423. * @param pSessionInfo - Session information.
  424. * @param Payload - Payload type.
  425. * @return 0 if success, -1 if error.
  426. **/
  427. int ProcIPMIReq ( SessionInfo_T* pSessionInfo, uint8_t Payload, MsgPkt_T *pReq, MsgPkt_T *pRes)
  428. {
  429. // ChannelInfo_T* pChannelInfo;
  430. // int RetVal = 0;
  431. //printf("ProcIPMIReq\n");
  432. /* Frame the Message Packet for Message Handler */
  433. pReq->Param = PARAM_IFC;
  434. pReq->SrcQ = gFd_LanResQ;
  435. if (PAYLOAD_IPMI_MSG == Payload)
  436. {
  437. //printf("Post to MsgHndlr from %d\n", gFd_LanResQ);
  438. PostMsg (gFd_MsgHndlrIfc, pReq);
  439. }
  440. if ( GetMsg (gFd_LanResQ, pRes, DEFAULT_TIMEOUT) != 0)
  441. {
  442. //FillIPMIResFailure (pReq, pRes);
  443. printf("---> RMCP get message error!\n");
  444. }
  445. if (PARAM_NO_RESPONSE == pRes->Param)
  446. {
  447. printf ("RMCP.c : No response from message handler\n");
  448. return -1;
  449. }
  450. //printf("ProcIPMIReq get response: Param %#x, netfn %#x, cmd %#x, len %#x\n", pRes->Param, pRes->NetFnLUN, pRes->Cmd, pRes->Size);
  451. if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd == 0x3A) && //Active Session , ipmi2.0 page 613
  452. (PAYLOAD_IPMI_MSG == Payload))
  453. {
  454. //TODO:
  455. }
  456. /* If Request IPMI Message is Close Session */
  457. if (((pReq->NetFnLUN >> 2) == 0x06) && (pReq->Cmd == 0x3C) && //close session
  458. (PAYLOAD_IPMI_MSG == Payload))
  459. {
  460. //TODO:
  461. }
  462. return 0;
  463. }
  464. /**
  465. * @brief Validate RMCP Header
  466. * @param pRMCPHdr - RMCP header.
  467. * @return TRUE if valid, FALSE if invalid.
  468. **/
  469. static uint8_t
  470. ValidateRMCPHdr ( RMCPHdr_T* pRMCPHdr)
  471. {
  472. /* If RMCP Packet is NULL */
  473. if (pRMCPHdr == NULL)
  474. {
  475. printf ("RMCP.c : RMCP Packet is NULL\n");
  476. return FALSE;
  477. }
  478. /* Verify RMCP Version */
  479. if (pRMCPHdr->Version != RMCP_VERSION)
  480. {
  481. printf ("RMCP.c : Invalid RMCP Version\n");
  482. return FALSE;
  483. }
  484. /* LOOK for RMCP MessageClass */
  485. if ((pRMCPHdr->MsgClass != IPMI_MESSAGE_CLASS) &&
  486. (pRMCPHdr->MsgClass != 0x06))
  487. {
  488. printf ("RMCP.c : Invalid Message Class\n");
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. // /**
  494. // * @brief Validate session header.
  495. // * @param SessionID - Session ID.
  496. // * @param SeqNo - Session Sequence Number.
  497. // * @return TRUE if valid, FALSE if invalid.
  498. // **/
  499. // static bool
  500. // ValidateSessionHdr (uint32_t SessionID, uint32_t SeqNo )
  501. // {
  502. // SessionInfo_T* pSessionInfo;
  503. // /* if its Pre Session commands */
  504. // if (0 == SessionID)
  505. // {
  506. // return TRUE;
  507. // }
  508. // pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
  509. // if ( pSessionInfo == NULL)
  510. // {
  511. // return FALSE;
  512. // }
  513. // /* If packet is already received - drop the packet */
  514. // /* if (ntohs(SeqNo) <= ntohs (CAST_32 (&pSessionInfo->InboundSeq)))
  515. // {
  516. // IPMI_DBG_PRINT ("RMCP: Duplicate Seq No - Packet dropped\n");
  517. // return FALSE;
  518. // }
  519. // */
  520. // /* inc the Sequence No */
  521. // return TRUE;
  522. // }
  523. /**
  524. * @brief Process RMCP Ping Message.
  525. * @param pRMCPReq - Request RMCP message.
  526. * @param pRMCPRes - Response RMCP message.
  527. * @return the response length.
  528. **/
  529. static uint8_t
  530. ProcessPingMsg ( RMCPHdr_T* pRMCPReq, RMCPHdr_T* pRMCPRes )
  531. {
  532. RMCPPingHdr_T* pReqPingHdr = ( RMCPPingHdr_T*)(pRMCPReq + 1);
  533. RMCPPingHdr_T* pResPingHdr = ( RMCPPingHdr_T*)(pRMCPRes + 1);
  534. if (PRESENCE_PING_MSGTYPE != pReqPingHdr->MsgType) { return 0; }
  535. if((pReqPingHdr->IANANum[0]!=0x00)||(pReqPingHdr->IANANum[1]!=0x00)||
  536. (pReqPingHdr->IANANum[2]!=0x11)||(pReqPingHdr->IANANum[3]!=0xBE))
  537. { return 0; }
  538. /* Construct Response Header */
  539. memcpy (pResPingHdr, pReqPingHdr, sizeof (RMCPPingHdr_T));
  540. pResPingHdr->MsgType = 0x40;
  541. pResPingHdr->DataLen = 0x10;
  542. /* Fill Response Data */
  543. memset (pResPingHdr + 1, 0, pResPingHdr->DataLen);
  544. *(( uint8_t*)(pResPingHdr + 1) + 8) = 0x81;
  545. *(( uint8_t*)(pResPingHdr + 1) + 4) = PING_IPMI_15_SUPPORT;
  546. #if IPMI20_SUPPORT == 1
  547. // *(( uint8_t*)(pResPingHdr + 1) + 4) |= PING_IPMI_20_SUPPORT;
  548. #endif
  549. // /*Update the OEM IANA Number for DCMI Discovery (36465 = Data Center Manageability Forum,Spec .1.5)*/
  550. // if(g_corefeatures.dcmi_1_5_support == ENABLED)
  551. // {
  552. // if(pBMCInfo->IpmiConfig.DCMISupport == 1)
  553. // {
  554. // *(( uint8_t*)(pResPingHdr + 1) + 2) = 0x8E;
  555. // *(( uint8_t*)(pResPingHdr + 1) + 3) = 0x71;
  556. // }
  557. // }
  558. return (sizeof (RMCPHdr_T) + sizeof (RMCPPingHdr_T) + pResPingHdr->DataLen);
  559. }
  560. /**
  561. * @brief Validate Authentication Code
  562. * @param pAuthCode - Request authentication code.
  563. * @param pPassword - Password string.
  564. * @param pSessionHdr - Request Session header.
  565. * @param pIPMIMsg - Request IPMI message.
  566. * @return TRUE if valid, FALSE if invalid.
  567. **/
  568. static uint8_t
  569. ValidateAuthCode ( uint8_t* pAuthCode, uint8_t* pPassword,
  570. SessionHdr_T* pSessionHdr, IPMIMsgHdr_T* pIPMIMsg)
  571. {
  572. uint8_t ComputedAuthCode [AUTH_CODE_LEN];
  573. memset(ComputedAuthCode, 0, sizeof (ComputedAuthCode));
  574. ComputeAuthCode (pPassword, pSessionHdr, pIPMIMsg,
  575. ComputedAuthCode, MULTI_SESSION_CHANNEL);
  576. // int i;
  577. // printf("pAuthCode: ");
  578. // for(i=0;i<AUTH_CODE_LEN;i++)
  579. // printf("%#x ", pAuthCode[i]);
  580. // printf("\n");
  581. // printf("pPassword: %s\n", pPassword);
  582. // printf("pComputeAuthCode: ");
  583. // for(i=0;i<AUTH_CODE_LEN;i++)
  584. // printf("%#x ", ComputedAuthCode[i]);
  585. // printf("\n");
  586. return (0 == memcmp (pAuthCode, ComputedAuthCode, AUTH_CODE_LEN));
  587. }
  588. #if IPMI20_SUPPORT
  589. // /*-------------------------------------------
  590. // * Frame20Payload
  591. // *-------------------------------------------*/
  592. // int
  593. // Frame20Payload (uint8_t PayloadType, RMCPHdr_T* pRMCPPkt,
  594. // uint8_t* pPayload, uint32_t PayloadLen,
  595. // SessionInfo_T* pSessionInfo )
  596. // {
  597. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  598. // SessionHdr2_T* pResSessionHdr = ( SessionHdr2_T*)(pRMCPPkt + 1);
  599. // uint8_t* pRes = ( uint8_t*)(pResSessionHdr + 1);
  600. // uint8_t* pConfHdr;
  601. // uint8_t* pConfPayld;
  602. // uint8_t* pIntPad;
  603. // uint8_t* pResMsgAuthCode;
  604. // uint8_t ConfPadLen, IntPadLen;
  605. // INT16U ConfPayldLen, AuthCodeLen;
  606. // int i, ResLen;
  607. // unsigned int seed = 1;
  608. // /* Fill Session Hdr */
  609. // pResSessionHdr->AuthType = RMCP_PLUS_FORMAT;
  610. // pResSessionHdr->PayloadType = PayloadType;
  611. // if (NULL == pSessionInfo)
  612. // {
  613. // pResSessionHdr->SessionID = 0;
  614. // pResSessionHdr->SessionSeqNum = 0;
  615. // }
  616. // else
  617. // {
  618. // /* Response packets should send the Remote Console
  619. // * Session ID so the remote console can correctly
  620. // * match up the session with its own table of active
  621. // * session IDs. */
  622. // pResSessionHdr->SessionID = pSessionInfo->RemConSessionID;
  623. // /* Increment session sequence number */
  624. // /* During RMCP Opensession , OutboundSeq initialized to 0 and but 0 is reserved */
  625. // /* and also When It reach 0xffffffff then It become zero */
  626. // if(0==pSessionInfo->OutboundSeq)
  627. // {
  628. // pSessionInfo->OutboundSeq=1;
  629. // }
  630. // pResSessionHdr->SessionSeqNum = htoipmi_u32(pSessionInfo->OutboundSeq++);
  631. // }
  632. // /* Fill Payload and Do Encryption if needed */
  633. // if ((NULL != pSessionInfo) &&
  634. // (0 != (pResSessionHdr->PayloadType & CONFIDENT_MASK)))
  635. // {
  636. // pConfHdr = ( uint8_t*)(pResSessionHdr + 1);
  637. // switch (pSessionInfo->ConfidentialityAlgorithm)
  638. // {
  639. // case CONF_AES_CBC_128:
  640. // /* Fill Init Vector */
  641. // for (i =0; i < CONF_AES_CBC_128_HDR_LEN; i++)
  642. // {
  643. // pConfHdr [i] = (uint8_t)rand_r (&seed);
  644. // }
  645. // pConfPayld = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
  646. // /* Add Padding; include size of confpadlen */
  647. // ConfPadLen = (PayloadLen + 1) % CONF_BLOCK_SIZE;
  648. // if (0 != ConfPadLen)
  649. // {
  650. // ConfPadLen = CONF_BLOCK_SIZE - ConfPadLen;
  651. // }
  652. // for (i = 0; i < ConfPadLen; i++)
  653. // {
  654. // *(pPayload + PayloadLen + i) = i + 1;
  655. // }
  656. // *(pPayload + PayloadLen + ConfPadLen) = ConfPadLen;
  657. // ConfPayldLen = PayloadLen + ConfPadLen + 1;
  658. // aesEncrypt (( uint8_t*)pPayload, ConfPayldLen,
  659. // ( uint8_t*)pConfHdr, pSessionInfo->Key2,
  660. // ( uint8_t*)pConfPayld);
  661. // IPMI_DBG_PRINT_BUF (( uint8_t*)pConfPayld, ConfPayldLen);
  662. // PayloadLen = ConfPayldLen + CONF_AES_CBC_128_HDR_LEN;
  663. // pBMCInfo->LANConfig.MsgReq.Size = PayloadLen;
  664. // break;
  665. // case CONF_xCR4_128:
  666. // case CONF_xCR4_40:
  667. // default:
  668. // IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
  669. // return 0;
  670. // }
  671. // }
  672. // else
  673. // {
  674. // _fmemcpy (pRes, pPayload, PayloadLen);
  675. // }
  676. // /* Fill Payload Length */
  677. // pResSessionHdr->IPMIMsgLen = htoipmi_u16 (PayloadLen);
  678. // ResLen = sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T) + PayloadLen;
  679. // /* Add Integrity Check Value */
  680. // if ((NULL != pSessionInfo) &&
  681. // (0 != (pResSessionHdr->PayloadType & INTEGRITY_MASK)))
  682. // {
  683. // /* Add Integrity Pad */
  684. // pIntPad = ( uint8_t*)(pResSessionHdr + 1) + PayloadLen;
  685. // IntPadLen = (sizeof (SessionHdr2_T) + PayloadLen + 2) % sizeof (uint32_t);
  686. // if (0 != IntPadLen)
  687. // {
  688. // IntPadLen = sizeof(uint32_t) - IntPadLen;
  689. // }
  690. // _fmemset (pIntPad, 0xFF, IntPadLen);
  691. // *(pIntPad + IntPadLen) = IntPadLen; /* Integrity Pad Len */
  692. // *(pIntPad + IntPadLen + 1) = 0x07; /* Next Header */
  693. // pResMsgAuthCode = pIntPad + IntPadLen + 2;
  694. // AuthCodeLen = sizeof (SessionHdr2_T) + PayloadLen + IntPadLen + 2;
  695. // ResLen += IntPadLen + 2;
  696. // switch (pSessionInfo->IntegrityAlgorithm)
  697. // {
  698. // case AUTH_HMAC_SHA1_96:
  699. // hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
  700. // ( uint8_t*)pResSessionHdr, AuthCodeLen,
  701. // (uint8_t *)pResMsgAuthCode, MAX_INTEGRITY_LEN);
  702. // ResLen += HMAC_SHA1_96_LEN;
  703. // break;
  704. // case AUTH_HMAC_MD5_128:
  705. // hmac_md5(pSessionInfo->Key1,HASH_KEY1_SIZE,( uint8_t*)pResSessionHdr, AuthCodeLen,
  706. // pResMsgAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
  707. // ResLen += HMAC_MD5_LEN;
  708. // break;
  709. // case AUTH_MD5_128:
  710. // MD5_128((char *)pSessionInfo->Password,MAX_PASSWORD_LEN,( INT8S*)pResSessionHdr, AuthCodeLen,
  711. // (char *)pResMsgAuthCode, MAX_MD5_INTEGRITY_LEN);
  712. // ResLen += MD5_LEN;
  713. // break;
  714. // case AUTH_HMAC_SHA256_128:
  715. // hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pResSessionHdr,
  716. // AuthCodeLen, (unsigned char *)pResMsgAuthCode, HMAC_SHA256_128_LEN);
  717. // ResLen += HMAC_SHA256_128_LEN;
  718. // break;
  719. // default:
  720. // IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
  721. // return 0;
  722. // }
  723. // }
  724. // return ResLen;
  725. // }
  726. // int RMCPplusSeqNumValidation(SessionInfo_T * pSessionInfo,uint32_t SessionSeqNum)
  727. // {
  728. // uint32_t SeqTrac[SIXTEEN_COUNT_WINDOW_LEN];
  729. // bool TrackRollOver = FALSE;
  730. // uint32_t TrackRollOverSeq = SEQNUM_ROLLOVER;
  731. // int i=0;
  732. // if( pSessionInfo->InboundSeq == SessionSeqNum)
  733. // return -1;
  734. // if((pSessionInfo->InboundSeq < (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT)) && (pSessionInfo->InboundSeq > RMCPPLUS_SEQLOWLIMIT))
  735. // {
  736. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  737. // {
  738. // if((pSessionInfo->InboundSeq -SessionSeqNum) > RMCPPLUS_SEQLOWLIMIT)
  739. // return -1;
  740. // else
  741. // {
  742. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  743. // {
  744. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  745. // {
  746. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  747. // return -1;
  748. // else
  749. // pSessionInfo->InboundRecv |= (1<<i);
  750. // }
  751. // }
  752. // }
  753. // }
  754. // else
  755. // {
  756. // if((SessionSeqNum - pSessionInfo->InboundSeq) > RMCPPLUS_SEQUPLIMIT)
  757. // return -1;
  758. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  759. // for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq); i++)
  760. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  761. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  762. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq)-1));
  763. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  764. // (uint8_t *)&SeqTrac[0],
  765. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  766. // pSessionInfo->InboundSeq = SessionSeqNum;
  767. // }
  768. // }
  769. // else if((pSessionInfo->InboundSeq < RMCPPLUS_SEQLOWLIMIT)
  770. // || (pSessionInfo->InboundSeq > (SEQNUM_ROLLOVER -RMCPPLUS_SEQUPLIMIT))) /* Checking condition for rollover */
  771. // {
  772. // if(SessionSeqNum < pSessionInfo->InboundSeq)
  773. // {
  774. // if(!((((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT) &&
  775. // (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) >= RMCPPLUS_SEQLOWLIMIT )) ||
  776. // ((((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
  777. // (pSessionInfo->InboundSeq -SessionSeqNum) >= RMCPPLUS_SEQLOWLIMIT)))
  778. // {
  779. // return -1;
  780. // }
  781. // else
  782. // {
  783. // if((pSessionInfo->InboundSeq -SessionSeqNum) <= RMCPPLUS_SEQLOWLIMIT)
  784. // {
  785. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  786. // {
  787. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  788. // {
  789. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  790. // return -1;
  791. // else
  792. // pSessionInfo->InboundRecv |= (1<<i);
  793. // }
  794. // }
  795. // }
  796. // else if(((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) <= RMCPPLUS_SEQUPLIMIT )
  797. // {
  798. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  799. // for(i=0; i < ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) ; i++)
  800. // {
  801. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  802. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  803. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  804. // {
  805. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  806. // TrackRollOver = TRUE;
  807. // }
  808. // else if(TrackRollOver == TRUE)
  809. // {
  810. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  811. // TrackRollOverSeq--;
  812. // }
  813. // }
  814. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  815. // TrackRollOver = FALSE;
  816. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1);
  817. // pSessionInfo->InboundRecv |= (1 << (((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1) -1));
  818. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[(SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1],
  819. // (uint8_t *)&SeqTrac[0],
  820. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - ((SEQNUM_ROLLOVER - pSessionInfo->InboundSeq) + SessionSeqNum+1))));
  821. // pSessionInfo->InboundSeq = SessionSeqNum;
  822. // }
  823. // }
  824. // }
  825. // else if(SessionSeqNum > pSessionInfo->InboundSeq)
  826. // {
  827. // if(!((((SessionSeqNum -pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT) &&
  828. // (((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) >= RMCPPLUS_SEQUPLIMIT )) ||
  829. // ((((SEQNUM_ROLLOVER - SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT ) &&
  830. // (SessionSeqNum-pSessionInfo->InboundSeq) >= RMCPPLUS_SEQLOWLIMIT)))
  831. // {
  832. // return -1;
  833. // }
  834. // else
  835. // {
  836. // if((SessionSeqNum - pSessionInfo->InboundSeq) <= RMCPPLUS_SEQUPLIMIT)
  837. // {
  838. // _fmemcpy((uint8_t *)SeqTrac,(uint8_t *)pSessionInfo->InboundTrac,(sizeof(uint32_t) * SIXTEEN_COUNT_WINDOW_LEN));
  839. // for(i=0; i < (SessionSeqNum - pSessionInfo->InboundSeq) ; i++)
  840. // {
  841. // if(((SessionSeqNum - (i+1)) != 0) && (TrackRollOver == FALSE))
  842. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  843. // else if(((SessionSeqNum - (i+1)) == 0) && (TrackRollOver == FALSE))
  844. // {
  845. // pSessionInfo->InboundTrac[i] = SessionSeqNum - (i+1);
  846. // TrackRollOver = TRUE;
  847. // }
  848. // else if(TrackRollOver == TRUE)
  849. // {
  850. // pSessionInfo->InboundTrac[i] = TrackRollOverSeq;
  851. // TrackRollOverSeq--;
  852. // }
  853. // }
  854. // TrackRollOverSeq = SEQNUM_ROLLOVER;
  855. // TrackRollOver = FALSE;
  856. // pSessionInfo->InboundRecv = pSessionInfo->InboundRecv << (SessionSeqNum - pSessionInfo->InboundSeq);
  857. // pSessionInfo->InboundRecv |= (1 << ((SessionSeqNum - pSessionInfo->InboundSeq) -1));
  858. // _fmemcpy((uint8_t *)&pSessionInfo->InboundTrac[SessionSeqNum - pSessionInfo->InboundSeq],
  859. // (uint8_t *)&SeqTrac[0],
  860. // (sizeof(uint32_t) *(SIXTEEN_COUNT_WINDOW_LEN - (SessionSeqNum - pSessionInfo->InboundSeq))));
  861. // pSessionInfo->InboundSeq = SessionSeqNum;
  862. // }
  863. // else if(((SEQNUM_ROLLOVER -SessionSeqNum) + pSessionInfo->InboundSeq+1) <= RMCPPLUS_SEQLOWLIMIT)
  864. // {
  865. // for(i=0; i < RMCPPLUS_SEQLOWLIMIT; i++)
  866. // {
  867. // if(SessionSeqNum == pSessionInfo->InboundTrac[i])
  868. // {
  869. // if(((1 << i) & pSessionInfo->InboundRecv) != 0)
  870. // return -1;
  871. // else
  872. // pSessionInfo->InboundRecv |= (1<<i);
  873. // }
  874. // }
  875. // }
  876. // }
  877. // }
  878. // }
  879. // return 0;
  880. // }
  881. // /**
  882. // * @brief Process IPMI 2.0 Payload.
  883. // * @param pRMCPReq - RMCP request message.
  884. // * @param pRMCPRes _ RMCP response message.
  885. // * @return 0 if success, -1 if error.
  886. // **/
  887. // static int
  888. // Proc20Payload ( RMCPHdr_T* pRMCPReq, RMCPHdr_T* pRMCPRes, MiscParams_T *pParams,uint8_t Channel )
  889. // {
  890. // SessionHdr2_T* pReqSession2Hdr = ( SessionHdr2_T*)(pRMCPReq + 1);
  891. // SessionHdr2_T* pResSession2Hdr = ( SessionHdr2_T*)(pRMCPRes + 1);
  892. // uint8_t* pReq = ( uint8_t *)(pReqSession2Hdr + 1);
  893. // uint8_t* pRes = ( uint8_t *)(pResSession2Hdr + 1);
  894. // SessionInfo_T* pSessionInfo = NULL;
  895. // uint8_t* pIntPad;
  896. // uint8_t* pConfHdr;
  897. // uint8_t* pConfPayld;
  898. // uint8_t* pReqMsgAuthCode;
  899. // UserInfo_T* pUserInfo;
  900. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  901. // uint8_t Payload, IntPadLen, ComputedAuthCode [25];
  902. // INT16U IPMIMsgLen, AuthCodeLen, ConfPayldLen;
  903. // uint32_t SessionID;
  904. // uint32_t SessionSeqNum;
  905. // int len, i;
  906. // uint8_t UserPswd [MAX_PASSWORD_LEN];
  907. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  908. // /* Get SessionID & Session Seq */
  909. // SessionID = pReqSession2Hdr->SessionID;
  910. // SessionSeqNum = pReqSession2Hdr->SessionSeqNum;
  911. // /* Validate IPMI Session Header */
  912. // if (TRUE != ValidateSessionHdr (SessionID, SessionSeqNum, BMCInst))
  913. // {
  914. // // IPMI_WARNING ("RMCP.c : IPMI Session header validation failed\n");
  915. // return 0;
  916. // }
  917. // IPMIMsgLen = ipmitoh_u16 (pReqSession2Hdr->IPMIMsgLen);
  918. // Payload = pReqSession2Hdr->PayloadType & 0x3F;
  919. // /* Process PreSession Payloads */
  920. // for (i = 0; i < sizeof (m_PayloadTbl) / sizeof (m_PayloadTbl [0]); i++)
  921. // {
  922. // if (m_PayloadTbl [i].Payload == Payload)
  923. // {
  924. // /* Copy RMCP & Session Hdr */
  925. // _fmemcpy (( uint8_t*)pRMCPRes, ( uint8_t*)pRMCPReq,
  926. // sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T));
  927. // /* For response the type is type + 1 */
  928. // pResSession2Hdr->PayloadType++;
  929. // /* Copy message tag from request */
  930. // *pRes = *pReq;
  931. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  932. // /* Call the function and pass the data after message tag */
  933. // len = m_PayloadTbl [i].PayloadHndlr ((pReq),
  934. // (uint8_t)(IPMIMsgLen - sizeof (uint8_t)), (pRes), pParams,Channel,BMCInst);
  935. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex,WAIT_INFINITE);
  936. // /* Copy the message length */
  937. // pResSession2Hdr->IPMIMsgLen = htoipmi_u16 ((len));
  938. // if(len!=0)
  939. // len += sizeof (RMCPHdr_T) + sizeof (SessionHdr2_T);
  940. // return len;
  941. // }
  942. // }
  943. // /* Check for Invalid Payload Type */
  944. // if ((PAYLOAD_IPMI_MSG != Payload) && (PAYLOAD_SOL != Payload))
  945. // {
  946. // IPMI_WARNING ("RMCP.c : Invalid payload\n");
  947. // return 0;
  948. // }
  949. // /* check for the pre-session commands */
  950. // if (0 == SessionID)
  951. // {
  952. // int i;
  953. // IPMIMsgHdr_T* pIPMIMsg = ( IPMIMsgHdr_T*) pReq;
  954. // for (i=0; i < sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T); i++)
  955. // {
  956. // if ((m_PreSessionCmdsTbl[i].NetFn == (pIPMIMsg->NetFnLUN >> 2)) &&
  957. // (m_PreSessionCmdsTbl[i].Cmd == pIPMIMsg->Cmd))
  958. // {
  959. // pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
  960. // _fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
  961. // break;
  962. // }
  963. // }
  964. // if (i >= (sizeof (m_PreSessionCmdsTbl) / sizeof (PreSessionCmd_T)))
  965. // {
  966. // IPMI_WARNING ("RMCP.c : Presession command not found\n");
  967. // return 0;
  968. // }
  969. // }
  970. // else
  971. // {
  972. // /* Get Session Information */
  973. // pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
  974. // if (NULL == pSessionInfo)
  975. // {
  976. // IPMI_WARNING ("RMCP.c : Proc20Payload - Invalid Session Id\n");
  977. // return 0;
  978. // }
  979. // /* Check if session is activated */
  980. // if (TRUE != pSessionInfo->Activated)
  981. // {
  982. // IPMI_WARNING ("RMCP.c : Session not activated with session id %lx\n", SessionID);
  983. // return 0;
  984. // }
  985. // if(pBMCInfo->IpmiConfig.LinkDownResilentSupport == 1)
  986. // {
  987. // if(pSessionInfo->Linkstat == TRUE)
  988. // {
  989. // pSessionInfo->Linkstat = FALSE;
  990. // memset(pSessionInfo->InboundTrac,0,SIXTEEN_COUNT_WINDOW_LEN);
  991. // }
  992. // }
  993. // if( (((( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN)>>2==NETFN_APP) &&
  994. // (((( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd)==CMD_SET_SESSION_PRIV_LEVEL) &&
  995. // ((pSessionInfo->EventFlag)== 1) )
  996. // {
  997. // pSessionInfo->EventFlag=0;
  998. // if ( 0 != AddLoginEvent ( pSessionInfo->UserId, NULL, EVENT_LOGIN, BMCInst ))
  999. // {
  1000. // TCRIT("Problem while adding Log record \n");
  1001. // }
  1002. // }
  1003. // if(RMCPplusSeqNumValidation(pSessionInfo,ipmitoh_u32(SessionSeqNum)) != 0)
  1004. // {
  1005. // return 0;
  1006. // }
  1007. // if (0 != (pReqSession2Hdr->PayloadType & INTEGRITY_MASK))
  1008. // {
  1009. // uint8_t Len;
  1010. // /* check Integrity pad which starts from auth type till auth code */
  1011. // pIntPad = ( uint8_t*)(pReqSession2Hdr + 1) + IPMIMsgLen;
  1012. // IntPadLen = (sizeof (SessionHdr2_T) + IPMIMsgLen + 2) % sizeof (uint32_t);
  1013. // if (0 != IntPadLen)
  1014. // {
  1015. // IntPadLen = sizeof(uint32_t) - IntPadLen;
  1016. // }
  1017. // if (pIntPad [IntPadLen] != IntPadLen)
  1018. // {
  1019. // IPMI_WARNING ("RMCP.c : Invalid Padlength\n");
  1020. // return 0;
  1021. // }
  1022. // /* Check auth code */
  1023. // pReqMsgAuthCode = pIntPad + IntPadLen + 2;
  1024. // AuthCodeLen = sizeof (SessionHdr2_T) + IPMIMsgLen + IntPadLen + 2;
  1025. // switch (pSessionInfo->IntegrityAlgorithm)
  1026. // {
  1027. // case AUTH_HMAC_SHA1_96:
  1028. // hmac_sha1 ((uint8_t *)pSessionInfo->Key1, HASH_KEY1_SIZE,
  1029. // ( uint8_t*)pReqSession2Hdr, AuthCodeLen,
  1030. // ( uint8_t*)ComputedAuthCode, MAX_INTEGRITY_LEN);
  1031. // Len = HMAC_SHA1_96_LEN;
  1032. // break;
  1033. // case AUTH_HMAC_MD5_128:
  1034. // hmac_md5 (pSessionInfo->Key1, HASH_KEY1_SIZE,
  1035. // ( uint8_t*)pReqSession2Hdr, AuthCodeLen,
  1036. // ( uint8_t*)ComputedAuthCode, MAX_HMAC_MD5_INTEGRITY_LEN);
  1037. // Len = HMAC_MD5_LEN;
  1038. // break;
  1039. // case AUTH_MD5_128:
  1040. // /* Get User Info */
  1041. // pUserInfo = getUserIdInfo((uint8_t)pSessionInfo->UserId, BMCInst);
  1042. // if (g_corefeatures.userpswd_encryption == ENABLED)
  1043. // {
  1044. // /* Get Encryption Key from the MBMCInfo_t structure */
  1045. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  1046. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pSessionInfo->UserId - 1].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  1047. // {
  1048. // TCRIT("Error in decrypting the user password for user ID:%d. .\n", pSessionInfo->UserId);
  1049. // return -1;
  1050. // }
  1051. // }
  1052. // else
  1053. // {
  1054. // _fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  1055. // }
  1056. // MD5_128((char *)pUserInfo->UserPassword, MAX_PASSWORD_LEN,
  1057. // ( INT8S*)pReqSession2Hdr, AuthCodeLen,
  1058. // ( INT8S*)ComputedAuthCode, MAX_MD5_INTEGRITY_LEN);
  1059. // Len= MD5_LEN;
  1060. // break;
  1061. // case AUTH_HMAC_SHA256_128:
  1062. // hmac_sha256 ((unsigned char *)pSessionInfo->Key1, SHA2_HASH_KEY_SIZE, (unsigned char *)pReqSession2Hdr,
  1063. // AuthCodeLen, (unsigned char *)ComputedAuthCode, SHA2_HASH_KEY_SIZE);
  1064. // Len= HMAC_SHA256_128_LEN;
  1065. // break;
  1066. // default:
  1067. // IPMI_WARNING ("RMCP.c : Invalid Integrity Algorithm\n");
  1068. // return 0;
  1069. // }
  1070. // IPMI_DBG_PRINT_BUF (( uint8_t*)ComputedAuthCode, Len);
  1071. // if (0 != _fmemcmp (( uint8_t*)ComputedAuthCode, pReqMsgAuthCode, Len))
  1072. // {
  1073. // return 0;
  1074. // }
  1075. // }
  1076. // /* Decrypt the message if Encrypted */
  1077. // /* Verify confidentiality header and trailer */
  1078. // if (0 != (pReqSession2Hdr->PayloadType & CONFIDENT_MASK))
  1079. // {
  1080. // pConfHdr = ( uint8_t*)(pReqSession2Hdr + 1);
  1081. // switch (pSessionInfo->ConfidentialityAlgorithm)
  1082. // {
  1083. // case CONF_AES_CBC_128:
  1084. // pConfPayld = pConfHdr + CONF_AES_CBC_128_HDR_LEN;
  1085. // ConfPayldLen = IPMIMsgLen - CONF_AES_CBC_128_HDR_LEN;
  1086. // aesDecrypt (( uint8_t*)pConfPayld, ConfPayldLen,
  1087. // ( uint8_t*)pConfHdr, pSessionInfo->Key2,
  1088. // ( uint8_t*)pBMCInfo->LANConfig.MsgReq.Data);
  1089. // /* Remove pad length */
  1090. // if (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] > CONF_BLOCK_SIZE)
  1091. // {
  1092. // IPMI_WARNING ("Invalid Conf Blocke size %d\n", pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1]);
  1093. // return 0;
  1094. // }
  1095. // ConfPayldLen -= (pBMCInfo->LANConfig.MsgReq.Data [ConfPayldLen - 1] + 1);
  1096. // break;
  1097. // case CONF_xCR4_128:
  1098. // case CONF_xCR4_40:
  1099. // default:
  1100. // IPMI_WARNING ("RMCP.c : Invalid confidentiality Algorithm\n");
  1101. // return 0;
  1102. // }
  1103. // pBMCInfo->LANConfig.MsgReq.Size = ConfPayldLen;
  1104. // }
  1105. // else
  1106. // {
  1107. // pBMCInfo->LANConfig.MsgReq.Size = IPMIMsgLen;
  1108. // _fmemcpy (pBMCInfo->LANConfig.MsgReq.Data, pReq, pBMCInfo->LANConfig.MsgReq.Size);
  1109. // }
  1110. // }
  1111. // /* Fill IPMI MsgPkt Request */
  1112. // pBMCInfo->LANConfig.MsgReq.Cmd = (( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->Cmd;
  1113. // pBMCInfo->LANConfig.MsgReq.NetFnLUN = (( IPMIMsgHdr_T*)pBMCInfo->LANConfig.MsgReq.Data)->NetFnLUN;
  1114. // pBMCInfo->LANConfig.MsgReq.SessionID = SessionID;
  1115. // pBMCInfo->LANConfig.MsgReq.SessionType = LAN_SESSION_TYPE;
  1116. // pBMCInfo->LANConfig.MsgReq.Channel =Channel;
  1117. // UpdateGetMsgTime( &pBMCInfo->LANConfig.MsgReq,IfcType, BMCInst);
  1118. // // Moved to line 966
  1119. // // Bug : if SessionID is 0 this Unlock will be called without a Lock
  1120. // //UNLOCK_BMC_SHARED_MEM();
  1121. // /* Process IPMI Request */
  1122. // if (0 != ProcIPMIReq (pSessionInfo, Payload, pParams,Channel, BMCInst))
  1123. // {
  1124. // return 0;
  1125. // }
  1126. // /* Fill Response data */
  1127. // _fmemcpy (pRMCPRes, pRMCPReq, sizeof (RMCPHdr_T) + sizeof (SessionHdr_T));
  1128. // return Frame20Payload (pReqSession2Hdr->PayloadType, pRMCPRes,
  1129. // pBMCInfo->LANConfig.MsgRes.Data, pBMCInfo->LANConfig.MsgRes.Size, pSessionInfo, BMCInst);
  1130. // }
  1131. // /****************************************************************************
  1132. // * fn AddLoginEvent
  1133. // * params:
  1134. // * pRMCPSession pointer to RMCP Session information
  1135. // * EvtType 0x9 - login, 0xa - logout, 0xb - autologout, 0xc - connection lost
  1136. // *
  1137. // * return 0 - success, -1 - failure
  1138. // ***************************************************************************/
  1139. // int AddLoginEvent ( uint8_t UserID, uint8_t* UserName, uint8_t EvtType )
  1140. // {
  1141. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1142. // int reslen = 0, ret = -1;
  1143. // int i = 0;
  1144. // AddSELRes_T AddSelRes;
  1145. // uint8_t IPAddr[IP_ADDR_LEN];
  1146. // SELOEM1Record_T OEMSELRec;
  1147. // #ifdef CONFIG_SPX_FEATURE_IANA_0
  1148. // uint8_t MfgID[] = { CONFIG_SPX_FEATURE_IANA_2,
  1149. // CONFIG_SPX_FEATURE_IANA_1,
  1150. // CONFIG_SPX_FEATURE_IANA_0 };
  1151. // #else
  1152. // uint8_t MfgID[] = { 0, 0, 0 };
  1153. // #endif
  1154. // /* Hook for RMCP Login Audit */
  1155. // if (g_PDKHandle[PDK_RMCPLOGINAUDIT] != NULL)
  1156. // {
  1157. // /* Return if event type bit is not set in event mask */
  1158. // for (i = 0; i < sizeof(m_IPMIAuditMaskMap)/sizeof(IPMIAuditMaskTbl_T); i++)
  1159. // {
  1160. // if ((EvtType == m_IPMIAuditMaskMap[i].EventType) &&
  1161. // (!(pBMCInfo->LoginAuditCfg.IPMIEventMask >> m_IPMIAuditMaskMap[i].EventMask) & 0x01))
  1162. // {
  1163. // return reslen;
  1164. // }
  1165. // }
  1166. // ret = ((int(*)(uint8_t , uint8_t, uint8_t*, uint8_t*,int))(g_PDKHandle[PDK_RMCPLOGINAUDIT]))(EvtType, UserID, UserName, pBMCInfo->LANConfig.MsgReq.IPAddr, BMCInst);
  1167. // if (ret != -1)
  1168. // {
  1169. // return 0;
  1170. // }
  1171. // if(g_corefeatures.global_ipv6 == ENABLED)
  1172. // {
  1173. // if(IN6_IS_ADDR_V4MAPPED(pBMCInfo->LANConfig.MsgReq.IPAddr))
  1174. // {
  1175. // /* The last bytes of IP6 contains IP4 address */
  1176. // _fmemcpy(IPAddr, &pBMCInfo->LANConfig.MsgReq.IPAddr[IP6_ADDR_LEN - IP_ADDR_LEN], sizeof (struct in_addr));
  1177. // }
  1178. // else
  1179. // {
  1180. // /*
  1181. // * IPV6 address so it will be filled with 0xff.
  1182. // */
  1183. // memset(IPAddr, 0xFF, sizeof (struct in_addr));
  1184. // }
  1185. // }
  1186. // else
  1187. // {
  1188. // _fmemcpy(IPAddr, pBMCInfo->LANConfig.MsgReq.IPAddr, sizeof (struct in_addr));
  1189. // }
  1190. // /* This structure values are AMI specific SEL Record data */
  1191. // OEMSELRec.ID = 0x00;
  1192. // OEMSELRec.Type = 0xc1;
  1193. // OEMSELRec.TimeStamp = 0x00;
  1194. // memcpy(OEMSELRec.MftrID, MfgID, sizeof(MfgID));
  1195. // OEMSELRec.OEMData[0] = EvtType;
  1196. // OEMSELRec.OEMData[1] = UserID;
  1197. // memcpy (&OEMSELRec.OEMData[2], IPAddr, IP_ADDR_LEN);
  1198. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SELConfig.SELMutex, WAIT_INFINITE);
  1199. // /*we are not posting login/logout audit logs to PEF*/
  1200. // reslen = LockedAddSELEntry((uint8_t *)&OEMSELRec, sizeof(SELOEM1Record_T), (uint8_t *)&AddSelRes, FALSE,POST_ONLY_SEL, BMCInst);
  1201. // /* Enable Reservation ID which was cancelled by this event */
  1202. // pBMCInfo->SELConfig.RsrvIDCancelled = FALSE;
  1203. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SELConfig.SELMutex);
  1204. // return ( (sizeof(uint8_t) == reslen) ? -1 : 0 ); //reslen is only Completion code size if error
  1205. // }
  1206. // return 0;
  1207. // }
  1208. #endif /*#if IPMI20_SUPPORT*/