Storlead.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. int Storlead_AuthorVerify(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  248. {
  249. AuthorVerify_T *pAuthorVerify = (AuthorVerify_T *)pReq;
  250. int i;
  251. printf("Storlead_AuthorVerify, username: %s, password: %s\n", pAuthorVerify->name, pAuthorVerify->password);
  252. for(i=0;i<MAX_USER_NUM;i++)
  253. {
  254. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserName, pAuthorVerify->name) == 0)
  255. {
  256. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserPassword, pAuthorVerify->password)==0)
  257. {
  258. *pRes = CC_NORMAL;
  259. return 1;
  260. }
  261. else
  262. {
  263. printf("Invalid password!\n");
  264. *pRes = CC_PASSWORD_TEST_FAILED;
  265. return 1;
  266. }
  267. }
  268. }
  269. printf("Invalid username!\n");
  270. *pRes = CC_PASSWORD_TEST_FAILED;
  271. return 1;
  272. }
  273. /*
  274. Req[0]: sensor number
  275. Req[1]: offset_lsb
  276. Req[2]: offset_msb
  277. Req[3]: readlen_lsb
  278. Req[4]: readlen_msb
  279. -----------------------
  280. Res[0]: ccode
  281. Res[1]: return len lsb
  282. Res[2]: return len msb
  283. */
  284. int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  285. {
  286. uint8_t *pSensorHistory = pRes+3;
  287. uint8_t sensorNum = pReq[0];
  288. uint16_t offset = (pReq[2]<<8) | pReq[1];
  289. uint16_t len = (pReq[4]<<8) | pReq[3];
  290. uint16_t total_len = 480;
  291. *pRes= CC_NORMAL;
  292. if(offset >= total_len)
  293. {
  294. *pRes = CC_PARAM_OUT_OF_RANGE;
  295. return 1;
  296. }
  297. if(getSensorHistory(sensorNum, pSensorHistory) != 0)
  298. {
  299. *pRes = CC_PARAM_OUT_OF_RANGE;
  300. return 1;
  301. };
  302. if(len > (total_len - offset))
  303. len = total_len - offset;
  304. printf("len = %d, offset = %d, total_len = %d\n", len, offset, total_len);
  305. *(pRes+1) = len&0xff;
  306. *(pRes+2) = (len>>8)&0xff;
  307. return len+3;
  308. }
  309. int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  310. {
  311. *pRes = CC_NORMAL;
  312. //for test
  313. int i;
  314. for(i=0;i<FAN_NUMBERS;i++)
  315. gFanInfo[i].speed++;
  316. memcpy(pRes+1, (uint8_t*)gFanInfo, FAN_NUMBERS*sizeof(FanInfo_T));
  317. return FAN_NUMBERS*sizeof(FanInfo_T) + 1;
  318. }
  319. int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  320. {
  321. uint8_t index = pReq[0];
  322. uint8_t mode = pReq[1]; //0: 自动, 1:手动
  323. uint8_t level = pReq[2];
  324. *pRes = CC_NORMAL;
  325. if(index >= FAN_NUMBERS)
  326. {
  327. printf("Invalid index %d\n", index);
  328. *pRes = CC_PARAM_OUT_OF_RANGE;
  329. return 1;
  330. }
  331. if(mode > 1)
  332. {
  333. printf("Invalid mode %d\n", mode);
  334. *pRes = CC_PARAM_OUT_OF_RANGE;
  335. return 1;
  336. }
  337. if(level > 100)
  338. level = 100;
  339. gFanInfo[index].mode = mode;
  340. if(mode == 1)
  341. {
  342. gFanInfo[index].level = level;
  343. }
  344. return 1;
  345. }
  346. /*
  347. Req[0]: ChassisManageEn
  348. */
  349. int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  350. {
  351. int i, index;
  352. MsgPkt_T ReqPkt;
  353. MsgPkt_T ResPkt;
  354. pRes[0] = CC_NORMAL;
  355. //if(pReq[0] == 0)
  356. if(g_BMCInfo.isChMC == 0)
  357. {
  358. for(i=0;i<BLADE_NUMBERS;i++)
  359. {
  360. gBladeStatus[i].present = 0;
  361. gBladeStatus[i].healthStatus = 0;
  362. sprintf(gBladeStatus[i].bladeName, "---");
  363. gBladeStatus[i].slotID = 0;
  364. gBladeStatus[i].pwrStatus = 0;
  365. }
  366. //当前模块的信息
  367. if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
  368. {
  369. gBladeStatus[g_BMCInfo.IndexInChassis].present = 1;
  370. gBladeStatus[g_BMCInfo.IndexInChassis].healthStatus = 1;
  371. memcpy(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName, g_BMCInfo.BladeName, 31);
  372. gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
  373. gBladeStatus[g_BMCInfo.IndexInChassis].pwrStatus = g_BMCInfo.PowerGoodFlag;
  374. gBladeStatus[g_BMCInfo.IndexInChassis].isChMC = 1; //从模块不能管理机箱,网页内显示机箱的默认选中刀片。
  375. }
  376. }
  377. else
  378. {
  379. for(index=0;index<BLADE_NUMBERS;index++)
  380. {
  381. if(gChassisIPMBAddr[index] == 0x20) //chMC
  382. {
  383. gBladeStatus[index].present = 1;
  384. gBladeStatus[index].healthStatus = 1;
  385. memcpy(gBladeStatus[index].bladeName, g_BMCInfo.BladeName, 31);
  386. gBladeStatus[index].slotID = g_BMCInfo.SlotID;
  387. gBladeStatus[index].pwrStatus = g_BMCInfo.PowerGoodFlag;
  388. gBladeStatus[index].isChMC = 1;
  389. continue;
  390. }
  391. ReqPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  392. ReqPkt.Cmd = CMD_GET_BLADE_INFO;
  393. ReqPkt.Size = 0;
  394. if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, gChassisIPMBAddr[index], PRIMARY_IPMB_CHANNEL))
  395. {
  396. // printf("RECV: ");
  397. // for(i=0;i<ResPkt.Size;i++)
  398. // printf("%x ", ResPkt.Data[i]);
  399. // printf("\n");
  400. if(ResPkt.Data[0] == 0)
  401. {
  402. gBladeStatus[index].present = 1;
  403. gBladeStatus[index].healthStatus = ResPkt.Data[1];
  404. memcpy(gBladeStatus[index].bladeName, &ResPkt.Data[2], 31);
  405. gBladeStatus[index].slotID = ResPkt.Data[33];
  406. gBladeStatus[index].pwrStatus = ResPkt.Data[34];
  407. gBladeStatus[index].isChMC = 0;
  408. }
  409. else
  410. {
  411. gBladeStatus[index].present = 0;
  412. gBladeStatus[index].healthStatus = 0;
  413. sprintf(gBladeStatus[index].bladeName, "---");
  414. gBladeStatus[index].slotID = 0;
  415. gBladeStatus[index].pwrStatus = 0;
  416. gBladeStatus[index].isChMC = 0;
  417. }
  418. }
  419. else
  420. {
  421. gBladeStatus[index].present = 0;
  422. gBladeStatus[index].healthStatus = 0;
  423. sprintf(gBladeStatus[index].bladeName, "---");
  424. gBladeStatus[index].slotID = 0;
  425. gBladeStatus[index].pwrStatus = 0;
  426. gBladeStatus[index].isChMC = 0;
  427. }
  428. }
  429. }
  430. memcpy(pRes+1, gBladeStatus, (BLADE_NUMBERS*sizeof(BladeStatus_T)));
  431. return 1+(BLADE_NUMBERS*sizeof(BladeStatus_T));
  432. }
  433. int Storlead_RestoreFactorSettings(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  434. {
  435. int i;
  436. pRes[0] = CC_NORMAL;
  437. //擦除Flash IpmiConfig
  438. sf_sector_erase(5, CONFIG_FLASH_START);
  439. return 1;
  440. }
  441. int Storlead_GetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  442. {
  443. pRes[0] = CC_NORMAL;
  444. uint8_t index = pReq[0];
  445. if(index > 0)
  446. {
  447. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  448. return 1;
  449. }
  450. //Update LanInfo
  451. char ip_buf[16];
  452. getip(ip_buf);
  453. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0);
  454. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1);
  455. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2);
  456. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3);
  457. char mask_buf[16];
  458. getnetmask(mask_buf);
  459. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0);
  460. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1);
  461. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2);
  462. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3);
  463. char broadcast_buf[16];
  464. getbroadcast(broadcast_buf);
  465. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0);
  466. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1);
  467. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2);
  468. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3);
  469. char mac_buf[18];
  470. getmac(mac_buf);
  471. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0);
  472. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1);
  473. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2);
  474. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3);
  475. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4);
  476. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5);
  477. //TODO: get default GetWay
  478. memcpy(pRes+1, &g_BMCInfo.IpmiConfig.LanInfo[index], sizeof(LanInfo_T));
  479. return 1+sizeof(LanInfo_T);
  480. }
  481. /*
  482. Req[0]: index
  483. Req[1]: isSave 0:掉电不保存,1:掉电保存
  484. Req[2~n]: LanInfo_T
  485. */
  486. int Storlead_SetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  487. {
  488. MsgPkt_T m_MsgPkt;
  489. uint8_t index = pReq[0];
  490. uint8_t isSave = pReq[1];
  491. LanInfo_T *pLanInfo = (LanInfo_T*)&pReq[2];
  492. if(index > 0) //只有一张网卡,index只能是0
  493. {
  494. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  495. return 1;
  496. }
  497. memcpy(&g_BMCInfo.IpmiConfig.LanInfo[index], pLanInfo, sizeof(LanInfo_T));
  498. m_MsgPkt.Param = PARAM_LAN;
  499. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  500. m_MsgPkt.Cmd = CMD_SET_LAN_INFO;
  501. m_MsgPkt.Size = sizeof(LanInfo_T)+2;
  502. m_MsgPkt.Data[0] = index;
  503. m_MsgPkt.Data[1] = isSave;
  504. memcpy(&m_MsgPkt.Data[2], pLanInfo, sizeof(LanInfo_T));
  505. PostMsg(gPendActionIfc, &m_MsgPkt);
  506. pRes[0] = CC_NORMAL;
  507. return 1;
  508. }
  509. /*
  510. res[0]: completeCode
  511. res[1]: healthStatus; //0: 未知(灰色) 1:健康(绿色) 2:警告(黄色)3:错误(红色)
  512. res[2-22]: bladeName[31]; //10个汉字或30个字符
  513. res[23]: slotID;
  514. res[24]: pwrStatus; //0:未上电(灰色) 1:已上电(绿色)
  515. */
  516. int Storlead_GetBladeInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  517. {
  518. pRes[0] = CC_NORMAL;
  519. pRes[1] = g_BMCInfo.BladeHealthSta;
  520. memcpy(&pRes[2], g_BMCInfo.BladeName, 31);
  521. pRes[33] = g_BMCInfo.SlotID;
  522. pRes[34] = g_BMCInfo.PowerGoodFlag;
  523. return 35;
  524. }
  525. /*
  526. Req[0] : sensor number
  527. */
  528. int Storlead_GetSensorName(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  529. {
  530. int i;
  531. SensorInfo_T* pSensorInfo;
  532. memset(pRes, 0, MAX_ID_STR_LEN+1);
  533. for(i=0;i<SENSOR_NUMBERS;i++)
  534. {
  535. pSensorInfo = (SensorInfo_T *)&g_BMCInfo.SensorSharedMem.SensorInfo [i];
  536. if(pReq[0] == pSensorInfo->SensorNumber)
  537. {
  538. memcpy(&pRes[1], ((FullSensorRec_T*)pSensorInfo->SDRRec)->IDStr, MAX_ID_STR_LEN);
  539. break;
  540. }
  541. }
  542. return MAX_ID_STR_LEN+1;
  543. }