RMCP.c 47 KB

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