MsgHndlr.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. * MsgHndlr.h
  17. * Message Handler.
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * : Rama Bisa <ramab@ami.com>
  21. * : Basavaraj Astekar <basavaraja@ami.com>
  22. * : Bakka Ravinder Reddy <bakkar@ami.com>
  23. *
  24. *****************************************************************/
  25. #ifndef MSG_HNDLR_H
  26. #define MSG_HNDLR_H
  27. #include "com_Message.h"
  28. #include "com_IPMIDefs.h"
  29. #pragma pack( 1 )
  30. #define BMC_LUN_00 0
  31. #define BMC_LUN_01 1
  32. #define BMC_LUN_10 2
  33. #define BMC_LUN_11 3
  34. #define LOOP_BACK_REQ 0x10
  35. #define LAN_IFC_SUP 0x0001
  36. #define SOL_IFC_SUP 0x0002
  37. #define SERIAL_IFC_SUP 0x0004
  38. #define AMI_DEVICE_SUP 0x0008
  39. #define USER_LOCKED 1
  40. #define USER_UNLOCKED 0
  41. #define MAX_NETFN 64
  42. // /*FLASH TYPE*/
  43. // #define YAFU_FLASH 1
  44. // #define TFTP_FLASH 2
  45. // #define HPM_FLASH 3
  46. /*Get the current cmd channel for OBSM*/
  47. //#define GetCurCmdChannel(BMCInst) g_BMCInfo[BMCInst].Msghndlr.CurChannel
  48. /*-----------------------
  49. * Command Handler Type
  50. *----------------------*/
  51. typedef int (*pCmdHndlr_T) ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes);
  52. /*----------------------
  53. * Command Handler map
  54. *----------------------*/
  55. typedef struct
  56. {
  57. uint8_t Cmd;
  58. uint8_t Privilege;
  59. pCmdHndlr_T CmdHndlr;
  60. uint8_t ReqLen; /* 0xFF - Any Length */
  61. uint16_t FFConfig;
  62. uint16_t IfcSupport;
  63. } CmdHndlrMap_T;
  64. /*-------------------------------
  65. * Extended Command Handler Type
  66. *-------------------------------*/
  67. typedef int (*pExCmdHndlr_T) ( uint8_t* pReq, uint32_t ReqLen, uint8_t* pRes);
  68. /*------------------------------
  69. * Extended Command Handler map
  70. *------------------------------*/
  71. typedef struct
  72. {
  73. uint8_t Cmd;
  74. uint8_t Privilege;
  75. pExCmdHndlr_T CmdHndlr;
  76. uint8_t ReqLen; /* 0xFF - Any Length */
  77. uint16_t FFConfig;
  78. uint16_t IfcSupport;
  79. } ExCmdHndlrMap_T;
  80. /*-------------------------
  81. * Message Handler Table
  82. *-------------------------*/
  83. typedef struct
  84. {
  85. uint8_t NetFn;
  86. const CmdHndlrMap_T* CmdHndlrMap;
  87. } MsgHndlrTbl_T;
  88. typedef struct
  89. {
  90. uint8_t NetFn;
  91. uint8_t GroupExtnCode;
  92. const CmdHndlrMap_T* CmdHndlrMap;
  93. } GroupExtnMsgHndlrTbl_T;
  94. /*-------------------------------------------------------------
  95. * Pending Bridged Response Tbl Size
  96. *
  97. * Do not increase beyond 60 as maximum sequence number is 64
  98. *------------------------------------------------------------*/
  99. #define MAX_PENDING_BRIDGE_RES 64
  100. #define MAX_PENDING_BRIDGE_TBL 2
  101. #define PRIMARY_PB_TBL 0
  102. #define SECONDARY_PB_TBL 1
  103. typedef union
  104. {
  105. IPMIMsgHdr_T IPMIMsgHdr;
  106. IPMIUDSMsg_T UDSMsgHdr;
  107. } ResMsgHdr_T;
  108. typedef struct
  109. {
  110. uint8_t Used;
  111. uint8_t TimeOut;
  112. uint8_t SeqNum; //转发到IPMB总线上的序号,也是PendingTbl的索引。
  113. uint8_t ChannelNum; //记录下发SendMessage命令的通道,Lan
  114. uint8_t DstSessionHandle;
  115. uint8_t SrcSessionHandle;
  116. uint32_t SrcSessionID;
  117. int DestQ; //记录下发SendMessage命令的接收队列,LanIfcQ
  118. uint8_t OriginSrc;
  119. IPMIMsgHdr_T ReqMsgHdr;
  120. ResMsgHdr_T ResMsgHdr;
  121. uint8_t ResDataOk; //jimbo add, 响应数据准备好了标志。
  122. int UDSSocket;
  123. } PendingBridgedResTbl_T;
  124. /*------------------------------
  125. * Pending Sequence Number
  126. *-----------------------------*/
  127. //#define NO_IPMB_PROTOCOL_CHANNEL 3
  128. #define MAX_PENDING_SEQ_NO 50
  129. #define SEQ_NO_EXPIRATION_TIME 5
  130. typedef struct
  131. {
  132. uint8_t Used;
  133. uint8_t TimeOut;
  134. uint8_t SeqNum;
  135. uint8_t NetFn;
  136. uint8_t Cmd;
  137. } PendingSeqNoTbl_T;
  138. #define MAX_IPMI_CMD_BLOCKS 3
  139. // typedef struct
  140. // {
  141. // uint8_t Channel; /**< Originator's channel number */
  142. // HQueue_T hSrcQ; /**< Originator Queue */
  143. // uint8_t Param; /**< Parameter */
  144. // uint8_t Cmd; /**< Command that needs to be processed */
  145. // uint8_t NetFnLUN; /**< Net function and LUN of command */
  146. // uint8_t Privilege; /**< Current privilege level */
  147. // uint32_t SessionID; /**< Session ID if any */
  148. // uint8_t RequestSize; /**< Size of the Request */
  149. // uint8_t Request [MSG_PAYLOAD_SIZE]; /**< Request Data buffer */
  150. // uint8_t ResponseSize; /**< Size of the response */
  151. // uint8_t Response [MSG_PAYLOAD_SIZE]; /**< Response Data buffer */
  152. // uint8_t* pRequest; /**< Pointer to Request data */
  153. // uint8_t* pResponse; /**< Pointer to Response data */
  154. // } IPMICmdMsg_T;
  155. typedef struct
  156. {
  157. uint8_t NetFnLUN;
  158. uint32_t SessionID;
  159. int SrcQ ;
  160. } KCSBridgeResInfo_T;
  161. #pragma pack( )
  162. /*------------------ Timer Task Table --------------------------*/
  163. typedef void (*pTimerFn_T) (void);
  164. typedef struct
  165. {
  166. uint8_t NumSecs;
  167. pTimerFn_T TimerFn;
  168. } TimerTaskTbl_T;
  169. /*-----------------------------------------------------------
  170. * Bridge Status
  171. *---------------------------------------------------------*/
  172. #define STATUS_OK 0x0
  173. #define STATUS_FAIL 0x1
  174. /* Extern declaration */
  175. extern int GetCmdHndlr(MsgPkt_T* pReq,MsgPkt_T* pRes,CmdHndlrMap_T* pCmdHndlrMap,
  176. uint32_t HdrOffset,uint8_t CmdOverride,CmdHndlrMap_T** CmdHndrl );
  177. extern int GetMsgHndlrMap (uint8_t NetFn, CmdHndlrMap_T ** pCmdHndlrMap);
  178. /**
  179. *@fn GroupExtnGetMsgHndlrMap
  180. *@brief Gets the exact command Handler by comparing NetFn
  181. *@param Netfn -NetFunction of the Cmd to execute
  182. *@GroupExtnCode - Group Extension code
  183. *@param pCmdHndlrMap Pointer to the Command Handler
  184. */
  185. extern int GroupExtnGetMsgHndlrMap (uint8_t NetFn, uint8_t GroupExtnCode, CmdHndlrMap_T ** pCmdHndlrMap);
  186. //extern PendingBridgedResTbl_T m_PendingBridgedResTbl[MAX_PENDING_BRIDGE_TBL][MAX_PENDING_BRIDGE_RES];
  187. extern uint8_t CalculateCheckSum2 ( uint8_t* Pkt, uint32_t Len);
  188. extern void SwapIPMIMsgHdr ( IPMIMsgHdr_T* pIPMIMsgReq, IPMIMsgHdr_T* pIPMIMsgRes);
  189. extern void SwapUDSIPMIMsg ( MsgPkt_T* pIPMIMsgReq, MsgPkt_T* pIPMIMsgRes);
  190. /**
  191. * @fn GetIfcSupport
  192. * @brief This function checks the support of Interface before
  193. * Interface specific commands are executed
  194. * @param IfcSupt - Interface support variable to be verified
  195. * @param IfcSupport - Gives the Interface presence support
  196. */
  197. //extern int GetIfcSupport(uint16_t IfcSupt,uint8_t *IfcSupport);
  198. /*------------------------
  199. * Privilege Levels
  200. *------------------------*/
  201. #define PRIV_NONE 0x00
  202. #define PRIV_CALLBACK 0x01
  203. #define PRIV_USER 0x02
  204. #define PRIV_OPERATOR 0x03
  205. #define PRIV_ADMIN 0x04
  206. #define PRIV_OEM 0x05
  207. #define PRIV_LOCAL 0x81
  208. #define PRIV_SYS_IFC 0x82
  209. /*------------------------------
  210. * Channel type used for BadPassword
  211. *------------------------------*/
  212. #define LAN_CHANNEL_BADP 0x1
  213. #define SERIAL_CHANNEL_BADP 0x2
  214. /*----------------------------
  215. * Command Handler Example (app.c)
  216. *----------------------------*/
  217. /*
  218. #ifdef APP_DEVICE
  219. .... Code ....
  220. const CmdHndlrMap_T g_APP_CmdHndlr [] =
  221. {
  222. { CMD_GET_DEV_ID, PRIV_USER, GET_DEV_ID, 0x00 },
  223. { CMD_BROADCAST_GET_DEV_ID, PRIV_LOCAL, BROADCAST_GET_DEV_ID, 0x00 },
  224. ...
  225. ...
  226. { 0x00, 0x00, 0x00, 0x00 }
  227. };
  228. #else
  229. const CmdHndlrMap_T g_APP_CmdHndlr [] = { 0x00, 0x00, 0x00, 0x00 };
  230. #endif // APP_DEVICE
  231. */
  232. /*---------------------------
  233. * app.h
  234. *---------------------------*/
  235. /*
  236. #ifndef APP_H
  237. #define APP_H
  238. #include "MsgHndlr.h"
  239. extern const CmdHndlrMap_T g_APP_CmdHndlr [];
  240. #endif
  241. */
  242. /*---------------------------------------------------
  243. * Parameters passed by through the message handler Q.
  244. *---------------------------------------------------*/
  245. // #define PARAM_IFC 0x01
  246. // #define PARAM_TIMER 0x02
  247. // #define PARAM_EXECUTE_SP 0x03
  248. // #define PARAM_SENSOR_MONITOR 0x04
  249. // #define PARAM_SENSOR_MONITOR_DONE 0x05
  250. // #define PARAM_IFC_READY 0x06
  251. #define RCVMSGQ_LENGTH 100
  252. #define NO_RESPONSE 0x10
  253. #define NORMAL_RESPONSE 0x11
  254. //#define BRIDGING_REQUEST 0x12
  255. /*----------------------------------------------------
  256. * Receive Message Queue Names
  257. *----------------------------------------------------*/
  258. extern char g_RcvMsgQ [3][RCVMSGQ_LENGTH];
  259. /*------------------------------------------------------------------
  260. *@fn RespondSendMessage
  261. *@brief Frames the Response packet when a IPMB destination is
  262. * unavialable
  263. *
  264. *@param pReq: Request Message Packet address
  265. *@param Status Status of SendIPMBPkt method
  266. *@param BMCInst: BMC Instance Number
  267. *
  268. *@return none
  269. *-----------------------------------------------------------------*/
  270. extern void RespondSendMessage ( MsgPkt_T* pReq, uint8_t Status);
  271. /**
  272. *@fn ValidateMsgHdr
  273. *@brief Validates the Message header and keeps track of the messages that has been bridged
  274. *@param pReq Request packet of the command to be executed
  275. *@return Returns -1 in case of the response to the bridged message
  276. * Returns 0 otherwise
  277. */
  278. extern int ValidateMsgHdr ( MsgPkt_T* pReq);
  279. #endif /* MSG_HNDLR_H */