UDSIfc.c 27 KB

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