UDSIfc.c 26 KB

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