Storlead.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #include <string.h>
  2. #include "OemSMMCmds.h"
  3. #include "com_BmcType.h"
  4. #include "main.h"
  5. #include "Storlead.h"
  6. #include "SensorMonitor.h"
  7. #include "Sensor.h"
  8. #include "com_IPMI_SDRRecord.h"
  9. #include "SDR.h"
  10. #include "SELRecord.h"
  11. int Storlead_GetSysInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  12. {
  13. char Title[] = "系统信息";
  14. char Text[] = "模块名称:多端口光纤接口模块;FPGA型号:XC7VX690T;简介: ";
  15. int len = 0,remainLen = 0;
  16. uint16_t offset = (pReq[1]<<8) | pReq[2];
  17. int totalLen = 0;
  18. char *pStr = NULL;
  19. int reqLen = (pReq[3]<<8) | pReq[4];
  20. switch(pReq[0])
  21. {
  22. case 0: //get Title
  23. while(Title[totalLen])
  24. {
  25. totalLen++;
  26. }printf("title total len = %#x\n",totalLen);
  27. pStr = Title;
  28. break;
  29. case 1:
  30. while(Text[totalLen])
  31. {
  32. totalLen++;
  33. }
  34. printf("text total len = %#x\n", totalLen);
  35. pStr = Text;
  36. break;
  37. default:
  38. *pRes = CC_PARAM_OUT_OF_RANGE;
  39. return 1;
  40. }
  41. *pRes= CC_NORMAL;
  42. if(offset > totalLen)
  43. {
  44. printf("Invalid offset: %#x\n", offset);
  45. *pRes= CC_PARAM_OUT_OF_RANGE;
  46. return 1;
  47. }
  48. if(reqLen == 0)
  49. {
  50. len = totalLen - offset;
  51. }
  52. else
  53. {
  54. len = (reqLen > (totalLen-offset)) ? (totalLen-offset) : reqLen;
  55. }
  56. remainLen = totalLen - offset - len;
  57. *(pRes+1) = (len>>8)&0xff;
  58. *(pRes+2) = len&0xff;
  59. *(pRes+3) = (remainLen>>8)&0xff;
  60. *(pRes+4) = remainLen&0xff;
  61. memcpy(pRes+5, pStr+offset, len);
  62. // int i;
  63. // printf("Example 80h: ");
  64. // for(i=0;i<5+len;i++)
  65. // printf("%#x ", pRes[i]);
  66. // printf("\n");
  67. return 5+len;
  68. }
  69. int Storlead_GetSensorInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  70. {
  71. printf("Storlead_GetSensorInfo\n" );
  72. StorleadGetSensorInfoRes_T *pGetSensorInfoRes = (StorleadGetSensorInfoRes_T *)pRes;
  73. uint8_t* pValidSensor = NULL;
  74. uint16_t SensorIndex = pReq[0];
  75. SensorInfo_T pSensor ;
  76. SenInfo_T SensorInfo;
  77. uint8_t SensorIsSigned = FALSE;
  78. uint16_t SensorReading = 0;
  79. SensorSharedMem_T* pSMSharedMem;
  80. SDRRecHdr_T* pSDRRec;
  81. FullSensorRec_T* FullSDR;
  82. CompactSensorRec_T* CompSDR;
  83. int i = 0;
  84. int totalsize;
  85. /* Get the Sensor Shared Memory */
  86. pSMSharedMem = (SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem;
  87. if(g_BMCInfo.SenConfig.ValidSensorCnt == 0)
  88. {
  89. pGetSensorInfoRes->CompletionCode = OEMCC_SENSOR_INFO_EMPTY;
  90. printf("ValidSensorCnt is 0\n");
  91. return 1;
  92. }
  93. if(SensorIndex >= g_BMCInfo.SenConfig.ValidSensorCnt)
  94. {
  95. pGetSensorInfoRes->CompletionCode = CC_PARAM_OUT_OF_RANGE;
  96. printf("Invalid SenosrIndex %d\n", SensorIndex);
  97. return 1;
  98. }
  99. //pValidSensor = (uint8_t*)(pAMIGetSensorInfoRes+1);
  100. // for(i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++)
  101. // {
  102. //SensorIndex = g_BMCInfo.SenConfig.ValidSensorList[i];
  103. pSensor = pSMSharedMem->SensorInfo[SensorIndex];
  104. /*Copy the SDR Header*/
  105. memcpy(&pGetSensorInfoRes->SensorInfo.hdr,pSensor.SDRRec,sizeof(SDRRecHdr_T));
  106. pGetSensorInfoRes->SensorInfo.SensorNumber = pSensor.SensorNumber;
  107. pGetSensorInfoRes->SensorInfo.SensorTypeCode = pSensor.SensorTypeCode;
  108. pGetSensorInfoRes->SensorInfo.EventTypeCode = pSensor.EventTypeCode;
  109. pGetSensorInfoRes->SensorInfo.Units1 = pSensor.Units1;
  110. pGetSensorInfoRes->SensorInfo.Units2 = pSensor.Units2;
  111. pGetSensorInfoRes->SensorInfo.Units3 = pSensor.Units3;
  112. pGetSensorInfoRes->SensorInfo.M_LSB = pSensor.M_LSB;
  113. pGetSensorInfoRes->SensorInfo.M_MSB_Tolerance = pSensor.M_MSB_Tolerance;
  114. pGetSensorInfoRes->SensorInfo.B_LSB = pSensor.B_LSB;
  115. pGetSensorInfoRes->SensorInfo.B_MSB_Accuracy = pSensor.B_MSB_Accuracy;
  116. pGetSensorInfoRes->SensorInfo.Accuracy_MSB_Exp = pSensor.Accuracy_MSB_Exp;
  117. pGetSensorInfoRes->SensorInfo.RExp_BExp = pSensor.RExp_BExp;
  118. pGetSensorInfoRes->SensorInfo.LowerNonCritical = pSensor.LowerNonCritical;
  119. pGetSensorInfoRes->SensorInfo.LowerCritical = pSensor.LowerCritical;
  120. pGetSensorInfoRes->SensorInfo.LowerNonRecoverable = pSensor.LowerNonRecoverable;
  121. pGetSensorInfoRes->SensorInfo.UpperNonCritical = pSensor.UpperNonCritical;
  122. pGetSensorInfoRes->SensorInfo.UpperCritical = pSensor.UpperCritical;
  123. pGetSensorInfoRes->SensorInfo.UpperNonRecoverable= pSensor.UpperNonRecoverable;
  124. pGetSensorInfoRes->SensorInfo.Settable_Readable_ThreshMask= pSensor.SettableThreshMask;
  125. pGetSensorInfoRes->SensorInfo.Flags = pSensor.EventFlags & 0xe0;
  126. if((pSensor.EventFlags & BIT5) != 0)
  127. {
  128. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  129. }
  130. SensorReading = pSensor.SensorReading;
  131. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  132. SensorIsSigned = ( 0 != (pSensor.InternalFlags & BIT1));
  133. if (THRESHOLD_SENSOR_CLASS == pSensor.EventTypeCode)
  134. {
  135. pGetSensorInfoRes->SensorInfo.SensorReading = (SensorReading & 0x00FF);
  136. pGetSensorInfoRes->SensorInfo.ComparisonStatus = 0;
  137. if((pSensor.DeassertionEventEnablesByte2 & BIT6) == BIT6 )
  138. {
  139. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonRecoverable) >= 0)
  140. {
  141. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT5;
  142. }
  143. }
  144. if((pSensor.DeassertionEventEnablesByte2 & BIT5) == BIT5 )
  145. {
  146. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperCritical) >= 0)
  147. {
  148. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT4;
  149. }
  150. }
  151. if((pSensor.DeassertionEventEnablesByte2 & BIT4) == BIT4 )
  152. {
  153. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonCritical) >= 0)
  154. {
  155. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT3;
  156. }
  157. }
  158. if((pSensor.AssertionEventEnablesByte2 & BIT6) == BIT6 )
  159. {
  160. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonRecoverable) <= 0)
  161. {
  162. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT2;
  163. }
  164. }
  165. if((pSensor.AssertionEventEnablesByte2 & BIT5) == BIT5 )
  166. {
  167. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerCritical) <= 0)
  168. {
  169. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT1;
  170. }
  171. }
  172. if((pSensor.AssertionEventEnablesByte2 & BIT4) == BIT4 )
  173. {
  174. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonCritical) <= 0)
  175. {
  176. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT0;
  177. }
  178. }
  179. pGetSensorInfoRes->SensorInfo.ComparisonStatus &= ((pSensor.SettableThreshMask >> 8) & 0xFF);
  180. pGetSensorInfoRes->SensorInfo.OptionalStatus = 0;
  181. // For Threshold sensor, [7:6] - reserved. Returned as 1b. Ignore on read.
  182. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= THRESHOLD_RESERVED_BIT;
  183. }
  184. else
  185. {
  186. pGetSensorInfoRes->SensorInfo.ComparisonStatus = (((uint8_t) (SensorReading & 0x00FF)) & ((uint8_t) (pSensor.SettableThreshMask & 0x00FF)) );
  187. pGetSensorInfoRes->SensorInfo.OptionalStatus = (((uint8_t) (SensorReading >> 8)) & ((uint8_t) (pSensor.SettableThreshMask >> 8)) );
  188. // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read.
  189. pGetSensorInfoRes->SensorInfo.OptionalStatus |= DISCRETE_RESERVED_BIT;
  190. }
  191. if((pSensor.EventFlags & BIT7) == 0)
  192. {
  193. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = 0;
  194. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = 0;
  195. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = 0;
  196. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = 0;
  197. }
  198. if((pSensor.SensorCaps & BIT6) == 0)
  199. {
  200. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionHistoryByte1 & pSensor.AssertionEventEnablesByte1);
  201. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionHistoryByte2 & pSensor.AssertionEventEnablesByte2);
  202. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionHistoryByte1 & pSensor.DeassertionEventEnablesByte1);
  203. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionHistoryByte2 & pSensor.DeassertionEventEnablesByte2);
  204. }
  205. else
  206. {
  207. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionEventOccuredByte1 & pSensor.AssertionEventEnablesByte1);
  208. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionEventOccuredByte2 & pSensor.AssertionEventEnablesByte2);
  209. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionEventOccuredByte1 & pSensor.DeassertionEventEnablesByte1);
  210. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionEventOccuredByte2 & pSensor.DeassertionEventEnablesByte2);
  211. }
  212. pSDRRec = GetSDRRec(pSensor.SDRRec->ID);
  213. if(pSensor.SDRRec->Type == FULL_SDR_REC) /*Full SDR*/
  214. {
  215. FullSDR = (FullSensorRec_T *)pSDRRec;
  216. pGetSensorInfoRes->SensorInfo.OwnerID = FullSDR->OwnerID;
  217. pGetSensorInfoRes->SensorInfo.OwnerLUN= FullSDR->OwnerLUN;
  218. pGetSensorInfoRes->SensorInfo.MaxReading = FullSDR->MaxReading;
  219. pGetSensorInfoRes->SensorInfo.MinReading = FullSDR->MinReading;
  220. pGetSensorInfoRes->SensorInfo.Linearization = FullSDR->Linearization;
  221. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  222. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,FullSDR->IDStr, MAX_ID_STR_LEN - (sizeof(FullSensorRec_T) - sizeof(SDRRecHdr_T) - FullSDR->hdr.Len));
  223. }
  224. else if(pSensor.SDRRec->Type == COMPACT_SDR_REC) /*Compact SDR*/
  225. {
  226. CompSDR = (CompactSensorRec_T *)pSDRRec;
  227. pGetSensorInfoRes->SensorInfo.OwnerID = CompSDR->OwnerID;
  228. pGetSensorInfoRes->SensorInfo.OwnerLUN= CompSDR->OwnerLUN;
  229. pGetSensorInfoRes->SensorInfo.MaxReading = 0;
  230. pGetSensorInfoRes->SensorInfo.MinReading = 0;
  231. pGetSensorInfoRes->SensorInfo.Linearization = 0;
  232. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  233. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,CompSDR->IDStr, MAX_ID_STR_LEN - (sizeof(CompactSensorRec_T) - sizeof(SDRRecHdr_T) - CompSDR->hdr.Len));
  234. }
  235. //memcpy(pValidSensor,(uint8_t *)&SensorInfo,sizeof(SenInfo_T));
  236. //pValidSensor = pValidSensor + sizeof(SenInfo_T);
  237. //}
  238. pGetSensorInfoRes->CompletionCode = CC_NORMAL;
  239. //pAMIGetSensorInfoRes->Noofentries = g_BMCInfo.SenConfig.ValidSensorCnt;
  240. //totalsize = sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * 11/*g_BMCInfo.SenConfig.ValidSensorCnt*/);
  241. // printf("return %d :", totalsize);
  242. // for(i=0;i<sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * g_BMCInfo.SenConfig.ValidSensorCnt);i++)
  243. // printf("%#x ", pRes[i]);
  244. // printf("\n");
  245. return sizeof(StorleadGetSensorInfoRes_T);
  246. }
  247. /*
  248. *@fn AMIGetSELEntires
  249. *@param This function retrieves the SEL entries
  250. *@return Returns CC_NORMAL
  251. */
  252. #define MAX_FULL_SEL_ENTRIES 900 //18*50=900, 50个SEL Entry, 每个18字节
  253. int Storlead_GetSELEntires(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  254. {
  255. AMIGetSELEntriesReq_T *pAMIGetSelEntriesReq = (AMIGetSELEntriesReq_T *)pReq;
  256. AMIGetSELEntriesRes_T *pAMIGetSelEntiresRes = (AMIGetSELEntriesRes_T *)pRes;
  257. SELRepository_T *m_sel = NULL;
  258. uint16_t NumRecords = 0;
  259. m_sel = (SELRepository_T*)g_BMCInfo.pSEL;
  260. NumRecords = m_sel->NumRecords;
  261. if(((NumRecords - pAMIGetSelEntriesReq->Noofentretrieved) * sizeof(SELRec_T)) < MAX_FULL_SEL_ENTRIES)
  262. {
  263. pAMIGetSelEntiresRes->Status = FULL_SEL_ENTRIES;
  264. pAMIGetSelEntiresRes->Noofentries = NumRecords - pAMIGetSelEntriesReq->Noofentretrieved;
  265. }
  266. else if(NumRecords == SEL_EMPTY_REPOSITORY)
  267. {
  268. pAMIGetSelEntiresRes->CompletionCode = OEMCC_SEL_EMPTY_REPOSITORY;
  269. return sizeof(*pRes);
  270. }
  271. else if (NumRecords < pAMIGetSelEntriesReq->Noofentretrieved)
  272. {
  273. pAMIGetSelEntiresRes->CompletionCode = OEMCC_SEL_CLEARED;
  274. return sizeof(*pRes);
  275. }
  276. else
  277. {
  278. pAMIGetSelEntiresRes->Status = PARTIAL_SEL_ENTRIES;
  279. pAMIGetSelEntiresRes->Noofentries = ((MAX_FULL_SEL_ENTRIES - sizeof(AMIGetSELEntriesRes_T))/sizeof(SELRec_T));
  280. }
  281. memcpy((uint8_t*)(pAMIGetSelEntiresRes + 1),(uint8_t*)&m_sel->SELRecord[pAMIGetSelEntriesReq->Noofentretrieved],
  282. sizeof(SELRec_T)*pAMIGetSelEntiresRes->Noofentries);
  283. pAMIGetSelEntiresRes->LastRecID = m_sel->LastRecID;
  284. pAMIGetSelEntiresRes->CompletionCode = CC_NORMAL;
  285. return sizeof(AMIGetSELEntriesRes_T) + (sizeof(SELRec_T) * pAMIGetSelEntiresRes->Noofentries);
  286. }
  287. int Storlead_AuthorVerify(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  288. {
  289. AuthorVerify_T *pAuthorVerify = (AuthorVerify_T *)pReq;
  290. int i;
  291. printf("Storlead_AuthorVerify, username: %s, password: %s\n", pAuthorVerify->name, pAuthorVerify->password);
  292. for(i=0;i<MAX_USER_NUM;i++)
  293. {
  294. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserName, pAuthorVerify->name) == 0)
  295. {
  296. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserPassword, pAuthorVerify->password)==0)
  297. {
  298. *pRes = CC_NORMAL;
  299. return 1;
  300. }
  301. else
  302. {
  303. printf("Invalid password!\n");
  304. *pRes = CC_PASSWORD_TEST_FAILED;
  305. return 1;
  306. }
  307. }
  308. }
  309. printf("Invalid username!\n");
  310. *pRes = CC_PASSWORD_TEST_FAILED;
  311. return 1;
  312. }
  313. int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  314. {
  315. uint8_t *pSensorHistory = pRes+3;
  316. uint8_t sensorNum = pReq[0];
  317. uint16_t offset = (pReq[1]<<8) | pReq[2];
  318. uint16_t len = (pReq[3]<<8) | pReq[4];
  319. uint16_t total_len = 480;
  320. *pRes= CC_NORMAL;
  321. if(offset >= total_len)
  322. {
  323. *pRes = CC_PARAM_OUT_OF_RANGE;
  324. return 1;
  325. }
  326. if(getSensorHistory(sensorNum, pSensorHistory) != 0)
  327. {
  328. *pRes = CC_PARAM_OUT_OF_RANGE;
  329. return 1;
  330. };
  331. if(len > (total_len - offset))
  332. len = total_len - offset;
  333. printf("len = %d, offset = %d, total_len = %d\n", len, offset, total_len);
  334. *(pRes+1) = (len>>8)&0xff;
  335. *(pRes+2) = len&0xff;
  336. return len+3;
  337. }
  338. int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  339. {
  340. *pRes = CC_NORMAL;
  341. memcpy(pRes+1, (uint8_t*)gFanInfo, FAN_NUMBERS*sizeof(FanInfo_T));
  342. return FAN_NUMBERS*sizeof(FanInfo_T) + 1;
  343. }
  344. int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  345. {
  346. uint8_t index = pReq[0];
  347. uint8_t mode = pReq[1]; //0: 自动, 1:手动
  348. uint8_t level = pReq[2];
  349. *pRes = CC_NORMAL;
  350. if(index >= FAN_NUMBERS)
  351. {
  352. printf("Invalid index %d\n", index);
  353. *pRes = CC_PARAM_OUT_OF_RANGE;
  354. return 1;
  355. }
  356. if(mode > 1)
  357. {
  358. printf("Invalid mode %d\n", mode);
  359. *pRes = CC_PARAM_OUT_OF_RANGE;
  360. return 1;
  361. }
  362. if(level > 100)
  363. level = 100;
  364. gFanInfo[index].mode = mode;
  365. if(mode == 1)
  366. {
  367. gFanInfo[index].level = level;
  368. }
  369. return 1;
  370. }
  371. /*
  372. Req[0]: ChassisManageEn
  373. */
  374. int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  375. {
  376. int i, index;
  377. uint8_t mReq[100] = {0};
  378. MsgPkt_T ReqPkt;
  379. MsgPkt_T ResPkt;
  380. pRes[0] = CC_NORMAL;
  381. //if(pReq[0] == 0)
  382. if(g_BMCInfo.isChMC == 0)
  383. {
  384. for(i=0;i<BLADE_NUMBERS;i++)
  385. {
  386. gBladeStatus[i].healthStatus = 0;
  387. sprintf(gBladeStatus[i].bladeName, "---");
  388. gBladeStatus[i].slotID = 0;
  389. gBladeStatus[i].pwrStatus = 0;
  390. }
  391. //当前模块的信息
  392. if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
  393. {
  394. gBladeStatus[g_BMCInfo.IndexInChassis].healthStatus = 1;
  395. memcpy(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName, g_BMCInfo.BladeName, 31);
  396. gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
  397. gBladeStatus[g_BMCInfo.IndexInChassis].pwrStatus = g_BMCInfo.PowerGoodFlag;
  398. }
  399. }
  400. else
  401. {
  402. for(index=0;index<BLADE_NUMBERS;index++)
  403. {
  404. if(gChassisIPMBAddr[index] == 0x20) //chMC
  405. {
  406. gBladeStatus[index].healthStatus = 1;
  407. memcpy(gBladeStatus[index].bladeName, g_BMCInfo.BladeName, 31);
  408. gBladeStatus[index].slotID = g_BMCInfo.SlotID;
  409. gBladeStatus[index].pwrStatus = g_BMCInfo.PowerGoodFlag;
  410. continue;
  411. }
  412. ReqPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  413. ReqPkt.Cmd = CMD_GET_BLADE_INFO;
  414. ReqPkt.Size = 0;
  415. if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, gChassisIPMBAddr[index], PRIMARY_IPMB_CHANNEL))
  416. {
  417. printf("RECV: ");
  418. for(i=0;i<ResPkt.Size;i++)
  419. printf("%x ", ResPkt.Data[i]);
  420. printf("\n");
  421. if(ResPkt.Data[0] == 0)
  422. {
  423. gBladeStatus[index].healthStatus = ResPkt.Data[1];
  424. memcpy(gBladeStatus[index].bladeName, &ResPkt.Data[2], 31);
  425. gBladeStatus[index].slotID = ResPkt.Data[33];
  426. gBladeStatus[index].pwrStatus = ResPkt.Data[34];
  427. }
  428. else
  429. {
  430. gBladeStatus[index].healthStatus = 0;
  431. sprintf(gBladeStatus[index].bladeName, "---");
  432. gBladeStatus[index].slotID = 0;
  433. gBladeStatus[index].pwrStatus = 0;
  434. }
  435. }
  436. else
  437. {
  438. gBladeStatus[index].healthStatus = 0;
  439. sprintf(gBladeStatus[index].bladeName, "---");
  440. gBladeStatus[index].slotID = 0;
  441. gBladeStatus[index].pwrStatus = 0;
  442. }
  443. }
  444. }
  445. memcpy(pRes+1, gBladeStatus, (BLADE_NUMBERS*sizeof(BladeStatus_T)));
  446. return 1+(BLADE_NUMBERS*sizeof(BladeStatus_T));
  447. }
  448. int Storlead_GetChassisInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  449. {
  450. /*
  451. typedef struct{
  452. uint8_t slotNum; //total slot numbers of chassis.
  453. uint8_t supportChassisManageFn;
  454. uint8_t chassisManageFnEnable;
  455. uint8_t curIndex;
  456. } OemChassisInfo_T;
  457. */
  458. pRes[0] = CC_NORMAL;
  459. pRes[1] = BLADE_NUMBERS;
  460. pRes[2] = g_BMCInfo.isChMC;
  461. pRes[3] = 0;//g_BMCInfo.BladeManageEn; //机箱管理使能,该字段废弃了。
  462. pRes[4] = g_BMCInfo.IndexInChassis;
  463. return 5;
  464. }
  465. int Storlead_RestoreFactorSettings(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  466. {
  467. int i;
  468. pRes[0] = CC_NORMAL;
  469. //擦除Flash IpmiConfig
  470. sf_sector_erase(5, CONFIG_FLASH_START);
  471. return 1;
  472. }
  473. int Storlead_GetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  474. {
  475. pRes[0] = CC_NORMAL;
  476. uint8_t index = pReq[0];
  477. if(index > 0)
  478. {
  479. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  480. return 1;
  481. }
  482. //Update LanInfo
  483. char ip_buf[16];
  484. getip(ip_buf);
  485. g_BMCInfo.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0);
  486. g_BMCInfo.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1);
  487. g_BMCInfo.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2);
  488. g_BMCInfo.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3);
  489. char mask_buf[16];
  490. getnetmask(mask_buf);
  491. g_BMCInfo.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0);
  492. g_BMCInfo.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1);
  493. g_BMCInfo.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2);
  494. g_BMCInfo.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3);
  495. char broadcast_buf[16];
  496. getbroadcast(broadcast_buf);
  497. g_BMCInfo.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0);
  498. g_BMCInfo.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1);
  499. g_BMCInfo.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2);
  500. g_BMCInfo.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3);
  501. char mac_buf[18];
  502. getmac(mac_buf);
  503. g_BMCInfo.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0);
  504. g_BMCInfo.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1);
  505. g_BMCInfo.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2);
  506. g_BMCInfo.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3);
  507. g_BMCInfo.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4);
  508. g_BMCInfo.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5);
  509. //TODO: get default GetWay
  510. memcpy(pRes+1, &g_BMCInfo.LanInfo[index], sizeof(LanInfo_T));
  511. return 1+sizeof(LanInfo_T);
  512. }
  513. int Storlead_SetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  514. {
  515. MsgPkt_T m_MsgPkt;
  516. uint8_t index = pReq[0];
  517. LanInfo_T *pLanInfo = (LanInfo_T*)&pReq[1];
  518. if(index > 0) //只有一张网卡,index只能是0
  519. {
  520. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  521. return 1;
  522. }
  523. memcpy(&g_BMCInfo.LanInfo[index], pLanInfo, sizeof(LanInfo_T));
  524. m_MsgPkt.Param = PARAM_LAN;
  525. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  526. m_MsgPkt.Cmd = CMD_SET_LAN_INFO;
  527. m_MsgPkt.Size = sizeof(LanInfo_T);
  528. memcpy(m_MsgPkt.Data, pLanInfo, sizeof(LanInfo_T));
  529. PostMsg(gPendActionIfc, &m_MsgPkt);
  530. pRes[0] = CC_NORMAL;
  531. return 1;
  532. }
  533. /*
  534. res[0]: completeCode
  535. res[1]: healthStatus; //0: 未知(灰色) 1:健康(绿色) 2:警告(黄色)3:错误(红色)
  536. res[2-22]: bladeName[31]; //10个汉字或30个字符
  537. res[23]: slotID;
  538. res[24]: pwrStatus; //0:未上电(灰色) 1:已上电(绿色)
  539. */
  540. int Storlead_GetBladeInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  541. {
  542. pRes[0] = CC_NORMAL;
  543. pRes[1] = g_BMCInfo.BladeHealthSta;
  544. memcpy(&pRes[2], g_BMCInfo.BladeName, 31);
  545. pRes[33] = g_BMCInfo.SlotID;
  546. pRes[34] = g_BMCInfo.PowerGoodFlag;
  547. return 35;
  548. }
  549. /*
  550. Req[0] : sensor name
  551. */
  552. int Storlead_GetSensorName(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  553. {
  554. int i;
  555. SensorInfo_T* pSensorInfo;
  556. memset(pRes, 0, MAX_ID_STR_LEN+1);
  557. for(i=0;i<SENSOR_NUMBERS;i++)
  558. {
  559. pSensorInfo = (SensorInfo_T *)&g_BMCInfo.SensorSharedMem.SensorInfo [i];
  560. if(pReq[0] == pSensorInfo->SensorNumber)
  561. {
  562. memcpy(&pRes[1], ((FullSensorRec_T*)pSensorInfo->SDRRec)->IDStr, MAX_ID_STR_LEN);
  563. break;
  564. }
  565. }
  566. return MAX_ID_STR_LEN+1;
  567. }