UDSIfc.c 27 KB

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