12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274 |
- #include <stdio.h>
- #include <stdint.h>
- //#include <linux/if.h>
- #include <linux/ip.h>
- //#include <dlfcn.h>
- #include <sys/prctl.h>
- //#include "nwcfg.h"
- #include "Util.h"
- #include "main.h"
- #include "Api.h"
- #include "Util.h"
- #include "com_IPMI_LANConfig.h"
- #include "com_IPMI_DeviceConfig.h"
- #include <string.h>
- /* Reserved bit macro definitions */
- #define RESERVED_BITS_SUSPENDBMCARPS 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
- #define RESERVED_BITS_GETIPUDPRMCPSTATS_CH 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
- #define RESERVED_BITS_GETIPUDPRMCPSTATS_CLRSTATE 0xFE //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1)
- /*** Local definitions ***/
- #define CHANNEL_ID_MASK 0x0f
- #define SET_IN_PROGRESS_MASK 0x03
- #define PARAMETER_REVISION_MASK 0x0f
- #define DEST_ADDR_DATA2_ADDR_FORMAT_MASK 0xf0
- #define PARAMETER_REVISION_FORMAT 0x11
- #define GET_PARAMETER_REVISION_MASK 0x80
- #define LAN_CALLBACK_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
- #define LAN_USER_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
- #define LAN_OPERATOR_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
- #define LAN_ADMIN_AUTH_SUPPORT 0x17 /* MD2 & MD5 supported */
- #define BRD_CAST_BIT_MASK 0xFF
- #define LOOP_BACK_BIT_MASK 0x7F
- #define SUBNET_MASK_BIT_CHECK 0x80
- #define LAN_CONFIGURATION_SET_IN_PROGRESS 0x01
- #define LAN_CONFIGURATION_SET_COMPLETE 0x00
- #define GRATIUTOUS_ENABLE_MASK 1
- #define ENABLE_ARP_RESPONSES 2
- #define SUSPEND_ARP_RSVD_BIT_MASK 0xFC
- #define ENABLE_ARPS 0x03
- #define SUSPEND_GRAT_ARP 0x01
- #define SUSPEND_ARP 0x02
- #define ARP_IGNORE_ON 8
- #define ARP_IGNORE_OFF 0
- /* Reserved Bits */
- #define RESERVED_VALUE_70 0x70
- #define RESERVED_VALUE_F0 0xF0
- // /**
- // *@fn NwInterfacePresenceCheck
- // *@brief This function is invoked to check network interface presence
- // *@param Interface - Char Pointer to buffer for which interface to check
- // */
- // static int NwInterfacePresenceCheck (char * Interface);
- // /*** Module Variables ***/
- // // uint8_t m_ArpSuspendReq;
- // char **explode(char separator, char *string);
- // int IPAddrCheck(uint8_t *Addr,int params);
- // extern int GetLanAMIParamValue (uint8_t* ParamSelect, uint8_t* ImpType);
- // extern IfcName_T Ifcnametable[MAX_LAN_CHANNELS];
- #define MAX_LAN_PARAMS_DATA 20
- typedef struct
- {
- uint8_t Params;
- uint8_t ReservedBits [MAX_LAN_PARAMS_DATA];
- uint8_t DataLen;
- } LANCfgRsvdBits_T;
- static LANCfgRsvdBits_T m_RsvdBitsCheck [] = {
- /* Param Reserved Bits Data Size */
- { 0, { 0xFC }, 0x1 }, /* Set In progress */
- { 1, { 0xC8 }, 0x1 }, /* Authenication type */
- { 2, { 0xC8,0xC8,0xC8,0xC8,0xC8 }, 0x5}, /* Authenication Support Enable */
- { 4, { 0xF0 }, 0x1 }, /* l */
- { 7, { 0x0,0x1F,0x01 }, 0x3 }, /* l */
- { 0xA, { 0xFC }, 0x1 }, /* l */
- { 0x11, { 0xF0 }, 0x1 }, /* l */
- { 0x12, { 0xF0,0x78,0x0,0xF8 }, 0x4 },
- { 0x13, { 0xF0,0x0F, 0xFE }, 0x3 },
- { 0x14, { 0x0,0x70}, 0x2 },
- { 0x15, { 0xF8 }, 0x1 },
- { 0x16, { 0xE0 }, 0x1 },
- { 0x17, { 0xFF }, 0x1 },
- { 0x18, { 0xFF }, 0x1 },
- { 0x19, { 0xF0,0x0F }, 0x2 },
- { 0x1A, { 0xFE }, 0x1 }
- };
- typedef struct
- {
- uint8_t OEMParam;
- uint8_t Length;
- }OEMParameterLength_T;
- static OEMParameterLength_T m_OEMParamLen [] = {
- // {LAN_PARAMS_AMI_OEM_IPV6_ENABLE, 1 },
- // {LAN_PARAMS_AMI_OEM_IPV6_IP_ADDR_SOURCE, 1 },
- // {LAN_PARAMS_AMI_OEM_IPV6_IP_ADDR, 17 },
- // {LAN_PARAMS_AMI_OEM_IPV6_PREFIX_LENGTH, 2},
- // {LAN_PARAMS_AMI_OEM_IPV6_GATEWAY_IP, 16}
- };
- /**
- * @brief LAN configuration request parameter lengths
- **/
- static const uint8_t LanconfigParameterLength [] = {
- 1, /* Set in progress */
- 1, /* Authentication type support */
- 5, /* Authentication type enables */
- 4, /* IP address */
- 1, /* IP address source */
- 6, /* MAC address */
- 4, /* Subnet mask */
- 3, /* IPv4 header parameters */
- 2, /* Primary RMCP port number */
- 2, /* Secondary RMCP port number */
- 1, /* BMC generated ARP control */
- 1, /* Gratuitous ARP */
- 4, /* Default Gateway address */
- 6, /* Default Gateway MAC address */
- 4, /* Backup Gateway address */
- 6, /* Backup Gateway MAC address */
- 18, /* Community string */
- 1, /* Number of destinations */
- 4, /* Destination type */
- 13, /* Destination address */
- 2, /* VLAN ID */
- 1, /* VLAN Priority */
- 1, /* Cipher suite entry support */
- 17, /* Cipher suite entries */
- 9, /* Cipher suite Privilege levels */
- 4, /* VLAN tags destination address */
- 6, /* Bad Password Threshold */
- (9+16) /* IPv6 Destination address */
- };
- /* A copy of ip_tos2prio with numeric format in "linux/net/ipv4/route.c" */
- static const uint8_t IP_TOS2PRIO[16] = {
- 0, /* TC_PRIO_BESTEFFORT, */
- 1, /* ECN_OR_COST(FILLER), */
- 0, /* TC_PRIO_BESTEFFORT, */
- 0, /* ECN_OR_COST(BESTEFFORT), */
- 2, /* TC_PRIO_BULK, */
- 2, /* ECN_OR_COST(BULK), */
- 2, /* TC_PRIO_BULK, */
- 2, /* ECN_OR_COST(BULK), */
- 6, /* TC_PRIO_INTERACTIVE, */
- 6, /* ECN_OR_COST(INTERACTIVE), */
- 6, /* TC_PRIO_INTERACTIVE, */
- 6, /* ECN_OR_COST(INTERACTIVE), */
- 4, /* TC_PRIO_INTERACTIVE_BULK, */
- 4, /* ECN_OR_COST(INTERACTIVE_BULK),*/
- 4, /* TC_PRIO_INTERACTIVE_BULK, */
- 4 /* ECN_OR_COST(INTERACTIVE_BULK) */
- };
- static uint8_t enableSetMACAddr = TRUE; //jimbo notice
- /*-------------------------------------------------------
- * SetLanConfigParam
- *-------------------------------------------------------*/
- int
- SetLanConfigParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
- {
- SetLanConfigReq_T* pSetLanReq = ( SetLanConfigReq_T*) pReq;
- SetLanConfigRes_T* pSetLanRes = ( SetLanConfigRes_T*) pRes;
- MsgPkt_T m_MsgPkt;
- int i,j=0;
- uint8_t index;
- int retValue=0,NIC_Count = 0;
- // uint16_t PriorityLevel[MAX_LAN_CHANNELS]= {0};
- uint8_t m_Lan_SetInProgress; /**< Contains setting LAN configuration status */
-
- uint8_t InvalidMac[MAC_ADDR_LEN] = {0,0,0,0,0,0};
- char old_mac[18];
- char macStr[18] = {0};
- char old_ip[16];
- char ipStr[16] = {0};
- char old_netmask[18];
- char netmaskStr[18] = {0};
- if ( ReqLen >= 2 )
- {
- ReqLen -= 2;
- }
- else
- {
- *pRes = CC_REQ_INV_LEN;
- return 1;
- }
-
- //自定义
- // if((pSetLanReq->ParameterSelect >= MIN_LAN_OEM_CONF_PARAM) &&
- // (pSetLanReq->ParameterSelect <= MAX_LAN_OEM_CONF_PARAM) )
- // {
- // /* Converts OEM parameter value to equivalent AMI parameter value */
- // if (0 != GetLanAMIParamValue (&pSetLanReq->ParameterSelect, &IsOemDefined) )
- // {
- // pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
- // return sizeof(uint8_t);
- // }
- // /* Hook for OEM to handle this parameter */
- // if ( (IsOemDefined) && (g_PDKHandle[PDK_SETLANOEMPARAM] != NULL) )
- // {
- // return ((int(*)(uint8_t *, uint8_t, uint8_t *,int))(g_PDKHandle[PDK_SETLANOEMPARAM]))(pReq, ReqLen, pRes, BMCInst);
- // }
-
- // }
- if(0x1b >pSetLanReq->ParameterSelect ) //Max known Lan paramter
- {
- if (ReqLen != LanconfigParameterLength [pSetLanReq->ParameterSelect ])
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (uint8_t);
- }
- }
- // /*Check the Request length for OEM parameter*/
- // for(i=0;i<sizeof(m_OEMParamLen)/sizeof(OEMParameterLength_T);i++)
- // {
- // if(m_OEMParamLen[i].OEMParam == pSetLanReq->ParameterSelect)
- // {
- // if(ReqLen != m_OEMParamLen[i].Length)
- // {
- // *pRes = CC_REQ_INV_LEN;
- // return sizeof(uint8_t);
- // }
- // }
- // }
- if(pSetLanReq->ChannelNum & RESERVED_VALUE_F0)
- {
- /* Alarm !!! Somebody is trying to set Reseved Bits */
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
- if(pSetLanReq->ChannelNum == LAN_RMCP_CHANNEL)
- index = 0;
- else
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
-
- /* Check for Reserved Bits */
- for (i = 0; i < sizeof (m_RsvdBitsCheck)/ sizeof (m_RsvdBitsCheck[0]); i++)
- {
- /* Check if this Parameter Selector needs Reserved bit checking !! */
- if (m_RsvdBitsCheck[i].Params == pSetLanReq->ParameterSelect)
- {
- //IPMI_DBG_PRINT_2 ("Param - %x, DataLen - %x\n", pSetLanReq->ParameterSelect, m_RsvdBitsCheck[i].DataLen);
- for (j = 0; j < m_RsvdBitsCheck[i].DataLen; j++)
- {
- // IPMI_DBG_PRINT_2 ("Cmp %x, %x\n", pReq[2+j], m_RsvdBitsCheck[i].ReservedBits[j]);
- if ( 0 != (pReq[2+j] & m_RsvdBitsCheck[i].ReservedBits[j]))
- {
- /* Alarm !!! Somebody is trying to set Reseved Bits */
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
- }
- }
- }
- // ptrChannelInfo = getChannelInfo (pSetLanReq->ChannelNum & 0x0F, BMCInst);
- // if(NULL == ptrChannelInfo)
- // {
- // *pRes = CC_INV_DATA_FIELD;
- // return sizeof(*pRes);
- // }
-
- printf ("Parameter = %X\n", pSetLanReq->ParameterSelect);
-
- switch (pSetLanReq->ParameterSelect)
- {
- case LAN_PARAM_SET_IN_PROGRESS:
- m_Lan_SetInProgress = g_BMCInfo.m_Lan_SetInProgress;
-
- /* Commit Write is optional and supported
- * only if rollback is supported */
- if ( (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) !=
- LAN_CONFIGURATION_SET_COMPLETE) &&
- (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) !=
- LAN_CONFIGURATION_SET_IN_PROGRESS) )
- {
- pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
- return sizeof(*pSetLanRes);
- }
- else if ((GetBits(m_Lan_SetInProgress, SET_IN_PROGRESS_MASK) ==
- LAN_CONFIGURATION_SET_IN_PROGRESS) &&
- (GetBits(pSetLanReq->ConfigData.SetInProgress, SET_IN_PROGRESS_MASK) ==
- LAN_CONFIGURATION_SET_IN_PROGRESS))
- {
- pSetLanRes->CompletionCode = CC_SET_IN_PROGRESS;
- return sizeof(*pSetLanRes);
- }
- g_BMCInfo.m_Lan_SetInProgress = pSetLanReq->ConfigData.SetInProgress;
- break;
- case LAN_PARAM_AUTH_TYPE_SUPPORT:
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof(*pRes);
- case LAN_PARAM_AUTH_TYPE_ENABLES:
- printf("---> Not implement!\n");
- // for(i=0;i<5;i++)
- // {
- // /* Check for Unsupported AuthType */
- // if (pBMCInfo->LANCfs[EthIndex].AuthTypeSupport != (pBMCInfo->LANCfs[EthIndex].AuthTypeSupport |pReq[2+i]))
- // {
- // IPMI_DBG_PRINT_2("\n Alarm !!! Somebody is trying to Unsupported Bit :%d \t%d\n",pReq[2+i],i);
- // *pRes = CC_INV_DATA_FIELD;
- // return sizeof (*pRes);
- // }
- // }
- // LOCK_BMC_SHARED_MEM(BMCInst);
- // _fmemcpy (&pBMCInfo->LANCfs[EthIndex].AuthTypeEnables,
- // &(pSetLanReq->ConfigData.AuthTypeEnables), sizeof(AuthTypeEnables_T));
- // _fmemcpy (ptrChannelInfo->AuthType,
- // &(pSetLanReq->ConfigData.AuthTypeEnables), sizeof(AuthTypeEnables_T));
- // UNLOCK_BMC_SHARED_MEM(BMCInst);
- break;
- case LAN_PARAM_IP_ADDRESS: //post cmd to chassisTimerTask
- if(IPAddrCheck(pSetLanReq->ConfigData.IPAddr,LAN_PARAM_IP_ADDRESS))
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (uint8_t);
- }
- getip(old_ip);
- sprintf(ipStr, "%d.%d.%d.%d", pSetLanReq->ConfigData.IPAddr[0],
- pSetLanReq->ConfigData.IPAddr[1], pSetLanReq->ConfigData.IPAddr[2],
- pSetLanReq->ConfigData.IPAddr[3]);
- if(strcmp(ipStr, old_ip) == 0)
- {
- printf("The same ip %s, do nothing\n", ipStr );
- *pRes = CC_NORMAL;
- return 1;
- }
- m_MsgPkt.Param = PARAM_LAN;
- m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
- m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
- m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
- m_MsgPkt.Data[0] = 0;//eth0
- m_MsgPkt.Data[1] = 0;//掉电不保存
- memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
- PostMsg(gPendActionIfc, &m_MsgPkt);
- //Update
- memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr, pSetLanReq->ConfigData.IPAddr, 4);
- FlushIpmiConfig();
- printf("---> old_ip: %s, new_ip: %s\n", old_ip, ipStr);
- printf("---> send data: %#x %#x %#x %#x %#x\n", m_MsgPkt.Data[0], m_MsgPkt.Data[1]
- , m_MsgPkt.Data[2], m_MsgPkt.Data[3], m_MsgPkt.Data[4]);
- break;
- case LAN_PARAM_IP_ADDRESS_SOURCE:
- printf("---> Not implement!\n");
- break;
- case LAN_PARAM_MAC_ADDRESS:
- /* According to IPMI 2.0 Specification Revision 3, the MAC address can be read only parameter*/
- //*pRes = CC_ATTEMPT_TO_SET_RO_PARAM;
- //return sizeof (*pRes);
-
- if((pSetLanReq->ConfigData.MACAddr[0]& BIT0)|| (memcmp(&InvalidMac,&pSetLanReq->ConfigData.MACAddr,MAC_ADDR_LEN) == 0))
- {
- pSetLanRes->CompletionCode = CC_INV_DATA_FIELD;
- return 1;
- }
- getmac(old_mac);
- sprintf(macStr, "%02x:%02x:%02x:%02x:%02x:%02x", pSetLanReq->ConfigData.MACAddr[0],
- pSetLanReq->ConfigData.MACAddr[1], pSetLanReq->ConfigData.MACAddr[2],
- pSetLanReq->ConfigData.MACAddr[3], pSetLanReq->ConfigData.MACAddr[4],
- pSetLanReq->ConfigData.MACAddr[5]);
- if(strcmp(macStr, old_mac) == 0)
- {
- printf("The same mac %s, do nothing\n", macStr );
- *pRes = CC_NORMAL;
- return 1;
- }
- if (!enableSetMACAddr)
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- else
- {
- m_MsgPkt.Param = PARAM_LAN;
- m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
- m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
- m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
- m_MsgPkt.Data[0] = 0;//eth0
- m_MsgPkt.Data[1] = 0;//掉电不保存
- memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
- PostMsg(gPendActionIfc, &m_MsgPkt);
- //Update
- memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr, pSetLanReq->ConfigData.MACAddr, 6);
- printf("---> old_mac: %s, new_mac: %s\n", old_mac, macStr);
- pSetLanRes->CompletionCode = CC_NORMAL;
- }
-
- break;
- case LAN_PARAM_SUBNET_MASK:
- getnetmask(old_netmask);
- sprintf(netmaskStr, "%d.%d.%d.%d", pSetLanReq->ConfigData.SubNetMask[0],
- pSetLanReq->ConfigData.SubNetMask[1], pSetLanReq->ConfigData.SubNetMask[2],
- pSetLanReq->ConfigData.SubNetMask[3]);
- if(strcmp(netmaskStr, old_netmask) == 0)
- {
- printf("The same netmask %s, do nothing\n", netmaskStr );
- *pRes = CC_NORMAL;
- return 1;
- }
-
- if(IPAddrCheck(pSetLanReq->ConfigData.SubNetMask,LAN_PARAM_SUBNET_MASK))
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (uint8_t);
- }
- m_MsgPkt.Param = PARAM_LAN;
- m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
- m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
- m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
- m_MsgPkt.Data[0] = 0;//eth0
- m_MsgPkt.Data[1] = 0;//掉电不保存
- memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
- PostMsg(gPendActionIfc, &m_MsgPkt);
- //Update
- memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].NetMask, pSetLanReq->ConfigData.SubNetMask, 4);
- pSetLanRes->CompletionCode = CC_NORMAL;
- break;
- case LAN_PARAM_IPv4_HEADER:
- printf("Not implement\n");
- break;
- case LAN_PARAM_PRI_RMCP_PORT:
- printf("Not implement\n"); //需要重启网络线程
- break;
- case LAN_PARAM_SEC_RMCP_PORT:
- /* Returning Invalid error message */
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- /*pPMConfig->LANConfig[EthIndex].SecondaryPort = ipmitoh_u16 (pSetLanReq->ConfigData.SecondaryPort);*/
- break;
- case LAN_PARAM_BMC_GENERATED_ARP_CONTROL:
- printf("Not implement\n");
- break;
- case LAN_PARAM_GRATITIOUS_ARP_INTERVAL:
- printf("Not implement\n");
- break;
- case LAN_PARAM_DEFAULT_GATEWAY_IP:
- if(IPAddrCheck(pSetLanReq->ConfigData.DefaultGatewayIPAddr,LAN_PARAM_DEFAULT_GATEWAY_IP))
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (uint8_t);
- }
- m_MsgPkt.Param = PARAM_LAN;
- m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_TRANSPORT;
- m_MsgPkt.Cmd = CMD_SET_LAN_CONFIGURATION_PARAMETERS;
- m_MsgPkt.Size = sizeof(SetLanConfigReq_T)+2;
- m_MsgPkt.Data[0] = 0;//eth0
- m_MsgPkt.Data[1] = 0;//掉电不保存
- memcpy(&m_MsgPkt.Data[2], pSetLanReq, sizeof(SetLanConfigReq_T));
- PostMsg(gPendActionIfc, &m_MsgPkt);
- //Update
- memcpy(g_BMCInfo.IpmiConfig.LanInfo[index].DefaultGW, pSetLanReq->ConfigData.DefaultGatewayIPAddr, 4);
- pSetLanRes->CompletionCode = CC_NORMAL;
-
- break;
- case LAN_PARAM_DEFAULT_GATEWAY_MAC:
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof(*pRes);
- break;
- case LAN_PARAM_BACKUP_GATEWAY_IP:
- printf("Not implement\n");
- break;
- case LAN_PARAM_BACKUP_GATEWAY_MAC:
- printf("Not implement\n");
- break;
- case LAN_PARAM_COMMUNITY_STRING:
- printf("Not implement\n");
- break;
- case LAN_PARAM_DEST_NUM:
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof(uint8_t);
- case LAN_PARAM_SELECT_DEST_TYPE:
- printf("Not implement\n");
- break;
- case LAN_PARAM_SELECT_DEST_ADDR:
- printf("Not implement\n");
- break;
- case LAN_PARAM_VLAN_ID:
- printf("Not implement\n");
- break;
- case LAN_PARAM_VLAN_PRIORITY:
- printf("Not implement\n");
- break;
- case LAN_PARAM_CIPHER_SUITE_ENTRY_SUP:
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof(uint8_t);
- case LAN_PARAM_CIPHER_SUITE_ENTRIES:
- pSetLanRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof(uint8_t);
- break;
- case LAN_PARAM_CIPHER_SUITE_PRIV_LEVELS:
- printf("Not implement\n");
- break;
- case LAN_PARAM_VLAN_TAGS:
- printf("Not implement\n");
- break;
- case LAN_PARAMS_BAD_PASSWORD_THRESHOLD:
- printf("Not implement\n");
- break;
- default:
- pSetLanRes->CompletionCode = CC_PARAM_NOT_SUPPORTED;
- return sizeof(uint8_t);
- }
-
- pSetLanRes->CompletionCode = CC_NORMAL;
- FlushIpmiConfig();
- return sizeof(*pSetLanRes);
- }
- /*
- *@fn IPAddrCheck function
- *@brief It will validate the IP Address and net Mask
- *@param Addr - IP Address or net Mask
- *@param params - parameter data to validate
- */
- int IPAddrCheck(uint8_t *Addr,int params)
- {
- int i,maskcount=0,bitmask =0,j,bitcheck=0;
- for(i=0;i< IP_ADDR_LEN;i++)
- {
- if(Addr[i] == BRD_CAST_BIT_MASK)
- {
- maskcount++;
- }
- }
- if(maskcount == IP_ADDR_LEN)
- {
- return 1;
- }
- if(params == LAN_PARAM_SUBNET_MASK)
- {
- if(Addr[0] == BRD_CAST_BIT_MASK)
- {
- for(i=1;i< IP_ADDR_LEN;i++)
- {
- if(Addr[i-1] == 0)
- {
- bitmask = 1;
- }
- if(Addr[i] != 0)
- {
- for(j=0;j<8;j++)
- {
- if((Addr[i]<<j) & SUBNET_MASK_BIT_CHECK)
- {
- if(bitcheck == 1)
- {
- return 1;
- }
- continue;
- }
- bitcheck=1;
- }
- if((bitcheck == 1 && Addr[i-1] != BRD_CAST_BIT_MASK) || (Addr[i] > 0 && bitmask == 1))
- {
- return 1;
- }
- }
- }
- return 0;
- }
- return 1;
- }
- if(Addr[0] == LOOP_BACK_BIT_MASK || Addr[0] == BRD_CAST_BIT_MASK)
- {
- return 1;
- }
- return 0;
- }
- // /*----------------------------------------------
- // * GratuitousARPTask
- // *----------------------------------------------*/
- // void* GratuitousARPTask (uint8_t *Addr)
- // {
- // uint8_t IntervalInSec;
- // uint8_t Status;
- // int nRet;
- // NWCFG_STRUCT NWConfig;
- // NWCFG6_STRUCT NWConfig6;
- // uint8_t EthIndex,netindex= 0xFF;
- // int BMCInst,i;
- // char IfcName[16];
- // BMCArg *GratArpArgs = (BMCArg *)Addr;
- // BMCInst = GratArpArgs->BMCInst;
- // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
- // memcpy(&EthIndex,GratArpArgs->Argument,GratArpArgs->Len);
- // memset(IfcName,0,sizeof(IfcName));
- // /*Get the EthIndex*/
- // if(GetIfcName(EthIndex,IfcName, BMCInst) == -1)
- // {
- // TCRIT("Error in Getting Ifcname\n");
- // return 0;
- // }
- // for(i=0;i<sizeof(Ifcnametable)/sizeof(IfcName_T);i++)
- // {
- // if(strcmp(Ifcnametable[i].Ifcname,IfcName) == 0)
- // {
- // netindex= Ifcnametable[i].Index;
- // break;
- // }
- // }
- // if(netindex == 0xFF)
- // {
- // TCRIT("Error in gettting netindex\n");
- // return 0;
- // }
- // if(Addr != NULL)
- // {
- // free(GratArpArgs->Argument);
- // free(Addr);
- // }
- // TDBG ("Gratuitous ARP thread starts for ethindex : %x\n",EthIndex);
- // while (1)
- // {
- // /*Is Gratiutous Arp Enabled */
- // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & GRATIUTOUS_ENABLE_MASK))
- // {
- // TDBG("Gratuitous ARP thread exits : Disable BMC-generated Gratuitous ARPs invoked\n");
- // break;
- // }
- // /*Is Gratiutous Arp Suspended */
- // Status = BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex];
- // if ((0 != (Status & GRATIUTOUS_ENABLE_MASK)) &&
- // (BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning == TRUE))
- // {
- // // Gratuitous ARP Suspended.
- // // sleep requested to access Shared memory for two different threads.
- // usleep (20);
- // continue;
- // }
- // nwReadNWCfg_v4_v6( &NWConfig,&NWConfig6, netindex,g_corefeatures.global_ipv6);
- // if(GetIfcName(EthIndex, IfcName,BMCInst) != 0)
- // {
- // TCRIT("Error in getting Interface Name for the Lan Index :%d\n",EthIndex);
-
- // }
- // if (NWConfig.IFName[0] == 0)
- // sprintf((char *)&NWConfig.IFName, "%s",IfcName);
- // TDBG ( "MAC is %2x:%2x:%2x:%2x:%2x:%2x \n", NWConfig.MAC [0], NWConfig.MAC [1],
- // NWConfig.MAC [2], NWConfig.MAC [3], NWConfig.MAC [4], NWConfig.MAC [5] );
- // TDBG ( "IP is %d.%d.%d.%d\n", NWConfig.IPAddr[0], NWConfig.IPAddr[1],
- // NWConfig.IPAddr[2], NWConfig.IPAddr[3]);
- // TDBG ( "Device Name : %s\n", (char *)&NWConfig.IFName);
- // nRet = SendGratuitousARPPacket((char *)&NWConfig.IFName, NWConfig.IPAddr, NWConfig.MAC);
- // if (0 != nRet)
- // {
- // TCRIT("Gratuitous ARP thread exits : Unable to Send Gratuitous ARP packet\n");
- // break;
- // }
- // TDBG ("Send Gratuitous Packet\n");
- // if (0 == pBMCInfo->LANCfs[EthIndex].GratitousARPInterval)
- // {
- // IntervalInSec = 2; //Default 2 secs
- // } else {
- // // Gratuitous ARP interval in 500 millisecond increments.
- // IntervalInSec = (pBMCInfo->LANCfs[EthIndex].GratitousARPInterval * 500)/1000;
- // }
- // usleep( IntervalInSec * 1000 * 1000 );
- // }
- // return 0;
- // }
- /*---------------------------------------------------
- * GetLanConfigParam
- *---------------------------------------------------*/
- int
- GetLanConfigParam ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
- {
- GetLanConfigReq_T* pGetLanReq = ( GetLanConfigReq_T*) pReq;
- GetLanConfigRes_T* pGetLanRes = ( GetLanConfigRes_T*) pRes;
- uint8_t EthIndex;
- char IfcName[16]; /* Eth interface name */
- pGetLanRes->CCParamRev.CompletionCode = CC_NORMAL;
- pGetLanRes->CCParamRev.ParamRevision = PARAMETER_REVISION_FORMAT;
- // printf("---> channel: %d, parameter: %#x, setslect: %#x, blockselect: %#x\n", pGetLanReq->ChannelNum, pGetLanReq->ParameterSelect, pGetLanReq->SetSelect, pGetLanReq->BlockSelect);
- if(pGetLanReq->ChannelNum & RESERVED_VALUE_70)
- {
- /* Alarm !!! Somebody is trying to set Reseved Bits */
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
-
- //! Validate the SetSelector value.
- if (0x00 != pGetLanReq->SetSelect)
- {
- printf("---> SetSelector not support!\n");
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
- //! Validate the BlockSelector value.
- if (0x00 != pGetLanReq->BlockSelect)
- {
- printf("---> BlockSelector not support!\n");
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (*pRes);
- }
- EthIndex= 0;
- sprintf(IfcName, "eth%d", EthIndex);
- if ((pGetLanReq->ChannelNum & GET_PARAMETER_REVISION_MASK) != 0)
- {
- if(MAX_LAN_CONF_PARAM >= pGetLanReq->ParameterSelect)
- {
- return sizeof(GetLanCCRev_T);
- }
- else
- {
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (*pRes);
- }
- }
- else
- {
- printf("GetLanConfigParam log4\n");
- switch(pGetLanReq->ParameterSelect)
- {
- case LAN_PARAM_SET_IN_PROGRESS:
- pGetLanRes->ConfigData.SetInProgress = 0;
- break;
- case LAN_PARAM_AUTH_TYPE_SUPPORT:
- pGetLanRes->ConfigData.AuthTypeSupport = 0x04; //only support MD5
- break;
- case LAN_PARAM_AUTH_TYPE_ENABLES:
- pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeCallBack = 0x04; //MD5
- pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeUser = 0x04;
- pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeOperator = 0x04;
- pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeAdmin = 0x04;
- pGetLanRes->ConfigData.AuthTypeEnables.AuthTypeOem = 0x04;
- break;
- case LAN_PARAM_IP_ADDRESS:
- pGetLanRes->ConfigData.IPAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[0];
- pGetLanRes->ConfigData.IPAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[1];
- pGetLanRes->ConfigData.IPAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[2];
- pGetLanRes->ConfigData.IPAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].IPAddr[3];
- break;
- case LAN_PARAM_IP_ADDRESS_SOURCE:
- pGetLanRes->ConfigData.IPAddrSrc = 1; //static
- break;
- case LAN_PARAM_MAC_ADDRESS:
- pGetLanRes->ConfigData.MACAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[0];
- pGetLanRes->ConfigData.MACAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[1];
- pGetLanRes->ConfigData.MACAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[2];
- pGetLanRes->ConfigData.MACAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[3];
- pGetLanRes->ConfigData.MACAddr[4] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[4];
- pGetLanRes->ConfigData.MACAddr[5] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].MACAddr[5];
- break;
- case LAN_PARAM_SUBNET_MASK:
- pGetLanRes->ConfigData.SubNetMask[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[0];
- pGetLanRes->ConfigData.SubNetMask[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[1];
- pGetLanRes->ConfigData.SubNetMask[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[2];
- pGetLanRes->ConfigData.SubNetMask[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].NetMask[3];
- break;
- case LAN_PARAM_IPv4_HEADER: //下面这些参数是多少不知道,参考LanIfc.c的SetIPv4Header函数。
- pGetLanRes->ConfigData.Ipv4HdrParam.TimeToLive = 64;
- pGetLanRes->ConfigData.Ipv4HdrParam.IpHeaderFlags = 0;
- pGetLanRes->ConfigData.Ipv4HdrParam.TypeOfService = 0x10; //default
- break;
- case LAN_PARAM_PRI_RMCP_PORT:
- pGetLanRes->ConfigData.PrimaryRMCPPort = LAN_RMCP_PORT; //LSB first
- break;
- case LAN_PARAM_SEC_RMCP_PORT:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_BMC_GENERATED_ARP_CONTROL:
- pGetLanRes->ConfigData.BMCGeneratedARPControl = 0;
- break;
- case LAN_PARAM_GRATITIOUS_ARP_INTERVAL:
- pGetLanRes->ConfigData.GratitousARPInterval = 4; //4*500ms
- break;
- case LAN_PARAM_DEFAULT_GATEWAY_IP:
- pGetLanRes->ConfigData.DefaultGatewayIPAddr[0] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[0];
- pGetLanRes->ConfigData.DefaultGatewayIPAddr[1] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[1];
- pGetLanRes->ConfigData.DefaultGatewayIPAddr[2] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[2];
- pGetLanRes->ConfigData.DefaultGatewayIPAddr[3] = g_BMCInfo.IpmiConfig.LanInfo[EthIndex].DefaultGW[3];
- break;
- case LAN_PARAM_DEFAULT_GATEWAY_MAC: //这个参数提供不了。
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_BACKUP_GATEWAY_IP:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_BACKUP_GATEWAY_MAC:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_COMMUNITY_STRING:
- sprintf(pGetLanRes->ConfigData.CommunityStr,"public");
- break;
- case LAN_PARAM_DEST_NUM:
- pGetLanRes->ConfigData.NumDest = 0;
- break;
- case LAN_PARAM_SELECT_DEST_TYPE:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_SELECT_DEST_ADDR:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_VLAN_ID:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_VLAN_PRIORITY:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_CIPHER_SUITE_ENTRY_SUP:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_CIPHER_SUITE_ENTRIES:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_CIPHER_SUITE_PRIV_LEVELS:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- case LAN_PARAM_VLAN_TAGS:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof (uint8_t);
- break;
- default:
- *pRes = CC_PARAM_NOT_SUPPORTED;
- return sizeof(uint8_t);
- break;
- }
- }
- return sizeof(GetLanCCRev_T) + LanconfigParameterLength[pGetLanReq->ParameterSelect];
- }
- // /*---------------------------------------------------
- // * SuspendBMCArps
- // *---------------------------------------------------*/
- // int
- // SuspendBMCArps ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
- // {
- // SuspendBMCArpsReq_T* pArpReq = ( SuspendBMCArpsReq_T*) pReq;
- // SuspendBMCArpsRes_T* pArpRes = ( SuspendBMCArpsRes_T*) pRes;
- // uint8_t EthIndex;
- // /* Verify Channel ID */
- // pArpRes->CompletionCode = CC_INV_DATA_FIELD;
- // if(pArpReq->ChannelNo & RESERVED_BITS_SUSPENDBMCARPS) return sizeof(*pRes);
- // if (!IsLANChannel(pArpReq->ChannelNo & CHANNEL_ID_MASK, BMCInst) )
- // {
- // return sizeof (*pRes);
- // }
- // EthIndex= GetEthIndex(pArpReq->ChannelNo & 0x0F,BMCInst);
- // if(0xff == EthIndex)
- // {
- // return sizeof (*pRes);
- // }
- // /* Reserved Bits Validation */
- // if (0 != (SUSPEND_ARP_RSVD_BIT_MASK & pArpReq->ArpSuspend))
- // {
- // return sizeof (*pRes);
- // }
- // if (BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning == TRUE)
- // BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] = pArpReq->ArpSuspend;
- // /* Update Response */
- // pArpRes->CompletionCode = CC_NORMAL;
- // pArpRes->ArpSuspendStatus = UpdateArpStatus(EthIndex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
- // return sizeof (SuspendBMCArpsRes_T);
- // }
- // /*---------------------------------------------------
- // * GetIPUDPRMCPStats
- // *---------------------------------------------------*/
- // int
- // GetIPUDPRMCPStats ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes, int BMCInst)
- // {
- // GetIPUDPRMCPStatsReq_T* pGetIPUDPRMCPStatsReq = ( GetIPUDPRMCPStatsReq_T*) pReq;
- // GetIPUDPRMCPStatsRes_T* pGetIPUDPRMCPStatsRes = ( GetIPUDPRMCPStatsRes_T*) pRes;
- // BMCSharedMem_T* pSharedMem = BMC_GET_SHARED_MEM (BMCInst);
- // FILE *fptr;
- // char FDRead[512], FSRead[512];
- // char *result = NULL;
- // char **StrArray;
- // int count = 0;
- // int cStrings =0;
- // if(pGetIPUDPRMCPStatsReq->ChannelNo & RESERVED_BITS_GETIPUDPRMCPSTATS_CH)
- // {
- // *pRes = CC_INV_DATA_FIELD;
- // return sizeof(*pRes);
- // }
- // if(pGetIPUDPRMCPStatsReq->ClearStatus & RESERVED_BITS_GETIPUDPRMCPSTATS_CLRSTATE)
- // {
- // *pRes = CC_INV_DATA_FIELD;
- // return sizeof(*pRes);
- // }
- // //Channel number [3:0] is valid.
- // if ( !IsLANChannel(pGetIPUDPRMCPStatsReq->ChannelNo & CHANNEL_ID_MASK, BMCInst) )
- // {
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_INV_DATA_FIELD;
- // return sizeof (*pRes);
- // }
- // //Clear the statistics if 1 is given in request.
- // if ( pGetIPUDPRMCPStatsReq->ClearStatus & 0x01 )
- // {
- // /* <TBD BalaT>
- // * Have to clear the already stored statistics when clear req is 1.
- // */
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
- // return sizeof (uint8_t);
- // }
- // //All Statistics values are initialised to 0.
- // memset (pGetIPUDPRMCPStatsRes, 0, sizeof(GetIPUDPRMCPStatsRes_T) );
- // //All the datas are taken from /proc/net/snmp file
- // fptr = fopen ("/proc/net/snmp","r+");
- // if (fptr == NULL)
- // {
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_COULD_NOT_PROVIDE_RESP;
- // return sizeof (uint8_t);
- // }
- // while( NULL != fgets(FDRead,512,fptr) )
- // {
- // if ( NULL != strstr (FDRead, "Ip: ") )
- // {
- // count++;
- // if (count == 2)
- // {
- // //To find the no. of valid strings in a line.
- // strcpy (FSRead, FDRead);
- // result = strtok( FSRead, " " );
- // while( result != NULL )
- // {
- // cStrings++;
- // result = strtok( NULL, " " );
- // }
- // //Condition to check so that explode doesnt try to read the strings from unknown location.
- // if ( cStrings == 20)
- // {
- // StrArray = explode (' ', FDRead);
- // }
- // else
- // {
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
- // return sizeof (uint8_t);
- // }
- // //All Statistics stops acumulating at FFFFh unless otherwise noted.
- // //IP packets received.
- // if ( atol((char *)StrArray[3]) > 0xffff)
- // pGetIPUDPRMCPStatsRes->IPPacketsRecv = ( ( atol((char *)StrArray[3]) ) % 65535);
- // else
- // pGetIPUDPRMCPStatsRes->IPPacketsRecv = atoi((char *)StrArray[3]);
- // //IP Header Error.
- // pGetIPUDPRMCPStatsRes->IPHeaderErr = atoi((char *)StrArray[4]);
- // //IP Address Error.
- // if ( atol((char *)StrArray[5]) > 0xffff)
- // pGetIPUDPRMCPStatsRes->IPAddrErr = ( ( atol((char *)StrArray[5]) ) % 65535);
- // else
- // pGetIPUDPRMCPStatsRes->IPAddrErr = atoi((char *)StrArray[5]);
- // //Fragmented IP Packets received.
- // if ( atol((char *)StrArray[17]) > 0xffff)
- // pGetIPUDPRMCPStatsRes->FragIPPacketsRecv = ( ( atol((char *)StrArray[17]) ) % 65535);
- // else
- // pGetIPUDPRMCPStatsRes->FragIPPacketsRecv = atoi((char *)StrArray[17]);
- // //IP packets Transmitted.
- // if ( atol((char *)StrArray[10]) > 0xffff)
- // pGetIPUDPRMCPStatsRes->IPPacketsTrans = ( ( atol((char *)StrArray[10]) ) % 65535);
- // else
- // pGetIPUDPRMCPStatsRes->IPPacketsTrans = atoi((char *)StrArray[10]);
- // count = 0;
- // }
- // }
-
- // if ( NULL != strstr (FDRead, "Udp: ") )
- // {
- // count++;
- // if (count == 2)
- // {
- // //To find the no. of valid strings in a line.
- // cStrings = 0;
- // strcpy (FSRead, FDRead);
- // result = strtok( FSRead, " " );
- // while( result != NULL )
- // {
- // cStrings++;
- // result = strtok( NULL, " " );
- // }
- // //Condition to check so that explode doesnt try to read the strings beyond the valid location.
- // if ( cStrings == 5)
- // {
- // StrArray = explode (' ', FDRead);
- // }
- // else
- // {
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
- // return sizeof (uint8_t);
- // }
- // //UDP packets received.
- // if ( atol((char *)StrArray[1]) > 0xffff)
- // pGetIPUDPRMCPStatsRes->UDPPacketsRecv = ( ( atol((char *)StrArray[1]) ) % 65535);
- // else
- // pGetIPUDPRMCPStatsRes->UDPPacketsRecv = atoi((char *)StrArray[1]);
- // count = 0;
- // }
- // }
- // }
- // fclose(fptr);
- // //Valid RMCP packets received.
- // pGetIPUDPRMCPStatsRes->ValidRMCPPackets = pSharedMem->gIPUDPRMCPStats;
- // //<TBD BalaT>To store the statistics across the system reset and power cycles
- // pGetIPUDPRMCPStatsRes->CompletionCode = CC_NORMAL;
- // return sizeof (GetIPUDPRMCPStatsRes_T);
- // }
- // /*-----------------------------------------------------
- // * explode
- // * Funntion to split the strings and store in an array
- // *-----------------------------------------------------*/
- // char **explode(char separator, char *string)
- // {
- // int start = 0, i, k = 1, count = 2;
- // char **strarr;
- // for (i = 0; string[i] != '\0'; i++)
- // /* how many rows do we need for our array? */
- // if (string[i] == separator)
- // count++;
- // /* count is at least 2 to make room for the entire string
- // * * and the ending NULL */
- // strarr = malloc(count * sizeof(char*));
- // i = 0;
- // while (*string++ != '\0')
- // {
- // if (*string == separator)
- // {
- // strarr[i] = malloc(k - start + 2);
- // strncpy(strarr[i], string - k + start, k - start + 1);
- // strarr[i][k - start + 1] = '\0'; /* guarantee null termination */
- // start = k;
- // i++;
- // }
- // k++;
- // }
- // /* copy the last part of the string after the last separator */
- // strarr[i] = malloc(k - start);
- // strncpy(strarr[i], string - k + start, k - start - 1);
- // strarr[i][k - start - 1] = '\0'; /* guarantee null termination */
- // strarr[++i] = NULL;
- // return strarr;
- // }
- // /*----------------------------------------------
- // * UpdateArpStatus
- // *----------------------------------------------*/
- // uint8_t
- // UpdateArpStatus (uint8_t EthIndex,BOOL IsTimerRunning, int BMCInst)
- // {
- // uint8_t GratArpSuspend;
- // uint8_t ArpSuspend;
- // uint8_t Status;
- // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- // char Cmds[50]={0}; // command string to perform BMC-generated ARP
- // char IfcName[16];
- // IPMI_DBG_PRINT_1 ("Timer - %x", IsTimerRunning);
- // GratArpSuspend = ArpSuspend = 1;
- // // Check Gratuitous ARP is Enabled
- // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & GRATIUTOUS_ENABLE_MASK))
- // {
- // GratArpSuspend = 0;
- // }
- // // Check ARP Response is Enabled
- // if (0 == (pBMCInfo->LANCfs[EthIndex].BMCGeneratedARPControl & ENABLE_ARP_RESPONSES))
- // {
- // ArpSuspend = 0;
- // }
- // /*Disable ARP */
- // if (TRUE == IsTimerRunning)
- // {
- // /* WDT is running, check and suspend ARP if necessary */
- // if( (0 != (BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] & SUSPEND_GRAT_ARP)) &&
- // (0 < GratArpSuspend) )
- // {
- // GratArpSuspend--;
- // }
- // if( (0 != (BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[EthIndex] & SUSPEND_ARP)) &&
- // (0 < ArpSuspend) )
- // {
- // ArpSuspend--;
- // }
- // }
-
- // memset(IfcName,0,sizeof(IfcName));
- // if(GetIfcName(EthIndex, IfcName, BMCInst) != 0)
- // {
- // TCRIT("Error in getting Interface Name for the Lan Index :%d\n", EthIndex);
- // }
- // else
- // {
- // /* Perform commands for BMC-generated Arp */
- // memset(Cmds, 0, sizeof(Cmds));
- // sprintf(Cmds, "/usr/local/bin/ArpSwitch.sh %s %d", IfcName, (!ArpSuspend) ? ARP_IGNORE_ON : ARP_IGNORE_OFF);
- // safe_system (Cmds);
- // /* Perform commands for BMC-generated Arp ends */
- // }
-
- // /* Update Status */
- // Status = ArpSuspend << 1;
- // Status = Status | GratArpSuspend;
- // return Status;
- // }
- // /**
- // *@fn NwInterfacePresenceCheck
- // *@brief This function is invoked to check network interface presence
- // *@param Interface - Char Pointer to Interface for which interface to check
- // *@return Returns 0 on success
- // */
- // static int
- // NwInterfacePresenceCheck (char * Interface)
- // {
- // int r;
- // int sockdes;
- // struct ifreq Ifreq;
- // unsigned char MAC[MAC_ADDR_LEN];
- // IPMI_DBG_PRINT_1 ("Checking the presence of %s\n", Interface);
- // sockdes = socket(PF_INET, SOCK_DGRAM, 0 );
- // if ( sockdes < 0 )
- // {
- // IPMI_ERROR("can't open socket: %s\n",strerror(errno));
- // return -1;
- // }
- // /* Get MAC address */
- // memset(&Ifreq,0,sizeof(struct ifreq));
- // memset(MAC, 0, MAC_ADDR_LEN);
- // strcpy(Ifreq.ifr_name, Interface);
- // Ifreq.ifr_hwaddr.sa_family = AF_INET;
- // r = ioctl(sockdes, SIOCGIFHWADDR, &Ifreq);
- // close (sockdes);
- // if ( r < 0 )
- // {
- // //IPMI_ERROR("IOCTL to get MAC failed: %d\n",r);
- // return -1;
- // }
- // IPMI_DBG_PRINT_1 (" %s Interface is present\n", Interface);
- // return 0;
- // }
|