RMCP.c 47 KB

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