LANConfig.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. //#include <linux/if.h>
  4. #include <linux/ip.h>
  5. //#include <dlfcn.h>
  6. #include <sys/prctl.h>
  7. //#include "nwcfg.h"
  8. #include "Util.h"
  9. #include "main.h"
  10. #include "Api.h"
  11. #include "Util.h"
  12. #include "com_IPMI_LANConfig.h"
  13. #include "com_IPMI_DeviceConfig.h"
  14. #include <string.h>
  15. /* Reserved bit macro definitions */
  16. #define RESERVED_BITS_SUSPENDBMCARPS 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  17. #define RESERVED_BITS_GETIPUDPRMCPSTATS_CH 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  18. #define RESERVED_BITS_GETIPUDPRMCPSTATS_CLRSTATE 0xFE //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1)
  19. /*** Local definitions ***/
  20. #define CHANNEL_ID_MASK 0x0f
  21. #define SET_IN_PROGRESS_MASK 0x03
  22. #define PARAMETER_REVISION_MASK 0x0f
  23. #define DEST_ADDR_DATA2_ADDR_FORMAT_MASK 0xf0
  24. #define PARAMETER_REVISION_FORMAT 0x11
  25. #define GET_PARAMETER_REVISION_MASK 0x80
  26. #define LAN_CALLBACK_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
  27. #define LAN_USER_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
  28. #define LAN_OPERATOR_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
  29. #define LAN_ADMIN_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
  30. #define BRD_CAST_BIT_MASK 0xFF
  31. #define LOOP_BACK_BIT_MASK 0x7F
  32. #define SUBNET_MASK_BIT_CHECK 0x80
  33. #define LAN_CONFIGURATION_SET_IN_PROGRESS 0x01
  34. #define LAN_CONFIGURATION_SET_COMPLETE 0x00
  35. #define GRATIUTOUS_ENABLE_MASK 1
  36. #define ENABLE_ARP_RESPONSES 2
  37. #define SUSPEND_ARP_RSVD_BIT_MASK 0xFC
  38. #define ENABLE_ARPS 0x03
  39. #define SUSPEND_GRAT_ARP 0x01
  40. #define SUSPEND_ARP 0x02
  41. #define ARP_IGNORE_ON 8
  42. #define ARP_IGNORE_OFF 0
  43. /* Reserved Bits */
  44. #define RESERVED_VALUE_70 0x70
  45. #define RESERVED_VALUE_F0 0xF0
  46. // /**
  47. // *@fn NwInterfacePresenceCheck
  48. // *@brief This function is invoked to check network interface presence
  49. // *@param Interface - Char Pointer to buffer for which interface to check
  50. // */
  51. // static int NwInterfacePresenceCheck (char * Interface);
  52. // /*** Module Variables ***/
  53. // // uint8_t m_ArpSuspendReq;
  54. // char **explode(char separator, char *string);
  55. // int IPAddrCheck(uint8_t *Addr,int params);
  56. // extern int GetLanAMIParamValue (uint8_t* ParamSelect, uint8_t* ImpType);
  57. // extern IfcName_T Ifcnametable[MAX_LAN_CHANNELS];
  58. #define MAX_LAN_PARAMS_DATA 20
  59. typedef struct
  60. {
  61. uint8_t Params;
  62. uint8_t ReservedBits [MAX_LAN_PARAMS_DATA];
  63. uint8_t DataLen;
  64. } LANCfgRsvdBits_T;
  65. static LANCfgRsvdBits_T m_RsvdBitsCheck [] = {
  66. /* Param Reserved Bits Data Size */
  67. { 0, { 0xFC }, 0x1 }, /* Set In progress */
  68. { 1, { 0xC8 }, 0x1 }, /* Authenication type */
  69. { 2, { 0xC8,0xC8,0xC8,0xC8,0xC8 }, 0x5}, /* Authenication Support Enable */
  70. { 4, { 0xF0 }, 0x1 }, /* l */
  71. { 7, { 0x0,0x1F,0x01 }, 0x3 }, /* l */
  72. { 0xA, { 0xFC }, 0x1 }, /* l */
  73. { 0x11, { 0xF0 }, 0x1 }, /* l */
  74. { 0x12, { 0xF0,0x78,0x0,0xF8 }, 0x4 },
  75. { 0x13, { 0xF0,0x0F, 0xFE }, 0x3 },
  76. { 0x14, { 0x0,0x70}, 0x2 },
  77. { 0x15, { 0xF8 }, 0x1 },
  78. { 0x16, { 0xE0 }, 0x1 },
  79. { 0x17, { 0xFF }, 0x1 },
  80. { 0x18, { 0xFF }, 0x1 },
  81. { 0x19, { 0xF0,0x0F }, 0x2 },
  82. { 0x1A, { 0xFE }, 0x1 }
  83. };
  84. typedef struct
  85. {
  86. uint8_t OEMParam;
  87. uint8_t Length;
  88. }OEMParameterLength_T;
  89. static OEMParameterLength_T m_OEMParamLen [] = {
  90. // {LAN_PARAMS_AMI_OEM_IPV6_ENABLE, 1 },
  91. // {LAN_PARAMS_AMI_OEM_IPV6_IP_ADDR_SOURCE, 1 },
  92. // {LAN_PARAMS_AMI_OEM_IPV6_IP_ADDR, 17 },
  93. // {LAN_PARAMS_AMI_OEM_IPV6_PREFIX_LENGTH, 2},
  94. // {LAN_PARAMS_AMI_OEM_IPV6_GATEWAY_IP, 16}
  95. };
  96. /**
  97. * @brief LAN configuration request parameter lengths
  98. **/
  99. static const uint8_t LanconfigParameterLength [] = {
  100. 1, /* Set in progress */
  101. 1, /* Authentication type support */
  102. 5, /* Authentication type enables */
  103. 4, /* IP address */
  104. 1, /* IP address source */
  105. 6, /* MAC address */
  106. 4, /* Subnet mask */
  107. 3, /* IPv4 header parameters */
  108. 2, /* Primary RMCP port number */
  109. 2, /* Secondary RMCP port number */
  110. 1, /* BMC generated ARP control */
  111. 1, /* Gratuitous ARP */
  112. 4, /* Default Gateway address */
  113. 6, /* Default Gateway MAC address */
  114. 4, /* Backup Gateway address */
  115. 6, /* Backup Gateway MAC address */
  116. 18, /* Community string */
  117. 1, /* Number of destinations */
  118. 4, /* Destination type */
  119. 13, /* Destination address */
  120. 2, /* VLAN ID */
  121. 1, /* VLAN Priority */
  122. 1, /* Cipher suite entry support */
  123. 17, /* Cipher suite entries */
  124. 9, /* Cipher suite Privilege levels */
  125. 4, /* VLAN tags destination address */
  126. 6, /* Bad Password Threshold */
  127. (9+16) /* IPv6 Destination address */
  128. };
  129. /* A copy of ip_tos2prio with numeric format in "linux/net/ipv4/route.c" */
  130. static const uint8_t IP_TOS2PRIO[16] = {
  131. 0, /* TC_PRIO_BESTEFFORT, */
  132. 1, /* ECN_OR_COST(FILLER), */
  133. 0, /* TC_PRIO_BESTEFFORT, */
  134. 0, /* ECN_OR_COST(BESTEFFORT), */
  135. 2, /* TC_PRIO_BULK, */
  136. 2, /* ECN_OR_COST(BULK), */
  137. 2, /* TC_PRIO_BULK, */
  138. 2, /* ECN_OR_COST(BULK), */
  139. 6, /* TC_PRIO_INTERACTIVE, */
  140. 6, /* ECN_OR_COST(INTERACTIVE), */
  141. 6, /* TC_PRIO_INTERACTIVE, */
  142. 6, /* ECN_OR_COST(INTERACTIVE), */
  143. 4, /* TC_PRIO_INTERACTIVE_BULK, */
  144. 4, /* ECN_OR_COST(INTERACTIVE_BULK),*/
  145. 4, /* TC_PRIO_INTERACTIVE_BULK, */
  146. 4 /* ECN_OR_COST(INTERACTIVE_BULK) */
  147. };
  148. static uint8_t enableSetMACAddr = TRUE; //jimbo notice
  149. /*-------------------------------------------------------
  150. * SetLanConfigParam
  151. *-------------------------------------------------------*/
  152. int
  153. SetLanConfigParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  154. {
  155. SetLanConfigReq_T* pSetLanReq = ( SetLanConfigReq_T*) pReq;
  156. SetLanConfigRes_T* pSetLanRes = ( SetLanConfigRes_T*) pRes;
  157. MsgPkt_T m_MsgPkt;
  158. int i,j=0;
  159. uint8_t index;
  160. int retValue=0,NIC_Count = 0;
  161. // uint16_t PriorityLevel[MAX_LAN_CHANNELS]= {0};
  162. uint8_t m_Lan_SetInProgress; /**< Contains setting LAN configuration status */
  163. uint8_t InvalidMac[MAC_ADDR_LEN] = {0,0,0,0,0,0};
  164. char old_mac[18];
  165. char macStr[18] = {0};
  166. char old_ip[16];
  167. char ipStr[16] = {0};
  168. char old_netmask[18];
  169. char netmaskStr[18] = {0};
  170. if ( ReqLen >= 2 )
  171. {
  172. ReqLen -= 2;
  173. }
  174. else
  175. {
  176. *pRes = CC_REQ_INV_LEN;
  177. return 1;
  178. }
  179. //自定义
  180. // if((pSetLanReq->ParameterSelect >= MIN_LAN_OEM_CONF_PARAM) &&
  181. // (pSetLanReq->ParameterSelect <= MAX_LAN_OEM_CONF_PARAM) )
  182. // {
  183. // /* Converts OEM parameter value to equivalent AMI parameter value */
  184. // if (0 != GetLanAMIParamValue (&pSetLanReq->ParameterSelect, &IsOemDefined) )
  185. // {
  186. // pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
  187. // return sizeof(uint8_t);
  188. // }
  189. // /* Hook for OEM to handle this parameter */
  190. // if ( (IsOemDefined) && (g_PDKHandle[PDK_SETLANOEMPARAM] != NULL) )
  191. // {
  192. // return ((int(*)(uint8_t *, uint8_t, uint8_t *,int))(g_PDKHandle[PDK_SETLANOEMPARAM]))(pReq, ReqLen, pRes, BMCInst);
  193. // }
  194. // }
  195. if(0x1b >pSetLanReq->ParameterSelect ) //Max known Lan paramter
  196. {
  197. if (ReqLen != LanconfigParameterLength [pSetLanReq->ParameterSelect ])
  198. {
  199. *pRes = CC_REQ_INV_LEN;
  200. return sizeof (uint8_t);
  201. }
  202. }
  203. // /*Check the Request length for OEM parameter*/
  204. // for(i=0;i<sizeof(m_OEMParamLen)/sizeof(OEMParameterLength_T);i++)
  205. // {
  206. // if(m_OEMParamLen[i].OEMParam == pSetLanReq->ParameterSelect)
  207. // {
  208. // if(ReqLen != m_OEMParamLen[i].Length)
  209. // {
  210. // *pRes = CC_REQ_INV_LEN;
  211. // return sizeof(uint8_t);
  212. // }
  213. // }
  214. // }
  215. if(pSetLanReq->ChannelNum & RESERVED_VALUE_F0)
  216. {
  217. /* Alarm !!! Somebody is trying to set Reseved Bits */
  218. *pRes = CC_INV_DATA_FIELD;
  219. return sizeof (*pRes);
  220. }
  221. if(pSetLanReq->ChannelNum == LAN_RMCP_CHANNEL)
  222. index = 0;
  223. else
  224. {
  225. *pRes = CC_INV_DATA_FIELD;
  226. return sizeof (*pRes);
  227. }
  228. /* Check for Reserved Bits */
  229. for (i = 0; i < sizeof (m_RsvdBitsCheck)/ sizeof (m_RsvdBitsCheck[0]); i++)
  230. {
  231. /* Check if this Parameter Selector needs Reserved bit checking !! */
  232. if (m_RsvdBitsCheck[i].Params == pSetLanReq->ParameterSelect)
  233. {
  234. //IPMI_DBG_PRINT_2 ("Param - %x, DataLen - %x\n", pSetLanReq->ParameterSelect, m_RsvdBitsCheck[i].DataLen);
  235. for (j = 0; j < m_RsvdBitsCheck[i].DataLen; j++)
  236. {
  237. // IPMI_DBG_PRINT_2 ("Cmp %x, %x\n", pReq[2+j], m_RsvdBitsCheck[i].ReservedBits[j]);
  238. if ( 0 != (pReq[2+j] & m_RsvdBitsCheck[i].ReservedBits[j]))
  239. {
  240. /* Alarm !!! Somebody is trying to set Reseved Bits */
  241. *pRes = CC_INV_DATA_FIELD;
  242. return sizeof (*pRes);
  243. }
  244. }
  245. }
  246. }
  247. // ptrChannelInfo = getChannelInfo (pSetLanReq->ChannelNum & 0x0F, BMCInst);
  248. // if(NULL == ptrChannelInfo)
  249. // {
  250. // *pRes = CC_INV_DATA_FIELD;
  251. // return sizeof(*pRes);
  252. // }
  253. printf ("Parameter = %X\n", pSetLanReq->ParameterSelect);
  254. switch (pSetLanReq->ParameterSelect)
  255. {
  256. case LAN_PARAM_SET_IN_PROGRESS:
  257. m_Lan_SetInProgress = g_BMCInfo.m_Lan_SetInProgress;
  258. /* Commit Write is optional and supported
  259. * only if rollback is supported */
  260. if ( (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) !=
  261. LAN_CONFIGURATION_SET_COMPLETE) &&
  262. (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) !=
  263. LAN_CONFIGURATION_SET_IN_PROGRESS) )
  264. {
  265. pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
  266. return sizeof(*pSetLanRes);
  267. }
  268. else if ((GetBits(m_Lan_SetInProgress, SET_IN_PROGRESS_MASK) ==
  269. LAN_CONFIGURATION_SET_IN_PROGRESS) &&
  270. (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) ==
  271. LAN_CONFIGURATION_SET_IN_PROGRESS))
  272. {
  273. pSetLanRes->CompletionCode = CC_SET_IN_PROGRESS;
  274. return sizeof(*pSetLanRes);
  275. }
  276. g_BMCInfo.m_Lan_SetInProgress = pSetLanReq->ConfigData.SetInProgress;
  277. break;
  278. case LAN_PARAM_AUTH_TYPE_SUPPORT:
  279. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  280. return sizeof(*pRes);
  281. case LAN_PARAM_AUTH_TYPE_ENABLES:
  282. printf("---> Not implement!\n");
  283. // for(i=0;i<5;i++)
  284. // {
  285. // /* Check for Unsupported AuthType */
  286. // if (pBMCInfo->LANCfs[EthIndex].AuthTypeSupport != (pBMCInfo->LANCfs[EthIndex].AuthTypeSupport |pReq[2+i]))
  287. // {
  288. // IPMI_DBG_PRINT_2("\n Alarm !!! Somebody is trying to Unsupported Bit :%d \t%d\n",pReq[2+i],i);
  289. // *pRes = CC_INV_DATA_FIELD;
  290. // return sizeof (*pRes);
  291. // }
  292. // }
  293. // LOCK_BMC_SHARED_MEM(BMCInst);
  294. // _fmemcpy (&pBMCInfo->LANCfs[EthIndex].AuthTypeEnables,
  295. // &(pSetLanReq->ConfigData.AuthTypeEnables), sizeof(AuthTypeEnables_T));
  296. // _fmemcpy (ptrChannelInfo->AuthType,
  297. // &(pSetLanReq->ConfigData.AuthTypeEnables), sizeof(AuthTypeEnables_T));
  298. // UNLOCK_BMC_SHARED_MEM(BMCInst);
  299. break;
  300. case LAN_PARAM_IP_ADDRESS: //post cmd to chassisTimerTask
  301. if(IPAddrCheck(pSetLanReq->ConfigData.IPAddr,LAN_PARAM_IP_ADDRESS))
  302. {
  303. *pRes = CC_INV_DATA_FIELD;
  304. return sizeof (uint8_t);
  305. }
  306. getip(old_ip);
  307. sprintf(ipStr, "%d.%d.%d.%d", pSetLanReq->ConfigData.IPAddr[0],
  308. pSetLanReq->ConfigData.IPAddr[1], pSetLanReq->ConfigData.IPAddr[2],
  309. pSetLanReq->ConfigData.IPAddr[3]);
  310. if(strcmp(ipStr, old_ip) == 0)
  311. {
  312. printf("The same ip %s, do nothing\n", ipStr );
  313. *pRes = CC_NORMAL;
  314. return 1;
  315. }
  316. m_MsgPkt.Param = PARAM_LAN;
  317. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
  318. m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
  319. m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
  320. m_MsgPkt.Data[0] = 0;//eth0
  321. m_MsgPkt.Data[1] = 0;//掉电不保存
  322. memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
  323. PostMsg(gPendActionIfc, &m_MsgPkt);
  324. //Update
  325. memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr, pSetLanReq->ConfigData.IPAddr, 4);
  326. FlushIpmiConfig();
  327. printf("---> old_ip: %s, new_ip: %s\n", old_ip, ipStr);
  328. printf("---> send data: %#x %#x %#x %#x %#x\n", m_MsgPkt.Data[0], m_MsgPkt.Data[1]
  329. , m_MsgPkt.Data[2], m_MsgPkt.Data[3], m_MsgPkt.Data[4]);
  330. break;
  331. case LAN_PARAM_IP_ADDRESS_SOURCE:
  332. printf("---> Not implement!\n");
  333. break;
  334. case LAN_PARAM_MAC_ADDRESS:
  335. /* According to IPMI 2.0 Specification Revision 3, the MAC address can be read only parameter*/
  336. //*pRes = CC_ATTEMPT_TO_SET_RO_PARAM;
  337. //return sizeof (*pRes);
  338. if((pSetLanReq->ConfigData.MACAddr[0]& BIT0)|| (memcmp(&InvalidMac,&pSetLanReq->ConfigData.MACAddr,MAC_ADDR_LEN) == 0))
  339. {
  340. pSetLanRes->CompletionCode = CC_INV_DATA_FIELD;
  341. return 1;
  342. }
  343. getmac(old_mac);
  344. sprintf(macStr, "%02x:%02x:%02x:%02x:%02x:%02x", pSetLanReq->ConfigData.MACAddr[0],
  345. pSetLanReq->ConfigData.MACAddr[1], pSetLanReq->ConfigData.MACAddr[2],
  346. pSetLanReq->ConfigData.MACAddr[3], pSetLanReq->ConfigData.MACAddr[4],
  347. pSetLanReq->ConfigData.MACAddr[5]);
  348. if(strcmp(macStr, old_mac) == 0)
  349. {
  350. printf("The same mac %s, do nothing\n", macStr );
  351. *pRes = CC_NORMAL;
  352. return 1;
  353. }
  354. if (!enableSetMACAddr)
  355. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  356. else
  357. {
  358. m_MsgPkt.Param = PARAM_LAN;
  359. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
  360. m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
  361. m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
  362. m_MsgPkt.Data[0] = 0;//eth0
  363. m_MsgPkt.Data[1] = 0;//掉电不保存
  364. memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
  365. PostMsg(gPendActionIfc, &m_MsgPkt);
  366. //Update
  367. memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr, pSetLanReq->ConfigData.MACAddr, 6);
  368. printf("---> old_mac: %s, new_mac: %s\n", old_mac, macStr);
  369. pSetLanRes->CompletionCode = CC_NORMAL;
  370. }
  371. break;
  372. case LAN_PARAM_SUBNET_MASK:
  373. getnetmask(old_netmask);
  374. sprintf(netmaskStr, "%d.%d.%d.%d", pSetLanReq->ConfigData.SubNetMask[0],
  375. pSetLanReq->ConfigData.SubNetMask[1], pSetLanReq->ConfigData.SubNetMask[2],
  376. pSetLanReq->ConfigData.SubNetMask[3]);
  377. if(strcmp(netmaskStr, old_netmask) == 0)
  378. {
  379. printf("The same netmask %s, do nothing\n", netmaskStr );
  380. *pRes = CC_NORMAL;
  381. return 1;
  382. }
  383. if(IPAddrCheck(pSetLanReq->ConfigData.SubNetMask,LAN_PARAM_SUBNET_MASK))
  384. {
  385. *pRes = CC_INV_DATA_FIELD;
  386. return sizeof (uint8_t);
  387. }
  388. m_MsgPkt.Param = PARAM_LAN;
  389. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
  390. m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
  391. m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
  392. m_MsgPkt.Data[0] = 0;//eth0
  393. m_MsgPkt.Data[1] = 0;//掉电不保存
  394. memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
  395. PostMsg(gPendActionIfc, &m_MsgPkt);
  396. //Update
  397. memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].NetMask, pSetLanReq->ConfigData.SubNetMask, 4);
  398. pSetLanRes->CompletionCode = CC_NORMAL;
  399. break;
  400. case LAN_PARAM_IPv4_HEADER:
  401. printf("Not implement\n");
  402. break;
  403. case LAN_PARAM_PRI_RMCP_PORT:
  404. printf("Not implement\n"); //需要重启网络线程
  405. break;
  406. case LAN_PARAM_SEC_RMCP_PORT:
  407. /* Returning Invalid error message */
  408. *pRes = CC_PARAM_NOT_SUPPORTED;
  409. return sizeof (uint8_t);
  410. /*pPMConfig->LANConfig[EthIndex].SecondaryPort = ipmitoh_u16 (pSetLanReq->ConfigData.SecondaryPort);*/
  411. break;
  412. case LAN_PARAM_BMC_GENERATED_ARP_CONTROL:
  413. printf("Not implement\n");
  414. break;
  415. case LAN_PARAM_GRATITIOUS_ARP_INTERVAL:
  416. printf("Not implement\n");
  417. break;
  418. case LAN_PARAM_DEFAULT_GATEWAY_IP:
  419. if(IPAddrCheck(pSetLanReq->ConfigData.DefaultGatewayIPAddr,LAN_PARAM_DEFAULT_GATEWAY_IP))
  420. {
  421. *pRes = CC_INV_DATA_FIELD;
  422. return sizeof (uint8_t);
  423. }
  424. m_MsgPkt.Param = PARAM_LAN;
  425. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
  426. m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
  427. m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
  428. m_MsgPkt.Data[0] = 0;//eth0
  429. m_MsgPkt.Data[1] = 0;//掉电不保存
  430. memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
  431. PostMsg(gPendActionIfc, &m_MsgPkt);
  432. //Update
  433. memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].DefaultGW, pSetLanReq->ConfigData.DefaultGatewayIPAddr, 4);
  434. pSetLanRes->CompletionCode = CC_NORMAL;
  435. break;
  436. case LAN_PARAM_DEFAULT_GATEWAY_MAC:
  437. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  438. return sizeof(*pRes);
  439. break;
  440. case LAN_PARAM_BACKUP_GATEWAY_IP:
  441. printf("Not implement\n");
  442. break;
  443. case LAN_PARAM_BACKUP_GATEWAY_MAC:
  444. printf("Not implement\n");
  445. break;
  446. case LAN_PARAM_COMMUNITY_STRING:
  447. printf("Not implement\n");
  448. break;
  449. case LAN_PARAM_DEST_NUM:
  450. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  451. return sizeof(uint8_t);
  452. case LAN_PARAM_SELECT_DEST_TYPE:
  453. printf("Not implement\n");
  454. break;
  455. case LAN_PARAM_SELECT_DEST_ADDR:
  456. printf("Not implement\n");
  457. break;
  458. case LAN_PARAM_VLAN_ID:
  459. printf("Not implement\n");
  460. break;
  461. case LAN_PARAM_VLAN_PRIORITY:
  462. printf("Not implement\n");
  463. break;
  464. case LAN_PARAM_CIPHER_SUITE_ENTRY_SUP:
  465. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  466. return sizeof(uint8_t);
  467. case LAN_PARAM_CIPHER_SUITE_ENTRIES:
  468. pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  469. return sizeof(uint8_t);
  470. break;
  471. case LAN_PARAM_CIPHER_SUITE_PRIV_LEVELS:
  472. printf("Not implement\n");
  473. break;
  474. case LAN_PARAM_VLAN_TAGS:
  475. printf("Not implement\n");
  476. break;
  477. case LAN_PARAMS_BAD_PASSWORD_THRESHOLD:
  478. printf("Not implement\n");
  479. break;
  480. default:
  481. pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
  482. return sizeof(uint8_t);
  483. }
  484. pSetLanRes->CompletionCode = CC_NORMAL;
  485. FlushIpmiConfig();
  486. return sizeof(*pSetLanRes);
  487. }
  488. /*
  489. *@fn IPAddrCheck function
  490. *@brief It will validate the IP Address and net Mask
  491. *@param Addr - IP Address or net Mask
  492. *@param params - parameter data to validate
  493. */
  494. int IPAddrCheck(uint8_t *Addr,int params)
  495. {
  496. int i,maskcount=0,bitmask =0,j,bitcheck=0;
  497. for(i=0;i< IP_ADDR_LEN;i++)
  498. {
  499. if(Addr[i] == BRD_CAST_BIT_MASK)
  500. {
  501. maskcount++;
  502. }
  503. }
  504. if(maskcount == IP_ADDR_LEN)
  505. {
  506. return 1;
  507. }
  508. if(params == LAN_PARAM_SUBNET_MASK)
  509. {
  510. if(Addr[0] == BRD_CAST_BIT_MASK)
  511. {
  512. for(i=1;i< IP_ADDR_LEN;i++)
  513. {
  514. if(Addr[i-1] == 0)
  515. {
  516. bitmask = 1;
  517. }
  518. if(Addr[i] != 0)
  519. {
  520. for(j=0;j<8;j++)
  521. {
  522. if((Addr[i]<<j) & SUBNET_MASK_BIT_CHECK)
  523. {
  524. if(bitcheck == 1)
  525. {
  526. return 1;
  527. }
  528. continue;
  529. }
  530. bitcheck=1;
  531. }
  532. if((bitcheck == 1 && Addr[i-1] != BRD_CAST_BIT_MASK) || (Addr[i] > 0 && bitmask == 1))
  533. {
  534. return 1;
  535. }
  536. }
  537. }
  538. return 0;
  539. }
  540. return 1;
  541. }
  542. if(Addr[0] == LOOP_BACK_BIT_MASK || Addr[0] == BRD_CAST_BIT_MASK)
  543. {
  544. return 1;
  545. }
  546. return 0;
  547. }
  548. // /*----------------------------------------------
  549. // * GratuitousARPTask
  550. // *----------------------------------------------*/
  551. // void* GratuitousARPTask (uint8_t *Addr)
  552. // {
  553. // uint8_t IntervalInSec;
  554. // uint8_t Status;
  555. // int nRet;
  556. // NWCFG_STRUCT NWConfig;
  557. // NWCFG6_STRUCT NWConfig6;
  558. // uint8_t EthIndex,netindex= 0xFF;
  559. // int BMCInst,i;
  560. // char IfcName[16];
  561. // BMCArg *GratArpArgs = (BMCArg *)Addr;
  562. // BMCInst = GratArpArgs->BMCInst;
  563. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  564. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  565. // memcpy(&EthIndex,GratArpArgs->Argument,GratArpArgs->Len);
  566. // memset(IfcName,0,sizeof(IfcName));
  567. // /*Get the EthIndex*/
  568. // if(GetIfcName(EthIndex,IfcName, BMCInst) == -1)
  569. // {
  570. // TCRIT("Error in Getting Ifcname\n");
  571. // return 0;
  572. // }
  573. // for(i=0;i<sizeof(Ifcnametable)/sizeof(IfcName_T);i++)
  574. // {
  575. // if(strcmp(Ifcnametable[i].Ifcname,IfcName) == 0)
  576. // {
  577. // netindex= Ifcnametable[i].Index;
  578. // break;
  579. // }
  580. // }
  581. // if(netindex == 0xFF)
  582. // {
  583. // TCRIT("Error in gettting netindex\n");
  584. // return 0;
  585. // }
  586. // if(Addr != NULL)
  587. // {
  588. // free(GratArpArgs->Argument);
  589. // free(Addr);
  590. // }
  591. // TDBG ("Gratuitous ARP thread starts for ethindex : %x\n",EthIndex);
  592. // while (1)
  593. // {
  594. // /*Is Gratiutous Arp Enabled */
  595. // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & GRATIUTOUS_ENABLE_MASK))
  596. // {
  597. // TDBG("Gratuitous ARP thread exits : Disable BMC-generated Gratuitous ARPs invoked\n");
  598. // break;
  599. // }
  600. // /*Is Gratiutous Arp Suspended */
  601. // Status = BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex];
  602. // if ((0 != (Status & GRATIUTOUS_ENABLE_MASK)) &&
  603. // (BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning == TRUE))
  604. // {
  605. // // Gratuitous ARP Suspended.
  606. // // sleep requested to access Shared memory for two different threads.
  607. // usleep (20);
  608. // continue;
  609. // }
  610. // nwReadNWCfg_v4_v6( &NWConfig,&NWConfig6, netindex,g_corefeatures.global_ipv6);
  611. // if(GetIfcName(EthIndex, IfcName,BMCInst) != 0)
  612. // {
  613. // TCRIT("Error in getting Interface Name for the Lan Index :%d\n",EthIndex);
  614. // }
  615. // if (NWConfig.IFName[0] == 0)
  616. // sprintf((char *)&NWConfig.IFName, "%s",IfcName);
  617. // TDBG ( "MAC is %2x:%2x:%2x:%2x:%2x:%2x \n", NWConfig.MAC [0], NWConfig.MAC [1],
  618. // NWConfig.MAC [2], NWConfig.MAC [3], NWConfig.MAC [4], NWConfig.MAC [5] );
  619. // TDBG ( "IP is %d.%d.%d.%d\n", NWConfig.IPAddr[0], NWConfig.IPAddr[1],
  620. // NWConfig.IPAddr[2], NWConfig.IPAddr[3]);
  621. // TDBG ( "Device Name : %s\n", (char *)&NWConfig.IFName);
  622. // nRet = SendGratuitousARPPacket((char *)&NWConfig.IFName, NWConfig.IPAddr, NWConfig.MAC);
  623. // if (0 != nRet)
  624. // {
  625. // TCRIT("Gratuitous ARP thread exits : Unable to Send Gratuitous ARP packet\n");
  626. // break;
  627. // }
  628. // TDBG ("Send Gratuitous Packet\n");
  629. // if (0 == pBMCInfo->LANCfs[EthIndex].GratitousARPInterval)
  630. // {
  631. // IntervalInSec = 2; //Default 2 secs
  632. // } else {
  633. // // Gratuitous ARP interval in 500 millisecond increments.
  634. // IntervalInSec = (pBMCInfo->LANCfs[EthIndex].GratitousARPInterval * 500)/1000;
  635. // }
  636. // usleep( IntervalInSec * 1000 * 1000 );
  637. // }
  638. // return 0;
  639. // }
  640. /*---------------------------------------------------
  641. * GetLanConfigParam
  642. *---------------------------------------------------*/
  643. int
  644. GetLanConfigParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  645. {
  646. GetLanConfigReq_T* pGetLanReq = ( GetLanConfigReq_T*) pReq;
  647. GetLanConfigRes_T* pGetLanRes = ( GetLanConfigRes_T*) pRes;
  648. uint8_t EthIndex;
  649. char IfcName[16]; /* Eth interface name */
  650. pGetLanRes->CCParamRev.CompletionCode = CC_NORMAL;
  651. pGetLanRes->CCParamRev.ParamRevision = PARAMETER_REVISION_FORMAT;
  652. // printf("---> channel: %d, parameter: %#x, setslect: %#x, blockselect: %#x\n", pGetLanReq->ChannelNum, pGetLanReq->ParameterSelect, pGetLanReq->SetSelect, pGetLanReq->BlockSelect);
  653. if(pGetLanReq->ChannelNum & RESERVED_VALUE_70)
  654. {
  655. /* Alarm !!! Somebody is trying to set Reseved Bits */
  656. *pRes = CC_INV_DATA_FIELD;
  657. return sizeof (*pRes);
  658. }
  659. //! Validate the SetSelector value.
  660. if (0x00 != pGetLanReq->SetSelect)
  661. {
  662. printf("---> SetSelector not support!\n");
  663. *pRes = CC_INV_DATA_FIELD;
  664. return sizeof (*pRes);
  665. }
  666. //! Validate the BlockSelector value.
  667. if (0x00 != pGetLanReq->BlockSelect)
  668. {
  669. printf("---> BlockSelector not support!\n");
  670. *pRes = CC_INV_DATA_FIELD;
  671. return sizeof (*pRes);
  672. }
  673. EthIndex= 0;
  674. sprintf(IfcName, "eth%d", EthIndex);
  675. if ((pGetLanReq->ChannelNum & GET_PARAMETER_REVISION_MASK) != 0)
  676. {
  677. if(MAX_LAN_CONF_PARAM >= pGetLanReq->ParameterSelect)
  678. {
  679. return sizeof(GetLanCCRev_T);
  680. }
  681. else
  682. {
  683. *pRes = CC_PARAM_NOT_SUPPORTED;
  684. return sizeof (*pRes);
  685. }
  686. }
  687. else
  688. {
  689. printf("GetLanConfigParam log4\n");
  690. switch(pGetLanReq->ParameterSelect)
  691. {
  692. case LAN_PARAM_SET_IN_PROGRESS:
  693. pGetLanRes->ConfigData.SetInProgress = 0;
  694. break;
  695. case LAN_PARAM_AUTH_TYPE_SUPPORT:
  696. pGetLanRes->ConfigData.AuthTypeSupport = 0x04; //only support MD5
  697. break;
  698. case LAN_PARAM_AUTH_TYPE_ENABLES:
  699. pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeCallBack = 0x04; //MD5
  700. pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeUser = 0x04;
  701. pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeOperator = 0x04;
  702. pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeAdmin = 0x04;
  703. pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeOem = 0x04;
  704. break;
  705. case LAN_PARAM_IP_ADDRESS:
  706. pGetLanRes->ConfigData.IPAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[0];
  707. pGetLanRes->ConfigData.IPAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[1];
  708. pGetLanRes->ConfigData.IPAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[2];
  709. pGetLanRes->ConfigData.IPAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[3];
  710. break;
  711. case LAN_PARAM_IP_ADDRESS_SOURCE:
  712. pGetLanRes->ConfigData.IPAddrSrc = 1; //static
  713. break;
  714. case LAN_PARAM_MAC_ADDRESS:
  715. pGetLanRes->ConfigData.MACAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[0];
  716. pGetLanRes->ConfigData.MACAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[1];
  717. pGetLanRes->ConfigData.MACAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[2];
  718. pGetLanRes->ConfigData.MACAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[3];
  719. pGetLanRes->ConfigData.MACAddr[4] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[4];
  720. pGetLanRes->ConfigData.MACAddr[5] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[5];
  721. break;
  722. case LAN_PARAM_SUBNET_MASK:
  723. pGetLanRes->ConfigData.SubNetMask[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[0];
  724. pGetLanRes->ConfigData.SubNetMask[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[1];
  725. pGetLanRes->ConfigData.SubNetMask[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[2];
  726. pGetLanRes->ConfigData.SubNetMask[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[3];
  727. break;
  728. case LAN_PARAM_IPv4_HEADER: //下面这些参数是多少不知道,参考LanIfc.c的SetIPv4Header函数。
  729. pGetLanRes->ConfigData.Ipv4HdrParam.TimeToLive = 64;
  730. pGetLanRes->ConfigData.Ipv4HdrParam.IpHeaderFlags = 0;
  731. pGetLanRes->ConfigData.Ipv4HdrParam.TypeOfService = 0x10; //default
  732. break;
  733. case LAN_PARAM_PRI_RMCP_PORT:
  734. pGetLanRes->ConfigData.PrimaryRMCPPort = LAN_RMCP_PORT; //LSB first
  735. break;
  736. case LAN_PARAM_SEC_RMCP_PORT:
  737. *pRes = CC_PARAM_NOT_SUPPORTED;
  738. return sizeof (uint8_t);
  739. break;
  740. case LAN_PARAM_BMC_GENERATED_ARP_CONTROL:
  741. pGetLanRes->ConfigData.BMCGeneratedARPControl = 0;
  742. break;
  743. case LAN_PARAM_GRATITIOUS_ARP_INTERVAL:
  744. pGetLanRes->ConfigData.GratitousARPInterval = 4; //4*500ms
  745. break;
  746. case LAN_PARAM_DEFAULT_GATEWAY_IP:
  747. pGetLanRes->ConfigData.DefaultGatewayIPAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[0];
  748. pGetLanRes->ConfigData.DefaultGatewayIPAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[1];
  749. pGetLanRes->ConfigData.DefaultGatewayIPAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[2];
  750. pGetLanRes->ConfigData.DefaultGatewayIPAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[3];
  751. break;
  752. case LAN_PARAM_DEFAULT_GATEWAY_MAC: //这个参数提供不了。
  753. *pRes = CC_PARAM_NOT_SUPPORTED;
  754. return sizeof (uint8_t);
  755. break;
  756. case LAN_PARAM_BACKUP_GATEWAY_IP:
  757. *pRes = CC_PARAM_NOT_SUPPORTED;
  758. return sizeof (uint8_t);
  759. break;
  760. case LAN_PARAM_BACKUP_GATEWAY_MAC:
  761. *pRes = CC_PARAM_NOT_SUPPORTED;
  762. return sizeof (uint8_t);
  763. break;
  764. case LAN_PARAM_COMMUNITY_STRING:
  765. sprintf(pGetLanRes->ConfigData.CommunityStr,"public");
  766. break;
  767. case LAN_PARAM_DEST_NUM:
  768. pGetLanRes->ConfigData.NumDest = 0;
  769. break;
  770. case LAN_PARAM_SELECT_DEST_TYPE:
  771. *pRes = CC_PARAM_NOT_SUPPORTED;
  772. return sizeof (uint8_t);
  773. break;
  774. case LAN_PARAM_SELECT_DEST_ADDR:
  775. *pRes = CC_PARAM_NOT_SUPPORTED;
  776. return sizeof (uint8_t);
  777. break;
  778. case LAN_PARAM_VLAN_ID:
  779. *pRes = CC_PARAM_NOT_SUPPORTED;
  780. return sizeof (uint8_t);
  781. break;
  782. case LAN_PARAM_VLAN_PRIORITY:
  783. *pRes = CC_PARAM_NOT_SUPPORTED;
  784. return sizeof (uint8_t);
  785. break;
  786. case LAN_PARAM_CIPHER_SUITE_ENTRY_SUP:
  787. *pRes = CC_PARAM_NOT_SUPPORTED;
  788. return sizeof (uint8_t);
  789. break;
  790. case LAN_PARAM_CIPHER_SUITE_ENTRIES:
  791. *pRes = CC_PARAM_NOT_SUPPORTED;
  792. return sizeof (uint8_t);
  793. break;
  794. case LAN_PARAM_CIPHER_SUITE_PRIV_LEVELS:
  795. *pRes = CC_PARAM_NOT_SUPPORTED;
  796. return sizeof (uint8_t);
  797. break;
  798. case LAN_PARAM_VLAN_TAGS:
  799. *pRes = CC_PARAM_NOT_SUPPORTED;
  800. return sizeof (uint8_t);
  801. break;
  802. default:
  803. *pRes = CC_PARAM_NOT_SUPPORTED;
  804. return sizeof(uint8_t);
  805. break;
  806. }
  807. }
  808. return sizeof(GetLanCCRev_T) + LanconfigParameterLength[pGetLanReq->ParameterSelect];
  809. }
  810. // /*---------------------------------------------------
  811. // * SuspendBMCArps
  812. // *---------------------------------------------------*/
  813. // int
  814. // SuspendBMCArps ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  815. // {
  816. // SuspendBMCArpsReq_T* pArpReq = ( SuspendBMCArpsReq_T*) pReq;
  817. // SuspendBMCArpsRes_T* pArpRes = ( SuspendBMCArpsRes_T*) pRes;
  818. // uint8_t EthIndex;
  819. // /* Verify Channel ID */
  820. // pArpRes->CompletionCode = CC_INV_DATA_FIELD;
  821. // if(pArpReq->ChannelNo & RESERVED_BITS_SUSPENDBMCARPS) return sizeof(*pRes);
  822. // if (!IsLANChannel(pArpReq->ChannelNo & CHANNEL_ID_MASK, BMCInst) )
  823. // {
  824. // return sizeof (*pRes);
  825. // }
  826. // EthIndex= GetEthIndex(pArpReq->ChannelNo & 0x0F,BMCInst);
  827. // if(0xff == EthIndex)
  828. // {
  829. // return sizeof (*pRes);
  830. // }
  831. // /* Reserved Bits Validation */
  832. // if (0 != (SUSPEND_ARP_RSVD_BIT_MASK & pArpReq->ArpSuspend))
  833. // {
  834. // return sizeof (*pRes);
  835. // }
  836. // if (BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning == TRUE)
  837. // BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] = pArpReq->ArpSuspend;
  838. // /* Update Response */
  839. // pArpRes->CompletionCode = CC_NORMAL;
  840. // pArpRes->ArpSuspendStatus = UpdateArpStatus(EthIndex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
  841. // return sizeof (SuspendBMCArpsRes_T);
  842. // }
  843. // /*---------------------------------------------------
  844. // * GetIPUDPRMCPStats
  845. // *---------------------------------------------------*/
  846. // int
  847. // GetIPUDPRMCPStats ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
  848. // {
  849. // GetIPUDPRMCPStatsReq_T* pGetIPUDPRMCPStatsReq = ( GetIPUDPRMCPStatsReq_T*) pReq;
  850. // GetIPUDPRMCPStatsRes_T* pGetIPUDPRMCPStatsRes = ( GetIPUDPRMCPStatsRes_T*) pRes;
  851. // BMCSharedMem_T* pSharedMem = BMC_GET_SHARED_MEM (BMCInst);
  852. // FILE *fptr;
  853. // char FDRead[512], FSRead[512];
  854. // char *result = NULL;
  855. // char **StrArray;
  856. // int count = 0;
  857. // int cStrings =0;
  858. // if(pGetIPUDPRMCPStatsReq->ChannelNo & RESERVED_BITS_GETIPUDPRMCPSTATS_CH)
  859. // {
  860. // *pRes = CC_INV_DATA_FIELD;
  861. // return sizeof(*pRes);
  862. // }
  863. // if(pGetIPUDPRMCPStatsReq->ClearStatus & RESERVED_BITS_GETIPUDPRMCPSTATS_CLRSTATE)
  864. // {
  865. // *pRes = CC_INV_DATA_FIELD;
  866. // return sizeof(*pRes);
  867. // }
  868. // //Channel number [3:0] is valid.
  869. // if ( !IsLANChannel(pGetIPUDPRMCPStatsReq->ChannelNo & CHANNEL_ID_MASK, BMCInst) )
  870. // {
  871. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_INV_DATA_FIELD;
  872. // return sizeof (*pRes);
  873. // }
  874. // //Clear the statistics if 1 is given in request.
  875. // if ( pGetIPUDPRMCPStatsReq->ClearStatus & 0x01 )
  876. // {
  877. // /* <TBD BalaT>
  878. // * Have to clear the already stored statistics when clear req is 1.
  879. // */
  880. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
  881. // return sizeof (uint8_t);
  882. // }
  883. // //All Statistics values are initialised to 0.
  884. // memset (pGetIPUDPRMCPStatsRes, 0, sizeof(GetIPUDPRMCPStatsRes_T) );
  885. // //All the datas are taken from /proc/net/snmp file
  886. // fptr = fopen ("/proc/net/snmp","r+");
  887. // if (fptr == NULL)
  888. // {
  889. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_COULD_NOT_PROVIDE_RESP;
  890. // return sizeof (uint8_t);
  891. // }
  892. // while( NULL != fgets(FDRead,512,fptr) )
  893. // {
  894. // if ( NULL != strstr (FDRead, "Ip: ") )
  895. // {
  896. // count++;
  897. // if (count == 2)
  898. // {
  899. // //To find the no. of valid strings in a line.
  900. // strcpy (FSRead, FDRead);
  901. // result = strtok( FSRead, " " );
  902. // while( result != NULL )
  903. // {
  904. // cStrings++;
  905. // result = strtok( NULL, " " );
  906. // }
  907. // //Condition to check so that explode doesnt try to read the strings from unknown location.
  908. // if ( cStrings == 20)
  909. // {
  910. // StrArray = explode (' ', FDRead);
  911. // }
  912. // else
  913. // {
  914. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
  915. // return sizeof (uint8_t);
  916. // }
  917. // //All Statistics stops acumulating at FFFFh unless otherwise noted.
  918. // //IP packets received.
  919. // if ( atol((char *)StrArray[3]) > 0xffff)
  920. // pGetIPUDPRMCPStatsRes->IPPacketsRecv = ( ( atol((char *)StrArray[3]) ) % 65535);
  921. // else
  922. // pGetIPUDPRMCPStatsRes->IPPacketsRecv = atoi((char *)StrArray[3]);
  923. // //IP Header Error.
  924. // pGetIPUDPRMCPStatsRes->IPHeaderErr = atoi((char *)StrArray[4]);
  925. // //IP Address Error.
  926. // if ( atol((char *)StrArray[5]) > 0xffff)
  927. // pGetIPUDPRMCPStatsRes->IPAddrErr = ( ( atol((char *)StrArray[5]) ) % 65535);
  928. // else
  929. // pGetIPUDPRMCPStatsRes->IPAddrErr = atoi((char *)StrArray[5]);
  930. // //Fragmented IP Packets received.
  931. // if ( atol((char *)StrArray[17]) > 0xffff)
  932. // pGetIPUDPRMCPStatsRes->FragIPPacketsRecv = ( ( atol((char *)StrArray[17]) ) % 65535);
  933. // else
  934. // pGetIPUDPRMCPStatsRes->FragIPPacketsRecv = atoi((char *)StrArray[17]);
  935. // //IP packets Transmitted.
  936. // if ( atol((char *)StrArray[10]) > 0xffff)
  937. // pGetIPUDPRMCPStatsRes->IPPacketsTrans = ( ( atol((char *)StrArray[10]) ) % 65535);
  938. // else
  939. // pGetIPUDPRMCPStatsRes->IPPacketsTrans = atoi((char *)StrArray[10]);
  940. // count = 0;
  941. // }
  942. // }
  943. // if ( NULL != strstr (FDRead, "Udp: ") )
  944. // {
  945. // count++;
  946. // if (count == 2)
  947. // {
  948. // //To find the no. of valid strings in a line.
  949. // cStrings = 0;
  950. // strcpy (FSRead, FDRead);
  951. // result = strtok( FSRead, " " );
  952. // while( result != NULL )
  953. // {
  954. // cStrings++;
  955. // result = strtok( NULL, " " );
  956. // }
  957. // //Condition to check so that explode doesnt try to read the strings beyond the valid location.
  958. // if ( cStrings == 5)
  959. // {
  960. // StrArray = explode (' ', FDRead);
  961. // }
  962. // else
  963. // {
  964. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
  965. // return sizeof (uint8_t);
  966. // }
  967. // //UDP packets received.
  968. // if ( atol((char *)StrArray[1]) > 0xffff)
  969. // pGetIPUDPRMCPStatsRes->UDPPacketsRecv = ( ( atol((char *)StrArray[1]) ) % 65535);
  970. // else
  971. // pGetIPUDPRMCPStatsRes->UDPPacketsRecv = atoi((char *)StrArray[1]);
  972. // count = 0;
  973. // }
  974. // }
  975. // }
  976. // fclose(fptr);
  977. // //Valid RMCP packets received.
  978. // pGetIPUDPRMCPStatsRes->ValidRMCPPackets = pSharedMem->gIPUDPRMCPStats;
  979. // //<TBD BalaT>To store the statistics across the system reset and power cycles
  980. // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
  981. // return sizeof (GetIPUDPRMCPStatsRes_T);
  982. // }
  983. // /*-----------------------------------------------------
  984. // * explode
  985. // * Funntion to split the strings and store in an array
  986. // *-----------------------------------------------------*/
  987. // char **explode(char separator, char *string)
  988. // {
  989. // int start = 0, i, k = 1, count = 2;
  990. // char **strarr;
  991. // for (i = 0; string[i] != '\0'; i++)
  992. // /* how many rows do we need for our array? */
  993. // if (string[i] == separator)
  994. // count++;
  995. // /* count is at least 2 to make room for the entire string
  996. // * * and the ending NULL */
  997. // strarr = malloc(count * sizeof(char*));
  998. // i = 0;
  999. // while (*string++ != '\0')
  1000. // {
  1001. // if (*string == separator)
  1002. // {
  1003. // strarr[i] = malloc(k - start + 2);
  1004. // strncpy(strarr[i], string - k + start, k - start + 1);
  1005. // strarr[i][k - start + 1] = '\0'; /* guarantee null termination */
  1006. // start = k;
  1007. // i++;
  1008. // }
  1009. // k++;
  1010. // }
  1011. // /* copy the last part of the string after the last separator */
  1012. // strarr[i] = malloc(k - start);
  1013. // strncpy(strarr[i], string - k + start, k - start - 1);
  1014. // strarr[i][k - start - 1] = '\0'; /* guarantee null termination */
  1015. // strarr[++i] = NULL;
  1016. // return strarr;
  1017. // }
  1018. // /*----------------------------------------------
  1019. // * UpdateArpStatus
  1020. // *----------------------------------------------*/
  1021. // uint8_t
  1022. // UpdateArpStatus (uint8_t EthIndex,BOOL IsTimerRunning, int BMCInst)
  1023. // {
  1024. // uint8_t GratArpSuspend;
  1025. // uint8_t ArpSuspend;
  1026. // uint8_t Status;
  1027. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  1028. // char Cmds[50]={0}; // command string to perform BMC-generated ARP
  1029. // char IfcName[16];
  1030. // IPMI_DBG_PRINT_1 ("Timer - %x", IsTimerRunning);
  1031. // GratArpSuspend = ArpSuspend = 1;
  1032. // // Check Gratuitous ARP is Enabled
  1033. // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & GRATIUTOUS_ENABLE_MASK))
  1034. // {
  1035. // GratArpSuspend = 0;
  1036. // }
  1037. // // Check ARP Response is Enabled
  1038. // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & ENABLE_ARP_RESPONSES))
  1039. // {
  1040. // ArpSuspend = 0;
  1041. // }
  1042. // /*Disable ARP */
  1043. // if (TRUE == IsTimerRunning)
  1044. // {
  1045. // /* WDT is running, check and suspend ARP if necessary */
  1046. // if( (0 != (BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] & SUSPEND_GRAT_ARP)) &&
  1047. // (0 < GratArpSuspend) )
  1048. // {
  1049. // GratArpSuspend--;
  1050. // }
  1051. // if( (0 != (BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] & SUSPEND_ARP)) &&
  1052. // (0 < ArpSuspend) )
  1053. // {
  1054. // ArpSuspend--;
  1055. // }
  1056. // }
  1057. // memset(IfcName,0,sizeof(IfcName));
  1058. // if(GetIfcName(EthIndex, IfcName, BMCInst) != 0)
  1059. // {
  1060. // TCRIT("Error in getting Interface Name for the Lan Index :%d\n", EthIndex);
  1061. // }
  1062. // else
  1063. // {
  1064. // /* Perform commands for BMC-generated Arp */
  1065. // memset(Cmds, 0, sizeof(Cmds));
  1066. // sprintf(Cmds, "/usr/local/bin/ArpSwitch.sh %s %d", IfcName, (!ArpSuspend) ? ARP_IGNORE_ON : ARP_IGNORE_OFF);
  1067. // safe_system (Cmds);
  1068. // /* Perform commands for BMC-generated Arp ends */
  1069. // }
  1070. // /* Update Status */
  1071. // Status = ArpSuspend << 1;
  1072. // Status = Status | GratArpSuspend;
  1073. // return Status;
  1074. // }
  1075. // /**
  1076. // *@fn NwInterfacePresenceCheck
  1077. // *@brief This function is invoked to check network interface presence
  1078. // *@param Interface - Char Pointer to Interface for which interface to check
  1079. // *@return Returns 0 on success
  1080. // */
  1081. // static int
  1082. // NwInterfacePresenceCheck (char * Interface)
  1083. // {
  1084. // int r;
  1085. // int sockdes;
  1086. // struct ifreq Ifreq;
  1087. // unsigned char MAC[MAC_ADDR_LEN];
  1088. // IPMI_DBG_PRINT_1 ("Checking the presence of %s\n", Interface);
  1089. // sockdes = socket(PF_INET, SOCK_DGRAM, 0 );
  1090. // if ( sockdes < 0 )
  1091. // {
  1092. // IPMI_ERROR("can't open socket: %s\n",strerror(errno));
  1093. // return -1;
  1094. // }
  1095. // /* Get MAC address */
  1096. // memset(&Ifreq,0,sizeof(struct ifreq));
  1097. // memset(MAC, 0, MAC_ADDR_LEN);
  1098. // strcpy(Ifreq.ifr_name, Interface);
  1099. // Ifreq.ifr_hwaddr.sa_family = AF_INET;
  1100. // r = ioctl(sockdes, SIOCGIFHWADDR, &Ifreq);
  1101. // close (sockdes);
  1102. // if ( r < 0 )
  1103. // {
  1104. // //IPMI_ERROR("IOCTL to get MAC failed: %d\n",r);
  1105. // return -1;
  1106. // }
  1107. // IPMI_DBG_PRINT_1 (" %s Interface is present\n", Interface);
  1108. // return 0;
  1109. // }