loopback_ifc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /****************************************************************
  2. ****************************************************************
  3. ** **
  4. ** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. ** **
  6. ** All Rights Reserved. **
  7. ** **
  8. ** 6145-F, Northbelt Parkway, Norcross, **
  9. ** **
  10. ** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. ** **
  12. ****************************************************************
  13. ****************************************************************/
  14. /*****************************************************************
  15. *
  16. * LANIfc.c
  17. * LAN Interface Handler
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * : Bakka Ravinder Reddy <bakkar@ami.com>
  21. *
  22. *****************************************************************/
  23. #include <stdio.h>
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include <errno.h>
  27. #include <pthread.h>
  28. #include <fcntl.h>
  29. #include <sys/socket.h>
  30. #include "com_IPMI_LANIfc.h"
  31. #include "com_IPMI_RMCP.h"
  32. #include "RMCP.h"
  33. #include "LOOPBACK_ifc.h"
  34. #include "com_IPMIDefs.h"
  35. #include "RMCP.h"
  36. #include "MD.h"
  37. #include <netdb.h> /* getaddrinfo(3) et al. */
  38. #include <netinet/in.h> /* sockaddr_in & sockaddr_in6 definition. */
  39. #include <net/if.h>
  40. #include <sys/prctl.h>
  41. #include "main.h"
  42. #include "Session.h"
  43. #define NO_OF_RETRY 3
  44. #define MAX_POSSIBLE_IPMI_DATA_SIZE 1000
  45. #define MAX_LAN_BUFFER_SIZE 1024
  46. #define LAN_TIMER_INTERVAL 10
  47. #define RMCP_CLASS_MSG_OFFSET 3
  48. #define IPMI_MSG_AUTH_TYPE_OFFSET 4
  49. #define RMCP_ASF_PING_MESSAGE_LENGTH 12
  50. #define IPMI_MSG_LEN_OFFSET 13
  51. #define IPMI20_MSG_LEN_OFFSET 14
  52. #define RMCP_CLASS_MSG_ASF 0x06
  53. #define RMCP_CLASS_MSG_IPMI 0x07
  54. //static void* LANTimer (void*);
  55. static void* RecvLANPkt (void*);
  56. static int SendLANPkt (MsgPkt_T *pRes );
  57. static void ProcessLANReq ( MsgPkt_T* pReq);
  58. static void ProcessBridgeMsg ( MsgPkt_T* pReq );
  59. static int InitUDPSocket(void);
  60. static int SetIPv4Header(int socketID);
  61. int gSocket_lo = -1;
  62. int gFd_LoIfcQ, gFd_LoResQ;
  63. /**
  64. * @brief LAN Interface Task.
  65. **/
  66. void *LoIfcTask (void *param)
  67. {
  68. MsgPkt_T Req;
  69. int i,BMC,Buffer = 0;
  70. uint8_t ethindex=0;
  71. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  72. int curThreadIndex = 0;
  73. /* Init LAN SMB */
  74. printf("LoIfc Task Started... \n");
  75. //create LAN_IFC_Q
  76. if(-1 != access(LO_IFC_Q, F_OK))
  77. {
  78. remove(LO_IFC_Q);
  79. }
  80. if(0 != mkfifo (LO_IFC_Q, 0777))
  81. {
  82. printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, LO_IFC_Q, strerror(errno));
  83. return (void*)-1;
  84. }
  85. gFd_LoIfcQ = open (LO_IFC_Q, O_RDWR);
  86. if(-1 == gFd_LoIfcQ)
  87. {
  88. printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, LO_IFC_Q, strerror(errno));
  89. return (void*)-1;
  90. }
  91. //create LAN_RES_Q
  92. if(-1 != access(LO_RES_Q, F_OK))
  93. {
  94. remove(LO_RES_Q);
  95. }
  96. if(0 != mkfifo (LO_RES_Q, 0777))
  97. {
  98. printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, LO_RES_Q, strerror(errno));
  99. return (void*)-1;
  100. }
  101. gFd_LoResQ = open (LO_RES_Q, O_RDWR);
  102. if(-1 == gFd_LoResQ)
  103. {
  104. printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, LO_RES_Q, strerror(errno));
  105. return (void*)-1;
  106. }
  107. /* Create LAN socket */
  108. if(0 != Lo_InitUDPSocket())
  109. {
  110. printf("%s: Create UDP socket failed! %s\n", __FUNCTION__, strerror(errno));
  111. return (void *)-1;
  112. }
  113. /*Create a thread to recv UDS Pkt */
  114. gThreadIndex++;
  115. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,RecvLoPkt,NULL))
  116. {
  117. printf("%s: Create RecvLANPkt thread failed! %s\n", __FUNCTION__, strerror(errno));
  118. return (void *)-1;
  119. }
  120. while (1)
  121. {
  122. /* Wait for a message in LANIfc interface Queue */
  123. if (0 != GetMsg (gFd_LoIfcQ, &Req, WAIT_INFINITE))
  124. {
  125. printf("LANIfc.c : Error fetching message from hLANIfc_Q\n");
  126. continue;
  127. }
  128. switch (Req.Param)
  129. {
  130. case LAN_SMB_REQUEST :
  131. ProcessLANReq (&Req);
  132. break;
  133. case BRIDGING_REQUEST :
  134. ProcessBridgeMsg (&Req );
  135. break;
  136. default :
  137. printf ("LOOPBACK_Ifc.c : Invalid request\n");
  138. break;
  139. }
  140. }
  141. }
  142. /**
  143. * @fn InitUnixDomainSocket
  144. * @brief This function is used to create the Socket for each BMC
  145. * @param BMCInst
  146. **/
  147. static int Lo_InitUDPSocket(void)
  148. {
  149. struct sockaddr_in local;
  150. char UDPIfcName [MAX_STR_LENGTH];
  151. int reuseaddr = 1;
  152. memset(UDPIfcName,0,sizeof(UDPIfcName));
  153. if(gSocket_Lo != -1)
  154. {
  155. close(gSocket_Lo);
  156. gSocket_Lo = -1;
  157. }
  158. memset(&local, 0, sizeof(struct sockaddr_in));
  159. local.sin_family = AF_INET;
  160. local.sin_port = htons(623);
  161. local.sin_addr.s_addr = htonl(INADDR_ANY);
  162. gSocket_LAN = socket(AF_INET,SOCK_DGRAM,0);
  163. if(-1 == gSocket_LAN)
  164. {
  165. printf("LANIfc.c : Unable to create the UDP Socket\n");
  166. return -1;
  167. }
  168. //printf("UDP Socket %d\n", gSocket_LAN);
  169. strcpy(UDPIfcName,"eth0");
  170. if (0 != setsockopt (gSocket_LAN, SOL_SOCKET,SO_BINDTODEVICE, UDPIfcName, sizeof (UDPIfcName)+1))
  171. {
  172. printf("LANIfc.c: SetSockOpt(SO_BINDTODEVICE) Failed for UDP Socket\n");
  173. return -1;
  174. }
  175. if (0 != setsockopt(gSocket_LAN, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)))
  176. {
  177. printf("LANIfc.c: Setsockopt(SO_REUSEADDR) Failed for UDP socket\n");
  178. }
  179. SetIPv4Header(gSocket_LAN);
  180. /* Bind */
  181. if (-1 == bind(gSocket_LAN,(struct sockaddr *)&local,sizeof(local)))
  182. {
  183. printf("LANIfc.c : Error binding UDP Socket, %d, %s\n", errno, strerror(errno));
  184. return -1;
  185. }
  186. //printf("Create UDP socket successfully, socket %d, port: %d\n", gSocket_LAN, local.sin_port);
  187. return 0;
  188. }
  189. /**
  190. * @fn ReadData
  191. * @brief This function receives the IPMI LAN request packets
  192. *
  193. * @param pMsgPkt - pointer to message packet
  194. * @param Socket - Socket handle
  195. **/
  196. static
  197. int ReadData (MsgPkt_T *pMsgPkt, int Socket )
  198. {
  199. unsigned int SourceLen = 0,Index,SocktIndex=0,addrlen=0;
  200. int Channel = 0;
  201. uint8_t *pData = pMsgPkt->Data;
  202. int16_t Len = 0;
  203. uint16_t RecvdLen = 0;
  204. uint16_t IPMIMsgLen = 0;
  205. uint16_t IPMIMsgOffset = 0;
  206. struct sockaddr_in Sourcev4;
  207. struct sockaddr_in server_v4addr;
  208. void *Source = NULL ;
  209. void *server_addr = NULL ;
  210. uint8_t WaitCount;
  211. int i;
  212. Source = &Sourcev4;
  213. SourceLen = sizeof (Sourcev4);
  214. //printf("ReadData:\n");
  215. //SourceLen = sizeof (Source);
  216. /* Read minimum bytes to find class of message */
  217. while (RecvdLen < RMCP_CLASS_MSG_OFFSET)
  218. {
  219. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
  220. // printf("Recv1 %d: ", Len);
  221. // for(i=0;i<Len;i++)
  222. // printf("%#x ", pData[RecvdLen+i]);
  223. // printf("\n");
  224. if ((Len >= -1) && (Len <= 0))
  225. {
  226. return -1;
  227. }
  228. RecvdLen += (uint16_t)Len;
  229. }
  230. /* if RMCP Presence Ping Requested */
  231. if (RMCP_CLASS_MSG_ASF == pData[RMCP_CLASS_MSG_OFFSET])
  232. {
  233. /* Read remaining RMCP ASF ping message */
  234. while (RecvdLen < RMCP_ASF_PING_MESSAGE_LENGTH)
  235. {
  236. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
  237. // printf("Recv2 %d: ", Len);
  238. // for(i=0;i<Len;i++)
  239. // printf("%#x ", pData[RecvdLen+i]);
  240. // printf("\n");
  241. if ((Len >= -1) && (Len <= 0))
  242. {
  243. return -1;
  244. }
  245. RecvdLen += (uint16_t)Len;
  246. }
  247. }
  248. /*else if IPMI RMCP request */
  249. else if (RMCP_CLASS_MSG_IPMI == pData[RMCP_CLASS_MSG_OFFSET])
  250. {
  251. /* Read minimum no of bytes for IPMI Auth type offset*/
  252. while (RecvdLen < IPMI_MSG_AUTH_TYPE_OFFSET)
  253. {
  254. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  255. // printf("Recv3 %d: ", Len);
  256. // for(i=0;i<Len;i++)
  257. // printf("%#x ", pData[RecvdLen+i]);
  258. // printf("\n");
  259. if ((Len >= -1) && (Len <= 0))
  260. {
  261. return -1;
  262. }
  263. RecvdLen += (uint16_t)Len;
  264. }
  265. /* Get the IPMI message length offset based on format/authentication type */
  266. if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
  267. {
  268. IPMIMsgOffset = IPMI20_MSG_LEN_OFFSET + 1;
  269. }
  270. else if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == AUTH_TYPE_NONE)
  271. {
  272. IPMIMsgOffset = IPMI_MSG_LEN_OFFSET;
  273. }
  274. else
  275. {
  276. IPMIMsgOffset = IPMI_MSG_LEN_OFFSET + AUTH_CODE_LEN;
  277. }
  278. /* Read minimum no of bytes for IPMI message length offset*/
  279. while (RecvdLen < IPMIMsgOffset)
  280. {
  281. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  282. // printf("Recv4 %d: ", Len);
  283. // for(i=0;i<Len;i++)
  284. // printf("%#x ", pData[RecvdLen+i]);
  285. // printf("\n");
  286. if ((Len >= -1) && (Len <= 0))
  287. {
  288. return -1;
  289. }
  290. RecvdLen += (uint16_t)Len;
  291. }
  292. /* Get the IPMI message length based on RMCP format type */
  293. if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
  294. {
  295. IPMIMsgLen = *((uint16_t*)&pData [IPMI20_MSG_LEN_OFFSET]);
  296. }
  297. else
  298. {
  299. IPMIMsgLen = pData [IPMIMsgOffset];
  300. }
  301. /* We are assuming that we cannot get more than 17 K data in IPMI Msg */
  302. /* This work around for fix the malformed IPMI Msg length */
  303. if(IPMIMsgOffset > MAX_POSSIBLE_IPMI_DATA_SIZE )
  304. {
  305. return -1;
  306. }
  307. /* Read the remaining IPMI message packets */
  308. WaitCount = 3;
  309. while (RecvdLen < IPMIMsgLen)
  310. {
  311. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  312. // printf("Recv5 %d: ", Len);
  313. // for(i=0;i<Len;i++)
  314. // printf("%#x ", pData[RecvdLen+i]);
  315. // printf("\n");
  316. if ((Len >= -1) && (Len <= 0))
  317. {
  318. if(Len == -1)
  319. {
  320. if(errno == EAGAIN)
  321. {
  322. WaitCount--;
  323. }
  324. else
  325. return -1;
  326. }
  327. else
  328. return -1;
  329. }
  330. if(WaitCount == 0)
  331. {
  332. return -1;
  333. }
  334. RecvdLen += (uint16_t)Len;
  335. }
  336. }/* else other RMCP class are not supported. */
  337. else
  338. {
  339. printf ("Unknown RMCP class\n");
  340. }
  341. pMsgPkt->Size = RecvdLen;
  342. pMsgPkt->UDPPort = ((struct sockaddr_in *)Source)->sin_port;
  343. pMsgPkt->Socket = Socket;
  344. pMsgPkt->Channel = LAN_RMCP_CHANNEL;
  345. // printf("\nLan received %d: ",RecvdLen);
  346. // for(i=0;i<RecvdLen;i++)
  347. // {
  348. // printf("%#x ", pData[i]);
  349. // }
  350. // printf("\n");
  351. if(SourceLen!=0)
  352. {
  353. memcpy (pMsgPkt->IPAddr, &((struct sockaddr_in *)Source)->sin_addr.s_addr, sizeof (struct in_addr));
  354. }
  355. pMsgPkt->Param = LAN_SMB_REQUEST;
  356. return 0;
  357. }
  358. void *RecvLANPkt(void *pArg)
  359. {
  360. MsgPkt_T MsgPkt;
  361. struct timeval Timeout;
  362. struct sockaddr_in local;
  363. int RetVal,max,Index = 0;
  364. unsigned int locallen;
  365. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  366. fd_set fds;
  367. memset(&local,0,sizeof(local));
  368. locallen=sizeof(local);
  369. printf("RecvLANPkt start...\n");
  370. while(1)
  371. {
  372. Timeout.tv_sec = SESSION_TIMEOUT;
  373. Timeout.tv_usec = 0;
  374. FD_ZERO(&fds);
  375. if(gSocket_LAN != -1)
  376. FD_SET(gSocket_LAN,&fds);
  377. max = gSocket_LAN+1;
  378. /*Waits for an event to occur on socket*/
  379. RetVal = select (max, &fds, NULL, NULL, &Timeout);
  380. if (-1 == RetVal)
  381. {
  382. continue;
  383. }
  384. if (0 == RetVal)
  385. {
  386. /* Its due to timeout - continue */
  387. continue;
  388. }
  389. /*Accepting Connection*/
  390. if(FD_ISSET(gSocket_LAN,&fds))
  391. {
  392. if(0 == ReadData( &MsgPkt,gSocket_LAN))
  393. {
  394. /* Post the request packet to LAN Interface Queue */
  395. if (0 != PostMsg (gFd_LanIfcQ, &MsgPkt))
  396. {
  397. printf ("Warning: LANIfc.c Error posting message to LANIfc Q\n");
  398. }
  399. }
  400. else
  401. {
  402. close(gSocket_LAN);
  403. gSocket_LAN = -1;
  404. }
  405. }
  406. }
  407. }
  408. /**
  409. * @fn SendLANPkt
  410. * @brief This function sends the IPMI LAN Response to the requester
  411. * @param pRes - Response message.
  412. **/
  413. int SendLANPkt (MsgPkt_T *pRes )
  414. {
  415. struct sockaddr_in Dest;
  416. //struct stat Stat;
  417. int ret = 0;
  418. /* Set the destination UDP port and IP Address */
  419. Dest.sin_family = AF_INET;
  420. Dest.sin_port = pRes->UDPPort;
  421. memcpy (&Dest.sin_addr.s_addr, pRes->IPAddr, sizeof (struct in_addr));
  422. /* Send the LAN response packet */
  423. //int i;
  424. //printf("\nLan send socket: %d, byte: %d: ", pRes->Socket, pRes->Size);
  425. // for (i = 0; i < pRes->Size; ++i)
  426. // {
  427. // printf("%#x ", pRes->Data[i]);
  428. // }
  429. //printf("\n");
  430. //Check the socket before send a message on a socket
  431. //if (fstat(pRes->Socket, &Stat) != -1)
  432. {
  433. ret = sendto (pRes->Socket, pRes->Data, pRes->Size, 0, (struct sockaddr*)&Dest, sizeof (Dest));
  434. if (ret == -1)
  435. {
  436. printf ("Warning: LANIfc.c Error sending response packets to LAN, %s\n",strerror(errno));
  437. }
  438. // else
  439. // {
  440. // printf ("LANIfc.c : LAN packet sent successfully\n");
  441. // }
  442. }
  443. return 1;
  444. }
  445. /**
  446. * @brief Process SMB Request.
  447. * @param pReq - Request message.
  448. **/
  449. static void
  450. ProcessLANReq ( MsgPkt_T* pReq )
  451. {
  452. MsgPkt_T Res;
  453. SessionInfo_T* pSessionInfo;
  454. SessionHdr_T* pSessionHdr;
  455. SessionHdr2_T* pSessionHdr2;
  456. uint32_t SessionID =0;
  457. /* Copy the request to response */
  458. Res = *pReq;
  459. /* Save the LAN header inofmation */
  460. pSessionHdr = (SessionHdr_T*) (((RMCPHdr_T*)pReq->Data) + 1);
  461. pSessionHdr2 = (SessionHdr2_T*)(((RMCPHdr_T*)pReq->Data) + 1);
  462. if (RMCP_PLUS_FORMAT == pSessionHdr->AuthType)
  463. {
  464. SessionID = pSessionHdr2->SessionID;
  465. pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
  466. }
  467. else
  468. {
  469. SessionID = pSessionHdr->SessionID;
  470. pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID );
  471. }
  472. if (NULL != pSessionInfo)
  473. {
  474. pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort = Res.UDPPort;
  475. pSessionInfo->hSocket = Res.Socket;
  476. //SocktIndex=GetSocketInfoIndex(pSessionInfo->hSocket );
  477. memcpy (pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, Res.IPAddr, sizeof (struct in_addr));
  478. memcpy (&pSessionInfo->LANRMCPPkt.RMCPHdr, Res.Data, sizeof (RMCPHdr_T));
  479. }
  480. /* Process the RMCP Request */
  481. Res.Size = ProcessRMCPReq ((RMCPHdr_T*)pReq->Data, (RMCPHdr_T*)Res.Data);
  482. /* ResLen is 0, don't send the packet */
  483. if (0 == Res.Size )
  484. {
  485. printf ("Note: LANIfc.c LAN request packet dropped, not processed\n");
  486. return;
  487. }
  488. /* Sent the response packet */
  489. SendLANPkt (&Res);
  490. return;
  491. }
  492. /*--------------------------------------------
  493. * ProcessBridgeMsg
  494. *--------------------------------------------*/
  495. static void
  496. ProcessBridgeMsg ( MsgPkt_T* pReq )
  497. {
  498. MsgPkt_T ResPkt;
  499. uint16_t PayLoadLen = 0;
  500. uint8_t PayLoadType = 0;
  501. SessionInfo_T *pSessionInfo = getSessionInfo (SESSION_HANDLE_INFO, pReq->Data);
  502. //printf ("LANIfc: Bridge Request\n");
  503. if (NULL == pSessionInfo)
  504. {
  505. printf ("Warning: LANIfc ProcessBridgeMsg - No Session with the LAN\n");
  506. return;
  507. }
  508. /* Copy Lan RMCP headers from Session Record */
  509. ResPkt.UDPPort = pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort;
  510. ResPkt.Socket = pSessionInfo->hSocket;
  511. memcpy (ResPkt.IPAddr, pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, sizeof (struct in_addr));
  512. memcpy (ResPkt.Data, &pSessionInfo->LANRMCPPkt.RMCPHdr, sizeof (RMCPHdr_T));
  513. // #if IPMI20_SUPPORT == 1
  514. // if (RMCP_PLUS_FORMAT == pSessionInfo->AuthType)
  515. // {
  516. // /* Fill Session Header */
  517. // pSessionInfo->OutboundSeq++;
  518. // PayLoadLen = pReq->Size - 1;
  519. // PayLoadType = pReq->Cmd;
  520. // PayLoadType |= (pSessionInfo->SessPyldInfo[PayLoadType].AuxConfig[0] & 0xC0);
  521. // PayLoadLen = Frame20Payload (PayLoadType, ( RMCPHdr_T*)&ResPkt.Data [0],
  522. // &pReq->Data[1], PayLoadLen, pSessionInfo );
  523. // }
  524. // else
  525. // #endif /*IPMI20_SUPPORT == 1*/
  526. {
  527. /* Fill Session Header */
  528. SessionHdr_T* pSessionHdr = ( SessionHdr_T*)(&ResPkt.Data [sizeof(RMCPHdr_T)]);
  529. uint8_t* pPayLoad = ( uint8_t*)(pSessionHdr + 1);
  530. pSessionHdr->AuthType = pSessionInfo->AuthType;
  531. pSessionHdr->SessionSeqNum = pSessionInfo->OutboundSeq++;
  532. pSessionHdr->SessionID = pSessionInfo->SessionID;
  533. /* If AuthType is not 0 - Compute AuthCode */
  534. if (0 != pSessionInfo->AuthType)
  535. {
  536. PayLoadLen = AUTH_CODE_LEN;
  537. pPayLoad [PayLoadLen++] = pReq->Size - 1;
  538. memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
  539. PayLoadLen += pReq->Size;
  540. PayLoadLen--;
  541. PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
  542. ComputeAuthCode (pSessionInfo->Password, pSessionHdr,
  543. ( IPMIMsgHdr_T*) &pPayLoad [AUTH_CODE_LEN+1],
  544. pPayLoad, MULTI_SESSION_CHANNEL);
  545. }
  546. else
  547. {
  548. pPayLoad [PayLoadLen++] = pReq->Size - 1;
  549. /* Fill the ipmi message */
  550. memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
  551. PayLoadLen += pReq->Size;
  552. PayLoadLen--;
  553. PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
  554. }
  555. }
  556. ResPkt.Size = PayLoadLen;
  557. if(pSessionInfo->Activated)
  558. {
  559. /* Sent the response packet */
  560. SendLANPkt (&ResPkt);
  561. }
  562. return;
  563. }
  564. // /**
  565. // * @fn LANTimer
  566. // * @brief This function handles the time out for lan connections.
  567. // * @param None
  568. // **/
  569. // static
  570. // void* LANTimer (void *pArg)
  571. // {
  572. // int *inst = (int*)pArg;
  573. // int BMCInst= *inst;
  574. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  575. // while (1)
  576. // {
  577. // UpdateTimeout (BMCInst);
  578. // sleep (LAN_TIMER_INTERVAL);
  579. // }
  580. // return 0;
  581. // }
  582. static int SetIPv4Header(int socketID)
  583. {
  584. uint8_t flag = 0;
  585. uint8_t TimeToLive = 64;
  586. //uint8_t TypeOfService = 0;
  587. if (setsockopt(socketID, IPPROTO_IP, IP_TTL,
  588. &TimeToLive, sizeof(uint8_t)) == -1)
  589. {
  590. printf("LANIfc.c: Setsockopt(IP_TTL) Failed for UDP socket:");
  591. return -1;
  592. }
  593. flag = 0; /* Never send DF frames. */
  594. if (setsockopt(socketID, IPPROTO_IP, IP_MTU_DISCOVER,
  595. &(flag), sizeof(uint8_t)) == -1)
  596. {
  597. printf("LANIfc.c: Setsockopt(IP_MTU_DISCOVER) Failed for UDP socket\n");
  598. return -1;
  599. }
  600. // if (setsockopt(socketID, IPPROTO_IP, IP_TOS,
  601. // &(pBMCInfo->LANCfs[ethIndex].Ipv4HdrParam.TypeOfService), sizeof(INT8U)) == -1)
  602. // {
  603. // printf("LANIfc.c: Setsockopt(IP_TOS) Failed for UDP socket\n");
  604. // return -1;
  605. // }
  606. return 0;
  607. }