Storlead.c 25 KB

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