RMCP.c 47 KB

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