UDSIfc.c 30 KB

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