123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802 |
- /*******************************************************************
- ********************************************************************
- **** **
- **** (C)Copyright 2008-2009, American Megatrends Inc. **
- **** **
- **** All Rights Reserved. **
- **** **
- **** 5555 , Oakbrook Pkwy, Norcross, **
- **** **
- **** Georgia - 30093, USA. Phone-(770)-246-8600. **
- **** **
- ********************************************************************
- ********************************************************************
- ********************************************************************
- **
- ** UDSIfc.c
- ** Unix Domain Socket Interface Handler
- **
- ** Author: Suresh V (sureshv@amiindia.co.in)
- *******************************************************************/
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <sys/prctl.h>
- #include "com_IPMI_App.h"
- #include "com_IPMIDefs.h"
- #include "com_Message.h"
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <pthread.h>
- #include "main.h"
- /*Function Prototypes*/
- //void CloseUDSSocket(int Socket );
- static int ProcessUDSReq(MsgPkt_T *pReq );
- int InitUnixDomainSocket(void);
- void *RecvUDSPkt(void *pArg);
- //int AddUDSSocket (int Socket,uint8_t IsLoopBackSocket, uint8_t IsFixedSocket );
- //int RemoveUDSSocket (int Socket );
- int ReadUDSData(MsgPkt_T *MsgPkt,int Socket );
- int SendUDSPkt (MsgPkt_T *pRes );
- //int SetUDSFd(fd_set *newfd,int *maximum );
- int FillUDSResponsePacket(MsgPkt_T *pReq, MsgPkt_T *pRes,uint8_t UDSCompletionCode );
- //static int UpdateUDSTimeout (void);
- //static void* UDSTimer (void *pArg);
- //int AddUDSInfo(MsgPkt_T *pUDSReq,MsgPkt_T *pUDSRes );
- //uint8_t RemoveUDSSession(SOCKET Socket );
- //int CheckReservedCmd(uint8_t Cmd);
- void *UDSIfcTask(void* pArg);
- // static uint8_t ReservedCmd[]={
- // CMD_GET_DEV_ID,
- // CMD_GET_USER_NAME,
- // CMD_SET_USER_PASSWORD};
- int gUDSSocket;
- int gFdUdsIfc, gFdUdsRes;
- /**
- * @fn UDSIfcTask
- * @brief This function is used to start the UDS Interface Task
- * @param Addr
- **/
- void *UDSIfcTask(void* pArg)
- {
- MsgPkt_T Req;
- prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
- //create UDS_IFC_Q
- if(-1 != access(UDS_IFC_Q, F_OK))
- {
- remove(UDS_IFC_Q);
- }
- if(0 != mkfifo (UDS_IFC_Q, 0777))
- {
- printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, UDS_IFC_Q, strerror(errno));
- return (void*)UDS_FAILURE;
- }
- gFdUdsIfc = open (UDS_IFC_Q, O_RDWR);
- if(-1 == gFdUdsIfc)
- {
- printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, UDS_IFC_Q, strerror(errno));
- return (void*)UDS_FAILURE;
- }
- //create UDS_RES_Q
- if(-1 != access(UDS_RES_Q, F_OK))
- {
- remove(UDS_RES_Q);
- }
- if(0 != mkfifo (UDS_RES_Q, 0777))
- {
- printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, UDS_RES_Q, strerror(errno));
- return (void*)UDS_FAILURE;
- }
- gFdUdsRes = open (UDS_RES_Q, O_RDWR);
- if(-1 == gFdUdsRes)
- {
- printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, UDS_RES_Q, strerror(errno));
- return (void*)UDS_FAILURE;
- }
- /* Open Unix Domain Socket */
- if(UDS_SUCCESS > InitUnixDomainSocket())
- {
- printf("%s: Open Unix Domain Socket failed\n", __FUNCTION__);
- return (void *)UDS_FAILURE;
- }
- /*Create a thread to recv UDS Pkt */
- gThreadIndex++;
- if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,RecvUDSPkt,NULL))
- {
- printf("%s: Create RecvUDSPkt thread failed! %s\n", __FUNCTION__, strerror(errno));
- return (void *)UDS_FAILURE;
- }
-
- // /* Create a thread to handle socket timeout */
- // IPMI_DBG_PRINT_1("UDSIfc.c: Creating UDSTimer thread with index %d\n", gthreadIndex);
- // OS_CREATE_TASK_THREAD(UDSTimer, (void*)&BMCInst, err, gthreadIDs[gthreadIndex]);
- while(TRUE)
- {
- if(UDS_SUCCESS != GetMsg(gFdUdsIfc, &Req, WAIT_INFINITE))
- {
- printf("UDSIfc.c: Error Fetching Data from UDSIfcQ\n");
- continue;
- }
-
- ProcessUDSReq(&Req);
- }
- return (void*)UDS_SUCCESS;
- }
- /**
- * @fn InitUnixDomainSocket
- * @brief This function is used to create the Socket for each BMC
- * @param BMCInst
- **/
- int InitUnixDomainSocket(void)
- {
- struct sockaddr_un local;
-
- memset(&local,0,sizeof(local));
- local.sun_family = AF_UNIX;
- strncpy(local.sun_path,UDS_SOCKET_PATH,strlen(UDS_SOCKET_PATH));
- // unlink(local.sun_path);
- gUDSSocket=socket(AF_UNIX,SOCK_STREAM,0);
- if(UDS_FAILURE == gUDSSocket)
- {
- printf("UDSIfc.c : Unable to create the UNIX Domain Socket\n");
- return UDS_FAILURE;
- }
- if(-1 != access(UDS_SOCKET_PATH, F_OK))
- {
- remove(UDS_SOCKET_PATH);
- }
- /* Bind pBMCInfo->UDSConfig.UDSSocket to the particular socket file in the path*/
- if (UDS_FAILURE == bind(gUDSSocket,(struct sockaddr *)&local,sizeof(local)))
- {
- printf("UDSIfc.c : Error binding UNIX Domain Socket, %d, %s\n", errno, strerror(errno));
- return UDS_FAILURE;
- }
- if (UDS_FAILURE == listen(gUDSSocket,UDS_SOCKET_QUE_LEN))
- {
- printf ("UDSIfc.c : Error listen\n");
- return UDS_FAILURE;
- }
-
- /* Changing the Permission of other user to
- * avoid permission denied problems while
- * client tries to connect to server */
- if(UDS_SUCCESS > chmod(local.sun_path,S_IRWXU|S_IRGRP|S_IXGRP|S_IRWXO))
- {
- printf("UDSIfc.c : Cannot Change the permission of Unix Domain Socket\n");
- }
- return UDS_SUCCESS;
- }
- /**
- * @fn RecvUDSPkt
- * @brief This functon is used to Recv the UDS Pkt
- * @param BMCInst
- **/
- void *RecvUDSPkt(void *pArg)
- {
- MsgPkt_T MsgPkt;
- struct timeval Timeout;
- struct sockaddr_un local;
- int RetVal,max,Index = 0;
- unsigned int locallen;
- int UDSSocket=-1;
- prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
- int curThreadIndex = 0;
- fd_set fds;
- memset(&local,0,sizeof(local));
- locallen=sizeof(local);
- while(TRUE)
- {
- Timeout.tv_sec = SESSION_TIMEOUT;
- Timeout.tv_usec = 0;
- FD_ZERO(&fds);
- if(gUDSSocket != -1)
- FD_SET(gUDSSocket,&fds);
- if(UDSSocket != -1)
- FD_SET(UDSSocket,&fds);
-
- max = (gUDSSocket > UDSSocket) ? gUDSSocket+1 : UDSSocket+1;
- /*Waits for an event to occur on socket*/
- RetVal = select (max, &fds, NULL, NULL, &Timeout);
- if (UDS_FAILURE == RetVal)
- {
- continue;
- }
- if (UDS_SUCCESS == RetVal)
- {
- /* Its due to timeout - continue */
- continue;
- }
-
- /*Accepting Connection*/
- if(FD_ISSET(gUDSSocket,&fds))
- {
- UDSSocket=accept(gUDSSocket,(struct sockaddr *)&local,&locallen);
- if(UDS_FAILURE == UDSSocket)
- {
- printf("UDSIfc.c:Accept Failed in UDSInterface");
- sleep(5);
- continue;
- }
- }
- if(FD_ISSET(UDSSocket,&fds))
- {
- if(UDS_SUCCESS == ReadUDSData( &MsgPkt,UDSSocket))
- {
- if (UDS_SUCCESS != PostMsg (gFdUdsIfc, &MsgPkt))
- {
- printf("UDSIfc.c:Cannot Post Data to UDSIfcQ\n");
- }
- }
- else
- {
- close(UDSSocket);
- UDSSocket = -1;
- }
- }
- }
- }
- /**
- * @fn ReadUDSData
- * @brief This function is used to read the data from socket
- * @param MsgPkt,Socket,BMCInst
- **/
- int ReadUDSData(MsgPkt_T *MsgPkt,int Socket )
- {
- uint8_t* pData =(uint8_t *) & MsgPkt->Data[0];
- uint16_t RecvdLen = 0,RemLen = 0,Len = 0;
- unsigned int SourceLen = 0;
- struct sockaddr_un Source;
- IPMIUDSMsg_T *pIPMIUDSMsg = (IPMIUDSMsg_T *)&pData[0];
- SourceLen = sizeof(Source);
- while (RecvdLen < sizeof(IPMIUDSMsg_T))
- {
- Len = recvfrom (Socket, &pData[RecvdLen],sizeof(IPMIUDSMsg_T),0,(struct sockaddr *)&Source,&SourceLen);
- if (Len <= 0)
- {
- return UDS_FAILURE;
- }
-
- int i;
- printf("---> server recv1 %#x: ", Len);
- for(i=0;i<Len;i++)
- printf("%#x ", pData[RecvdLen+i]);
- printf("\n");
- RecvdLen += Len;
- }
- RemLen = pIPMIUDSMsg->IPMIMsgLen-RecvdLen;
- while(RemLen>0)
- {
- Len = recvfrom (Socket,&pData[RecvdLen],pIPMIUDSMsg->IPMIMsgLen-RecvdLen,0,(struct sockaddr *)&Source,&SourceLen);
- if(Len <= 0)
- {
- return UDS_FAILURE;
- }
- int i;
- printf("---> server recv2 %#x: ", Len);
- for(i=0;i<Len;i++)
- printf("%#x ", pData[RecvdLen+i]);
- printf("\n");
- RecvdLen += Len;
- RemLen -= Len;
- }
- MsgPkt->SessionID = pIPMIUDSMsg->SessionID;
- MsgPkt->Cmd = pIPMIUDSMsg->Cmd;
- MsgPkt->NetFnLUN = pIPMIUDSMsg->NetFnLUN;
- MsgPkt->Privilege = pIPMIUDSMsg->Privilege;
- MsgPkt->Socket = Socket;
- MsgPkt->Size = RecvdLen;
- // MsgPkt->Param = UDS_SMB_PARAM;
- MsgPkt->Channel = pIPMIUDSMsg->ChannelNum;
- // MsgPkt->SessionType = UDS_SESSION_TYPE;
- strcpy ((char *)MsgPkt->SrcQ, UDS_RES_Q);
- return UDS_SUCCESS;
- }
- /**
- * @fn ProcessUDSReq
- * @brief This function is used to Process the Request
- * @param pReq,BMCInst
- **/
- static int ProcessUDSReq(MsgPkt_T *pReq )
- {
- MsgPkt_T pRes;
- int RetVal = 0;
- // /*Check Whether the request is from valid session id*/
- // if(pReq->SessionID != 0)
- // {
- // pUDSSessionInfo = GetUDSSessionInfo (UDS_SESSION_ID_INFO,&pReq->SessionID, BMCInst);
- // if(pUDSSessionInfo == NULL)
- // {
- // IPMI_WARNING("Session Info is NULL for the requested Session ID\n");
- // FillUDSResponsePacket(pReq,&pRes,CC_INV_DATA_FIELD,BMCInst);
- // SendUDSPkt(&pRes,BMCInst);
- // return UDS_FAILURE;
- // }
- // /*Resetting the TimeoutValue for the requested session*/
- // pUDSSessionInfo->SessionTimeoutValue = g_BMCInfo[BMCInst].IpmiConfig.SessionTimeOut;
- // }
- // else if((pReq->SessionID == 0) && CheckReservedCmd(pReq->Cmd))
- // {
- // FillUDSResponsePacket(pReq,&pRes,CC_INV_DATA_FIELD,BMCInst);
- // SendUDSPkt(&pRes,BMCInst);
- // return UDS_FAILURE;
- // }
- // /*Posting the request to Msg Handler for processing the command */
- // if (UDS_SUCCESS != PostMsg (pReq, MSG_HNDLR_Q, BMCInst))
- // {
- // IPMI_ASSERT (FALSE);
- // return UDS_FAILURE;
- // }
- // /* Get the response from the Message handler Task */
- // memset(&pRes,0,sizeof(MsgPkt_T));
- // if (UDS_SUCCESS != GetMsg (&pRes, UDS_RES_Q, WAIT_INFINITE, BMCInst))
- // {
- // IPMI_ASSERT (FALSE);
- // return UDS_FAILURE;
- // }
- // if(!CheckReservedCmd(pRes.Cmd) && (pRes.SessionID == 0) && (pRes.Cmd != ReservedCmd[1]))
- // {
- // RetVal = AddUDSInfo(pReq,&pRes,BMCInst);
- // }
- FillUDSResponsePacket(pReq,&pRes,CC_NORMAL);
- /* Sending the Packet to the corresponding client*/
- //if((UDS_SUCCESS == RetVal) || (UDS_FAILURE == RetVal))
- {
- SendUDSPkt(&pRes);
- }
- return UDS_SUCCESS;
- }
- /**
- * @fn SendUDSPkt
- * @brief This function sends the IPMI UDS Response to the requestor
- * @param pRes - Response message.
- **/
- int SendUDSPkt (MsgPkt_T *pRes)
- {
- int i;
- printf("---> server Send %#x: ", pRes->Size);
- for(i=0;i<pRes->Size;i++)
- printf("%#x ", pRes->Data[i]);
- printf("\n");
- /* Send the UDS response packet */
- if(UDS_FAILURE == send(pRes->Socket,pRes->Data,pRes->Size,MSG_NOSIGNAL))
- {
- if((EBADF == errno) || (EPIPE == errno))
- {
- return UDS_SUCCESS;
- }
- else
- {
- printf("UDSIfc.c: Send UDS Pkt Failed\n");
- return UDS_FAILURE;
- }
- }
- return UDS_SUCCESS;
- }
- /**
- * @fn FillUDSResponsePacket
- * @brief This function fills the pRes when Error Occured
- * @param pReq,pRes,CompletionCode,BMCInst
- **/
- int FillUDSResponsePacket(MsgPkt_T *pReq,MsgPkt_T *pRes,uint8_t UDSCompletionCode )
- {
- IPMIUDSMsg_T *pIPMIUDSMsgReq = (IPMIUDSMsg_T *)&pReq->Data[0];
- IPMIUDSMsg_T *pIPMIUDSMsgRes = (IPMIUDSMsg_T *)&pRes->Data[0];
- uint8_t *byCompletionCode = (uint8_t *)&pRes->Data[sizeof(IPMIUDSMsg_T)];
- pRes->Socket = pReq->Socket;
- pReq->Cmd = pIPMIUDSMsgReq->Cmd;
- pIPMIUDSMsgRes->SessionID = pIPMIUDSMsgReq->SessionID;
- pIPMIUDSMsgRes->Cmd = pIPMIUDSMsgReq->Cmd;
- pIPMIUDSMsgRes->NetFnLUN = pIPMIUDSMsgReq->NetFnLUN;
- pIPMIUDSMsgRes->Privilege = pIPMIUDSMsgReq->Privilege;
- pIPMIUDSMsgRes->IPMIMsgLen = sizeof(IPMIUDSMsg_T)+sizeof(uint8_t)+1;
- pIPMIUDSMsgRes->ChannelNum = pIPMIUDSMsgReq->ChannelNum;
- pIPMIUDSMsgRes->AuthFlag = pIPMIUDSMsgReq->AuthFlag;
-
- strcpy( (char *)pIPMIUDSMsgRes->UserName, (char *)pIPMIUDSMsgReq->UserName);
- memcpy(pIPMIUDSMsgRes->IPAddr, pIPMIUDSMsgReq->IPAddr, 16);
- pRes->Size = pIPMIUDSMsgRes->IPMIMsgLen;
- *byCompletionCode = UDSCompletionCode;
- return UDS_SUCCESS;
- }
- // /**
- // * @fn UpdateUDSTimeout
- // * @brief This function Updates the timeout value for each socket opened
- // * @param BMCInst
- // **/
- // static int
- // UpdateUDSTimeout (void)
- // {
- // int Index = 0;
- // int TimeOut=0;
- // _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
- // SocketTbl_T *SocketTable = pBMCInfo->pUDSocketTbl;
- // for (Index = 0; Index < (pBMCInfo->IpmiConfig.MaxSession + 1); Index++ )
- // {
- // if((SocketTable[Index].Valid))
- // {
- // TimeOut = pBMCInfo->IpmiConfig.SessionTimeOut;
- // if (SocketTable[Index].Time >= TimeOut)
- // {
- // IPMI_DBG_PRINT("Local Socket Timed Out\n");
- // close (SocketTable[Index].Socket);
- // /* Acquire the UDS Socket Mutex Lock */
- // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
- // SocketTable[Index].Socket = 0;
- // SocketTable[Index].Valid = 0;
- // /* Release the UDS Socket Mutex Lock */
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
- // }
- // else
- // { /* update the time */
- // /* Acquire the UDS Socket Mutex Lock */
- // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->UDSSocketTblMutex, WAIT_INFINITE);
- // SocketTable[Index].Time += UDS_TIMER_INTERVAL;
- // /* Release the UDS Socket Mutex Lock */
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->UDSSocketTblMutex);
- // }
- // }
- // }
- // return UDS_SUCCESS;
- // }
- // /**
- // * @fn UDSTimer
- // * @brief This function handles the time out for uds connections.
- // * @param None
- // **/
- // static
- // void* UDSTimer (void *pArg)
- // {
- // int *inst = (int*)pArg;
- // int BMCInst= *inst;
- // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
- // while (TRUE)
- // {
- // UpdateUDSTimeout (BMCInst);
- // sleep (UDS_TIMER_INTERVAL);
- // }
- // return UDS_SUCCESS;
- // }
- // /**
- // * @fn AddUDSInfo
- // * @brief This function adds the session information in Session Table
- // * @param UDS Request Packet,UDS Response Packet,BMCInst
- // **/
- // int AddUDSInfo(MsgPkt_T *pUDSReq,MsgPkt_T *pUDSRes )
- // {
- // uint8 *byCompletionCode = (uint8 *)&pUDSRes->Data[sizeof(IPMIUDSMsg_T)];
- // IPMIUDSMsg_T *pRes = (IPMIUDSMsg_T *)&pUDSRes->Data[0];
- // _FAR_ ChannelInfo_T *pChanneludsInfo = NULL;
- // _FAR_ ChannelUserInfo_T *pChUserInfo = NULL;
- // _FAR_ UserInfo_T *pUserInfo = NULL;
- // UDSSessionTbl_T UDSSessionInfo;
- // INT32U SessionID;
- // uint8_t UserID,Index,SessionHandle=0;
- // unsigned int seed=1;
- // _FAR_ BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- // char UserPswd[MAX_PASSWORD_LEN];
- // uint8_t ChannelNum = CH_NOT_USED;
- // uint8_t PwdEncKey[MAX_SIZE_KEY + 1] = {0};
- // _fmemset(&UDSSessionInfo,0,sizeof(UDSSessionTbl_T));
- // if(*byCompletionCode == CC_NORMAL)
- // {
- // if(ReservedCmd[0] == pRes->Cmd)
- // {
- // UserID = 0;
- // }
- // else
- // {
- // UserID = (uint8)pUDSReq->Data[sizeof(IPMIUDSMsg_T)];
- // }
- // if(pBMCInfo ->UDSSessionTblInfo.SessionCount >= pBMCInfo->IpmiConfig.MaxSession)
- // {
- // IPMI_WARNING("UDSIfc.c:Maximum Session Limit Reached\n");
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_ACTIVATE_SESS_NO_SESSION_SLOT_AVAILABLE,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // do
- // {
- // SessionID = ((INT32U)rand_r(&seed) >> 16);
- // } while ((NULL != GetUDSSessionInfo (UDS_SESSION_ID_INFO,&SessionID, BMCInst)) || (0 == SessionID));
- // SessionHandle = BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle;
-
- // do
- // {
- // SessionHandle += 1;
- // } while (NULL != GetUDSSessionInfo (UDS_SESSION_HANDLE_INFO,&SessionHandle, BMCInst));
- // LOCK_BMC_SHARED_MEM(BMCInst);
- // BMC_GET_SHARED_MEM(BMCInst)->UDSSessionHandle = SessionHandle;
- // UNLOCK_BMC_SHARED_MEM(BMCInst);
- // pChanneludsInfo = GetLANChannelInfoForUDS(pUDSReq->Channel,&ChannelNum,&pRes->ChannelNum,BMCInst);
- // if(pChanneludsInfo == NULL)
- // {
- // IPMI_WARNING("UDSIfc.c:Invalid Channel\n");
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // if(0 != UserID)
- // {
- // pUserInfo = getUserIdInfo (UserID & 0x3F, BMCInst);
- // if (g_corefeatures.userpswd_encryption == ENABLED)
- // {
- // /* Get Encryption Key from the MBMCInfo_t structure */
- // LOCK_BMC_SHARED_MEM(BMCInst);
- // memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
- // UNLOCK_BMC_SHARED_MEM(BMCInst);
- // if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[(UserID - 1) & 0x3F].EncryptedPswd), MAX_PASSWORD_LEN, (INT8S *)UserPswd, MAX_PASSWORD_LEN, PwdEncKey))
- // {
- // TCRIT("Error in decrypting the user password for user ID:%d. .\n", UserID);
- // FillUDSResponsePacket(pUDSReq, pUDSRes, CC_UNSPECIFIED_ERR, BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket, BMCInst);
- // return UDS_FAILURE;
- // }
- // }
- // else
- // {
- // _fmemcpy (UserPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
- // }
- // if (NULL == pUserInfo)
- // {
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)UserPswd)!= 0) && (pUserInfo->UserStatus == FALSE))
- // {
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
- // pChUserInfo = getChUserIdInfo (UserID & 0x3F, &Index, pChanneludsInfo->ChannelUserInfo, BMCInst);
- // if (NULL == pChUserInfo)
- // {
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_DATA_FIELD,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // else if(pChUserInfo->AccessLimit == PRIV_LEVEL_NO_ACCESS)
- // {
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INSUFFIENT_PRIVILEGE,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // else if((strlen((char *)pUserInfo->UserName) != 0) && (strlen((char *)pUserInfo->UserPassword)!= 0) && (pChUserInfo->IPMIMessaging == FALSE))
- // {
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
- // FillUDSResponsePacket(pUDSReq,pUDSRes,CC_INV_CMD,BMCInst);
- // SendUDSPkt(pUDSRes,BMCInst);
- // CloseUDSSocket(pUDSRes->Socket,BMCInst);
- // return UDS_PARAM_FAILURE;
- // }
- // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
- // }
- // if(0 != UserID)
- // {
- // UDSSessionInfo.LoggedInPrivilege = pChUserInfo->AccessLimit;
- // }
- // else
- // {
- // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
- // }
- // UDSSessionInfo.Activated = TRUE;
- // UDSSessionInfo.UDSSocket = pUDSRes->Socket;
- // UDSSessionInfo.LoggedInUserID= UserID;
- // UDSSessionInfo.LoggedInPrivilege = pUDSReq->Privilege;
- // UDSSessionInfo.LoggedInChannel = ChannelNum;
- // UDSSessionInfo.SessionID = SessionID;
- // UDSSessionInfo.SessionTimeoutValue = pBMCInfo->IpmiConfig.SessionTimeOut;
- // UDSSessionInfo.AuthenticationMechanism = pRes->AuthFlag;
- // UDSSessionInfo.LoggedInSessionHandle = SessionHandle;
- // UDSSessionInfo.UDSChannelNum = UDS_CHANNEL;
- // _fmemcpy( (char *)UDSSessionInfo.LoggedInUsername, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->UserName,MAX_USERNAME_LEN);
- // _fmemcpy( (char *)UDSSessionInfo.LoggedInPassword, UserPswd,MAX_PASSWORD_LEN);
- // _fmemcpy( (char *)UDSSessionInfo.IPAddr, (char *)((IPMIUDSMsg_T *)&pUDSReq->Data[0])->IPAddr,IP6_ADDR_LEN);
- // UDSSessionInfo.ProcessID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ProcessID;
- // UDSSessionInfo.ThreadID = ((IPMIUDSMsg_T *)&pUDSReq->Data[0])->ThreadID;
- // AddUDSSession(&UDSSessionInfo,BMCInst);
- // /*Assigning the Privilege Level and Session ID*/
- // pRes->SessionID = SessionID;
- // pRes->Privilege = UDSSessionInfo.LoggedInPrivilege;
- // return UDS_SUCCESS;
- // }
- // return UDS_FAILURE;
- // }
- // /**
- // * @fn RemoveUDSSession
- // * @brief This function deletes the session information in Session Table
- // * @param Socket,BMCInst
- // **/
- // uint8_t RemoveUDSSession(SOCKET Socket )
- // {
- // _FAR_ UDSSessionTbl_T *pUDSSessionInfo = NULL;
- // pUDSSessionInfo = GetUDSSessionInfo(UDS_SOCKET_ID_INFO,&Socket,BMCInst);
- // if(NULL != pUDSSessionInfo)
- // {
- // DeleteUDSSession(pUDSSessionInfo,BMCInst);
- // }
- // return UDS_SUCCESS;
- // }
- // /**
- // * @fn CloseUDSSocket
- // * @brief This function removes the socket and closes it
- // * @param Socket,BMCInst
- // **/
- // void CloseUDSSocket(int Socket )
- // {
- // close(Socket);
- // RemoveUDSSocket(Socket,BMCInst);
- // }
- // /**
- // * @fn CheckReservedCmd
- // * @brief This function is used to check whether the triggered command
- // * belongs to Reserved List
- // * @param Cmd - Command Number
- // **/
- // int CheckReservedCmd(uint8_t Cmd)
- // {
- // int index = 0;
- // for(index = 0;index < sizeof(ReservedCmd); index++)
- // {
- // if(ReservedCmd[index] == Cmd)
- // {
- // return UDS_SUCCESS;
- // }
- // }
- // return UDS_CMD_FAILURE;
- // }
- // /**
- // * @fn GetLANChannelInfoForUDS
- // * @brief This function is used to get the LAN Channel Info
- // * @param - Requested UDS Channel number,BMC Instance and out pointer which points
- // to LAN Channel Number.
- // **/
- // ChannelInfo_T* GetLANChannelInfoForUDS(uint8_t ReqUDSChannel,uint8_t *LANChannel,uint8_t *ResChannelNum )
- // {
- // BMCInfo_t *pBMCInfo = (BMCInfo_t *)&g_BMCInfo[BMCInst];
- // uint8_t Ch = 0;
- // ChannelInfo_T *UDSChannelInfo = NULL;
- // for(Ch = 1;Ch <= MAX_LAN_CHANNELS; Ch++)
- // {
- // if(ReqUDSChannel == UDS_CHANNEL)
- // {
- // if((pBMCInfo->RMCPLAN1Ch != CH_NOT_USED) && (*LANChannel == CH_NOT_USED))
- // {
- // *LANChannel = pBMCInfo->RMCPLAN1Ch;
- // }
- // else if((pBMCInfo->RMCPLAN2Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN2Ch))
- // {
- // *LANChannel = pBMCInfo->RMCPLAN2Ch;
- // }
- // else if((pBMCInfo->RMCPLAN3Ch != CH_NOT_USED) && (*LANChannel != pBMCInfo->RMCPLAN3Ch))
- // {
- // *LANChannel = pBMCInfo->RMCPLAN3Ch;
- // }
- // }
- // else
- // {
- // *LANChannel = ReqUDSChannel;
- // }
- // UDSChannelInfo = getChannelInfo(*LANChannel,BMCInst);
- // if((UDSChannelInfo == NULL) || (UDSChannelInfo->ActiveSession >= UDSChannelInfo->SessionLimit))
- // {
- // if((ReqUDSChannel != UDS_CHANNEL) || (Ch == MAX_LAN_CHANNELS))
- // {
- // *LANChannel = CH_NOT_USED;
- // return NULL;
- // }
- // }
- // else if(UDSChannelInfo != NULL)
- // {
- // *ResChannelNum = *LANChannel;
- // return UDSChannelInfo;
- // }
- // }
- // *LANChannel = CH_NOT_USED;
- // return NULL;
- // }
|