AppDevice+.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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. * AppDevice.c
  17. * AppDevice Commands 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. #define ENABLE_DEBUG_MACROS 0
  26. #include "Types.h"
  27. #include "Debug.h"
  28. #include "IPMIDefs.h"
  29. #include "PMConfig.h"
  30. #include "SharedMem.h"
  31. #include "IPMI_Main.h"
  32. #include "Support.h"
  33. #include "IPMI_AppDevice+.h"
  34. #include "AppDevice+.h"
  35. #include "RMCP.h"
  36. #include "RMCP+.h"
  37. #include "NVRAccess.h"
  38. #include "Platform.h"
  39. #include "SOL.h"
  40. #include "KCS.h"
  41. //#include "nwcfg.h"
  42. #include "Ethaddr.h"
  43. #include "IPMIConf.h"
  44. //#include "safesystem.h"
  45. #ifdef APP_DEVICE
  46. /*** Local Macros definitions ***/
  47. #define SET_KEYS_OPER_READ 00
  48. #define SET_KEYS_OPER_SET 01
  49. #define SET_KEYS_OPER_LOCK 02
  50. #define SET_KEYS_OPER_TEST 03
  51. #define KEY_ID_KR 0
  52. #define KEY_ID_KG 1
  53. #define IPMI_PYLD_TYPE 0
  54. #define ENCRYPTION_ONLY 0x80
  55. #define AUTHENTICATION_ONLY 0x40
  56. #define ENCRYPTION_AUTHENTICATION 0xC0
  57. #define AUTHTYPE_RMCP_PLUS_FORMAT 0x06
  58. #define UNSUPPORTED_PAYLOAD_TYPE 0x20
  59. /* Reserved bit macro definitions */
  60. #define RESERVED_BITS_SETCHSECKEY 0xF0 //(BIT7 | BIT6 | BIT5 |BIT4)
  61. #define RESERVED_BITS_GETSYSIFCCAPS 0XF0
  62. /*** Module variables ***/
  63. #if GET_SYS_IFC_CAPS != UNIMPLEMENTED
  64. _FAR_ static const INT8U m_SSIfcData[] =
  65. {0x80 | 0x08 | 0x00, 80, 80}; /**< SMBUS Interface capabilities data */
  66. _FAR_ static const INT8U m_KCSIfcData[] = {0x00, 0xFF};/**< KCS Interface capabilities data */
  67. #endif /* GET_SYS_IFC_CAPS */
  68. static const INT8U m_SupportedAlgrothims [] = { 0x00, 0x01, 0x02, 0x03, 0x40, 0x41, 0x42, 0x43, 0x80, 0x81 };
  69. /*---------------------------------------
  70. * ActivatePayload
  71. *---------------------------------------*/
  72. int
  73. ActivatePayload (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  74. {
  75. _NEAR_ ActivatePayloadReq_T* Req = (_NEAR_ ActivatePayloadReq_T*)pReq;
  76. _NEAR_ ActivatePayloadRes_T* Res = (_NEAR_ ActivatePayloadRes_T*)pRes;
  77. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo;//[BMCInst];
  78. int i;
  79. INT16U ActvtInst = 0;
  80. INT8U EthIndex;
  81. MsgPkt_T MsgPkt;
  82. struct stat fp;
  83. char solsessionfile[MAXFILESIZE] = {0};
  84. INT8U Index;
  85. _FAR_ ChannelInfo_T* pChannelInfo=NULL;
  86. _FAR_ ChannelUserInfo_T* pChUserInfo=NULL;
  87. _FAR_ SessionInfo_T* pSessInfo=NULL;
  88. INT32U *CurSesID,*curchannel;
  89. if((Req->PayldType & (BIT7 | BIT6)) || (Req->PayldInst & (BIT7 | BIT6 | BIT5 | BIT4))
  90. || (Req->PayldInst == 0) || (Req->PayldType == IPMI_PYLD_TYPE))
  91. {
  92. *pRes = CC_INV_DATA_FIELD;
  93. return sizeof(*pRes);
  94. }
  95. /* Check Payload Instance */
  96. if(Req->PayldInst > MAX_PAYLD_INST)
  97. {
  98. IPMI_DBG_PRINT ("AppDevice+.c : ActivatePayload - Payload instance exceeded the limit\n");
  99. Res->CompletionCode = CC_INST_EXCEEDED;
  100. return sizeof(*pRes);
  101. }
  102. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  103. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  104. if(0xff == EthIndex)
  105. {
  106. *pRes = CC_INV_DATA_FIELD;
  107. return sizeof (INT8U);
  108. }
  109. Res->CompletionCode = CC_INV_DATA_FIELD;
  110. OS_THREAD_TLS_GET(g_tls.CurSessionID,CurSesID);
  111. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  112. /* Activate Payload */
  113. pSessInfo = getSessionInfo (SESSION_ID_INFO, CurSesID, BMCInst);
  114. if (NULL == pSessInfo)
  115. {
  116. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  117. *pRes = CC_UNSPECIFIED_ERR;
  118. return sizeof (*pRes);
  119. }
  120. if(pSessInfo->AuthType != AUTHTYPE_RMCP_PLUS_FORMAT)
  121. {
  122. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  123. *pRes = CC_INV_DATA_FIELD;
  124. return sizeof (INT8U);
  125. }
  126. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  127. {
  128. if ((0 != Req->PayldType) &&
  129. (Req->PayldType == pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type))
  130. {
  131. break;
  132. }
  133. }
  134. /* Check if PayloadType exist */
  135. if (i >= MAX_PYLDS_SUPPORT)
  136. {
  137. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  138. /* Check Payload Type No */
  139. Res->CompletionCode = CC_PAYLOAD_NOT_ENABLED;
  140. IPMI_DBG_PRINT_1 ("AppDevice+.c : ActivatePayload - Payload not enabled %x\n", Req->PayldType);
  141. return sizeof (*pRes);
  142. }
  143. /* Activate Payload */
  144. pSessInfo = getSessionInfo (SESSION_ID_INFO,CurSesID, BMCInst);
  145. if (NULL == pSessInfo)
  146. {
  147. return sizeof (*pRes);
  148. }
  149. pChannelInfo = getChannelInfo (*curchannel & 0xF, BMCInst);
  150. if (NULL == pChannelInfo)
  151. {
  152. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  153. *pRes = CC_INV_DATA_FIELD;
  154. return sizeof (*pRes);
  155. }
  156. pChUserInfo = getChUserIdInfo ((pSessInfo->UserId & 0x3F),
  157. &Index,
  158. pChannelInfo->ChannelUserInfo, BMCInst);
  159. if (NULL == pChUserInfo)
  160. {
  161. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  162. return sizeof (*pRes);
  163. }
  164. ActvtInst = getPayloadActiveInst (Req->PayldType, BMCInst);
  165. if (0 != (ActvtInst & (1 << (Req->PayldInst - 1))))
  166. {
  167. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  168. IPMI_DBG_PRINT ("AppDevice+.c : ActivatePayload - Payload already active\n");
  169. Res->CompletionCode = CC_INST_ALREADY_ACTIVE;
  170. return sizeof (*pRes);
  171. }
  172. /* Encryption can not be enabled, if encryption was not negotiated at the
  173. time of session activation */
  174. if ( (0 == pSessInfo->ConfidentialityAlgorithm) && (Req->AuxData[0] & ENCRYPTION_ONLY) )
  175. {
  176. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  177. Res->CompletionCode = CC_CANNOT_ACTIVATE_WITH_ENCR;
  178. return sizeof (*pRes);
  179. }
  180. /* Authentication(Integrity) can not be enabled, if Integrity was not negotiated at the
  181. time of session activation */
  182. if ( (0 == pSessInfo->IntegrityAlgorithm) && (Req->AuxData[0] & AUTHENTICATION_ONLY) )
  183. {
  184. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  185. Res->CompletionCode = CC_INV_DATA_FIELD;
  186. return sizeof (*pRes);
  187. }
  188. if (Req->PayldType == PAYLOAD_SOL)
  189. {
  190. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  191. /*get information abt this channel*/
  192. pChannelInfo = getChannelInfo ((*curchannel & 0xF), BMCInst);
  193. if(NULL == pChannelInfo)
  194. {
  195. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  196. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  197. Res->CompletionCode = CC_INV_DATA_FIELD;
  198. return sizeof (*pRes);
  199. }
  200. /*get information abt this session*/
  201. pSessInfo = getSessionInfo (SESSION_ID_INFO,CurSesID, BMCInst);
  202. if ((pSessInfo != NULL) && (pChannelInfo != NULL))
  203. {
  204. /*get information abt this user*/
  205. pChUserInfo = getChUserIdInfo (pSessInfo->UserId, &Index, pChannelInfo->ChannelUserInfo, BMCInst);
  206. if (pChUserInfo != NULL)
  207. {
  208. pChUserInfo->ActivatingSOL = TRUE;
  209. }
  210. }
  211. else
  212. {
  213. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  214. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  215. *pRes = CC_INV_DATA_FIELD;
  216. return sizeof (INT8U);
  217. }
  218. if((Req->AuxData[0] & (BIT4 | BIT0)) || ((Req->AuxData[0] & BIT3) && (Req->AuxData[0] & BIT2)))
  219. {
  220. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  221. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  222. Res->CompletionCode = CC_INV_DATA_FIELD;
  223. return sizeof (*pRes);
  224. }
  225. if (0 == pBMCInfo->SOLCfg[EthIndex].SOLEnable)
  226. {
  227. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  228. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  229. Res->CompletionCode = CC_PAYLOAD_NOT_ENABLED;
  230. return sizeof (*pRes);
  231. }
  232. if (0 == (pChUserInfo->PayloadEnables [0]& 0x2))
  233. {
  234. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  235. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  236. Res->CompletionCode = CC_PAYLOAD_NOT_ENABLED;
  237. return sizeof (*pRes);
  238. }
  239. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  240. /* If encryption is used, authentication must also be used */
  241. if ((Req->AuxData[0] & ENCRYPTION_ONLY) && !(Req->AuxData[0] & AUTHENTICATION_ONLY))
  242. {
  243. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  244. Res->CompletionCode = CC_INV_DATA_FIELD;
  245. return sizeof (*pRes);
  246. }
  247. /* checked if forced encryption is enabled */
  248. if (ENCRYPTION_ONLY == (pBMCInfo->SOLCfg[EthIndex].SOLAuth & ENCRYPTION_ONLY ) )
  249. {
  250. /* Check for authentication and encryption activations */
  251. if (ENCRYPTION_ONLY != (Req->AuxData[0] & ENCRYPTION_ONLY))
  252. {
  253. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  254. Res->CompletionCode = CC_CANNOT_ACTIVATE_WITHOUT_ENCR;
  255. return sizeof (*pRes);
  256. }
  257. }
  258. /* checked if forced authentication is enabled */
  259. if (AUTHENTICATION_ONLY == (pBMCInfo->SOLCfg[EthIndex].SOLAuth & AUTHENTICATION_ONLY ) )
  260. {
  261. /* Check for authentication activations */
  262. if (AUTHENTICATION_ONLY != (Req->AuxData[0] & AUTHENTICATION_ONLY))
  263. {
  264. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  265. Res->CompletionCode = CC_CANNOT_ACTIVATE_WITHOUT_ENCR;
  266. return sizeof (*pRes);
  267. }
  268. }
  269. /* To check the SOL Priveilege */
  270. if(pSessInfo->Privilege < (pBMCInfo->SOLCfg[EthIndex].SOLAuth & 0xF))
  271. {
  272. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  273. Res->CompletionCode = CC_INSUFFIENT_PRIVILEGE;
  274. return sizeof (*pRes);
  275. }
  276. /* PDK to Check SOL connected from CLI*/
  277. if(g_PDKHandle[PDK_ISSOLCONNECTED] != NULL)
  278. {
  279. ((INT8U(*)(int)) g_PDKHandle[PDK_ISSOLCONNECTED])(BMCInst);
  280. }
  281. /*Check the sol session file. If its exist CIM might establish the SOL session using solssh, so return the completion code as 0x80.
  282. *Otherwise create the sol session file to prevent the CIM to establish the SOL session.
  283. */
  284. sprintf(solsessionfile,"%s%d",SOL_SESSION_FILE,BMCInst);
  285. if(stat(solsessionfile,&fp) != 0)
  286. {
  287. memset(solsessionfile,0,MAXFILESIZE);
  288. sprintf(solsessionfile,"touch %s%d",SOL_SESSION_FILE,BMCInst);
  289. safe_system(solsessionfile);
  290. }
  291. else
  292. {
  293. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  294. *pRes = CC_INST_ALREADY_ACTIVE;
  295. return sizeof(INT8U);
  296. }
  297. pSessInfo->Activated = TRUE;
  298. if(pBMCInfo->IpmiConfig.SOLIfcSupport == 1)
  299. {
  300. BMC_GET_SHARED_MEM (BMCInst)->SOLSessID = pSessInfo->SessionID;
  301. pSessInfo->TimeOutValue = pBMCInfo->IpmiConfig.SOLSessionTimeOut;
  302. /* If SOL timeout value equals 0, then SOL will never timeout.. */
  303. if( pBMCInfo->IpmiConfig.SOLSessionTimeOut == 0)
  304. pSessInfo->TimeOutValue = pBMCInfo->IpmiConfig.SessionTimeOut;
  305. MsgPkt.Param = START_SOL;
  306. MsgPkt.Size = 0;
  307. if( 0 != PostMsg (&MsgPkt, SOL_IFC_Q,BMCInst))
  308. {
  309. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  310. IPMI_WARNING ("AppDevice+.c : Error posting message to SOLIfc_Q\n");
  311. Res->CompletionCode = CC_UNSPECIFIED_ERR;
  312. return sizeof(*pRes);
  313. }
  314. MsgPkt.Param = ACTIVATE_SOL;
  315. MsgPkt.Size = 0;
  316. if( 0 != PostMsg (&MsgPkt, SOL_IFC_Q,BMCInst))
  317. {
  318. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  319. IPMI_WARNING ("AppDevice+.c : Error posting message to SOLIfc_Q\n");
  320. Res->CompletionCode = CC_UNSPECIFIED_ERR;
  321. return sizeof(*pRes);
  322. }
  323. }
  324. }
  325. ActvtInst |= 1 << (Req->PayldInst - 1);
  326. pSessInfo->SessPyldInfo [Req->PayldType].ActivatedInst = ActvtInst;
  327. pSessInfo->SessPyldInfo [Req->PayldType].Type = Req->PayldType;
  328. _fmemcpy (pSessInfo->SessPyldInfo [Req->PayldType].AuxConfig, Req->AuxData, 4);
  329. /* Load Response */
  330. Res->CompletionCode = CC_NORMAL;
  331. _fmemset (Res->AuxData, 0, 4);
  332. Res->InboundPayldSize = (Req->PayldType == PAYLOAD_SOL)? htoipmi_u16 (MAX_SOL_IN_PAYLD_SIZE): htoipmi_u16 (MAX_IN_PAYLD_SIZE);
  333. Res->OutboundPayldSize = (Req->PayldType == PAYLOAD_SOL)? htoipmi_u16 (MAX_SOL_OUT_PAYLD_SIZE): htoipmi_u16 (MAX_OUT_PAYLD_SIZE);
  334. Res->UDPPort = htoipmi_u16(623);
  335. Res->VLANNo = 0xFFFF;
  336. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  337. return sizeof (ActivatePayloadRes_T);
  338. }
  339. /*---------------------------------------
  340. * DeactivatePayload
  341. *---------------------------------------*/
  342. int
  343. DeactivatePayload (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  344. {
  345. _NEAR_ DeactivatePayloadReq_T* Req = (_NEAR_ DeactivatePayloadReq_T*)pReq;
  346. int i;
  347. INT16U ActvtInst = 0;
  348. INT32U SolSessionID;
  349. MsgPkt_T MsgPkt;
  350. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  351. INT8U EthIndex;
  352. _FAR_ ChannelInfo_T* pChannelInfo=NULL;
  353. _FAR_ ChannelUserInfo_T* pChUserInfo=NULL;
  354. _FAR_ SessionInfo_T* pSessInfo=NULL;
  355. INT8U Index;
  356. char solsessionfile[MAXFILESIZE] = {0};
  357. struct stat fp;
  358. INT32U *CurSesID,*curchannel;
  359. if((Req->PayldType & (BIT7 | BIT6)) || (Req->PayldInst & (BIT7 | BIT6 | BIT5 | BIT4))
  360. || (Req->PayldInst == 0) || (Req->PayldType == IPMI_PYLD_TYPE))
  361. {
  362. *pRes = CC_INV_DATA_FIELD;
  363. return sizeof(*pRes);
  364. }
  365. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  366. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  367. if(0xff == EthIndex)
  368. {
  369. *pRes = CC_INV_DATA_FIELD;
  370. return sizeof (INT8U);
  371. }
  372. /* Check Payload Type No */
  373. *pRes = CC_INV_DATA_FIELD;
  374. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  375. {
  376. if ((0 != Req->PayldType) &&
  377. (Req->PayldType == pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type))
  378. {
  379. break;
  380. }
  381. }
  382. /* Check if PayloadType exist */
  383. if (MAX_PYLDS_SUPPORT == i)
  384. {
  385. return sizeof (*pRes);
  386. }
  387. /* Check Payload Instance */
  388. if (Req->PayldInst > MAX_PAYLD_INST)
  389. {
  390. return sizeof (*pRes);
  391. }
  392. if ((0 == pBMCInfo->SOLCfg[EthIndex].SOLEnable) && (1 == Req->PayldType))
  393. {
  394. *pRes = CC_PAYLOAD_NOT_ENABLED;
  395. return sizeof (*pRes);
  396. }
  397. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  398. SolSessionID =BMC_GET_SHARED_MEM (BMCInst)->SOLSessID ;
  399. /* Deactivate Payload */
  400. pSessInfo = getSessionInfo (SESSION_ID_INFO,&SolSessionID, BMCInst);
  401. if (NULL == pSessInfo)
  402. {
  403. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  404. IPMI_DBG_PRINT ("AppDevice+.c : Deactivate Payload - Invalid Session Id\n");
  405. *pRes = CC_INST_ALREADY_INACTIVE;
  406. return sizeof (*pRes);
  407. }
  408. ActvtInst = pSessInfo->SessPyldInfo [Req->PayldType].ActivatedInst;
  409. if (0 == (ActvtInst & (1 << (Req->PayldInst - 1))))
  410. {
  411. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  412. IPMI_DBG_PRINT ("AppDevice+.c : Deactivate Payload - Payload already deactivated\n");
  413. *pRes = CC_INST_ALREADY_INACTIVE;
  414. return sizeof (*pRes);
  415. }
  416. ActvtInst &= ~(1 << (Req->PayldInst - 1));
  417. pSessInfo->SessPyldInfo [Req->PayldType].ActivatedInst = ActvtInst;
  418. #if 0
  419. _fmemcpy (pSessInfo->SessPyldInfo [Req->PayldType].AuxConfig, Req->AuxData, 4);
  420. if(pBMCInfo->IpmiConfig.SOLIfcSupport == 1)
  421. {
  422. if (Req->PayldType == PAYLOAD_SOL)
  423. {
  424. pSessInfo->SessPyldInfo [Req->PayldType].Type = 0;
  425. pSessInfo->TimeOutValue = pBMCInfo->IpmiConfig.SessionTimeOut;
  426. }
  427. }
  428. #endif
  429. if(pBMCInfo->IpmiConfig.SOLIfcSupport == 1)
  430. {
  431. if (Req->PayldType == PAYLOAD_SOL)
  432. {
  433. /*Remove the solsession file while deactivating the SOL,so that CIM can establish the SOL session using solssh app*/
  434. sprintf(solsessionfile,"%s%d",SOL_SESSION_FILE,BMCInst);
  435. if(stat(solsessionfile,&fp) == 0)
  436. {
  437. unlink(solsessionfile);
  438. }
  439. /*get information abt this channel*/
  440. pChannelInfo = getChannelInfo ((*curchannel & 0xF), BMCInst);
  441. if(NULL == pChannelInfo)
  442. {
  443. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  444. *pRes = CC_INV_DATA_FIELD;
  445. return sizeof (*pRes);
  446. }
  447. OS_THREAD_TLS_GET(g_tls.CurSessionID,CurSesID);
  448. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  449. /*get information abt this session*/
  450. pSessInfo = getSessionInfo (SESSION_ID_INFO,CurSesID, BMCInst);
  451. if ((pSessInfo != NULL) && (pChannelInfo != NULL))
  452. {
  453. /*get information abt this user*/
  454. pChUserInfo = getChUserIdInfo (pSessInfo->UserId, &Index, pChannelInfo->ChannelUserInfo, BMCInst);
  455. if (pChUserInfo != NULL)
  456. {
  457. pChUserInfo->ActivatingSOL = FALSE;
  458. }
  459. }
  460. else
  461. {
  462. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  463. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  464. *pRes = CC_UNSPECIFIED_ERR;
  465. return sizeof (*pRes);
  466. }
  467. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  468. /* Deactivate SOL */
  469. MsgPkt.Param = DEACTIVATE_SOL;
  470. MsgPkt.Size = 0;
  471. if( 0 != PostMsg (&MsgPkt, SOL_IFC_Q,BMCInst))
  472. {
  473. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  474. IPMI_WARNING ("AppDevice+.c : Error posting message to SOLIfc_Q\n");
  475. *pRes = CC_UNSPECIFIED_ERR;
  476. return sizeof(*pRes);
  477. }
  478. /* PDK to Check SOL connected from CLI*/
  479. if(g_PDKHandle[PDK_ISSOLCONNECTED] != NULL)
  480. {
  481. ((INT8U(*)(int)) g_PDKHandle[PDK_ISSOLCONNECTED])(BMCInst);
  482. }
  483. }
  484. /*Required delay of 0.5 sec, when the sol session consecutively deactivate
  485. and activate. If there is no delay means, sol send the Deactivated packet
  486. to both the session unknowingly*/
  487. usleep (500000);
  488. }
  489. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  490. /* Load Response */
  491. *pRes = CC_NORMAL;
  492. return sizeof (*pRes);
  493. }
  494. /*---------------------------------------
  495. * GetPayldActStatus
  496. *---------------------------------------*/
  497. int
  498. GetPayldActStatus (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  499. {
  500. _NEAR_ GetPayldActStatRes_T* Res = (_NEAR_ GetPayldActStatRes_T*)pRes;
  501. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  502. int i;
  503. /* Check Payload Type No */
  504. Res->CompletionCode = CC_INV_DATA_FIELD;
  505. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  506. {
  507. /* We dont know Which LAN channel we need .so Returning default 0 . */
  508. if ((0 != pReq[0]) &&
  509. (pReq[0] == pBMCInfo->RMCPPlus[0].PayloadInfo [i].Type))
  510. {
  511. break;
  512. }
  513. }
  514. /* Check if PayloadType exist */
  515. if (MAX_PYLDS_SUPPORT == i && (IPMI_PYLD_TYPE != pReq[0]))
  516. {
  517. return sizeof (*pRes);
  518. }
  519. Res->CompletionCode = CC_NORMAL;
  520. Res->InstCap = MAX_PAYLD_INST;
  521. if(IPMI_PYLD_TYPE == pReq[0])
  522. {
  523. Res->ActivatedInst = 1;
  524. }
  525. else
  526. {
  527. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  528. Res->ActivatedInst = htoipmi_u16 (getPayloadActiveInst (*pReq, BMCInst));
  529. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  530. }
  531. return sizeof (GetPayldActStatRes_T);
  532. }
  533. /*---------------------------------------
  534. * GetPayldInstInfo
  535. *---------------------------------------*/
  536. int
  537. GetPayldInstInfo (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  538. {
  539. _NEAR_ GetPayldInstInfoReq_T* Req = (_NEAR_ GetPayldInstInfoReq_T*)pReq;
  540. _NEAR_ GetPayldInstInfoRes_T* Res = (_NEAR_ GetPayldInstInfoRes_T*)pRes;
  541. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  542. int i;
  543. /* Check Payload Type No & Totally 16 payload instances can be supported */
  544. if ((Req->PayldInst == 0) || (Req->PayldType == IPMI_PYLD_TYPE)
  545. || (Req->PayldType >= UNSUPPORTED_PAYLOAD_TYPE) || (Req->PayldInst > MAX_PAYLD_INST))
  546. {
  547. *pRes = CC_INV_DATA_FIELD;
  548. return sizeof (*pRes);
  549. }
  550. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  551. {
  552. // if ((0 != Req->PayldType) &&
  553. /* We dont know Which LAN channel we need .so Returning default 0 . */
  554. if (Req->PayldType == pBMCInfo->RMCPPlus[0].PayloadInfo [i].Type)
  555. {
  556. break;
  557. }
  558. }
  559. /* Check if PayloadType exist */
  560. if (MAX_PYLDS_SUPPORT == i) { return sizeof (*pRes); }
  561. /* Load Response */
  562. _fmemset (Res, 0, sizeof (GetPayldInstInfoRes_T));
  563. Res->CompletionCode = CC_NORMAL;
  564. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  565. Res->SessionID = getPayloadInstInfo (Req->PayldType, Req->PayldInst, BMCInst);
  566. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  567. if (Req->PayldType == PAYLOAD_SOL)
  568. {
  569. Res->SpecificInfo[0] = SYS_SERIAL_PORT_NUM;
  570. }
  571. return sizeof (GetPayldInstInfoRes_T);
  572. }
  573. /*---------------------------------------
  574. * SetUsrPayloadAccess
  575. *---------------------------------------*/
  576. int
  577. SetUsrPayloadAccess (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  578. {
  579. _NEAR_ SetUsrPayldAccReq_T* Req = (_NEAR_ SetUsrPayldAccReq_T*)pReq;
  580. _FAR_ ChannelInfo_T* pChannelInfo;
  581. _FAR_ ChannelUserInfo_T* pChUserInfo;
  582. _FAR_ ChannelUserInfo_T* pNVRChUserInfo;
  583. INT8U Index;
  584. int i,j;
  585. INT8U Operation;
  586. INT8U ChannelNum;
  587. INT8U EthIndex,*curchannel;
  588. BMCInfo_t *pBMCInfo= &g_BMCInfo[BMCInst];
  589. // char ChFilename[MAX_CHFILE_NAME];
  590. /* Check Channel No */
  591. *pRes = CC_INV_DATA_FIELD;
  592. /* Check for Reserved Bits */
  593. if((0 != (Req->ChannelNum & 0xf0)) ||
  594. ((((Req->UserId & 0xc0) >> 6) != 0x00) && (((Req->UserId & 0xc0) >> 6) != 0x01)))
  595. return sizeof (*pRes);
  596. /*Check for Payload Reserved Bits */
  597. if((0 != (Req->PayloadEnables[0] & 0xfd)) ||
  598. ( 0 != (Req->PayloadEnables[1] & 0xff)) ||
  599. ( 0 != (Req->PayloadEnables[3] & 0xff)))
  600. return sizeof (*pRes);
  601. ChannelNum = *pReq & 0x0F;
  602. if (0x0E == ChannelNum)
  603. {
  604. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  605. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  606. }else
  607. {
  608. EthIndex= GetEthIndex(ChannelNum, BMCInst);
  609. }
  610. if(0xff == EthIndex)
  611. {
  612. *pRes = CC_INV_DATA_FIELD;
  613. return sizeof (*pRes);
  614. }
  615. /* Check UserID */
  616. if (0 == (Req->UserId & 0x3F))
  617. {
  618. return sizeof (*pRes);
  619. }
  620. pChannelInfo = getChannelInfo (Req->ChannelNum & 0x0F, BMCInst);
  621. if (NULL == pChannelInfo)
  622. {
  623. *pRes = CC_INV_DATA_FIELD;
  624. return sizeof (*pRes);
  625. }
  626. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  627. pChUserInfo = getChUserIdInfo ((Req->UserId & 0x3F),
  628. &Index,
  629. pChannelInfo->ChannelUserInfo, BMCInst);
  630. if (NULL == pChUserInfo)
  631. {
  632. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  633. return sizeof (*pRes);
  634. }
  635. /*Check if the setting is for OEM/ Standard */
  636. Operation = Req->UserId >> 6;
  637. pNVRChUserInfo = GetNVRChUserConfigs(pChannelInfo,BMCInst);
  638. /* Set Access settings */
  639. for (i = 0; i < MAX_PLD_ENABLES; i++)
  640. {
  641. for (j = 0; j < 8; j++)
  642. {
  643. if ((i == 0) && (j == 0)) { continue; } //For IPMI payload
  644. if (0 == (Req->PayloadEnables [i] & (1 << j)))
  645. {
  646. continue;
  647. }
  648. switch (Operation)
  649. {
  650. case 0: /* Enable */
  651. pChUserInfo->PayloadEnables [i] |= (1 << j);
  652. pNVRChUserInfo[Index].PayloadEnables [i] |= (1 << j);
  653. break;
  654. case 1: /* Disable */
  655. pChUserInfo->PayloadEnables [i] &= ~(1 << j);
  656. pNVRChUserInfo[Index].PayloadEnables [i] &= ~(1 << j);
  657. break;
  658. }
  659. }
  660. }
  661. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  662. FlushChConfigs((INT8U*)GetNVRChConfigs(pChannelInfo,BMCInst),Req->ChannelNum,BMCInst);
  663. /* Load Response */
  664. *pRes = CC_NORMAL;
  665. return sizeof (*pRes);
  666. }
  667. /*---------------------------------------
  668. * GetUsrPayloadAccess
  669. *---------------------------------------*/
  670. int
  671. GetUsrPayloadAccess (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  672. {
  673. _NEAR_ GetUsrPayldAccReq_T* Req = (_NEAR_ GetUsrPayldAccReq_T*)pReq;
  674. _NEAR_ GetUsrPayldAccRes_T* Res = (_NEAR_ GetUsrPayldAccRes_T*)pRes;
  675. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  676. _FAR_ ChannelInfo_T* pChannelInfo;
  677. _FAR_ ChannelUserInfo_T* pChUserInfo;
  678. INT8U Index;
  679. INT8U ChannelNum,*curchannel;
  680. INT8U EthIndex;
  681. /* Check Channel No */
  682. Res->CompletionCode = CC_INV_DATA_FIELD;
  683. /* Check for reserved Bits */
  684. if((0 != (Req->ChannelNum & 0xf0)) || (0 != (Req->UserId & 0xc0)))
  685. return sizeof (*pRes);
  686. ChannelNum = *pReq & 0x0F;
  687. if (0x0E == ChannelNum)
  688. {
  689. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  690. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  691. ChannelNum = *curchannel & 0xF;
  692. }else
  693. {
  694. EthIndex= GetEthIndex(ChannelNum, BMCInst);
  695. }
  696. if(0xff == EthIndex)
  697. {
  698. *pRes = CC_INV_DATA_FIELD;
  699. return sizeof (*pRes);
  700. }
  701. /* Check UserID */
  702. if (0 == (Req->UserId & 0x3F))
  703. {
  704. IPMI_WARNING ("Invalid User\n");
  705. return sizeof (*pRes);
  706. }
  707. pChannelInfo = getChannelInfo (ChannelNum, BMCInst);
  708. if (NULL == pChannelInfo)
  709. {
  710. IPMI_WARNING ("Unable to get Ch infor %d\n", ChannelNum);
  711. *pRes = CC_INV_DATA_FIELD;
  712. return sizeof (*pRes);
  713. }
  714. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  715. pChUserInfo = getChUserIdInfo ((Req->UserId & 0x3F),
  716. &Index,
  717. pChannelInfo->ChannelUserInfo, BMCInst);
  718. if (NULL == pChUserInfo)
  719. {
  720. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  721. IPMI_DBG_PRINT_1 ("Unable to get Ch user infor %d \n", Req->UserId);
  722. return sizeof (*pRes);
  723. }
  724. /* Get Access settings */
  725. _fmemcpy (Res->PayloadEnables, pChUserInfo->PayloadEnables, MAX_PLD_ENABLES);
  726. Res->CompletionCode = CC_NORMAL;
  727. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  728. return sizeof (GetUsrPayldAccRes_T);
  729. }
  730. /*---------------------------------------
  731. * GetChPayloadSupport
  732. *---------------------------------------*/
  733. int
  734. GetChPayloadSupport (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  735. {
  736. _NEAR_ GetChPayldSupRes_T* Res = (_NEAR_ GetChPayldSupRes_T*)pRes;
  737. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  738. INT8U ChannelNum,*curchannel;
  739. INT8U EthIndex;
  740. Res->CompletionCode = CC_INV_DATA_FIELD;
  741. if( *pReq & (BIT7 | BIT6 | BIT5 | BIT4))
  742. {
  743. *pRes = CC_INV_DATA_FIELD;
  744. return sizeof(*pRes);
  745. }
  746. ChannelNum = *pReq;
  747. if (0x0E == ChannelNum)
  748. {
  749. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  750. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  751. }else
  752. {
  753. EthIndex= GetEthIndex(ChannelNum, BMCInst);
  754. }
  755. if(0xff == EthIndex)
  756. {
  757. *pRes = CC_INV_DATA_FIELD;
  758. return sizeof (*pRes);
  759. }
  760. LOCK_BMC_SHARED_MEM(BMCInst);
  761. /* Load Payload Supported */
  762. _fmemcpy (&Res->StdPldtype1, (_FAR_ INT8U*)&pBMCInfo->RMCPPlus[EthIndex].PayloadSupport,
  763. sizeof (PayloadSupport_T));
  764. UNLOCK_BMC_SHARED_MEM(BMCInst);
  765. /* Load Response */
  766. Res->CompletionCode = CC_NORMAL;
  767. Res->Rsvd = 0x0000;
  768. return sizeof (GetChPayldSupRes_T);
  769. }
  770. /*---------------------------------------
  771. * GetChPayloadVersion
  772. *---------------------------------------*/
  773. int
  774. GetChPayloadVersion (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  775. {
  776. _NEAR_ GetChPayldVerReq_T* Req = (_NEAR_ GetChPayldVerReq_T*)pReq;
  777. _NEAR_ GetChPayldVerRes_T* Res = (_NEAR_ GetChPayldVerRes_T*)pRes;
  778. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  779. int i;
  780. INT8U ChannelNum,*curchannel;
  781. INT8U EthIndex;
  782. /* Check Channel No */
  783. Res->CompletionCode = CC_INV_DATA_FIELD;
  784. if( Req->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4))
  785. {
  786. *pRes = CC_INV_DATA_FIELD;
  787. return sizeof(*pRes);
  788. }
  789. ChannelNum = *pReq & 0x0F;
  790. if (0x0E == ChannelNum)
  791. {
  792. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  793. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  794. }else
  795. {
  796. EthIndex= GetEthIndex(ChannelNum, BMCInst);
  797. }
  798. if(0xff == EthIndex)
  799. {
  800. *pRes = CC_INV_DATA_FIELD;
  801. return sizeof (*pRes);
  802. }
  803. /* Check Payload Type No */
  804. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  805. {
  806. if (Req->PayloadNum == pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type)
  807. {
  808. break;
  809. }
  810. }
  811. /* Check if PayloadType exist */
  812. if (MAX_PYLDS_SUPPORT == i)
  813. {
  814. IPMI_DBG_PRINT_1("AppDevice+.c : GetChPayloadVersion - Payload type (%x) not available on given channel. \n",Req->PayloadNum);
  815. Res->CompletionCode = CC_PAYLOAD_NOT_AVAILABLE;
  816. return sizeof (*pRes);
  817. }
  818. /* Load Payload Version */
  819. Res->CompletionCode = CC_NORMAL;
  820. Res->FormatVer = pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Version;
  821. return sizeof (GetChPayldVerRes_T);
  822. }
  823. /*---------------------------------------
  824. * GetChOemPayloadInfo
  825. *---------------------------------------*/
  826. int
  827. GetChOemPayloadInfo (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  828. {
  829. _NEAR_ GetChOemPayldInfoReq_T* Req = (_NEAR_ GetChOemPayldInfoReq_T*)pReq;
  830. _NEAR_ GetChOemPayldInfoRes_T* Res = (_NEAR_ GetChOemPayldInfoRes_T*)pRes;
  831. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  832. int i;
  833. INT8U ChannelNum,*curchannel;
  834. INT8U EthIndex;
  835. /* Check Channel No */
  836. Res->CompletionCode = CC_INV_DATA_FIELD;
  837. if( Req->ChannelNum & (BIT7 | BIT6 | BIT5 | BIT4))
  838. {
  839. *pRes = CC_INV_DATA_FIELD;
  840. return sizeof(*pRes);
  841. }
  842. ChannelNum = *pReq & 0x0F;
  843. if (0x0E == ChannelNum)
  844. {
  845. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  846. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  847. }else
  848. {
  849. EthIndex= GetEthIndex(ChannelNum, BMCInst);
  850. }
  851. if(0xff == EthIndex)
  852. {
  853. *pRes = CC_INV_DATA_FIELD;
  854. return sizeof (*pRes);
  855. }
  856. LOCK_BMC_SHARED_MEM(BMCInst);
  857. /* Check Payload Type No */
  858. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  859. {
  860. if ((Req->PayloadNum == pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type) &&
  861. (0 == _fmemcmp (&Req->OemIANA, pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].OemPldIANA, sizeof (Req->OemIANA))) &&
  862. (0 == _fmemcmp (&Req->OemPyldId, pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].OemPldID, sizeof (Req->OemPyldId))))
  863. {
  864. break;
  865. }
  866. }
  867. UNLOCK_BMC_SHARED_MEM(BMCInst);
  868. /* Check if PayloadType exist */
  869. if (MAX_PYLDS_SUPPORT == i)
  870. {
  871. *pRes = CC_PARAM_NOT_SUPPORTED;
  872. return sizeof (*pRes);
  873. }
  874. /* Load Payload Version */
  875. Res->CompletionCode = CC_NORMAL;
  876. LOCK_BMC_SHARED_MEM(BMCInst);
  877. _fmemcpy (&Res->PayloadNum, &pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type, sizeof (PayloadInfo_T));
  878. UNLOCK_BMC_SHARED_MEM(BMCInst);
  879. return sizeof (GetChOemPayldInfoRes_T);
  880. }
  881. /*---------------------------------------
  882. * GetChCipherSuites
  883. *---------------------------------------*/
  884. int
  885. GetChCipherSuites (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  886. {
  887. _NEAR_ GetChCipherSuitesReq_T* Req = (_NEAR_ GetChCipherSuitesReq_T*)pReq;
  888. _NEAR_ GetChCipherSuitesRes_T* Res = (_NEAR_ GetChCipherSuitesRes_T*)pRes;
  889. INT8U Channel, Ix, ResLen,*curchannel;
  890. INT8U EthIndex;
  891. /* Check if the Channel No is valid */
  892. Channel = Req->ChannelNum;
  893. Res->CompletionCode = CC_INV_DATA_FIELD ;
  894. if((Req->ChannelNum & (BIT7 | BIT6 | BIT5 |BIT4)) || (Req->PayloadType & (BIT7 | BIT6)) ||
  895. (Req->ListIndex & BIT6))
  896. {
  897. *pRes = CC_INV_DATA_FIELD;
  898. return sizeof(*pRes);
  899. }
  900. if (0x0E == Channel)
  901. {
  902. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  903. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  904. }else
  905. {
  906. EthIndex= GetEthIndex(Channel, BMCInst);
  907. }
  908. if(0xff == EthIndex)
  909. {
  910. *pRes = CC_INV_DATA_FIELD;
  911. return sizeof (*pRes);
  912. }
  913. /* Check if the Payload is valid */
  914. if (Req->PayloadType >= MAX_PYLDS_SUPPORT)
  915. {
  916. return sizeof (*pRes);
  917. }
  918. if (Req->ListIndex & 0x80)
  919. {
  920. /* Get ListIndex */
  921. Ix = Req->ListIndex & 0x3F;
  922. /* Load Cipher Suites Response */
  923. Res->CompletionCode = CC_NORMAL;
  924. Res->ChannelNum = GetLANChannel(EthIndex, BMCInst);
  925. if (Ix > (sizeof (g_CipherRec)/16))
  926. {
  927. return 2;
  928. }
  929. ResLen = sizeof (g_CipherRec) - (Ix * 16);
  930. ResLen = (ResLen >= 16) ? 16 : ResLen;
  931. _fmemcpy (Res + 1, &g_CipherRec [Ix * 16], ResLen);
  932. }
  933. else
  934. {
  935. /* Get ListIndex */
  936. Ix = Req->ListIndex & 0x3F;
  937. /* Load Cipher Suites Response */
  938. Res->CompletionCode = CC_NORMAL;
  939. Res->ChannelNum = GetLANChannel(EthIndex, BMCInst);
  940. if (Ix <= 1)
  941. {
  942. ResLen = sizeof (m_SupportedAlgrothims);
  943. _fmemcpy (Res + 1, m_SupportedAlgrothims, ResLen);
  944. }
  945. else
  946. {
  947. ResLen = 0x00;
  948. }
  949. }
  950. return sizeof (GetChCipherSuitesRes_T) + ResLen;
  951. }
  952. /*---------------------------------------
  953. * SetChSecurityKeys
  954. *---------------------------------------*/
  955. int
  956. SetChSecurityKeys (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  957. {
  958. _NEAR_ SetChSecurityKeysReq_T* Req = (_NEAR_ SetChSecurityKeysReq_T*)pReq;
  959. _NEAR_ SetChSecurityKeysRes_T* Res = (_NEAR_ SetChSecurityKeysRes_T*)pRes;
  960. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  961. _FAR_ INT8U* pKeys;
  962. int Keysize, ResLen;
  963. INT8U EthIndex,*curchannel;
  964. if(Req->ChannelNum & RESERVED_BITS_SETCHSECKEY)
  965. {
  966. *pRes = CC_INV_DATA_FIELD;
  967. return sizeof(*pRes);
  968. }
  969. /* Check Channel No */
  970. Res->CompletionCode = CC_INV_DATA_FIELD;
  971. if (0x0E == Req->ChannelNum)
  972. {
  973. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  974. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  975. }else
  976. {
  977. EthIndex= GetEthIndex(Req->ChannelNum, BMCInst);
  978. }
  979. if(0xff == EthIndex)
  980. {
  981. *pRes = CC_INV_DATA_FIELD;
  982. return sizeof (*pRes);
  983. }
  984. /* Check the Reserved Bit in Request */
  985. if(Req->Operation > 2)
  986. {
  987. *pRes = CC_INV_DATA_FIELD;
  988. return sizeof (*pRes);
  989. }
  990. /* Check Key Id */
  991. if (KEY_ID_KR == Req->KeyID)
  992. {
  993. pKeys = (_FAR_ INT8U*)pBMCInfo->RMCPPlus[EthIndex].PseudoGenKey;
  994. }
  995. else if (KEY_ID_KG == Req->KeyID)
  996. {
  997. pKeys = (_FAR_ INT8U*)pBMCInfo->RMCPPlus[EthIndex].KGHashKey;
  998. }
  999. else
  1000. {
  1001. /* Invalid ID */
  1002. return sizeof (*pRes);
  1003. }
  1004. Res->CompletionCode = CC_NORMAL;
  1005. if (TRUE == pBMCInfo->RMCPPlus[EthIndex].LockKey [Req->KeyID])
  1006. {
  1007. Res->LockStatus = 0x01;
  1008. }
  1009. else
  1010. {
  1011. Res->LockStatus = 0x02;
  1012. }
  1013. ResLen = sizeof (SetChSecurityKeysRes_T);
  1014. /* Perform Operation */
  1015. switch (Req->Operation)
  1016. {
  1017. case SET_KEYS_OPER_READ:
  1018. if (TRUE == pBMCInfo->RMCPPlus[EthIndex].LockKey [Req->KeyID])
  1019. {
  1020. Res->CompletionCode = CC_KEYS_LOCKED;
  1021. return sizeof (*pRes);
  1022. }
  1023. LOCK_BMC_SHARED_MEM(BMCInst);
  1024. _fmemcpy (pRes + sizeof (SetChSecurityKeysRes_T), pKeys, HASH_KEY_LEN);
  1025. UNLOCK_BMC_SHARED_MEM(BMCInst);
  1026. ResLen = sizeof (SetChSecurityKeysRes_T) + HASH_KEY_LEN;
  1027. break;
  1028. case SET_KEYS_OPER_SET :
  1029. Keysize = ReqLen - sizeof (SetChSecurityKeysReq_T);
  1030. if (Keysize > HASH_KEY_LEN)
  1031. {
  1032. Res->CompletionCode = CC_TOO_MANY_KEY_BYTES;
  1033. return sizeof (*pRes);
  1034. }
  1035. else if (Keysize < HASH_KEY_LEN)
  1036. {
  1037. Res->CompletionCode = CC_INSUF_KEY_BYTES;
  1038. return sizeof (*pRes);
  1039. }
  1040. if (TRUE == pBMCInfo->RMCPPlus[EthIndex].LockKey [Req->KeyID])
  1041. {
  1042. Res->CompletionCode = CC_KEYS_LOCKED;
  1043. return sizeof (*pRes);
  1044. }
  1045. LOCK_BMC_SHARED_MEM(BMCInst);
  1046. _fmemset (pKeys, 0, HASH_KEY_LEN);
  1047. _fmemcpy (pKeys, pReq + sizeof (SetChSecurityKeysReq_T), Keysize);
  1048. UNLOCK_BMC_SHARED_MEM(BMCInst);
  1049. break;
  1050. case SET_KEYS_OPER_LOCK:
  1051. if (Req->KeyID == KEY_ID_KG)
  1052. {
  1053. Res->CompletionCode = CC_INV_DATA_FIELD;
  1054. ResLen = 1;
  1055. }
  1056. else
  1057. {
  1058. pBMCInfo->RMCPPlus[EthIndex].LockKey [Req->KeyID] = TRUE;
  1059. Res->LockStatus = 0x01;
  1060. }
  1061. break;
  1062. default:
  1063. return sizeof (*pRes);
  1064. }
  1065. return ResLen;
  1066. }
  1067. /*---------------------------------------
  1068. * SusResPayldEncrypt
  1069. *---------------------------------------*/
  1070. int
  1071. SusResPayldEncrypt (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  1072. {
  1073. _NEAR_ SusResPayldEncryptReq_T* Req = (_NEAR_ SusResPayldEncryptReq_T*)pReq;
  1074. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1075. int i;
  1076. _FAR_ SessionInfo_T* pSessInfo;
  1077. INT32U SessionID;
  1078. INT8U EthIndex,*curchannel;
  1079. if((Req->PayldType & (BIT7 | BIT6)) || (Req->PayldInst & (BIT7 | BIT6 | BIT5 | BIT4))
  1080. || (Req->PayldInst == 0))
  1081. {
  1082. *pRes = CC_INV_DATA_FIELD;
  1083. return sizeof(*pRes);
  1084. }
  1085. if(Req->Operation & (BIT7 | BIT6 | BIT5 | BIT4))
  1086. {
  1087. *pRes = CC_INV_DATA_FIELD;
  1088. return sizeof(*pRes);
  1089. }
  1090. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  1091. EthIndex= GetEthIndex(*curchannel & 0xF, BMCInst);
  1092. if(0xff== EthIndex)
  1093. {
  1094. *pRes = CC_INV_DATA_FIELD;
  1095. return sizeof (INT8U);
  1096. }
  1097. if (0 == Req->PayldType)
  1098. {
  1099. /* Encryption can not be Suspended/Resumed for IPMI payload type */
  1100. /* For IPMI payload type, The "Suspend/Resume Payload Encryption" command controls
  1101. whether asynchronous (unrequested) messages from the BMC are encrypted or not */
  1102. *pRes = CC_OP_NOT_SUPPORTED;
  1103. return sizeof (*pRes);
  1104. }
  1105. /* Check Payload Type No */
  1106. for (i = 0; i < MAX_PYLDS_SUPPORT; i++)
  1107. {
  1108. if (Req->PayldType == pBMCInfo->RMCPPlus[EthIndex].PayloadInfo [i].Type)
  1109. {
  1110. break;
  1111. }
  1112. }
  1113. /* Check if PayloadType exist */
  1114. if (MAX_PYLDS_SUPPORT == i)
  1115. {
  1116. *pRes = CC_OP_NOT_SUPPORTED;
  1117. return sizeof (*pRes);
  1118. }
  1119. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SessionTblMutex, WAIT_INFINITE);
  1120. if (0 == (htoipmi_u16 (getPayloadActiveInst (*pReq, BMCInst) & (1 << (Req->PayldInst - 1)))))
  1121. {
  1122. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1123. *pRes = CC_INST_NOT_ACTIVE;
  1124. return sizeof (*pRes);
  1125. }
  1126. /* Check Payload Instance */
  1127. if (Req->PayldInst > MAX_PAYLD_INST)
  1128. {
  1129. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1130. *pRes = CC_OP_NOT_ALLOWED;
  1131. return sizeof (*pRes);
  1132. }
  1133. SessionID = BMC_GET_SHARED_MEM (BMCInst)->SOLSessID;
  1134. pSessInfo = getSessionInfo (SESSION_ID_INFO, &SessionID, BMCInst);
  1135. *pRes = CC_NORMAL;
  1136. switch (Req->Operation)
  1137. {
  1138. case 0:
  1139. /* Encryption can not be suspended if Force SOL Payload Encryption */
  1140. if (pBMCInfo->SOLCfg[EthIndex].SOLAuth & ENCRYPTION_ONLY || (!(pSessInfo->SessPyldInfo[Req->PayldType].AuxConfig [0] & ENCRYPTION_ONLY)))
  1141. {
  1142. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1143. *pRes = CC_OP_NOT_ALLOWED;
  1144. return sizeof (*pRes);
  1145. }
  1146. pSessInfo->SessPyldInfo [Req->PayldType].AuxConfig [0] &= (~ENCRYPTION_ONLY);
  1147. break;
  1148. case 1:
  1149. if(pSessInfo->SessPyldInfo[Req->PayldType].AuxConfig [0] & ENCRYPTION_ONLY)
  1150. {
  1151. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1152. *pRes = CC_OP_NOT_ALLOWED;
  1153. return sizeof (*pRes);
  1154. }
  1155. if ((pSessInfo->IntegrityAlgorithm) && (pSessInfo->ConfidentialityAlgorithm))
  1156. {
  1157. pSessInfo->SessPyldInfo [Req->PayldType].AuxConfig [0] |= ENCRYPTION_ONLY;
  1158. }
  1159. else
  1160. {
  1161. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1162. *pRes = CC_ENC_NOT_AVAILABLE;
  1163. return sizeof (*pRes);
  1164. }
  1165. break;
  1166. case 2:
  1167. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1168. *pRes = CC_OP_NOT_SUPPORTED;
  1169. return sizeof (*pRes);
  1170. break;
  1171. default:
  1172. *pRes = CC_INV_DATA_FIELD;
  1173. }
  1174. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SessionTblMutex);
  1175. return sizeof (*pRes);
  1176. }
  1177. /*---------------------------------------
  1178. * GetSysIfcCaps
  1179. *---------------------------------------*/
  1180. int
  1181. GetSysIfcCaps (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  1182. {
  1183. _NEAR_ GetSysIfcCapsRes_T* pCommonRes = (_NEAR_ GetSysIfcCapsRes_T*)pRes;
  1184. INT8U ResLen;
  1185. pCommonRes->CompletionCode = CC_NORMAL;
  1186. pCommonRes->Rsrvd = 0;
  1187. ResLen = sizeof (GetSysIfcCapsRes_T);
  1188. if(*pReq & RESERVED_BITS_GETSYSIFCCAPS)
  1189. {
  1190. pCommonRes->CompletionCode=CC_INV_DATA_FIELD;
  1191. return(*pRes);
  1192. }
  1193. switch (pReq [0] & 0x0F)
  1194. {
  1195. /* case 0: // SMBUS ifc
  1196. ResLen += sizeof (m_SSIfcData);
  1197. _fmemcpy (pCommonRes + 1, m_SSIfcData, sizeof (m_SSIfcData));
  1198. break;*/
  1199. case 1: // KCS ifc
  1200. ResLen += sizeof (m_KCSIfcData);
  1201. _fmemcpy (pCommonRes + 1, m_KCSIfcData, sizeof (m_KCSIfcData));
  1202. break;
  1203. default:
  1204. pCommonRes->CompletionCode = CC_INV_DATA_FIELD;
  1205. ResLen = sizeof (INT8U);
  1206. }
  1207. return ResLen;
  1208. }
  1209. #endif /* APP_DEVICE */