UDSIfc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. // int i;
  340. // printf("---> server Send size: %d: ", pRes->Size);
  341. // for(i=0;i<pRes->Size;i++)
  342. // printf("%#x ", pRes->Data[i]);
  343. // printf("\n");
  344. //printf("Send UDS!\n");
  345. /* Send the UDS response packet */
  346. if(UDS_FAILURE == send(pRes->Socket,pRes->Data,pRes->Size,MSG_NOSIGNAL))
  347. {
  348. if((EBADF == errno) || (EPIPE == errno))
  349. {
  350. return UDS_SUCCESS;
  351. }
  352. else
  353. {
  354. printf("UDSIfc.c: Send UDS Pkt Failed\n");
  355. return UDS_FAILURE;
  356. }
  357. }
  358. return UDS_SUCCESS;
  359. }
  360. /**
  361. * @fn FillUDSResponsePacket
  362. * @brief This function fills the pRes when Error Occured
  363. * @param pReq,pRes,CompletionCode,BMCInst
  364. **/
  365. int FillUDSResponsePacket(MsgPkt_T *pReq,MsgPkt_T *pRes,uint8_t UDSCompletionCode )
  366. {
  367. IPMIUDSMsg_T *pIPMIUDSMsgReq = (IPMIUDSMsg_T *)&pReq->Data[0];
  368. IPMIUDSMsg_T *pIPMIUDSMsgRes = (IPMIUDSMsg_T *)&pRes->Data[0];
  369. uint8_t *byCompletionCode = (uint8_t *)&pRes->Data[sizeof(IPMIUDSMsg_T)];
  370. pRes->Socket = pReq->Socket;
  371. pReq->Cmd = pIPMIUDSMsgReq->Cmd;
  372. pIPMIUDSMsgRes->SessionID = pIPMIUDSMsgReq->SessionID;
  373. pIPMIUDSMsgRes->Cmd = pIPMIUDSMsgReq->Cmd;
  374. pIPMIUDSMsgRes->NetFnLUN = pIPMIUDSMsgReq->NetFnLUN;
  375. // pIPMIUDSMsgRes->Privilege = pIPMIUDSMsgReq->Privilege;
  376. pIPMIUDSMsgRes->IPMIMsgLen = sizeof(IPMIUDSMsg_T)+sizeof(uint8_t)+1;
  377. pIPMIUDSMsgRes->ChannelNum = pIPMIUDSMsgReq->ChannelNum;
  378. // pIPMIUDSMsgRes->AuthFlag = pIPMIUDSMsgReq->AuthFlag;
  379. // strcpy( (char *)pIPMIUDSMsgRes->UserName, (char *)pIPMIUDSMsgReq->UserName);
  380. // memcpy(pIPMIUDSMsgRes->IPAddr, pIPMIUDSMsgReq->IPAddr, 16);
  381. pRes->Size = pIPMIUDSMsgRes->IPMIMsgLen;
  382. *byCompletionCode = UDSCompletionCode;
  383. return UDS_SUCCESS;
  384. }
  385. // /**
  386. // * @fn UpdateUDSTimeout
  387. // * @brief This function Updates the timeout value for each socket opened
  388. // * @param BMCInst
  389. // **/
  390. // static int
  391. // UpdateUDSTimeout (void)
  392. // {
  393. // int Index = 0;
  394. // int TimeOut=0;
  395. // _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  396. // SocketTbl_T *SocketTable = pBMCInfo->pUDSocketTbl;
  397. // for (Index = 0; Index < (pBMCInfo->IpmiConfig.MaxSession + 1); Index++ )
  398. // {
  399. // if((SocketTable[Index].Valid))
  400. // {
  401. // TimeOut = pBMCInfo->IpmiConfig.SessionTimeOut;
  402. // if (SocketTable[Index].Time >= TimeOut)
  403. // {
  404. // IPMI_DBG_PRINT("Local Socket Timed Out\n");
  405. // close (SocketTable[Index].Socket);
  406. // /* Acquire the UDS Socket Mutex Lock */
  407. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
  408. // SocketTable[Index].Socket = 0;
  409. // SocketTable[Index].Valid = 0;
  410. // /* Release the UDS Socket Mutex Lock */
  411. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
  412. // }
  413. // else
  414. // { /* update the time */
  415. // /* Acquire the UDS Socket Mutex Lock */
  416. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
  417. // SocketTable[Index].Time += UDS_TIMER_INTERVAL;
  418. // /* Release the UDS Socket Mutex Lock */
  419. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
  420. // }
  421. // }
  422. // }
  423. // return UDS_SUCCESS;
  424. // }
  425. // /**
  426. // * @fn UDSTimer
  427. // * @brief This function handles the time out for uds connections.
  428. // * @param None
  429. // **/
  430. // static
  431. // void* UDSTimer (void *pArg)
  432. // {
  433. // int *inst = (int*)pArg;
  434. // int BMCInst= *inst;
  435. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  436. // while (TRUE)
  437. // {
  438. // UpdateUDSTimeout (BMCInst);
  439. // sleep (UDS_TIMER_INTERVAL);
  440. // }
  441. // return UDS_SUCCESS;
  442. // }
  443. // /**
  444. // * @fn AddUDSInfo
  445. // * @brief This function adds the session information in Session Table
  446. // * @param UDS Request Packet,UDS Response Packet,BMCInst
  447. // **/
  448. // int AddUDSInfo(MsgPkt_T *pUDSReq,MsgPkt_T *pUDSRes )
  449. // {
  450. // uint8 *byCompletionCode = (uint8 *)&pUDSRes->Data[sizeof(IPMIUDSMsg_T)];
  451. // IPMIUDSMsg_T *pRes = (IPMIUDSMsg_T *)&pUDSRes->Data[0];
  452. // _FAR_ ChannelInfo_T *pChanneludsInfo = NULL;
  453. // _FAR_ ChannelUserInfo_T *pChUserInfo = NULL;
  454. // _FAR_ UserInfo_T *pUserInfo = NULL;
  455. // UDSSessionTbl_T UDSSessionInfo;
  456. // INT32U SessionID;
  457. // uint8_t UserID,Index,SessionHandle=0;
  458. // unsigned int seed=1;
  459. // _FAR_ BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  460. // char UserPswd[MAX_PASSWORD_LEN];
  461. // uint8_t ChannelNum = CH_NOT_USED;
  462. // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
  463. // _fmemset(&UDSSessionInfo,0,sizeof(UDSSessionTbl_T));
  464. // if(*byCompletionCode == CC_NORMAL)
  465. // {
  466. // if(ReservedCmd[0] == pRes->Cmd)
  467. // {
  468. // UserID = 0;
  469. // }
  470. // else
  471. // {
  472. // UserID = (uint8)pUDSReq->Data[sizeof(IPMIUDSMsg_T)];
  473. // }
  474. // if(pBMCInfo ->UDSSessionTblInfo.SessionCount >= pBMCInfo->IpmiConfig.MaxSession)
  475. // {
  476. // IPMI_WARNING("UDSIfc.c:Maximum Session Limit Reached\n");
  477. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_ACTIVATE_SESS_NO_SESSION_SLOT_AVAILABLE,BMCInst);
  478. // SendUDSPkt(pUDSRes,BMCInst);
  479. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  480. // return UDS_PARAM_FAILURE;
  481. // }
  482. // do
  483. // {
  484. // SessionID = ((INT32U)rand_r(&seed) >> 16);
  485. // } while ((NULL != GetUDSSessionInfo (UDS_SESSION_ID_INFO,&SessionID, BMCInst)) || (0 == SessionID));
  486. // SessionHandle = BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle;
  487. // do
  488. // {
  489. // SessionHandle += 1;
  490. // } while (NULL != GetUDSSessionInfo (UDS_SESSION_HANDLE_INFO,&SessionHandle, BMCInst));
  491. // LOCK_BMC_SHARED_MEM(BMCInst);
  492. // BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle = SessionHandle;
  493. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  494. // pChanneludsInfo = GetLANChannelInfoForUDS(pUDSReq->Channel,&ChannelNum,&pRes->ChannelNum,BMCInst);
  495. // if(pChanneludsInfo == NULL)
  496. // {
  497. // IPMI_WARNING("UDSIfc.c:Invalid Channel\n");
  498. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  499. // SendUDSPkt(pUDSRes,BMCInst);
  500. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  501. // return UDS_PARAM_FAILURE;
  502. // }
  503. // if(0 != UserID)
  504. // {
  505. // pUserInfo = getUserIdInfo (UserID & 0x3F, BMCInst);
  506. // if (g_corefeatures.userpswd_encryption == ENABLED)
  507. // {
  508. // /* Get Encryption Key from the MBMCInfo_t structure */
  509. // LOCK_BMC_SHARED_MEM(BMCInst);
  510. // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  511. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  512. // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[(UserID - 1) & 0x3F].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  513. // {
  514. // TCRIT("Error in decrypting the user password for user ID:%d. .\n", UserID);
  515. // FillUDSResponsePacket(pUDSReq, pUDSRes, CC_UNSPECIFIED_ERR, BMCInst);
  516. // SendUDSPkt(pUDSRes,BMCInst);
  517. // CloseUDSSocket(pUDSRes->Socket, BMCInst);
  518. // return UDS_FAILURE;
  519. // }
  520. // }
  521. // else
  522. // {
  523. // _fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  524. // }
  525. // if (NULL == pUserInfo)
  526. // {
  527. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  528. // SendUDSPkt(pUDSRes,BMCInst);
  529. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  530. // return UDS_PARAM_FAILURE;
  531. // }
  532. // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)UserPswd)!= 0) && (pUserInfo->UserStatus == FALSE))
  533. // {
  534. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
  535. // SendUDSPkt(pUDSRes,BMCInst);
  536. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  537. // return UDS_PARAM_FAILURE;
  538. // }
  539. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  540. // pChUserInfo = getChUserIdInfo (UserID & 0x3F, &Index, pChanneludsInfo->ChannelUserInfo, BMCInst);
  541. // if (NULL == pChUserInfo)
  542. // {
  543. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  544. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
  545. // SendUDSPkt(pUDSRes,BMCInst);
  546. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  547. // return UDS_PARAM_FAILURE;
  548. // }
  549. // else if(pChUserInfo->AccessLimit == PRIV_LEVEL_NO_ACCESS)
  550. // {
  551. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  552. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INSUFFIENT_PRIVILEGE,BMCInst);
  553. // SendUDSPkt(pUDSRes,BMCInst);
  554. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  555. // return UDS_PARAM_FAILURE;
  556. // }
  557. // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)pUserInfo->UserPassword)!= 0) && (pChUserInfo->IPMIMessaging == FALSE))
  558. // {
  559. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  560. // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
  561. // SendUDSPkt(pUDSRes,BMCInst);
  562. // CloseUDSSocket(pUDSRes->Socket,BMCInst);
  563. // return UDS_PARAM_FAILURE;
  564. // }
  565. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  566. // }
  567. // if(0 != UserID)
  568. // {
  569. // UDSSessionInfo.LoggedInPrivilege = pChUserInfo->AccessLimit;
  570. // }
  571. // else
  572. // {
  573. // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
  574. // }
  575. // UDSSessionInfo.Activated = TRUE;
  576. // UDSSessionInfo.UDSSocket = pUDSRes->Socket;
  577. // UDSSessionInfo.LoggedInUserID= UserID;
  578. // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
  579. // UDSSessionInfo.LoggedInChannel = ChannelNum;
  580. // UDSSessionInfo.SessionID = SessionID;
  581. // UDSSessionInfo.SessionTimeoutValue = pBMCInfo->IpmiConfig.SessionTimeOut;
  582. // UDSSessionInfo.AuthenticationMechanism = pRes->AuthFlag;
  583. // UDSSessionInfo.LoggedInSessionHandle = SessionHandle;
  584. // UDSSessionInfo.UDSChannelNum = UDS_CHANNEL;
  585. // _fmemcpy( (char *)UDSSessionInfo.LoggedInUsername, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->UserName,MAX_USERNAME_LEN);
  586. // _fmemcpy( (char *)UDSSessionInfo.LoggedInPassword, UserPswd,MAX_PASSWORD_LEN);
  587. // _fmemcpy( (char *)UDSSessionInfo.IPAddr, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->IPAddr,IP6_ADDR_LEN);
  588. // UDSSessionInfo.ProcessID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ProcessID;
  589. // UDSSessionInfo.ThreadID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ThreadID;
  590. // AddUDSSession(&UDSSessionInfo,BMCInst);
  591. // /*Assigning the Privilege Level and Session ID*/
  592. // pRes->SessionID = SessionID;
  593. // pRes->Privilege = UDSSessionInfo.LoggedInPrivilege;
  594. // return UDS_SUCCESS;
  595. // }
  596. // return UDS_FAILURE;
  597. // }
  598. // /**
  599. // * @fn RemoveUDSSession
  600. // * @brief This function deletes the session information in Session Table
  601. // * @param Socket,BMCInst
  602. // **/
  603. // uint8_t RemoveUDSSession(SOCKET Socket )
  604. // {
  605. // _FAR_ UDSSessionTbl_T *pUDSSessionInfo = NULL;
  606. // pUDSSessionInfo = GetUDSSessionInfo(UDS_SOCKET_ID_INFO,&Socket,BMCInst);
  607. // if(NULL != pUDSSessionInfo)
  608. // {
  609. // DeleteUDSSession(pUDSSessionInfo,BMCInst);
  610. // }
  611. // return UDS_SUCCESS;
  612. // }
  613. // /**
  614. // * @fn CloseUDSSocket
  615. // * @brief This function removes the socket and closes it
  616. // * @param Socket,BMCInst
  617. // **/
  618. // void CloseUDSSocket(int Socket )
  619. // {
  620. // close(Socket);
  621. // RemoveUDSSocket(Socket,BMCInst);
  622. // }
  623. // /**
  624. // * @fn CheckReservedCmd
  625. // * @brief This function is used to check whether the triggered command
  626. // * belongs to Reserved List
  627. // * @param Cmd - Command Number
  628. // **/
  629. // int CheckReservedCmd(uint8_t Cmd)
  630. // {
  631. // int index = 0;
  632. // for(index = 0;index < sizeof(ReservedCmd); index++)
  633. // {
  634. // if(ReservedCmd[index] == Cmd)
  635. // {
  636. // return UDS_SUCCESS;
  637. // }
  638. // }
  639. // return UDS_CMD_FAILURE;
  640. // }
  641. // /**
  642. // * @fn GetLANChannelInfoForUDS
  643. // * @brief This function is used to get the LAN Channel Info
  644. // * @param - Requested UDS Channel number,BMC Instance and out pointer which points
  645. // to LAN Channel Number.
  646. // **/
  647. // ChannelInfo_T* GetLANChannelInfoForUDS(uint8_t ReqUDSChannel,uint8_t *LANChannel,uint8_t *ResChannelNum )
  648. // {
  649. // BMCInfo_t *pBMCInfo = (BMCInfo_t *)&g_BMCInfo[BMCInst];
  650. // uint8_t Ch = 0;
  651. // ChannelInfo_T *UDSChannelInfo = NULL;
  652. // for(Ch = 1;Ch <= MAX_LAN_CHANNELS; Ch++)
  653. // {
  654. // if(ReqUDSChannel == UDS_CHANNEL)
  655. // {
  656. // if((pBMCInfo->RMCPLAN1Ch != CH_NOT_USED) && (*LANChannel == CH_NOT_USED))
  657. // {
  658. // *LANChannel = pBMCInfo->RMCPLAN1Ch;
  659. // }
  660. // else if((pBMCInfo->RMCPLAN2Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN2Ch))
  661. // {
  662. // *LANChannel = pBMCInfo->RMCPLAN2Ch;
  663. // }
  664. // else if((pBMCInfo->RMCPLAN3Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN3Ch))
  665. // {
  666. // *LANChannel = pBMCInfo->RMCPLAN3Ch;
  667. // }
  668. // }
  669. // else
  670. // {
  671. // *LANChannel = ReqUDSChannel;
  672. // }
  673. // UDSChannelInfo = getChannelInfo(*LANChannel,BMCInst);
  674. // if((UDSChannelInfo == NULL) || (UDSChannelInfo->ActiveSession >= UDSChannelInfo->SessionLimit))
  675. // {
  676. // if((ReqUDSChannel != UDS_CHANNEL) || (Ch == MAX_LAN_CHANNELS))
  677. // {
  678. // *LANChannel = CH_NOT_USED;
  679. // return NULL;
  680. // }
  681. // }
  682. // else if(UDSChannelInfo != NULL)
  683. // {
  684. // *ResChannelNum = *LANChannel;
  685. // return UDSChannelInfo;
  686. // }
  687. // }
  688. // *LANChannel = CH_NOT_USED;
  689. // return NULL;
  690. // }
  691. /*--------------------------------------------
  692. * ProcessBridgeMsg
  693. *--------------------------------------------*/
  694. static void
  695. ProcessUDSBridgeMsg ( MsgPkt_T* pReq )
  696. {
  697. MsgPkt_T ResPkt;
  698. /* Sent the response packet */
  699. SendUDSPkt(pReq);
  700. return;
  701. }