UDSIfc.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. /*******************************************************************
  2. ********************************************************************
  3. **** **
  4. **** (C)Copyright 2008-2009, American Megatrends Inc. **
  5. **** **
  6. **** All Rights Reserved. **
  7. **** **
  8. **** 5555 , Oakbrook Pkwy, Norcross, **
  9. **** **
  10. **** Georgia - 30093, USA. Phone-(770)-246-8600. **
  11. **** **
  12. ********************************************************************
  13. ********************************************************************
  14. ********************************************************************
  15. **
  16. ** UDSIfc.c
  17. ** Unix Domain Socket Interface Handler
  18. **
  19. ** Author: Suresh V (sureshv@amiindia.co.in)
  20. *******************************************************************/
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <sys/socket.h>
  24. #include <sys/un.h>
  25. #include <sys/prctl.h>
  26. #include "com_IPMI_App.h"
  27. #include "com_IPMIDefs.h"
  28. #include "com_Message.h"
  29. #include <errno.h>
  30. #include <fcntl.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <unistd.h>
  34. #include <string.h>
  35. #include <pthread.h>
  36. #include "main.h"
  37. /*Function Prototypes*/
  38. //void CloseUDSSocket(int Socket );
  39. static int ProcessUDSReq(MsgPkt_T *pReq );
  40. int InitUnixDomainSocket(void);
  41. void *RecvUDSPkt(void *pArg);
  42. //int AddUDSSocket (int Socket,uint8_t IsLoopBackSocket, uint8_t IsFixedSocket );
  43. //int RemoveUDSSocket (int Socket );
  44. int ReadUDSData(MsgPkt_T *MsgPkt,int Socket );
  45. int SendUDSPkt (MsgPkt_T *pRes );
  46. //int SetUDSFd(fd_set *newfd,int *maximum );
  47. int FillUDSResponsePacket(MsgPkt_T *pReq, MsgPkt_T *pRes,uint8_t UDSCompletionCode );
  48. //static int UpdateUDSTimeout (void);
  49. //static void* UDSTimer (void *pArg);
  50. //int AddUDSInfo(MsgPkt_T *pUDSReq,MsgPkt_T *pUDSRes );
  51. //uint8_t RemoveUDSSession(SOCKET Socket );
  52. //int CheckReservedCmd(uint8_t Cmd);
  53. void *UDSIfcTask(void* pArg);
  54. // static uint8_t ReservedCmd[]={
  55. // CMD_GET_DEV_ID,
  56. // CMD_GET_USER_NAME,
  57. // CMD_SET_USER_PASSWORD};
  58. int gUDSSocket;
  59. int gFdUdsIfc, gFdUdsRes;
  60. /**
  61. * @fn UDSIfcTask
  62. * @brief This function is used to start the UDS Interface Task
  63. * @param Addr
  64. **/
  65. void *UDSIfcTask(void* pArg)
  66. {
  67. MsgPkt_T Req;
  68. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  69. //create UDS_IFC_Q
  70. if(-1 != access(UDS_IFC_Q, F_OK))
  71. {
  72. remove(UDS_IFC_Q);
  73. }
  74. if(0 != mkfifo (UDS_IFC_Q, 0777))
  75. {
  76. printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, UDS_IFC_Q, strerror(errno));
  77. return (void*)UDS_FAILURE;
  78. }
  79. gFdUdsIfc = open (UDS_IFC_Q, O_RDWR);
  80. if(-1 == gFdUdsIfc)
  81. {
  82. printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, UDS_IFC_Q, strerror(errno));
  83. return (void*)UDS_FAILURE;
  84. }
  85. //create UDS_RES_Q
  86. if(-1 != access(UDS_RES_Q, F_OK))
  87. {
  88. remove(UDS_RES_Q);
  89. }
  90. if(0 != mkfifo (UDS_RES_Q, 0777))
  91. {
  92. printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, UDS_RES_Q, strerror(errno));
  93. return (void*)UDS_FAILURE;
  94. }
  95. gFdUdsRes = open (UDS_RES_Q, O_RDWR);
  96. if(-1 == gFdUdsRes)
  97. {
  98. printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, UDS_RES_Q, strerror(errno));
  99. return (void*)UDS_FAILURE;
  100. }
  101. /* Open Unix Domain Socket */
  102. if(UDS_SUCCESS > InitUnixDomainSocket())
  103. {
  104. printf("%s: Open Unix Domain Socket failed\n", __FUNCTION__);
  105. return (void *)UDS_FAILURE;
  106. }
  107. /*Create a thread to recv UDS Pkt */
  108. gThreadIndex++;
  109. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,RecvUDSPkt,NULL))
  110. {
  111. printf("%s: Create RecvUDSPkt thread failed! %s\n", __FUNCTION__, strerror(errno));
  112. return (void *)UDS_FAILURE;
  113. }
  114. // /* Create a thread to handle socket timeout */
  115. // IPMI_DBG_PRINT_1("UDSIfc.c: Creating UDSTimer thread with index %d\n", gthreadIndex);
  116. // OS_CREATE_TASK_THREAD(UDSTimer, (void*)&BMCInst, err, gthreadIDs[gthreadIndex]);
  117. while(TRUE)
  118. {
  119. if(UDS_SUCCESS != GetMsg(gFdUdsIfc, &Req, WAIT_INFINITE))
  120. {
  121. printf("UDSIfc.c: Error Fetching Data from UDSIfcQ\n");
  122. continue;
  123. }
  124. ProcessUDSReq(&Req);
  125. }
  126. return (void*)UDS_SUCCESS;
  127. }
  128. /**
  129. * @fn InitUnixDomainSocket
  130. * @brief This function is used to create the Socket for each BMC
  131. * @param BMCInst
  132. **/
  133. int InitUnixDomainSocket(void)
  134. {
  135. struct sockaddr_un local;
  136. memset(&local,0,sizeof(local));
  137. local.sun_family = AF_UNIX;
  138. strncpy(local.sun_path,UDS_SOCKET_PATH,strlen(UDS_SOCKET_PATH));
  139. // unlink(local.sun_path);
  140. gUDSSocket=socket(AF_UNIX,SOCK_STREAM,0);
  141. if(UDS_FAILURE == gUDSSocket)
  142. {
  143. printf("UDSIfc.c : Unable to create the UNIX Domain Socket\n");
  144. return UDS_FAILURE;
  145. }
  146. if(-1 != access(UDS_SOCKET_PATH, F_OK))
  147. {
  148. remove(UDS_SOCKET_PATH);
  149. }
  150. /* Bind pBMCInfo->UDSConfig.UDSSocket to the particular socket file in the path*/
  151. if (UDS_FAILURE == bind(gUDSSocket,(struct sockaddr *)&local,sizeof(local)))
  152. {
  153. printf("UDSIfc.c : Error binding UNIX Domain Socket, %d, %s\n", errno, strerror(errno));
  154. return UDS_FAILURE;
  155. }
  156. if (UDS_FAILURE == listen(gUDSSocket,UDS_SOCKET_QUE_LEN))
  157. {
  158. printf ("UDSIfc.c : Error listen\n");
  159. return UDS_FAILURE;
  160. }
  161. /* Changing the Permission of other user to
  162. * avoid permission denied problems while
  163. * client tries to connect to server */
  164. if(UDS_SUCCESS > chmod(local.sun_path,S_IRWXU|S_IRGRP|S_IXGRP|S_IRWXO))
  165. {
  166. printf("UDSIfc.c : Cannot Change the permission of Unix Domain Socket\n");
  167. }
  168. return UDS_SUCCESS;
  169. }
  170. /**
  171. * @fn RecvUDSPkt
  172. * @brief This functon is used to Recv the UDS Pkt
  173. * @param BMCInst
  174. **/
  175. void *RecvUDSPkt(void *pArg)
  176. {
  177. MsgPkt_T MsgPkt;
  178. struct timeval Timeout;
  179. struct sockaddr_un local;
  180. int RetVal,max,Index = 0;
  181. unsigned int locallen;
  182. int UDSSocket=-1;
  183. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  184. int curThreadIndex = 0;
  185. fd_set fds;
  186. memset(&local,0,sizeof(local));
  187. locallen=sizeof(local);
  188. while(TRUE)
  189. {
  190. Timeout.tv_sec = SESSION_TIMEOUT;
  191. Timeout.tv_usec = 0;
  192. FD_ZERO(&fds);
  193. if(gUDSSocket != -1)
  194. FD_SET(gUDSSocket,&fds);
  195. if(UDSSocket != -1)
  196. FD_SET(UDSSocket,&fds);
  197. max = (gUDSSocket > UDSSocket) ? gUDSSocket+1 : UDSSocket+1;
  198. /*Waits for an event to occur on socket*/
  199. RetVal = select (max, &fds, NULL, NULL, &Timeout);
  200. if (UDS_FAILURE == RetVal)
  201. {
  202. continue;
  203. }
  204. if (UDS_SUCCESS == RetVal)
  205. {
  206. /* Its due to timeout - continue */
  207. continue;
  208. }
  209. /*Accepting Connection*/
  210. if(FD_ISSET(gUDSSocket,&fds))
  211. {
  212. UDSSocket=accept(gUDSSocket,(struct sockaddr *)&local,&locallen);
  213. if(UDS_FAILURE == UDSSocket)
  214. {
  215. printf("UDSIfc.c:Accept Failed in UDSInterface");
  216. sleep(5);
  217. continue;
  218. }
  219. }
  220. if(FD_ISSET(UDSSocket,&fds))
  221. {
  222. if(UDS_SUCCESS == ReadUDSData( &MsgPkt,UDSSocket))
  223. {
  224. if (UDS_SUCCESS != PostMsg (gFdUdsIfc, &MsgPkt))
  225. {
  226. printf("UDSIfc.c:Cannot Post Data to UDSIfcQ\n");
  227. }
  228. }
  229. else
  230. {
  231. close(UDSSocket);
  232. UDSSocket = -1;
  233. }
  234. }
  235. }
  236. }
  237. /**
  238. * @fn ReadUDSData
  239. * @brief This function is used to read the data from socket
  240. * @param MsgPkt,Socket,BMCInst
  241. **/
  242. int ReadUDSData(MsgPkt_T *MsgPkt,int Socket )
  243. {
  244. uint8_t* pData =(uint8_t *) & MsgPkt->Data[0];
  245. uint16_t RecvdLen = 0,RemLen = 0,Len = 0;
  246. unsigned int SourceLen = 0;
  247. struct sockaddr_un Source;
  248. IPMIUDSMsg_T *pIPMIUDSMsg = (IPMIUDSMsg_T *)&pData[0];
  249. SourceLen = sizeof(Source);
  250. while (RecvdLen < sizeof(IPMIUDSMsg_T))
  251. {
  252. Len = recvfrom (Socket, &pData[RecvdLen],sizeof(IPMIUDSMsg_T),0,(struct sockaddr *)&Source,&SourceLen);
  253. if (Len <= 0)
  254. {
  255. return UDS_FAILURE;
  256. }
  257. int i;
  258. printf("---> server recv1 %#x: ", Len);
  259. for(i=0;i<Len;i++)
  260. printf("%#x ", pData[RecvdLen+i]);
  261. printf("\n");
  262. RecvdLen += Len;
  263. }
  264. RemLen = pIPMIUDSMsg->IPMIMsgLen-RecvdLen;
  265. while(RemLen>0)
  266. {
  267. Len = recvfrom (Socket,&pData[RecvdLen],pIPMIUDSMsg->IPMIMsgLen-RecvdLen,0,(struct sockaddr *)&Source,&SourceLen);
  268. if(Len <= 0)
  269. {
  270. return UDS_FAILURE;
  271. }
  272. int i;
  273. printf("---> server recv2 %#x: ", Len);
  274. for(i=0;i<Len;i++)
  275. printf("%#x ", pData[RecvdLen+i]);
  276. printf("\n");
  277. RecvdLen += Len;
  278. RemLen -= Len;
  279. }
  280. MsgPkt->SessionID = pIPMIUDSMsg->SessionID;
  281. MsgPkt->Cmd = pIPMIUDSMsg->Cmd;
  282. MsgPkt->NetFnLUN = pIPMIUDSMsg->NetFnLUN;
  283. MsgPkt->Privilege = pIPMIUDSMsg->Privilege;
  284. MsgPkt->Socket = Socket;
  285. MsgPkt->Size = RecvdLen;
  286. // MsgPkt->Param = UDS_SMB_PARAM;
  287. MsgPkt->Channel = pIPMIUDSMsg->ChannelNum;
  288. // MsgPkt->SessionType = UDS_SESSION_TYPE;
  289. strcpy ((char *)MsgPkt->SrcQ, UDS_RES_Q);
  290. return UDS_SUCCESS;
  291. }
  292. /**
  293. * @fn ProcessUDSReq
  294. * @brief This function is used to Process the Request
  295. * @param pReq,BMCInst
  296. **/
  297. static int ProcessUDSReq(MsgPkt_T *pReq )
  298. {
  299. MsgPkt_T pRes;
  300. int RetVal = 0;
  301. // /*Check Whether the request is from valid session id*/
  302. // if(pReq->SessionID != 0)
  303. // {
  304. // pUDSSessionInfo = GetUDSSessionInfo (UDS_SESSION_ID_INFO,&pReq->SessionID, BMCInst);
  305. // if(pUDSSessionInfo == NULL)
  306. // {
  307. // IPMI_WARNING("Session Info is NULL for the requested Session ID\n");
  308. // FillUDSResponsePacket(pReq,&pRes,CC_INV_DATA_FIELD,BMCInst);
  309. // SendUDSPkt(&pRes,BMCInst);
  310. // return UDS_FAILURE;
  311. // }
  312. // /*Resetting the TimeoutValue for the requested session*/
  313. // pUDSSessionInfo->SessionTimeoutValue = g_BMCInfo[BMCInst].IpmiConfig.SessionTimeOut;
  314. // }
  315. // else if((pReq->SessionID == 0) && CheckReservedCmd(pReq->Cmd))
  316. // {
  317. // FillUDSResponsePacket(pReq,&pRes,CC_INV_DATA_FIELD,BMCInst);
  318. // SendUDSPkt(&pRes,BMCInst);
  319. // return UDS_FAILURE;
  320. // }
  321. // /*Posting the request to Msg Handler for processing the command */
  322. // if (UDS_SUCCESS != PostMsg (pReq, MSG_HNDLR_Q, BMCInst))
  323. // {
  324. // IPMI_ASSERT (FALSE);
  325. // return UDS_FAILURE;
  326. // }
  327. // /* Get the response from the Message handler Task */
  328. // memset(&pRes,0,sizeof(MsgPkt_T));
  329. // if (UDS_SUCCESS != GetMsg (&pRes, UDS_RES_Q, WAIT_INFINITE, BMCInst))
  330. // {
  331. // IPMI_ASSERT (FALSE);
  332. // return UDS_FAILURE;
  333. // }
  334. // if(!CheckReservedCmd(pRes.Cmd) && (pRes.SessionID == 0) && (pRes.Cmd != ReservedCmd[1]))
  335. // {
  336. // RetVal = AddUDSInfo(pReq,&pRes,BMCInst);
  337. // }
  338. FillUDSResponsePacket(pReq,&pRes,CC_NORMAL);
  339. /* Sending the Packet to the corresponding client*/
  340. //if((UDS_SUCCESS == RetVal) || (UDS_FAILURE == RetVal))
  341. {
  342. SendUDSPkt(&pRes);
  343. }
  344. return UDS_SUCCESS;
  345. }
  346. /**
  347. * @fn SendUDSPkt
  348. * @brief This function sends the IPMI UDS Response to the requestor
  349. * @param pRes - Response message.
  350. **/
  351. int SendUDSPkt (MsgPkt_T *pRes)
  352. {
  353. int i;
  354. printf("---> server Send %#x: ", pRes->Size);
  355. for(i=0;i<pRes->Size;i++)
  356. printf("%#x ", pRes->Data[i]);
  357. printf("\n");
  358. /* Send the UDS response packet */
  359. if(UDS_FAILURE == send(pRes->Socket,pRes->Data,pRes->Size,MSG_NOSIGNAL))
  360. {
  361. if((EBADF == errno) || (EPIPE == errno))
  362. {
  363. return UDS_SUCCESS;
  364. }
  365. else
  366. {
  367. printf("UDSIfc.c: Send UDS Pkt Failed\n");
  368. return UDS_FAILURE;
  369. }
  370. }
  371. return UDS_SUCCESS;
  372. }
  373. /**
  374. * @fn FillUDSResponsePacket
  375. * @brief This function fills the pRes when Error Occured
  376. * @param pReq,pRes,CompletionCode,BMCInst
  377. **/
  378. int FillUDSResponsePacket(MsgPkt_T *pReq,MsgPkt_T *pRes,uint8_t UDSCompletionCode )
  379. {
  380. IPMIUDSMsg_T *pIPMIUDSMsgReq = (IPMIUDSMsg_T *)&pReq->Data[0];
  381. IPMIUDSMsg_T *pIPMIUDSMsgRes = (IPMIUDSMsg_T *)&pRes->Data[0];
  382. uint8_t *byCompletionCode = (uint8_t *)&pRes->Data[sizeof(IPMIUDSMsg_T)];
  383. pRes->Socket = pReq->Socket;
  384. pReq->Cmd = pIPMIUDSMsgReq->Cmd;
  385. pIPMIUDSMsgRes->SessionID = pIPMIUDSMsgReq->SessionID;
  386. pIPMIUDSMsgRes->Cmd = pIPMIUDSMsgReq->Cmd;
  387. pIPMIUDSMsgRes->NetFnLUN = pIPMIUDSMsgReq->NetFnLUN;
  388. pIPMIUDSMsgRes->Privilege = pIPMIUDSMsgReq->Privilege;
  389. pIPMIUDSMsgRes->IPMIMsgLen = sizeof(IPMIUDSMsg_T)+sizeof(uint8_t)+1;
  390. pIPMIUDSMsgRes->ChannelNum = pIPMIUDSMsgReq->ChannelNum;
  391. pIPMIUDSMsgRes->AuthFlag = pIPMIUDSMsgReq->AuthFlag;
  392. strcpy( (char *)pIPMIUDSMsgRes->UserName, (char *)pIPMIUDSMsgReq->UserName);
  393. memcpy(pIPMIUDSMsgRes->IPAddr, pIPMIUDSMsgReq->IPAddr, 16);
  394. pRes->Size = pIPMIUDSMsgRes->IPMIMsgLen;
  395. *byCompletionCode = UDSCompletionCode;
  396. return UDS_SUCCESS;
  397. }
  398. // /**
  399. // * @fn UpdateUDSTimeout
  400. // * @brief This function Updates the timeout value for each socket opened
  401. // * @param BMCInst
  402. // **/
  403. // static int
  404. // UpdateUDSTimeout (void)
  405. // {
  406. // int Index = 0;
  407. // int TimeOut=0;
  408. // _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  409. // SocketTbl_T *SocketTable = pBMCInfo->pUDSocketTbl;
  410. // for (Index = 0; Index < (pBMCInfo->IpmiConfig.MaxSession + 1); Index++ )
  411. // {
  412. // if((SocketTable[Index].Valid))
  413. // {
  414. // TimeOut = pBMCInfo->IpmiConfig.SessionTimeOut;
  415. // if (SocketTable[Index].Time >= TimeOut)
  416. // {
  417. // IPMI_DBG_PRINT("Local Socket Timed Out\n");
  418. // close (SocketTable[Index].Socket);
  419. // /* Acquire the UDS Socket Mutex Lock */
  420. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
  421. // SocketTable[Index].Socket = 0;
  422. // SocketTable[Index].Valid = 0;
  423. // /* Release the UDS Socket Mutex Lock */
  424. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
  425. // }
  426. // else
  427. // { /* update the time */
  428. // /* Acquire the UDS Socket Mutex Lock */
  429. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
  430. // SocketTable[Index].Time += UDS_TIMER_INTERVAL;
  431. // /* Release the UDS Socket Mutex Lock */
  432. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
  433. // }
  434. // }
  435. // }
  436. // return UDS_SUCCESS;
  437. // }
  438. // /**
  439. // * @fn UDSTimer
  440. // * @brief This function handles the time out for uds connections.
  441. // * @param None
  442. // **/
  443. // static
  444. // void* UDSTimer (void *pArg)
  445. // {
  446. // int *inst = (int*)pArg;
  447. // int BMCInst= *inst;
  448. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  449. // while (TRUE)
  450. // {
  451. // UpdateUDSTimeout (BMCInst);
  452. // sleep (UDS_TIMER_INTERVAL);
  453. // }
  454. // return UDS_SUCCESS;
  455. // }
  456. // /**
  457. // * @fn AddUDSInfo
  458. // * @brief This function adds the session information in Session Table
  459. // * @param UDS Request Packet,UDS Response Packet,BMCInst
  460. // **/
  461. // int AddUDSInfo(MsgPkt_T *pUDSReq,MsgPkt_T *pUDSRes )
  462. // {
  463. // uint8 *byCompletionCode = (uint8 *)&pUDSRes->Data[sizeof(IPMIUDSMsg_T)];
  464. // IPMIUDSMsg_T *pRes = (IPMIUDSMsg_T *)&pUDSRes->Data[0];
  465. // _FAR_ ChannelInfo_T *pChanneludsInfo = NULL;
  466. // _FAR_ ChannelUserInfo_T *pChUserInfo = NULL;
  467. // _FAR_ UserInfo_T *pUserInfo = NULL;
  468. // UDSSessionTbl_T UDSSessionInfo;
  469. // INT32U SessionID;
  470. // uint8_t UserID,Index,SessionHandle=0;
  471. // unsigned int seed=1;
  472. // _FAR_ BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  473. // char UserPswd[MAX_PASSWORD_LEN];
  474. // uint8_t ChannelNum = CH_NOT_USED;
  475. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  476. // _fmemset(&UDSSessionInfo,0,sizeof(UDSSessionTbl_T));
  477. // if(*byCompletionCode == CC_NORMAL)
  478. // {
  479. // if(ReservedCmd[0] == pRes->Cmd)
  480. // {
  481. // UserID = 0;
  482. // }
  483. // else
  484. // {
  485. // UserID = (uint8)pUDSReq->Data[sizeof(IPMIUDSMsg_T)];
  486. // }
  487. // if(pBMCInfo ->UDSSessionTblInfo.SessionCount >= pBMCInfo->IpmiConfig.MaxSession)
  488. // {
  489. // IPMI_WARNING("UDSIfc.c:Maximum Session Limit Reached\n");
  490. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_ACTIVATE_SESS_NO_SESSION_SLOT_AVAILABLE,BMCInst);
  491. // SendUDSPkt(pUDSRes,BMCInst);
  492. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  493. // return UDS_PARAM_FAILURE;
  494. // }
  495. // do
  496. // {
  497. // SessionID = ((INT32U)rand_r(&seed) >> 16);
  498. // } while ((NULL != GetUDSSessionInfo (UDS_SESSION_ID_INFO,&SessionID, BMCInst)) || (0 == SessionID));
  499. // SessionHandle = BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle;
  500. // do
  501. // {
  502. // SessionHandle += 1;
  503. // } while (NULL != GetUDSSessionInfo (UDS_SESSION_HANDLE_INFO,&SessionHandle, BMCInst));
  504. // LOCK_BMC_SHARED_MEM(BMCInst);
  505. // BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle = SessionHandle;
  506. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  507. // pChanneludsInfo = GetLANChannelInfoForUDS(pUDSReq->Channel,&ChannelNum,&pRes->ChannelNum,BMCInst);
  508. // if(pChanneludsInfo == NULL)
  509. // {
  510. // IPMI_WARNING("UDSIfc.c:Invalid Channel\n");
  511. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  512. // SendUDSPkt(pUDSRes,BMCInst);
  513. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  514. // return UDS_PARAM_FAILURE;
  515. // }
  516. // if(0 != UserID)
  517. // {
  518. // pUserInfo = getUserIdInfo (UserID & 0x3F, BMCInst);
  519. // if (g_corefeatures.userpswd_encryption == ENABLED)
  520. // {
  521. // /* Get Encryption Key from the MBMCInfo_t structure */
  522. // LOCK_BMC_SHARED_MEM(BMCInst);
  523. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  524. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  525. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[(UserID - 1) & 0x3F].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  526. // {
  527. // TCRIT("Error in decrypting the user password for user ID:%d. .\n", UserID);
  528. // FillUDSResponsePacket(pUDSReq, pUDSRes, CC_UNSPECIFIED_ERR, BMCInst);
  529. // SendUDSPkt(pUDSRes,BMCInst);
  530. // CloseUDSSocket(pUDSRes->Socket, BMCInst);
  531. // return UDS_FAILURE;
  532. // }
  533. // }
  534. // else
  535. // {
  536. // _fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  537. // }
  538. // if (NULL == pUserInfo)
  539. // {
  540. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  541. // SendUDSPkt(pUDSRes,BMCInst);
  542. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  543. // return UDS_PARAM_FAILURE;
  544. // }
  545. // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)UserPswd)!= 0) && (pUserInfo->UserStatus == FALSE))
  546. // {
  547. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
  548. // SendUDSPkt(pUDSRes,BMCInst);
  549. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  550. // return UDS_PARAM_FAILURE;
  551. // }
  552. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  553. // pChUserInfo = getChUserIdInfo (UserID & 0x3F, &Index, pChanneludsInfo->ChannelUserInfo, BMCInst);
  554. // if (NULL == pChUserInfo)
  555. // {
  556. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  557. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  558. // SendUDSPkt(pUDSRes,BMCInst);
  559. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  560. // return UDS_PARAM_FAILURE;
  561. // }
  562. // else if(pChUserInfo->AccessLimit == PRIV_LEVEL_NO_ACCESS)
  563. // {
  564. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  565. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INSUFFIENT_PRIVILEGE,BMCInst);
  566. // SendUDSPkt(pUDSRes,BMCInst);
  567. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  568. // return UDS_PARAM_FAILURE;
  569. // }
  570. // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)pUserInfo->UserPassword)!= 0) && (pChUserInfo->IPMIMessaging == FALSE))
  571. // {
  572. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  573. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
  574. // SendUDSPkt(pUDSRes,BMCInst);
  575. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  576. // return UDS_PARAM_FAILURE;
  577. // }
  578. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  579. // }
  580. // if(0 != UserID)
  581. // {
  582. // UDSSessionInfo.LoggedInPrivilege = pChUserInfo->AccessLimit;
  583. // }
  584. // else
  585. // {
  586. // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
  587. // }
  588. // UDSSessionInfo.Activated = TRUE;
  589. // UDSSessionInfo.UDSSocket = pUDSRes->Socket;
  590. // UDSSessionInfo.LoggedInUserID= UserID;
  591. // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
  592. // UDSSessionInfo.LoggedInChannel = ChannelNum;
  593. // UDSSessionInfo.SessionID = SessionID;
  594. // UDSSessionInfo.SessionTimeoutValue = pBMCInfo->IpmiConfig.SessionTimeOut;
  595. // UDSSessionInfo.AuthenticationMechanism = pRes->AuthFlag;
  596. // UDSSessionInfo.LoggedInSessionHandle = SessionHandle;
  597. // UDSSessionInfo.UDSChannelNum = UDS_CHANNEL;
  598. // _fmemcpy( (char *)UDSSessionInfo.LoggedInUsername, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->UserName,MAX_USERNAME_LEN);
  599. // _fmemcpy( (char *)UDSSessionInfo.LoggedInPassword, UserPswd,MAX_PASSWORD_LEN);
  600. // _fmemcpy( (char *)UDSSessionInfo.IPAddr, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->IPAddr,IP6_ADDR_LEN);
  601. // UDSSessionInfo.ProcessID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ProcessID;
  602. // UDSSessionInfo.ThreadID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ThreadID;
  603. // AddUDSSession(&UDSSessionInfo,BMCInst);
  604. // /*Assigning the Privilege Level and Session ID*/
  605. // pRes->SessionID = SessionID;
  606. // pRes->Privilege = UDSSessionInfo.LoggedInPrivilege;
  607. // return UDS_SUCCESS;
  608. // }
  609. // return UDS_FAILURE;
  610. // }
  611. // /**
  612. // * @fn RemoveUDSSession
  613. // * @brief This function deletes the session information in Session Table
  614. // * @param Socket,BMCInst
  615. // **/
  616. // uint8_t RemoveUDSSession(SOCKET Socket )
  617. // {
  618. // _FAR_ UDSSessionTbl_T *pUDSSessionInfo = NULL;
  619. // pUDSSessionInfo = GetUDSSessionInfo(UDS_SOCKET_ID_INFO,&Socket,BMCInst);
  620. // if(NULL != pUDSSessionInfo)
  621. // {
  622. // DeleteUDSSession(pUDSSessionInfo,BMCInst);
  623. // }
  624. // return UDS_SUCCESS;
  625. // }
  626. // /**
  627. // * @fn CloseUDSSocket
  628. // * @brief This function removes the socket and closes it
  629. // * @param Socket,BMCInst
  630. // **/
  631. // void CloseUDSSocket(int Socket )
  632. // {
  633. // close(Socket);
  634. // RemoveUDSSocket(Socket,BMCInst);
  635. // }
  636. // /**
  637. // * @fn CheckReservedCmd
  638. // * @brief This function is used to check whether the triggered command
  639. // * belongs to Reserved List
  640. // * @param Cmd - Command Number
  641. // **/
  642. // int CheckReservedCmd(uint8_t Cmd)
  643. // {
  644. // int index = 0;
  645. // for(index = 0;index < sizeof(ReservedCmd); index++)
  646. // {
  647. // if(ReservedCmd[index] == Cmd)
  648. // {
  649. // return UDS_SUCCESS;
  650. // }
  651. // }
  652. // return UDS_CMD_FAILURE;
  653. // }
  654. // /**
  655. // * @fn GetLANChannelInfoForUDS
  656. // * @brief This function is used to get the LAN Channel Info
  657. // * @param - Requested UDS Channel number,BMC Instance and out pointer which points
  658. // to LAN Channel Number.
  659. // **/
  660. // ChannelInfo_T* GetLANChannelInfoForUDS(uint8_t ReqUDSChannel,uint8_t *LANChannel,uint8_t *ResChannelNum )
  661. // {
  662. // BMCInfo_t *pBMCInfo = (BMCInfo_t *)&g_BMCInfo[BMCInst];
  663. // uint8_t Ch = 0;
  664. // ChannelInfo_T *UDSChannelInfo = NULL;
  665. // for(Ch = 1;Ch <= MAX_LAN_CHANNELS; Ch++)
  666. // {
  667. // if(ReqUDSChannel == UDS_CHANNEL)
  668. // {
  669. // if((pBMCInfo->RMCPLAN1Ch != CH_NOT_USED) && (*LANChannel == CH_NOT_USED))
  670. // {
  671. // *LANChannel = pBMCInfo->RMCPLAN1Ch;
  672. // }
  673. // else if((pBMCInfo->RMCPLAN2Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN2Ch))
  674. // {
  675. // *LANChannel = pBMCInfo->RMCPLAN2Ch;
  676. // }
  677. // else if((pBMCInfo->RMCPLAN3Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN3Ch))
  678. // {
  679. // *LANChannel = pBMCInfo->RMCPLAN3Ch;
  680. // }
  681. // }
  682. // else
  683. // {
  684. // *LANChannel = ReqUDSChannel;
  685. // }
  686. // UDSChannelInfo = getChannelInfo(*LANChannel,BMCInst);
  687. // if((UDSChannelInfo == NULL) || (UDSChannelInfo->ActiveSession >= UDSChannelInfo->SessionLimit))
  688. // {
  689. // if((ReqUDSChannel != UDS_CHANNEL) || (Ch == MAX_LAN_CHANNELS))
  690. // {
  691. // *LANChannel = CH_NOT_USED;
  692. // return NULL;
  693. // }
  694. // }
  695. // else if(UDSChannelInfo != NULL)
  696. // {
  697. // *ResChannelNum = *LANChannel;
  698. // return UDSChannelInfo;
  699. // }
  700. // }
  701. // *LANChannel = CH_NOT_USED;
  702. // return NULL;
  703. // }