Storlead.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. /*
  314. Req[0]: sensor number
  315. Req[1]: offset_lsb
  316. Req[2]: offset_msb
  317. Req[3]: readlen_lsb
  318. Req[4]: readlen_msb
  319. -----------------------
  320. Res[0]: ccode
  321. Res[1]: return len lsb
  322. Res[2]: return len msb
  323. */
  324. int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  325. {
  326. uint8_t *pSensorHistory = pRes+3;
  327. uint8_t sensorNum = pReq[0];
  328. uint16_t offset = (pReq[2]<<8) | pReq[1];
  329. uint16_t len = (pReq[4]<<8) | pReq[3];
  330. uint16_t total_len = 480;
  331. *pRes= CC_NORMAL;
  332. if(offset >= total_len)
  333. {
  334. *pRes = CC_PARAM_OUT_OF_RANGE;
  335. return 1;
  336. }
  337. if(getSensorHistory(sensorNum, pSensorHistory) != 0)
  338. {
  339. *pRes = CC_PARAM_OUT_OF_RANGE;
  340. return 1;
  341. };
  342. if(len > (total_len - offset))
  343. len = total_len - offset;
  344. printf("len = %d, offset = %d, total_len = %d\n", len, offset, total_len);
  345. *(pRes+1) = len&0xff;
  346. *(pRes+2) = (len>>8)&0xff;
  347. return len+3;
  348. }
  349. int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  350. {
  351. *pRes = CC_NORMAL;
  352. memcpy(pRes+1, (uint8_t*)gFanInfo, FAN_NUMBERS*sizeof(FanInfo_T));
  353. return FAN_NUMBERS*sizeof(FanInfo_T) + 1;
  354. }
  355. int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  356. {
  357. uint8_t index = pReq[0];
  358. uint8_t mode = pReq[1]; //0: 自动, 1:手动
  359. uint8_t level = pReq[2];
  360. *pRes = CC_NORMAL;
  361. if(index >= FAN_NUMBERS)
  362. {
  363. printf("Invalid index %d\n", index);
  364. *pRes = CC_PARAM_OUT_OF_RANGE;
  365. return 1;
  366. }
  367. if(mode > 1)
  368. {
  369. printf("Invalid mode %d\n", mode);
  370. *pRes = CC_PARAM_OUT_OF_RANGE;
  371. return 1;
  372. }
  373. if(level > 100)
  374. level = 100;
  375. gFanInfo[index].mode = mode;
  376. if(mode == 1)
  377. {
  378. gFanInfo[index].level = level;
  379. }
  380. return 1;
  381. }
  382. /*
  383. Req[0]: ChassisManageEn
  384. */
  385. int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  386. {
  387. int i, index;
  388. uint8_t mReq[100] = {0};
  389. MsgPkt_T ReqPkt;
  390. MsgPkt_T ResPkt;
  391. pRes[0] = CC_NORMAL;
  392. //if(pReq[0] == 0)
  393. if(g_BMCInfo.isChMC == 0)
  394. {
  395. for(i=0;i<BLADE_NUMBERS;i++)
  396. {
  397. gBladeStatus[i].present = 0;
  398. gBladeStatus[i].healthStatus = 0;
  399. sprintf(gBladeStatus[i].bladeName, "---");
  400. gBladeStatus[i].slotID = 0;
  401. gBladeStatus[i].pwrStatus = 0;
  402. }
  403. //当前模块的信息
  404. if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
  405. {
  406. gBladeStatus[g_BMCInfo.IndexInChassis].present = 1;
  407. gBladeStatus[g_BMCInfo.IndexInChassis].healthStatus = 1;
  408. memcpy(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName, g_BMCInfo.BladeName, 31);
  409. gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
  410. gBladeStatus[g_BMCInfo.IndexInChassis].pwrStatus = g_BMCInfo.PowerGoodFlag;
  411. gBladeStatus[g_BMCInfo.IndexInChassis].isChMC = 1; //从模块不能管理机箱,网页内显示机箱的默认选中刀片。
  412. }
  413. }
  414. else
  415. {
  416. for(index=0;index<BLADE_NUMBERS;index++)
  417. {
  418. if(gChassisIPMBAddr[index] == 0x20) //chMC
  419. {
  420. gBladeStatus[index].present = 1;
  421. gBladeStatus[index].healthStatus = 1;
  422. memcpy(gBladeStatus[index].bladeName, g_BMCInfo.BladeName, 31);
  423. gBladeStatus[index].slotID = g_BMCInfo.SlotID;
  424. gBladeStatus[index].pwrStatus = g_BMCInfo.PowerGoodFlag;
  425. gBladeStatus[index].isChMC = 1;
  426. continue;
  427. }
  428. ReqPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  429. ReqPkt.Cmd = CMD_GET_BLADE_INFO;
  430. ReqPkt.Size = 0;
  431. if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, gChassisIPMBAddr[index], PRIMARY_IPMB_CHANNEL))
  432. {
  433. printf("RECV: ");
  434. for(i=0;i<ResPkt.Size;i++)
  435. printf("%x ", ResPkt.Data[i]);
  436. printf("\n");
  437. if(ResPkt.Data[0] == 0)
  438. {
  439. gBladeStatus[index].present = 1;
  440. gBladeStatus[index].healthStatus = ResPkt.Data[1];
  441. memcpy(gBladeStatus[index].bladeName, &ResPkt.Data[2], 31);
  442. gBladeStatus[index].slotID = ResPkt.Data[33];
  443. gBladeStatus[index].pwrStatus = ResPkt.Data[34];
  444. gBladeStatus[index].isChMC = 0;
  445. }
  446. else
  447. {
  448. gBladeStatus[index].present = 0;
  449. gBladeStatus[index].healthStatus = 0;
  450. sprintf(gBladeStatus[index].bladeName, "---");
  451. gBladeStatus[index].slotID = 0;
  452. gBladeStatus[index].pwrStatus = 0;
  453. gBladeStatus[index].isChMC = 0;
  454. }
  455. }
  456. else
  457. {
  458. gBladeStatus[index].present = 0;
  459. gBladeStatus[index].healthStatus = 0;
  460. sprintf(gBladeStatus[index].bladeName, "---");
  461. gBladeStatus[index].slotID = 0;
  462. gBladeStatus[index].pwrStatus = 0;
  463. gBladeStatus[index].isChMC = 0;
  464. }
  465. }
  466. }
  467. memcpy(pRes+1, gBladeStatus, (BLADE_NUMBERS*sizeof(BladeStatus_T)));
  468. return 1+(BLADE_NUMBERS*sizeof(BladeStatus_T));
  469. }
  470. int Storlead_GetChassisInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  471. {
  472. /*
  473. typedef struct{
  474. uint8_t slotNum; //total slot numbers of chassis.
  475. uint8_t supportChassisManageFn;
  476. uint8_t chassisManageFnEnable;
  477. uint8_t curIndex;
  478. } OemChassisInfo_T;
  479. */
  480. pRes[0] = CC_NORMAL;
  481. pRes[1] = BLADE_NUMBERS;
  482. pRes[2] = g_BMCInfo.isChMC;
  483. pRes[3] = 0;//g_BMCInfo.BladeManageEn; //机箱管理使能,该字段废弃了。
  484. pRes[4] = g_BMCInfo.IndexInChassis;
  485. return 5;
  486. }
  487. int Storlead_RestoreFactorSettings(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  488. {
  489. int i;
  490. pRes[0] = CC_NORMAL;
  491. //擦除Flash IpmiConfig
  492. sf_sector_erase(5, CONFIG_FLASH_START);
  493. return 1;
  494. }
  495. int Storlead_GetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  496. {
  497. pRes[0] = CC_NORMAL;
  498. uint8_t index = pReq[0];
  499. if(index > 0)
  500. {
  501. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  502. return 1;
  503. }
  504. //Update LanInfo
  505. char ip_buf[16];
  506. getip(ip_buf);
  507. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0);
  508. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1);
  509. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2);
  510. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3);
  511. char mask_buf[16];
  512. getnetmask(mask_buf);
  513. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0);
  514. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1);
  515. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2);
  516. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3);
  517. char broadcast_buf[16];
  518. getbroadcast(broadcast_buf);
  519. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0);
  520. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1);
  521. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2);
  522. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3);
  523. char mac_buf[18];
  524. getmac(mac_buf);
  525. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0);
  526. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1);
  527. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2);
  528. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3);
  529. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4);
  530. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5);
  531. //TODO: get default GetWay
  532. memcpy(pRes+1, &g_BMCInfo.IpmiConfig.LanInfo[index], sizeof(LanInfo_T));
  533. return 1+sizeof(LanInfo_T);
  534. }
  535. /*
  536. Req[0]: index
  537. Req[1]: isSave 0:掉电不保存,1:掉电保存
  538. Req[2~n]: LanInfo_T
  539. */
  540. int Storlead_SetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  541. {
  542. MsgPkt_T m_MsgPkt;
  543. uint8_t index = pReq[0];
  544. uint8_t isSave = pReq[1];
  545. LanInfo_T *pLanInfo = (LanInfo_T*)&pReq[2];
  546. if(index > 0) //只有一张网卡,index只能是0
  547. {
  548. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  549. return 1;
  550. }
  551. memcpy(&g_BMCInfo.IpmiConfig.LanInfo[index], pLanInfo, sizeof(LanInfo_T));
  552. m_MsgPkt.Param = PARAM_LAN;
  553. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  554. m_MsgPkt.Cmd = CMD_SET_LAN_INFO;
  555. m_MsgPkt.Size = sizeof(LanInfo_T)+2;
  556. m_MsgPkt.Data[0] = index;
  557. m_MsgPkt.Data[1] = isSave;
  558. memcpy(&m_MsgPkt.Data[2], pLanInfo, sizeof(LanInfo_T));
  559. PostMsg(gPendActionIfc, &m_MsgPkt);
  560. pRes[0] = CC_NORMAL;
  561. return 1;
  562. }
  563. /*
  564. res[0]: completeCode
  565. res[1]: healthStatus; //0: 未知(灰色) 1:健康(绿色) 2:警告(黄色)3:错误(红色)
  566. res[2-22]: bladeName[31]; //10个汉字或30个字符
  567. res[23]: slotID;
  568. res[24]: pwrStatus; //0:未上电(灰色) 1:已上电(绿色)
  569. */
  570. int Storlead_GetBladeInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  571. {
  572. pRes[0] = CC_NORMAL;
  573. pRes[1] = g_BMCInfo.BladeHealthSta;
  574. memcpy(&pRes[2], g_BMCInfo.BladeName, 31);
  575. pRes[33] = g_BMCInfo.SlotID;
  576. pRes[34] = g_BMCInfo.PowerGoodFlag;
  577. return 35;
  578. }
  579. /*
  580. Req[0] : sensor name
  581. */
  582. int Storlead_GetSensorName(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  583. {
  584. int i;
  585. SensorInfo_T* pSensorInfo;
  586. memset(pRes, 0, MAX_ID_STR_LEN+1);
  587. for(i=0;i<SENSOR_NUMBERS;i++)
  588. {
  589. pSensorInfo = (SensorInfo_T *)&g_BMCInfo.SensorSharedMem.SensorInfo [i];
  590. if(pReq[0] == pSensorInfo->SensorNumber)
  591. {
  592. memcpy(&pRes[1], ((FullSensorRec_T*)pSensorInfo->SDRRec)->IDStr, MAX_ID_STR_LEN);
  593. break;
  594. }
  595. }
  596. return MAX_ID_STR_LEN+1;
  597. }