LANIfc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. //绑定网卡
  190. //strcpy(UDPIfcName,"eth0");
  191. // if (0 != setsockopt (gSocket_LAN, SOL_SOCKET,SO_BINDTODEVICE, UDPIfcName, sizeof (UDPIfcName)+1))
  192. // {
  193. // printf("LANIfc.c: SetSockOpt(SO_BINDTODEVICE) Failed for UDP Socket\n");
  194. // return -1;
  195. // }
  196. if (0 != setsockopt(gSocket_LAN, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)))
  197. {
  198. printf("LANIfc.c: Setsockopt(SO_REUSEADDR) Failed for UDP socket\n");
  199. }
  200. SetIPv4Header(gSocket_LAN);
  201. /* Bind */
  202. if (-1 == bind(gSocket_LAN,(struct sockaddr *)&local,sizeof(local)))
  203. {
  204. printf("LANIfc.c : Error binding UDP Socket, %d, %s\n", errno, strerror(errno));
  205. return -1;
  206. }
  207. //printf("Create UDP socket successfully, socket %d, port: %d\n", gSocket_LAN, local.sin_port);
  208. return 0;
  209. }
  210. /**
  211. * @fn ReadData
  212. * @brief This function receives the IPMI LAN request packets
  213. *
  214. * @param pMsgPkt - pointer to message packet
  215. * @param Socket - Socket handle
  216. **/
  217. static
  218. int ReadData (MsgPkt_T *pMsgPkt, int Socket )
  219. {
  220. unsigned int SourceLen = 0,Index,SocktIndex=0,addrlen=0;
  221. int Channel = 0;
  222. uint8_t *pData = pMsgPkt->Data;
  223. int16_t Len = 0;
  224. uint16_t RecvdLen = 0;
  225. uint16_t IPMIMsgLen = 0;
  226. uint16_t IPMIMsgOffset = 0;
  227. struct sockaddr_in Sourcev4;
  228. struct sockaddr_in server_v4addr;
  229. void *Source = NULL ;
  230. void *server_addr = NULL ;
  231. uint8_t WaitCount;
  232. int i;
  233. Source = &Sourcev4;
  234. SourceLen = sizeof (Sourcev4);
  235. //printf("ReadData:\n");
  236. //SourceLen = sizeof (Source);
  237. /* Read minimum bytes to find class of message */
  238. while (RecvdLen < RMCP_CLASS_MSG_OFFSET)
  239. {
  240. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
  241. // printf("Recv1 %d: ", Len);
  242. // for(i=0;i<Len;i++)
  243. // printf("%#x ", pData[RecvdLen+i]);
  244. // printf("\n");
  245. if ((Len >= -1) && (Len <= 0))
  246. {
  247. return -1;
  248. }
  249. RecvdLen += (uint16_t)Len;
  250. }
  251. /* if RMCP Presence Ping Requested */
  252. if (RMCP_CLASS_MSG_ASF == pData[RMCP_CLASS_MSG_OFFSET])
  253. {
  254. /* Read remaining RMCP ASF ping message */
  255. while (RecvdLen < RMCP_ASF_PING_MESSAGE_LENGTH)
  256. {
  257. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0, (struct sockaddr *)Source, &SourceLen);
  258. // printf("Recv2 %d: ", Len);
  259. // for(i=0;i<Len;i++)
  260. // printf("%#x ", pData[RecvdLen+i]);
  261. // printf("\n");
  262. if ((Len >= -1) && (Len <= 0))
  263. {
  264. return -1;
  265. }
  266. RecvdLen += (uint16_t)Len;
  267. }
  268. }
  269. /*else if IPMI RMCP request */
  270. else if (RMCP_CLASS_MSG_IPMI == pData[RMCP_CLASS_MSG_OFFSET])
  271. {
  272. /* Read minimum no of bytes for IPMI Auth type offset*/
  273. while (RecvdLen < IPMI_MSG_AUTH_TYPE_OFFSET)
  274. {
  275. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  276. // printf("Recv3 %d: ", Len);
  277. // for(i=0;i<Len;i++)
  278. // printf("%#x ", pData[RecvdLen+i]);
  279. // printf("\n");
  280. if ((Len >= -1) && (Len <= 0))
  281. {
  282. return -1;
  283. }
  284. RecvdLen += (uint16_t)Len;
  285. }
  286. /* Get the IPMI message length offset based on format/authentication type */
  287. if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
  288. {
  289. IPMIMsgOffset = IPMI20_MSG_LEN_OFFSET + 1;
  290. }
  291. else if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == AUTH_TYPE_NONE)
  292. {
  293. IPMIMsgOffset = IPMI_MSG_LEN_OFFSET;
  294. }
  295. else
  296. {
  297. IPMIMsgOffset = IPMI_MSG_LEN_OFFSET + AUTH_CODE_LEN;
  298. }
  299. /* Read minimum no of bytes for IPMI message length offset*/
  300. while (RecvdLen < IPMIMsgOffset)
  301. {
  302. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  303. // printf("Recv4 %d: ", Len);
  304. // for(i=0;i<Len;i++)
  305. // printf("%#x ", pData[RecvdLen+i]);
  306. // printf("\n");
  307. if ((Len >= -1) && (Len <= 0))
  308. {
  309. return -1;
  310. }
  311. RecvdLen += (uint16_t)Len;
  312. }
  313. /* Get the IPMI message length based on RMCP format type */
  314. if (pData [IPMI_MSG_AUTH_TYPE_OFFSET] == RMCP_PLUS_FORMAT)
  315. {
  316. IPMIMsgLen = *((uint16_t*)&pData [IPMI20_MSG_LEN_OFFSET]);
  317. }
  318. else
  319. {
  320. IPMIMsgLen = pData [IPMIMsgOffset];
  321. }
  322. /* We are assuming that we cannot get more than 17 K data in IPMI Msg */
  323. /* This work around for fix the malformed IPMI Msg length */
  324. if(IPMIMsgOffset > MAX_POSSIBLE_IPMI_DATA_SIZE )
  325. {
  326. return -1;
  327. }
  328. /* Read the remaining IPMI message packets */
  329. WaitCount = 3;
  330. while (RecvdLen < IPMIMsgLen)
  331. {
  332. Len = recvfrom (Socket, &pData[RecvdLen], MAX_LAN_BUFFER_SIZE, 0,(struct sockaddr *)Source, &SourceLen);
  333. // printf("Recv5 %d: ", Len);
  334. // for(i=0;i<Len;i++)
  335. // printf("%#x ", pData[RecvdLen+i]);
  336. // printf("\n");
  337. if ((Len >= -1) && (Len <= 0))
  338. {
  339. if(Len == -1)
  340. {
  341. if(errno == EAGAIN)
  342. {
  343. WaitCount--;
  344. }
  345. else
  346. return -1;
  347. }
  348. else
  349. return -1;
  350. }
  351. if(WaitCount == 0)
  352. {
  353. return -1;
  354. }
  355. RecvdLen += (uint16_t)Len;
  356. }
  357. }/* else other RMCP class are not supported. */
  358. else
  359. {
  360. printf ("Unknown RMCP class\n");
  361. }
  362. pMsgPkt->Size = RecvdLen;
  363. pMsgPkt->UDPPort = ((struct sockaddr_in *)Source)->sin_port;
  364. pMsgPkt->Socket = Socket;
  365. pMsgPkt->Channel = LAN_RMCP_CHANNEL;
  366. // printf("\nLan received %d: ",RecvdLen);
  367. // for(i=0;i<RecvdLen;i++)
  368. // {
  369. // printf("%#x ", pData[i]);
  370. // }
  371. // printf("\n");
  372. if(SourceLen!=0)
  373. {
  374. memcpy (pMsgPkt->IPAddr, &((struct sockaddr_in *)Source)->sin_addr.s_addr, sizeof (struct in_addr));
  375. }
  376. pMsgPkt->Param = LAN_SMB_REQUEST;
  377. return 0;
  378. }
  379. void *RecvLANPkt(void *pArg)
  380. {
  381. MsgPkt_T MsgPkt;
  382. struct timeval Timeout;
  383. struct sockaddr_in local;
  384. int RetVal,max,Index = 0;
  385. unsigned int locallen;
  386. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  387. fd_set fds;
  388. memset(&local,0,sizeof(local));
  389. locallen=sizeof(local);
  390. printf("RecvLANPkt start...\n");
  391. while(1)
  392. {
  393. Timeout.tv_sec = SESSION_TIMEOUT;
  394. Timeout.tv_usec = 0;
  395. FD_ZERO(&fds);
  396. if(gSocket_LAN != -1)
  397. FD_SET(gSocket_LAN,&fds);
  398. max = gSocket_LAN+1;
  399. /*Waits for an event to occur on socket*/
  400. RetVal = select (max, &fds, NULL, NULL, &Timeout);
  401. if (-1 == RetVal)
  402. {
  403. continue;
  404. }
  405. if (0 == RetVal)
  406. {
  407. /* Its due to timeout - continue */
  408. continue;
  409. }
  410. /*Accepting Connection*/
  411. if(FD_ISSET(gSocket_LAN,&fds))
  412. {
  413. if(0 == ReadData( &MsgPkt,gSocket_LAN))
  414. {
  415. //printf("---> Lan rcv: %d.%d.%d.%d:%d\n", MsgPkt.IPAddr[0],MsgPkt.IPAddr[1],MsgPkt.IPAddr[2],MsgPkt.IPAddr[3],MsgPkt.UDPPort);
  416. /* Post the request packet to LAN Interface Queue */
  417. if (0 != PostMsg (gFd_LanIfcQ, &MsgPkt))
  418. {
  419. printf ("Warning: LANIfc.c Error posting message to LANIfc Q\n");
  420. }
  421. }
  422. else
  423. {
  424. close(gSocket_LAN);
  425. gSocket_LAN = -1;
  426. }
  427. }
  428. }
  429. }
  430. /**
  431. * @fn SendLANPkt
  432. * @brief This function sends the IPMI LAN Response to the requester
  433. * @param pRes - Response message.
  434. **/
  435. int SendLANPkt (MsgPkt_T *pRes )
  436. {
  437. struct sockaddr_in Dest;
  438. //struct stat Stat;
  439. int ret = 0;
  440. /* Set the destination UDP port and IP Address */
  441. Dest.sin_family = AF_INET;
  442. Dest.sin_port = pRes->UDPPort;
  443. memcpy (&Dest.sin_addr.s_addr, pRes->IPAddr, sizeof (struct in_addr));
  444. /* Send the LAN response packet */
  445. //int i;
  446. //printf("\nLan send socket: %d, byte: %d: ", pRes->Socket, pRes->Size);
  447. // for (i = 0; i < pRes->Size; ++i)
  448. // {
  449. // printf("%#x ", pRes->Data[i]);
  450. // }
  451. //printf("\n");
  452. //Check the socket before send a message on a socket
  453. //if (fstat(pRes->Socket, &Stat) != -1)
  454. {
  455. //printf("---> Lan sendto %d:%d\n", Dest.sin_addr.s_addr,Dest.sin_port);
  456. ret = sendto (pRes->Socket, pRes->Data, pRes->Size, 0, (struct sockaddr*)&Dest, sizeof (Dest));
  457. if (ret == -1)
  458. {
  459. printf ("Warning: LANIfc.c Error sending response packets to LAN, %s\n",strerror(errno));
  460. }
  461. // else
  462. // {
  463. // printf ("LANIfc.c : LAN packet sent successfully\n");
  464. // }
  465. }
  466. return 1;
  467. }
  468. /**
  469. * @brief Process SMB Request.
  470. * @param pReq - Request message.
  471. **/
  472. static void
  473. ProcessLANReq ( MsgPkt_T* pReq )
  474. {
  475. MsgPkt_T Res;
  476. SessionInfo_T* pSessionInfo;
  477. SessionHdr_T* pSessionHdr;
  478. SessionHdr2_T* pSessionHdr2;
  479. uint32_t SessionID =0;
  480. /* Copy the request to response */
  481. Res = *pReq;
  482. /* Save the LAN header inofmation */
  483. pSessionHdr = (SessionHdr_T*) (((RMCPHdr_T*)pReq->Data) + 1);
  484. pSessionHdr2 = (SessionHdr2_T*)(((RMCPHdr_T*)pReq->Data) + 1);
  485. if (RMCP_PLUS_FORMAT == pSessionHdr->AuthType)
  486. {
  487. SessionID = pSessionHdr2->SessionID;
  488. pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID);
  489. }
  490. else
  491. {
  492. SessionID = pSessionHdr->SessionID;
  493. pSessionInfo = getSessionInfo (SESSION_ID_INFO, &SessionID );
  494. }
  495. if (NULL != pSessionInfo)
  496. {
  497. pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort = Res.UDPPort;
  498. pSessionInfo->hSocket = Res.Socket;
  499. //SocktIndex=GetSocketInfoIndex(pSessionInfo->hSocket );
  500. memcpy (pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, Res.IPAddr, sizeof (struct in_addr));
  501. memcpy (&pSessionInfo->LANRMCPPkt.RMCPHdr, Res.Data, sizeof (RMCPHdr_T));
  502. }
  503. /* Process the RMCP Request */
  504. Res.Size = ProcessRMCPReq ((RMCPHdr_T*)pReq->Data, (RMCPHdr_T*)Res.Data);
  505. /* ResLen is 0, don't send the packet */
  506. if (0 == Res.Size )
  507. {
  508. printf ("Note: LANIfc.c LAN request packet dropped, not processed\n");
  509. return;
  510. }
  511. /* Sent the response packet */
  512. SendLANPkt (&Res);
  513. return;
  514. }
  515. /*--------------------------------------------
  516. * ProcessBridgeMsg
  517. *--------------------------------------------*/
  518. static void
  519. ProcessBridgeMsg ( MsgPkt_T* pReq )
  520. {
  521. MsgPkt_T ResPkt;
  522. uint16_t PayLoadLen = 0;
  523. uint8_t PayLoadType = 0;
  524. SessionInfo_T *pSessionInfo = getSessionInfo (SESSION_HANDLE_INFO, pReq->Data);
  525. //printf ("LANIfc: Bridge Request\n");
  526. if (NULL == pSessionInfo)
  527. {
  528. printf ("Warning: LANIfc ProcessBridgeMsg - No Session with the LAN\n");
  529. return;
  530. }
  531. /* Copy Lan RMCP headers from Session Record */
  532. ResPkt.UDPPort = pSessionInfo->LANRMCPPkt.UDPHdr.SrcPort;
  533. ResPkt.Socket = pSessionInfo->hSocket;
  534. memcpy (ResPkt.IPAddr, pSessionInfo->LANRMCPPkt.IPHdr.Srcv4Addr, sizeof (struct in_addr));
  535. memcpy (ResPkt.Data, &pSessionInfo->LANRMCPPkt.RMCPHdr, sizeof (RMCPHdr_T));
  536. // #if IPMI20_SUPPORT == 1
  537. // if (RMCP_PLUS_FORMAT == pSessionInfo->AuthType)
  538. // {
  539. // /* Fill Session Header */
  540. // pSessionInfo->OutboundSeq++;
  541. // PayLoadLen = pReq->Size - 1;
  542. // PayLoadType = pReq->Cmd;
  543. // PayLoadType |= (pSessionInfo->SessPyldInfo[PayLoadType].AuxConfig[0] & 0xC0);
  544. // PayLoadLen = Frame20Payload (PayLoadType, ( RMCPHdr_T*)&ResPkt.Data [0],
  545. // &pReq->Data[1], PayLoadLen, pSessionInfo );
  546. // }
  547. // else
  548. // #endif /*IPMI20_SUPPORT == 1*/
  549. {
  550. /* Fill Session Header */
  551. SessionHdr_T* pSessionHdr = ( SessionHdr_T*)(&ResPkt.Data [sizeof(RMCPHdr_T)]);
  552. uint8_t* pPayLoad = ( uint8_t*)(pSessionHdr + 1);
  553. pSessionHdr->AuthType = pSessionInfo->AuthType;
  554. pSessionHdr->SessionSeqNum = pSessionInfo->OutboundSeq++;
  555. pSessionHdr->SessionID = pSessionInfo->SessionID;
  556. /* If AuthType is not 0 - Compute AuthCode */
  557. if (0 != pSessionInfo->AuthType)
  558. {
  559. PayLoadLen = AUTH_CODE_LEN;
  560. pPayLoad [PayLoadLen++] = pReq->Size - 1;
  561. memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
  562. PayLoadLen += pReq->Size;
  563. PayLoadLen--;
  564. PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
  565. ComputeAuthCode (pSessionInfo->Password, pSessionHdr,
  566. ( IPMIMsgHdr_T*) &pPayLoad [AUTH_CODE_LEN+1],
  567. pPayLoad, MULTI_SESSION_CHANNEL);
  568. }
  569. else
  570. {
  571. pPayLoad [PayLoadLen++] = pReq->Size - 1;
  572. /* Fill the ipmi message */
  573. memcpy (&pPayLoad [PayLoadLen], (pReq->Data + 1), (pReq->Size - 1));
  574. PayLoadLen += pReq->Size;
  575. PayLoadLen--;
  576. PayLoadLen += sizeof (SessionHdr_T) + sizeof (RMCPHdr_T);
  577. }
  578. }
  579. ResPkt.Size = PayLoadLen;
  580. if(pSessionInfo->Activated)
  581. {
  582. /* Sent the response packet */
  583. SendLANPkt (&ResPkt);
  584. }
  585. return;
  586. }
  587. // /**
  588. // * @fn LANTimer
  589. // * @brief This function handles the time out for lan connections.
  590. // * @param None
  591. // **/
  592. // static
  593. // void* LANTimer (void *pArg)
  594. // {
  595. // int *inst = (int*)pArg;
  596. // int BMCInst= *inst;
  597. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  598. // while (1)
  599. // {
  600. // UpdateTimeout (BMCInst);
  601. // sleep (LAN_TIMER_INTERVAL);
  602. // }
  603. // return 0;
  604. // }
  605. static int SetIPv4Header(int socketID)
  606. {
  607. uint8_t flag = 0;
  608. uint8_t TimeToLive = 64;
  609. //uint8_t TypeOfService = 0;
  610. if (setsockopt(socketID, IPPROTO_IP, IP_TTL,
  611. &TimeToLive, sizeof(uint8_t)) == -1)
  612. {
  613. printf("LANIfc.c: Setsockopt(IP_TTL) Failed for UDP socket:");
  614. return -1;
  615. }
  616. flag = 0; /* Never send DF frames. */
  617. if (setsockopt(socketID, IPPROTO_IP, IP_MTU_DISCOVER,
  618. &(flag), sizeof(uint8_t)) == -1)
  619. {
  620. printf("LANIfc.c: Setsockopt(IP_MTU_DISCOVER) Failed for UDP socket\n");
  621. return -1;
  622. }
  623. // if (setsockopt(socketID, IPPROTO_IP, IP_TOS,
  624. // &(pBMCInfo->LANCfs[ethIndex].Ipv4HdrParam.TypeOfService), sizeof(INT8U)) == -1)
  625. // {
  626. // printf("LANIfc.c: Setsockopt(IP_TOS) Failed for UDP socket\n");
  627. // return -1;
  628. // }
  629. return 0;
  630. }