#include #include "OemSMMCmds.h" #include "com_BmcType.h" #include "main.h" #include "Storlead.h" #include "SensorMonitor.h" #include "Sensor.h" #include "com_IPMI_SDRRecord.h" #include "SDR.h" #include "SELRecord.h" int Storlead_GetSysInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes) { char Title[] = "系统信息"; char Text[] = "模块名称:多端口光纤接口模块;FPGA型号:XC7VX690T;简介: "; int len = 0,remainLen = 0; uint16_t offset = (pReq[1]<<8) | pReq[2]; int totalLen = 0; char *pStr = NULL; int reqLen = (pReq[3]<<8) | pReq[4]; switch(pReq[0]) { case 0: //get Title while(Title[totalLen]) { totalLen++; }printf("title total len = %#x\n",totalLen); pStr = Title; break; case 1: while(Text[totalLen]) { totalLen++; } printf("text total len = %#x\n", totalLen); pStr = Text; break; default: *pRes = CC_PARAM_OUT_OF_RANGE; return 1; } *pRes= CC_NORMAL; if(offset > totalLen) { printf("Invalid offset: %#x\n", offset); *pRes= CC_PARAM_OUT_OF_RANGE; return 1; } if(reqLen == 0) { len = totalLen - offset; } else { len = (reqLen > (totalLen-offset)) ? (totalLen-offset) : reqLen; } remainLen = totalLen - offset - len; *(pRes+1) = (len>>8)&0xff; *(pRes+2) = len&0xff; *(pRes+3) = (remainLen>>8)&0xff; *(pRes+4) = remainLen&0xff; memcpy(pRes+5, pStr+offset, len); // int i; // printf("Example 80h: "); // for(i=0;i<5+len;i++) // printf("%#x ", pRes[i]); // printf("\n"); return 5+len; } int Storlead_GetSensorInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes) { // printf("Storlead_GetSensorInfo\n" ); StorleadGetSensorInfoRes_T *pGetSensorInfoRes = (StorleadGetSensorInfoRes_T *)pRes; uint8_t* pValidSensor = NULL; uint16_t SensorIndex = pReq[0]; SensorInfo_T pSensor ; SenInfo_T SensorInfo; uint8_t SensorIsSigned = FALSE; uint16_t SensorReading = 0; SensorSharedMem_T* pSMSharedMem; SDRRecHdr_T* pSDRRec; FullSensorRec_T* FullSDR; CompactSensorRec_T* CompSDR; int i = 0; int totalsize; /* Get the Sensor Shared Memory */ pSMSharedMem = (SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; if(g_BMCInfo.SenConfig.ValidSensorCnt == 0) { pGetSensorInfoRes->CompletionCode = OEMCC_SENSOR_INFO_EMPTY; printf("ValidSensorCnt is 0\n"); return 1; } if(SensorIndex >= g_BMCInfo.SenConfig.ValidSensorCnt) { pGetSensorInfoRes->CompletionCode = CC_PARAM_OUT_OF_RANGE; printf("Invalid SenosrIndex %d\n", SensorIndex); return 1; } //pValidSensor = (uint8_t*)(pAMIGetSensorInfoRes+1); // for(i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++) // { //SensorIndex = g_BMCInfo.SenConfig.ValidSensorList[i]; pSensor = pSMSharedMem->SensorInfo[SensorIndex]; /*Copy the SDR Header*/ memcpy(&pGetSensorInfoRes->SensorInfo.hdr,pSensor.SDRRec,sizeof(SDRRecHdr_T)); pGetSensorInfoRes->SensorInfo.SensorNumber = pSensor.SensorNumber; pGetSensorInfoRes->SensorInfo.SensorTypeCode = pSensor.SensorTypeCode; pGetSensorInfoRes->SensorInfo.EventTypeCode = pSensor.EventTypeCode; pGetSensorInfoRes->SensorInfo.Units1 = pSensor.Units1; pGetSensorInfoRes->SensorInfo.Units2 = pSensor.Units2; pGetSensorInfoRes->SensorInfo.Units3 = pSensor.Units3; pGetSensorInfoRes->SensorInfo.M_LSB = pSensor.M_LSB; pGetSensorInfoRes->SensorInfo.M_MSB_Tolerance = pSensor.M_MSB_Tolerance; pGetSensorInfoRes->SensorInfo.B_LSB = pSensor.B_LSB; pGetSensorInfoRes->SensorInfo.B_MSB_Accuracy = pSensor.B_MSB_Accuracy; pGetSensorInfoRes->SensorInfo.Accuracy_MSB_Exp = pSensor.Accuracy_MSB_Exp; pGetSensorInfoRes->SensorInfo.RExp_BExp = pSensor.RExp_BExp; pGetSensorInfoRes->SensorInfo.LowerNonCritical = pSensor.LowerNonCritical; pGetSensorInfoRes->SensorInfo.LowerCritical = pSensor.LowerCritical; pGetSensorInfoRes->SensorInfo.LowerNonRecoverable = pSensor.LowerNonRecoverable; pGetSensorInfoRes->SensorInfo.UpperNonCritical = pSensor.UpperNonCritical; pGetSensorInfoRes->SensorInfo.UpperCritical = pSensor.UpperCritical; pGetSensorInfoRes->SensorInfo.UpperNonRecoverable= pSensor.UpperNonRecoverable; pGetSensorInfoRes->SensorInfo.Settable_Readable_ThreshMask= pSensor.SettableThreshMask; pGetSensorInfoRes->SensorInfo.Flags = pSensor.EventFlags & 0xe0; if((pSensor.EventFlags & BIT5) != 0) { pGetSensorInfoRes->SensorInfo.SensorReading = 0; } SensorReading = pSensor.SensorReading; pGetSensorInfoRes->SensorInfo.SensorReading = 0; SensorIsSigned = ( 0 != (pSensor.InternalFlags & BIT1)); if (THRESHOLD_SENSOR_CLASS == pSensor.EventTypeCode) { pGetSensorInfoRes->SensorInfo.SensorReading = (SensorReading & 0x00FF); pGetSensorInfoRes->SensorInfo.ComparisonStatus = 0; if((pSensor.DeassertionEventEnablesByte2 & BIT6) == BIT6 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonRecoverable) >= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT5; } } if((pSensor.DeassertionEventEnablesByte2 & BIT5) == BIT5 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperCritical) >= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT4; } } if((pSensor.DeassertionEventEnablesByte2 & BIT4) == BIT4 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonCritical) >= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT3; } } if((pSensor.AssertionEventEnablesByte2 & BIT6) == BIT6 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonRecoverable) <= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT2; } } if((pSensor.AssertionEventEnablesByte2 & BIT5) == BIT5 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerCritical) <= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT1; } } if((pSensor.AssertionEventEnablesByte2 & BIT4) == BIT4 ) { if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonCritical) <= 0) { pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT0; } } pGetSensorInfoRes->SensorInfo.ComparisonStatus &= ((pSensor.SettableThreshMask >> 8) & 0xFF); pGetSensorInfoRes->SensorInfo.OptionalStatus = 0; // For Threshold sensor, [7:6] - reserved. Returned as 1b. Ignore on read. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= THRESHOLD_RESERVED_BIT; } else { pGetSensorInfoRes->SensorInfo.ComparisonStatus = (((uint8_t) (SensorReading & 0x00FF)) & ((uint8_t) (pSensor.SettableThreshMask & 0x00FF)) ); pGetSensorInfoRes->SensorInfo.OptionalStatus = (((uint8_t) (SensorReading >> 8)) & ((uint8_t) (pSensor.SettableThreshMask >> 8)) ); // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read. pGetSensorInfoRes->SensorInfo.OptionalStatus |= DISCRETE_RESERVED_BIT; } if((pSensor.EventFlags & BIT7) == 0) { pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = 0; pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = 0; pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = 0; pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = 0; } if((pSensor.SensorCaps & BIT6) == 0) { pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionHistoryByte1 & pSensor.AssertionEventEnablesByte1); pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionHistoryByte2 & pSensor.AssertionEventEnablesByte2); pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionHistoryByte1 & pSensor.DeassertionEventEnablesByte1); pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionHistoryByte2 & pSensor.DeassertionEventEnablesByte2); } else { pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionEventOccuredByte1 & pSensor.AssertionEventEnablesByte1); pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionEventOccuredByte2 & pSensor.AssertionEventEnablesByte2); pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionEventOccuredByte1 & pSensor.DeassertionEventEnablesByte1); pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionEventOccuredByte2 & pSensor.DeassertionEventEnablesByte2); } pSDRRec = GetSDRRec(pSensor.SDRRec->ID); if(pSensor.SDRRec->Type == FULL_SDR_REC) /*Full SDR*/ { FullSDR = (FullSensorRec_T *)pSDRRec; pGetSensorInfoRes->SensorInfo.OwnerID = FullSDR->OwnerID; pGetSensorInfoRes->SensorInfo.OwnerLUN= FullSDR->OwnerLUN; pGetSensorInfoRes->SensorInfo.MaxReading = FullSDR->MaxReading; pGetSensorInfoRes->SensorInfo.MinReading = FullSDR->MinReading; pGetSensorInfoRes->SensorInfo.Linearization = FullSDR->Linearization; memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN); strncpy(pGetSensorInfoRes->SensorInfo.SensorName,FullSDR->IDStr, MAX_ID_STR_LEN - (sizeof(FullSensorRec_T) - sizeof(SDRRecHdr_T) - FullSDR->hdr.Len)); } else if(pSensor.SDRRec->Type == COMPACT_SDR_REC) /*Compact SDR*/ { CompSDR = (CompactSensorRec_T *)pSDRRec; pGetSensorInfoRes->SensorInfo.OwnerID = CompSDR->OwnerID; pGetSensorInfoRes->SensorInfo.OwnerLUN= CompSDR->OwnerLUN; pGetSensorInfoRes->SensorInfo.MaxReading = 0; pGetSensorInfoRes->SensorInfo.MinReading = 0; pGetSensorInfoRes->SensorInfo.Linearization = 0; memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN); strncpy(pGetSensorInfoRes->SensorInfo.SensorName,CompSDR->IDStr, MAX_ID_STR_LEN - (sizeof(CompactSensorRec_T) - sizeof(SDRRecHdr_T) - CompSDR->hdr.Len)); } //memcpy(pValidSensor,(uint8_t *)&SensorInfo,sizeof(SenInfo_T)); //pValidSensor = pValidSensor + sizeof(SenInfo_T); //} pGetSensorInfoRes->CompletionCode = CC_NORMAL; //pAMIGetSensorInfoRes->Noofentries = g_BMCInfo.SenConfig.ValidSensorCnt; //totalsize = sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * 11/*g_BMCInfo.SenConfig.ValidSensorCnt*/); // printf("return %d :", totalsize); // for(i=0;iNumRecords; // if(((NumRecords - pAMIGetSelEntriesReq->Noofentretrieved) * sizeof(SELRec_T)) < MAX_FULL_SEL_ENTRIES) // { // pAMIGetSelEntiresRes->Status = FULL_SEL_ENTRIES; // pAMIGetSelEntiresRes->Noofentries = NumRecords - pAMIGetSelEntriesReq->Noofentretrieved; // } // else if(NumRecords == SEL_EMPTY_REPOSITORY) // { // pAMIGetSelEntiresRes->CompletionCode = OEMCC_SEL_EMPTY_REPOSITORY; // return sizeof(*pRes); // } // else if (NumRecords < pAMIGetSelEntriesReq->Noofentretrieved) // { // pAMIGetSelEntiresRes->CompletionCode = OEMCC_SEL_CLEARED; // return sizeof(*pRes); // } // else // { // pAMIGetSelEntiresRes->Status = PARTIAL_SEL_ENTRIES; // pAMIGetSelEntiresRes->Noofentries = ((MAX_FULL_SEL_ENTRIES - sizeof(AMIGetSELEntriesRes_T))/sizeof(SELRec_T)); // } // memcpy((uint8_t*)(pAMIGetSelEntiresRes + 1),(uint8_t*)&m_sel->SELRecord[pAMIGetSelEntriesReq->Noofentretrieved], // sizeof(SELRec_T)*pAMIGetSelEntiresRes->Noofentries); // pAMIGetSelEntiresRes->LastRecID = m_sel->LastRecID; // pAMIGetSelEntiresRes->CompletionCode = CC_NORMAL; // return sizeof(AMIGetSELEntriesRes_T) + (sizeof(SELRec_T) * pAMIGetSelEntiresRes->Noofentries); return 1; } int Storlead_AuthorVerify(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { AuthorVerify_T *pAuthorVerify = (AuthorVerify_T *)pReq; int i; printf("Storlead_AuthorVerify, username: %s, password: %s\n", pAuthorVerify->name, pAuthorVerify->password); for(i=0;iname) == 0) { if(strcmp(g_BMCInfo.UserInfoTbl[i].UserPassword, pAuthorVerify->password)==0) { *pRes = CC_NORMAL; return 1; } else { printf("Invalid password!\n"); *pRes = CC_PASSWORD_TEST_FAILED; return 1; } } } printf("Invalid username!\n"); *pRes = CC_PASSWORD_TEST_FAILED; return 1; } /* Req[0]: sensor number Req[1]: offset_lsb Req[2]: offset_msb Req[3]: readlen_lsb Req[4]: readlen_msb ----------------------- Res[0]: ccode Res[1]: return len lsb Res[2]: return len msb */ int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { uint8_t *pSensorHistory = pRes+3; uint8_t sensorNum = pReq[0]; uint16_t offset = (pReq[2]<<8) | pReq[1]; uint16_t len = (pReq[4]<<8) | pReq[3]; uint16_t total_len = 480; *pRes= CC_NORMAL; if(offset >= total_len) { *pRes = CC_PARAM_OUT_OF_RANGE; return 1; } if(getSensorHistory(sensorNum, pSensorHistory) != 0) { *pRes = CC_PARAM_OUT_OF_RANGE; return 1; }; if(len > (total_len - offset)) len = total_len - offset; printf("len = %d, offset = %d, total_len = %d\n", len, offset, total_len); *(pRes+1) = len&0xff; *(pRes+2) = (len>>8)&0xff; return len+3; } int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { *pRes = CC_NORMAL; //for test int i; for(i=0;i= FAN_NUMBERS) { printf("Invalid index %d\n", index); *pRes = CC_PARAM_OUT_OF_RANGE; return 1; } if(mode > 1) { printf("Invalid mode %d\n", mode); *pRes = CC_PARAM_OUT_OF_RANGE; return 1; } if(level > 100) level = 100; gFanInfo[index].mode = mode; if(mode == 1) { gFanInfo[index].level = level; } return 1; } /* Req[0]: ChassisManageEn */ int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { int i, index; uint8_t mReq[100] = {0}; MsgPkt_T ReqPkt; MsgPkt_T ResPkt; pRes[0] = CC_NORMAL; //if(pReq[0] == 0) if(g_BMCInfo.isChMC == 0) { for(i=0;i 0) { pRes[0] = CC_PARAM_OUT_OF_RANGE; return 1; } //Update LanInfo char ip_buf[16]; getip(ip_buf); g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0); g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1); g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2); g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3); char mask_buf[16]; getnetmask(mask_buf); g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0); g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1); g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2); g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3); char broadcast_buf[16]; getbroadcast(broadcast_buf); g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0); g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1); g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2); g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3); char mac_buf[18]; getmac(mac_buf); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4); g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5); //TODO: get default GetWay memcpy(pRes+1, &g_BMCInfo.IpmiConfig.LanInfo[index], sizeof(LanInfo_T)); return 1+sizeof(LanInfo_T); } /* Req[0]: index Req[1]: isSave 0:掉电不保存,1:掉电保存 Req[2~n]: LanInfo_T */ int Storlead_SetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { MsgPkt_T m_MsgPkt; uint8_t index = pReq[0]; uint8_t isSave = pReq[1]; LanInfo_T *pLanInfo = (LanInfo_T*)&pReq[2]; if(index > 0) //只有一张网卡,index只能是0 { pRes[0] = CC_PARAM_OUT_OF_RANGE; return 1; } memcpy(&g_BMCInfo.IpmiConfig.LanInfo[index], pLanInfo, sizeof(LanInfo_T)); m_MsgPkt.Param = PARAM_LAN; m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD; m_MsgPkt.Cmd = CMD_SET_LAN_INFO; m_MsgPkt.Size = sizeof(LanInfo_T)+2; m_MsgPkt.Data[0] = index; m_MsgPkt.Data[1] = isSave; memcpy(&m_MsgPkt.Data[2], pLanInfo, sizeof(LanInfo_T)); PostMsg(gPendActionIfc, &m_MsgPkt); pRes[0] = CC_NORMAL; return 1; } /* res[0]: completeCode res[1]: healthStatus; //0: 未知(灰色) 1:健康(绿色) 2:警告(黄色)3:错误(红色) res[2-22]: bladeName[31]; //10个汉字或30个字符 res[23]: slotID; res[24]: pwrStatus; //0:未上电(灰色) 1:已上电(绿色) */ int Storlead_GetBladeInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { pRes[0] = CC_NORMAL; pRes[1] = g_BMCInfo.BladeHealthSta; memcpy(&pRes[2], g_BMCInfo.BladeName, 31); pRes[33] = g_BMCInfo.SlotID; pRes[34] = g_BMCInfo.PowerGoodFlag; return 35; } /* Req[0] : sensor number */ int Storlead_GetSensorName(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes) { int i; SensorInfo_T* pSensorInfo; memset(pRes, 0, MAX_ID_STR_LEN+1); for(i=0;iSensorNumber) { memcpy(&pRes[1], ((FullSensorRec_T*)pSensorInfo->SDRRec)->IDStr, MAX_ID_STR_LEN); break; } } return MAX_ID_STR_LEN+1; }