LANIfc.c 20 KB

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