Storlead.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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. #include "driver.h"
  12. #include "fcntl.h"
  13. #include "Api.h"
  14. int Storlead_GetSysInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  15. {
  16. char Title[] = "系统信息";
  17. char Text[] = "模块名称:多端口光纤接口模块;FPGA型号:XC7VX690T;简介: ";
  18. int len = 0,remainLen = 0;
  19. uint16_t offset = (pReq[2]<<8) | pReq[1];
  20. int totalLen = 0;
  21. char *pStr = NULL;
  22. int reqLen = (pReq[4]<<8) | pReq[3];
  23. switch(pReq[0])
  24. {
  25. case 0: //get Title
  26. while(Title[totalLen])
  27. {
  28. totalLen++;
  29. }
  30. //printf("title total len = %#x\n",totalLen);
  31. pStr = Title;
  32. break;
  33. case 1:
  34. while(Text[totalLen])
  35. {
  36. totalLen++;
  37. }
  38. //printf("text total len = %#x\n", totalLen);
  39. pStr = Text;
  40. break;
  41. default:
  42. *pRes = CC_PARAM_OUT_OF_RANGE;
  43. return 1;
  44. }
  45. *pRes= CC_NORMAL;
  46. if(offset > totalLen)
  47. {
  48. printf("Invalid offset: %#x\n", offset);
  49. *pRes= CC_PARAM_OUT_OF_RANGE;
  50. return 1;
  51. }
  52. if(reqLen == 0)
  53. {
  54. len = totalLen - offset;
  55. }
  56. else
  57. {
  58. len = (reqLen > (totalLen-offset)) ? (totalLen-offset) : reqLen;
  59. }
  60. remainLen = totalLen - offset - len;
  61. *(pRes+1) = len&0xff;
  62. *(pRes+2) = (len>>8)&0xff;
  63. *(pRes+3) = remainLen&0xff;
  64. *(pRes+4) = (remainLen>>8)&0xff;
  65. memcpy(pRes+5, pStr+offset, len);
  66. // int i;
  67. // printf("Example 80h: ");
  68. // for(i=0;i<5+len;i++)
  69. // printf("%#x ", pRes[i]);
  70. // printf("\n");
  71. return 5+len;
  72. }
  73. int Storlead_GetSensorInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  74. {
  75. StorleadGetSensorInfoRes_T *pGetSensorInfoRes = (StorleadGetSensorInfoRes_T *)pRes;
  76. uint8_t* pValidSensor = NULL;
  77. uint16_t SensorIndex = pReq[0];
  78. SensorInfo_T pSensor ;
  79. SenInfo_T SensorInfo;
  80. uint8_t SensorIsSigned = FALSE;
  81. uint16_t SensorReading = 0;
  82. SensorSharedMem_T* pSMSharedMem;
  83. SDRRecHdr_T* pSDRRec;
  84. FullSensorRec_T* FullSDR;
  85. CompactSensorRec_T* CompSDR;
  86. int i = 0;
  87. int totalsize;
  88. /* Get the Sensor Shared Memory */
  89. pSMSharedMem = (SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem;
  90. if(g_BMCInfo.SenConfig.ValidSensorCnt == 0)
  91. {
  92. pGetSensorInfoRes->CompletionCode = OEMCC_SENSOR_INFO_EMPTY;
  93. printf("ValidSensorCnt is 0\n");
  94. return 1;
  95. }
  96. if(SensorIndex >= g_BMCInfo.SenConfig.ValidSensorCnt)
  97. {
  98. pGetSensorInfoRes->CompletionCode = CC_PARAM_OUT_OF_RANGE;
  99. printf("Invalid SenosrIndex %d\n", SensorIndex);
  100. return 1;
  101. }
  102. //pValidSensor = (uint8_t*)(pAMIGetSensorInfoRes+1);
  103. // for(i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++)
  104. // {
  105. //SensorIndex = g_BMCInfo.SenConfig.ValidSensorList[i];
  106. pSensor = pSMSharedMem->SensorInfo[SensorIndex];
  107. /*Copy the SDR Header*/
  108. memcpy(&pGetSensorInfoRes->SensorInfo.hdr,pSensor.SDRRec,sizeof(SDRRecHdr_T));
  109. pGetSensorInfoRes->SensorInfo.SensorNumber = pSensor.SensorNumber;
  110. pGetSensorInfoRes->SensorInfo.SensorTypeCode = pSensor.SensorTypeCode;
  111. pGetSensorInfoRes->SensorInfo.EventTypeCode = pSensor.EventTypeCode;
  112. pGetSensorInfoRes->SensorInfo.Units1 = pSensor.Units1;
  113. pGetSensorInfoRes->SensorInfo.Units2 = pSensor.Units2;
  114. pGetSensorInfoRes->SensorInfo.Units3 = pSensor.Units3;
  115. pGetSensorInfoRes->SensorInfo.M_LSB = pSensor.M_LSB;
  116. pGetSensorInfoRes->SensorInfo.M_MSB_Tolerance = pSensor.M_MSB_Tolerance;
  117. pGetSensorInfoRes->SensorInfo.B_LSB = pSensor.B_LSB;
  118. pGetSensorInfoRes->SensorInfo.B_MSB_Accuracy = pSensor.B_MSB_Accuracy;
  119. pGetSensorInfoRes->SensorInfo.Accuracy_MSB_Exp = pSensor.Accuracy_MSB_Exp;
  120. pGetSensorInfoRes->SensorInfo.RExp_BExp = pSensor.RExp_BExp;
  121. pGetSensorInfoRes->SensorInfo.LowerNonCritical = pSensor.LowerNonCritical;
  122. pGetSensorInfoRes->SensorInfo.LowerCritical = pSensor.LowerCritical;
  123. pGetSensorInfoRes->SensorInfo.LowerNonRecoverable = pSensor.LowerNonRecoverable;
  124. pGetSensorInfoRes->SensorInfo.UpperNonCritical = pSensor.UpperNonCritical;
  125. pGetSensorInfoRes->SensorInfo.UpperCritical = pSensor.UpperCritical;
  126. pGetSensorInfoRes->SensorInfo.UpperNonRecoverable= pSensor.UpperNonRecoverable;
  127. pGetSensorInfoRes->SensorInfo.Settable_Readable_ThreshMask= pSensor.SettableThreshMask;
  128. pGetSensorInfoRes->SensorInfo.Flags = pSensor.EventFlags & 0xe0;
  129. if((pSensor.EventFlags & BIT5) != 0)
  130. {
  131. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  132. }
  133. SensorReading = pSensor.SensorReading;
  134. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  135. SensorIsSigned = ( 0 != (pSensor.InternalFlags & BIT1));
  136. if (THRESHOLD_SENSOR_CLASS == pSensor.EventTypeCode)
  137. {
  138. pGetSensorInfoRes->SensorInfo.SensorReading = (SensorReading & 0x00FF);
  139. pGetSensorInfoRes->SensorInfo.ComparisonStatus = 0;
  140. if((pSensor.DeassertionEventEnablesByte2 & BIT6) == BIT6 )
  141. {
  142. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonRecoverable) >= 0)
  143. {
  144. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT5;
  145. }
  146. }
  147. if((pSensor.DeassertionEventEnablesByte2 & BIT5) == BIT5 )
  148. {
  149. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperCritical) >= 0)
  150. {
  151. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT4;
  152. }
  153. }
  154. if((pSensor.DeassertionEventEnablesByte2 & BIT4) == BIT4 )
  155. {
  156. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonCritical) >= 0)
  157. {
  158. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT3;
  159. }
  160. }
  161. if((pSensor.AssertionEventEnablesByte2 & BIT6) == BIT6 )
  162. {
  163. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonRecoverable) <= 0)
  164. {
  165. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT2;
  166. }
  167. }
  168. if((pSensor.AssertionEventEnablesByte2 & BIT5) == BIT5 )
  169. {
  170. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerCritical) <= 0)
  171. {
  172. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT1;
  173. }
  174. }
  175. if((pSensor.AssertionEventEnablesByte2 & BIT4) == BIT4 )
  176. {
  177. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonCritical) <= 0)
  178. {
  179. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT0;
  180. }
  181. }
  182. pGetSensorInfoRes->SensorInfo.ComparisonStatus &= ((pSensor.SettableThreshMask >> 8) & 0xFF);
  183. pGetSensorInfoRes->SensorInfo.OptionalStatus = 0;
  184. // For Threshold sensor, [7:6] - reserved. Returned as 1b. Ignore on read.
  185. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= THRESHOLD_RESERVED_BIT;
  186. }
  187. else
  188. {
  189. pGetSensorInfoRes->SensorInfo.ComparisonStatus = (((uint8_t) (SensorReading & 0x00FF)) & ((uint8_t) (pSensor.SettableThreshMask & 0x00FF)) );
  190. pGetSensorInfoRes->SensorInfo.OptionalStatus = (((uint8_t) (SensorReading >> 8)) & ((uint8_t) (pSensor.SettableThreshMask >> 8)) );
  191. // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read.
  192. pGetSensorInfoRes->SensorInfo.OptionalStatus |= DISCRETE_RESERVED_BIT;
  193. }
  194. if((pSensor.EventFlags & BIT7) == 0)
  195. {
  196. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = 0;
  197. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = 0;
  198. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = 0;
  199. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = 0;
  200. }
  201. if((pSensor.SensorCaps & BIT6) == 0)
  202. {
  203. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionHistoryByte1 & pSensor.AssertionEventEnablesByte1);
  204. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionHistoryByte2 & pSensor.AssertionEventEnablesByte2);
  205. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionHistoryByte1 & pSensor.DeassertionEventEnablesByte1);
  206. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionHistoryByte2 & pSensor.DeassertionEventEnablesByte2);
  207. }
  208. else
  209. {
  210. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionEventOccuredByte1 & pSensor.AssertionEventEnablesByte1);
  211. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionEventOccuredByte2 & pSensor.AssertionEventEnablesByte2);
  212. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionEventOccuredByte1 & pSensor.DeassertionEventEnablesByte1);
  213. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionEventOccuredByte2 & pSensor.DeassertionEventEnablesByte2);
  214. }
  215. pSDRRec = GetSDRRec(pSensor.SDRRec->ID);
  216. if(pSensor.SDRRec->Type == FULL_SDR_REC) /*Full SDR*/
  217. {
  218. FullSDR = (FullSensorRec_T *)pSDRRec;
  219. pGetSensorInfoRes->SensorInfo.OwnerID = g_BMCInfo.PrimaryIPMBAddr;//FullSDR->OwnerID;
  220. pGetSensorInfoRes->SensorInfo.OwnerLUN= FullSDR->OwnerLUN;
  221. pGetSensorInfoRes->SensorInfo.MaxReading = FullSDR->MaxReading;
  222. pGetSensorInfoRes->SensorInfo.MinReading = FullSDR->MinReading;
  223. pGetSensorInfoRes->SensorInfo.Linearization = FullSDR->Linearization;
  224. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  225. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,FullSDR->IDStr, MAX_ID_STR_LEN - (sizeof(FullSensorRec_T) - sizeof(SDRRecHdr_T) - FullSDR->hdr.Len));
  226. }
  227. else if(pSensor.SDRRec->Type == COMPACT_SDR_REC) /*Compact SDR*/
  228. {
  229. CompSDR = (CompactSensorRec_T *)pSDRRec;
  230. pGetSensorInfoRes->SensorInfo.OwnerID = g_BMCInfo.PrimaryIPMBAddr; //CompSDR->OwnerID;
  231. pGetSensorInfoRes->SensorInfo.OwnerLUN= CompSDR->OwnerLUN;
  232. pGetSensorInfoRes->SensorInfo.MaxReading = 0;
  233. pGetSensorInfoRes->SensorInfo.MinReading = 0;
  234. pGetSensorInfoRes->SensorInfo.Linearization = 0;
  235. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  236. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,CompSDR->IDStr, MAX_ID_STR_LEN - (sizeof(CompactSensorRec_T) - sizeof(SDRRecHdr_T) - CompSDR->hdr.Len));
  237. }
  238. //memcpy(pValidSensor,(uint8_t *)&SensorInfo,sizeof(SenInfo_T));
  239. //pValidSensor = pValidSensor + sizeof(SenInfo_T);
  240. //}
  241. pGetSensorInfoRes->CompletionCode = CC_NORMAL;
  242. //pAMIGetSensorInfoRes->Noofentries = g_BMCInfo.SenConfig.ValidSensorCnt;
  243. //totalsize = sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * 11/*g_BMCInfo.SenConfig.ValidSensorCnt*/);
  244. // printf("return %d :", totalsize);
  245. // for(i=0;i<sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * g_BMCInfo.SenConfig.ValidSensorCnt);i++)
  246. // printf("%#x ", pRes[i]);
  247. // printf("\n");
  248. return sizeof(StorleadGetSensorInfoRes_T);
  249. }
  250. int Storlead_AuthorVerify(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  251. {
  252. AuthorVerify_T *pAuthorVerify = (AuthorVerify_T *)pReq;
  253. int i;
  254. printf("Storlead_AuthorVerify, username: %s, password: %s\n", pAuthorVerify->name, pAuthorVerify->password);
  255. for(i=0;i<MAX_USER_NUM;i++)
  256. {
  257. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserName, pAuthorVerify->name) == 0)
  258. {
  259. if(strcmp(g_BMCInfo.UserInfoTbl[i].UserPassword, pAuthorVerify->password)==0)
  260. {
  261. *pRes = CC_NORMAL;
  262. return 1;
  263. }
  264. else
  265. {
  266. printf("Invalid password!\n");
  267. *pRes = CC_PASSWORD_TEST_FAILED;
  268. return 1;
  269. }
  270. }
  271. }
  272. printf("Invalid username!\n");
  273. *pRes = CC_PASSWORD_TEST_FAILED;
  274. return 1;
  275. }
  276. /*
  277. Req[0]: sensor number
  278. Req[1]: offset_lsb
  279. Req[2]: offset_msb
  280. Req[3]: readlen_lsb
  281. Req[4]: readlen_msb
  282. -----------------------
  283. Res[0]: ccode
  284. Res[1]: return len lsb
  285. Res[2]: return len msb
  286. */
  287. int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  288. {
  289. uint8_t *pSensorHistory = pRes+3;
  290. uint8_t sensorNum = pReq[0];
  291. uint16_t offset = (pReq[2]<<8) | pReq[1];
  292. uint16_t len = (pReq[4]<<8) | pReq[3];
  293. uint16_t total_len = 480;
  294. *pRes= CC_NORMAL;
  295. if(offset >= total_len)
  296. {
  297. *pRes = CC_PARAM_OUT_OF_RANGE;
  298. return 1;
  299. }
  300. if(getSensorHistory(sensorNum, pSensorHistory) != 0)
  301. {
  302. *pRes = CC_PARAM_OUT_OF_RANGE;
  303. return 1;
  304. };
  305. if(len > (total_len - offset))
  306. len = total_len - offset;
  307. printf("Storlead_GetSensorHistory(): len = %d, offset = %d, total_len = %d\n", len, offset, total_len);
  308. *(pRes+1) = len&0xff;
  309. *(pRes+2) = (len>>8)&0xff;
  310. return len+3;
  311. }
  312. int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  313. {
  314. *pRes = CC_NORMAL;
  315. //for test
  316. int i;
  317. for(i=0;i<FAN_NUMBERS;i++)
  318. gFanInfo[i].speed++;
  319. memcpy(pRes+1, (uint8_t*)gFanInfo, FAN_NUMBERS*sizeof(FanInfo_T));
  320. return FAN_NUMBERS*sizeof(FanInfo_T) + 1;
  321. }
  322. int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  323. {
  324. uint8_t index = pReq[0];
  325. uint8_t mode = pReq[1]; //0: 自动, 1:手动
  326. uint8_t level = pReq[2];
  327. *pRes = CC_NORMAL;
  328. if(index >= FAN_NUMBERS)
  329. {
  330. printf("Invalid index %d\n", index);
  331. *pRes = CC_PARAM_OUT_OF_RANGE;
  332. return 1;
  333. }
  334. if(mode > 1)
  335. {
  336. printf("Invalid mode %d\n", mode);
  337. *pRes = CC_PARAM_OUT_OF_RANGE;
  338. return 1;
  339. }
  340. if(level > 100)
  341. level = 100;
  342. gFanInfo[index].mode = mode;
  343. if(mode == 1)
  344. {
  345. gFanInfo[index].level = level;
  346. }
  347. return 1;
  348. }
  349. /*
  350. Req[0]: ChassisManageEn
  351. */
  352. int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  353. {
  354. int i, index;
  355. MsgPkt_T ReqPkt;
  356. MsgPkt_T ResPkt;
  357. pRes[0] = CC_NORMAL;
  358. //if(pReq[0] == 0)
  359. if(g_BMCInfo.isChMC == 0)
  360. {
  361. for(i=0;i<BLADE_NUMBERS;i++)
  362. {
  363. gBladeStatus[i].present = 0;
  364. gBladeStatus[i].healthStatus = 0;
  365. sprintf(gBladeStatus[i].bladeName, "---");
  366. gBladeStatus[i].slotID = 0;
  367. gBladeStatus[i].pwrStatus = 0;
  368. }
  369. //当前模块的信息
  370. if(g_BMCInfo.IndexInChassis < BLADE_NUMBERS)
  371. {
  372. gBladeStatus[g_BMCInfo.IndexInChassis].present = 1;
  373. gBladeStatus[g_BMCInfo.IndexInChassis].healthStatus = 1;
  374. memcpy(gBladeStatus[g_BMCInfo.IndexInChassis].bladeName, g_BMCInfo.BladeName, 31);
  375. gBladeStatus[g_BMCInfo.IndexInChassis].slotID = g_BMCInfo.SlotID;
  376. gBladeStatus[g_BMCInfo.IndexInChassis].pwrStatus = g_BMCInfo.PowerGoodFlag;
  377. gBladeStatus[g_BMCInfo.IndexInChassis].isChMC = 1; //从模块不能管理机箱,网页内显示机箱的默认选中刀片。
  378. }
  379. }
  380. else
  381. {
  382. for(index=0;index<BLADE_NUMBERS;index++)
  383. {
  384. if(gChassisIPMBAddr[index] == 0x20) //chMC
  385. {
  386. gBladeStatus[index].present = 1;
  387. gBladeStatus[index].healthStatus = 1;
  388. memcpy(gBladeStatus[index].bladeName, g_BMCInfo.BladeName, 31);
  389. gBladeStatus[index].slotID = g_BMCInfo.SlotID;
  390. gBladeStatus[index].pwrStatus = g_BMCInfo.PowerGoodFlag;
  391. gBladeStatus[index].isChMC = 1;
  392. continue;
  393. }
  394. ReqPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  395. ReqPkt.Cmd = CMD_GET_BLADE_INFO;
  396. ReqPkt.Size = 0;
  397. if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, gChassisIPMBAddr[index], PRIMARY_IPMB_CHANNEL))
  398. {
  399. // printf("RECV: ");
  400. // for(i=0;i<ResPkt.Size;i++)
  401. // printf("%x ", ResPkt.Data[i]);
  402. // printf("\n");
  403. if(ResPkt.Data[0] == 0)
  404. {
  405. gBladeStatus[index].present = 1;
  406. gBladeStatus[index].healthStatus = ResPkt.Data[1];
  407. memcpy(gBladeStatus[index].bladeName, &ResPkt.Data[2], 31);
  408. gBladeStatus[index].slotID = ResPkt.Data[33];
  409. gBladeStatus[index].pwrStatus = ResPkt.Data[34];
  410. gBladeStatus[index].isChMC = 0;
  411. }
  412. else
  413. {
  414. gBladeStatus[index].present = 0;
  415. gBladeStatus[index].healthStatus = 0;
  416. sprintf(gBladeStatus[index].bladeName, "---");
  417. gBladeStatus[index].slotID = 0;
  418. gBladeStatus[index].pwrStatus = 0;
  419. gBladeStatus[index].isChMC = 0;
  420. }
  421. }
  422. else
  423. {
  424. gBladeStatus[index].present = 0;
  425. gBladeStatus[index].healthStatus = 0;
  426. sprintf(gBladeStatus[index].bladeName, "---");
  427. gBladeStatus[index].slotID = 0;
  428. gBladeStatus[index].pwrStatus = 0;
  429. gBladeStatus[index].isChMC = 0;
  430. }
  431. }
  432. }
  433. memcpy(pRes+1, gBladeStatus, (BLADE_NUMBERS*sizeof(BladeStatus_T)));
  434. return 1+(BLADE_NUMBERS*sizeof(BladeStatus_T));
  435. }
  436. int Storlead_RestoreFactorSettings(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  437. {
  438. int i;
  439. pRes[0] = CC_NORMAL;
  440. //擦除Flash IpmiConfig
  441. pthread_mutex_lock(&Flash_Mutex);
  442. sf_sector_erase(5, CONFIG_FLASH_START);
  443. pthread_mutex_unlock(&Flash_Mutex);
  444. return 1;
  445. }
  446. int Storlead_GetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  447. {
  448. pRes[0] = CC_NORMAL;
  449. uint8_t index = pReq[0];
  450. if(index > 0)
  451. {
  452. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  453. return 1;
  454. }
  455. //Update LanInfo
  456. char ip_buf[16];
  457. getip(ip_buf);
  458. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0);
  459. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1);
  460. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2);
  461. g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3);
  462. char mask_buf[16];
  463. getnetmask(mask_buf);
  464. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0);
  465. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1);
  466. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2);
  467. g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3);
  468. char broadcast_buf[16];
  469. getbroadcast(broadcast_buf);
  470. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0);
  471. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1);
  472. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2);
  473. g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3);
  474. char mac_buf[18];
  475. getmac(mac_buf);
  476. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0);
  477. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1);
  478. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2);
  479. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3);
  480. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4);
  481. g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5);
  482. //TODO: get default GetWay
  483. memcpy(pRes+1, &g_BMCInfo.IpmiConfig.LanInfo[index], sizeof(LanInfo_T));
  484. return 1+sizeof(LanInfo_T);
  485. }
  486. /*
  487. Req[0]: index
  488. Req[1]: isSave 0:掉电不保存,1:掉电保存
  489. Req[2~n]: LanInfo_T
  490. */
  491. int Storlead_SetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  492. {
  493. MsgPkt_T m_MsgPkt;
  494. uint8_t index = pReq[0];
  495. uint8_t isSave = pReq[1];
  496. LanInfo_T *pLanInfo = (LanInfo_T*)&pReq[2];
  497. if(index > 0) //只有一张网卡,index只能是0
  498. {
  499. pRes[0] = CC_PARAM_OUT_OF_RANGE;
  500. return 1;
  501. }
  502. memcpy(&g_BMCInfo.IpmiConfig.LanInfo[index], pLanInfo, sizeof(LanInfo_T));
  503. m_MsgPkt.Param = PARAM_LAN;
  504. m_MsgPkt.NetFnLUN = NETFNLUN_IPMI_STORLEAD;
  505. m_MsgPkt.Cmd = CMD_SET_LAN_INFO;
  506. m_MsgPkt.Size = sizeof(LanInfo_T)+2;
  507. m_MsgPkt.Data[0] = index;
  508. m_MsgPkt.Data[1] = isSave;
  509. memcpy(&m_MsgPkt.Data[2], pLanInfo, sizeof(LanInfo_T));
  510. PostMsg(gPendActionIfc, &m_MsgPkt);
  511. pRes[0] = CC_NORMAL;
  512. return 1;
  513. }
  514. /*
  515. res[0]: completeCode
  516. res[1]: healthStatus; //0: 未知(灰色) 1:健康(绿色) 2:警告(黄色)3:错误(红色)
  517. res[2-22]: bladeName[31]; //10个汉字或30个字符
  518. res[23]: slotID;
  519. res[24]: pwrStatus; //0:未上电(灰色) 1:已上电(绿色)
  520. */
  521. int Storlead_GetBladeInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  522. {
  523. pRes[0] = CC_NORMAL;
  524. pRes[1] = g_BMCInfo.BladeHealthSta;
  525. memcpy(&pRes[2], g_BMCInfo.BladeName, 31);
  526. pRes[33] = g_BMCInfo.SlotID;
  527. pRes[34] = g_BMCInfo.PowerGoodFlag;
  528. return 35;
  529. }
  530. /*
  531. Req[0] : sensor number
  532. */
  533. int Storlead_GetSensorName(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  534. {
  535. int i;
  536. SensorInfo_T* pSensorInfo;
  537. memset(pRes, 0, MAX_ID_STR_LEN+1);
  538. for(i=0;i<SENSOR_NUMBERS;i++)
  539. {
  540. pSensorInfo = (SensorInfo_T *)&g_BMCInfo.SensorSharedMem.SensorInfo [i];
  541. if(pReq[0] == pSensorInfo->SensorNumber)
  542. {
  543. memcpy(&pRes[1], ((FullSensorRec_T*)pSensorInfo->SDRRec)->IDStr, MAX_ID_STR_LEN);
  544. break;
  545. }
  546. }
  547. return MAX_ID_STR_LEN+1;
  548. }
  549. int Storlead_GetCurRunTime(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  550. {
  551. pRes[0] = CC_NORMAL;
  552. pRes[1] = g_BMCInfo.BootValidMinutes&0xff; //LSB
  553. pRes[2] = (g_BMCInfo.BootValidMinutes>>8)&0xff;
  554. pRes[3] = (g_BMCInfo.BootValidMinutes>>16)&0xff;
  555. pRes[4] = (g_BMCInfo.BootValidMinutes>>24)&0xff;
  556. return 5;
  557. }
  558. int Storlead_SaveConfig(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  559. {
  560. pRes[0] = CC_NORMAL;
  561. int i;
  562. iflash_t iflash_arg;
  563. int ret = 0;
  564. int fd = open("/dev/iflash", O_RDWR);
  565. ret = ioctl(fd, IFLASH_UNLOCK, NULL);
  566. if(ret != 0)
  567. {
  568. printf("error: ret = %d\n", ret);
  569. }
  570. iflash_arg.sector = 8;
  571. ret = ioctl(fd, IFLASH_ERASESECTOR, &iflash_arg);
  572. if(ret != 0)
  573. {
  574. printf("error: ret = %d\n", ret);
  575. }
  576. /**** IpmiConfig + user info + FRU + SDR ****/
  577. //IpmiConfig 4KB
  578. iflash_arg.address = 0x08080000;
  579. iflash_arg.len = sizeof(IPMIConfig_T); //最大256字节
  580. memcpy(iflash_arg.data, &g_BMCInfo.IpmiConfig, sizeof(IPMIConfig_T));
  581. ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
  582. if(ret != 0)
  583. {
  584. printf("error: ret = %d\n", ret);
  585. }
  586. //user info 4KB
  587. uint8_t usrinfolen = 50;//sizeof(UserInfo_T);
  588. for(i=0;i<MAX_USER_NUM;i++)
  589. {
  590. iflash_arg.address = 0x08081000 + usrinfolen*i;//sizeof(UserInfo_T)*i;
  591. iflash_arg.len = usrinfolen;//sizeof(UserInfo_T); //最大256字节
  592. memcpy(iflash_arg.data, &(g_BMCInfo.UserInfoTbl[i]), usrinfolen);
  593. ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
  594. if(ret != 0)
  595. {
  596. printf("error: ret = %d\n", ret);
  597. }
  598. }
  599. //FRU 4KB
  600. iflash_arg.address = 0x08082000;
  601. iflash_arg.len = sizeof(OemFRUData_T); //最大256字节
  602. memcpy(iflash_arg.data, &g_BMCInfo.FRU, sizeof(OemFRUData_T));
  603. ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
  604. if(ret != 0)
  605. {
  606. printf("error: ret = %d\n", ret);
  607. }
  608. //SDR 4KB
  609. uint32_t sdrSize =
  610. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  611. uint32_t writebytes = 0;
  612. while(sdrSize>0)
  613. {
  614. iflash_arg.address = 0x08083000 + writebytes;
  615. if(sdrSize > 256)
  616. {
  617. iflash_arg.len = 256; //最大256字节
  618. memcpy(iflash_arg.data, g_BMCInfo.pSDR+writebytes, 256);
  619. // printf("L1: ");
  620. // for(i=0;i<iflash_arg.len;i++)
  621. // printf("%02x ", iflash_arg.data[i]);
  622. // printf("\n");
  623. writebytes += 256;
  624. sdrSize -= 256;
  625. }
  626. else
  627. {
  628. iflash_arg.len = sdrSize; //最大256字节
  629. memcpy(iflash_arg.data, g_BMCInfo.pSDR+writebytes, sdrSize);
  630. // printf("L2: ");
  631. // for(i=0;i<iflash_arg.len;i++)
  632. // printf("%02x ", iflash_arg.data[i]);
  633. // printf("\n");
  634. writebytes += sdrSize;
  635. sdrSize = 0;
  636. }
  637. ret = ioctl(fd, IFLASH_WRITEBYTE, &iflash_arg);
  638. if(ret != 0)
  639. {
  640. printf("error: ret = %d\n", ret);
  641. }
  642. }
  643. ret = ioctl(fd, IFLASH_LOCK, NULL);
  644. if(ret != 0)
  645. {
  646. printf("error: ret = %d\n", ret);
  647. }
  648. close(fd);
  649. return 1;
  650. }
  651. int Storlead_RestoreConfig(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
  652. {
  653. pRes[0] = CC_NORMAL;
  654. int i;
  655. uint8_t buf[32] = {0};
  656. /**** IpmiConfig + user info + FRU + SDR ****/
  657. memcpy(buf, (uint8_t*)0x08080000, 32);
  658. if(strcmp(buf, FirstPowerOnStr) != 0)
  659. {
  660. printf("No invalid config data!\n");
  661. return 1;
  662. }
  663. //IpmiConfig 4KB
  664. memcpy(&g_BMCInfo.IpmiConfig, (uint8_t*)0x08080000, sizeof(IPMIConfig_T));
  665. FlushIPMIToFlash();
  666. //user info 4KB
  667. uint8_t usrinfolen = 50;
  668. for(i=0;i<MAX_USER_NUM;i++)
  669. {
  670. memcpy(&(g_BMCInfo.UserInfoTbl[i]), (uint8_t*)0x08081000 + usrinfolen*i, sizeof(UserInfo_T));
  671. }
  672. FlushUserInfoTbl();
  673. //FRU 4KB
  674. memcpy(&g_BMCInfo.FRU, (uint8_t*)0x08082000, sizeof(OemFRUData_T));
  675. FlushFRUToFlash();
  676. //SDR 4KB
  677. uint32_t sdrSize =
  678. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) +
  679. sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  680. memcpy(g_BMCInfo.pSDR, (uint8_t*)0x08083000, sdrSize);
  681. // printf("read: ");
  682. // for(i=0;i<sdrSize;i++)
  683. // printf("%02x ", ((uint8_t*)0x08083000)[i]);
  684. // printf("\n");
  685. FlushSDRToFlash();
  686. return 1;
  687. }