Storlead.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. int Storlead_GetSysInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  11. {
  12. char Title[] = "CPU info";
  13. char Text[] = "CPU:Intel;Freq:1 GHZ;Memory:8 GB;Brief:This section test long string. Very very long string. long enough? not long";
  14. int len = 0,remainLen = 0;
  15. uint16_t offset = (pReq[1]<<8) | pReq[2];
  16. int totalLen = 0;
  17. char *pStr = NULL;
  18. int reqLen = (pReq[3]<<8) | pReq[4];
  19. switch(pReq[0])
  20. {
  21. case 0: //get Title
  22. while(Title[totalLen])
  23. {
  24. totalLen++;
  25. }printf("title total len = %#x\n",totalLen);
  26. pStr = Title;
  27. break;
  28. case 1:
  29. while(Text[totalLen])
  30. {
  31. totalLen++;
  32. }
  33. printf("text total len = %#x\n", totalLen);
  34. pStr = Text;
  35. break;
  36. default:
  37. *pRes = CC_PARAM_OUT_OF_RANGE;
  38. return 1;
  39. }
  40. *pRes= CC_NORMAL;
  41. if(offset > totalLen)
  42. {
  43. printf("Invalid offset: %#x\n", offset);
  44. *pRes= CC_PARAM_OUT_OF_RANGE;
  45. return 1;
  46. }
  47. if(reqLen == 0)
  48. {
  49. len = totalLen - offset;
  50. }
  51. else
  52. {
  53. len = (reqLen > (totalLen-offset)) ? (totalLen-offset) : reqLen;
  54. }
  55. remainLen = totalLen - offset - len;
  56. *(pRes+1) = (len>>8)&0xff;
  57. *(pRes+2) = len&0xff;
  58. *(pRes+3) = (remainLen>>8)&0xff;
  59. *(pRes+4) = remainLen&0xff;
  60. memcpy(pRes+5, pStr+offset, len);
  61. // int i;
  62. // printf("Example 80h: ");
  63. // for(i=0;i<5+len;i++)
  64. // printf("%#x ", pRes[i]);
  65. // printf("\n");
  66. return 5+len;
  67. }
  68. int Storlead_GetSensorInfo(uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  69. {
  70. printf("Storlead_GetSensorInfo\n" );
  71. StorleadGetSensorInfoRes_T *pGetSensorInfoRes = (StorleadGetSensorInfoRes_T *)pRes;
  72. uint8_t* pValidSensor = NULL;
  73. uint16_t SensorIndex = pReq[0];
  74. SensorInfo_T pSensor ;
  75. SenInfo_T SensorInfo;
  76. uint8_t SensorIsSigned = FALSE;
  77. uint16_t SensorReading = 0;
  78. SensorSharedMem_T* pSMSharedMem;
  79. SDRRecHdr_T* pSDRRec;
  80. FullSensorRec_T* FullSDR;
  81. CompactSensorRec_T* CompSDR;
  82. int i = 0;
  83. int totalsize;
  84. /* Get the Sensor Shared Memory */
  85. pSMSharedMem = (SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem;
  86. if(g_BMCInfo.SenConfig.ValidSensorCnt == 0)
  87. {
  88. pGetSensorInfoRes->CompletionCode = OEMCC_SENSOR_INFO_EMPTY;
  89. printf("ValidSensorCnt is 0\n");
  90. return 1;
  91. }
  92. if(SensorIndex >= g_BMCInfo.SenConfig.ValidSensorCnt)
  93. {
  94. pGetSensorInfoRes->CompletionCode = CC_PARAM_OUT_OF_RANGE;
  95. printf("Invalid SenosrIndex %d\n", SensorIndex);
  96. return 1;
  97. }
  98. //pValidSensor = (uint8_t*)(pAMIGetSensorInfoRes+1);
  99. // for(i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++)
  100. // {
  101. //SensorIndex = g_BMCInfo.SenConfig.ValidSensorList[i];
  102. pSensor = pSMSharedMem->SensorInfo[SensorIndex];
  103. /*Copy the SDR Header*/
  104. memcpy(&pGetSensorInfoRes->SensorInfo.hdr,pSensor.SDRRec,sizeof(SDRRecHdr_T));
  105. pGetSensorInfoRes->SensorInfo.SensorNumber = pSensor.SensorNumber;
  106. pGetSensorInfoRes->SensorInfo.SensorTypeCode = pSensor.SensorTypeCode;
  107. pGetSensorInfoRes->SensorInfo.EventTypeCode = pSensor.EventTypeCode;
  108. pGetSensorInfoRes->SensorInfo.Units1 = pSensor.Units1;
  109. pGetSensorInfoRes->SensorInfo.Units2 = pSensor.Units2;
  110. pGetSensorInfoRes->SensorInfo.Units3 = pSensor.Units3;
  111. pGetSensorInfoRes->SensorInfo.M_LSB = pSensor.M_LSB;
  112. pGetSensorInfoRes->SensorInfo.M_MSB_Tolerance = pSensor.M_MSB_Tolerance;
  113. pGetSensorInfoRes->SensorInfo.B_LSB = pSensor.B_LSB;
  114. pGetSensorInfoRes->SensorInfo.B_MSB_Accuracy = pSensor.B_MSB_Accuracy;
  115. pGetSensorInfoRes->SensorInfo.Accuracy_MSB_Exp = pSensor.Accuracy_MSB_Exp;
  116. pGetSensorInfoRes->SensorInfo.RExp_BExp = pSensor.RExp_BExp;
  117. pGetSensorInfoRes->SensorInfo.LowerNonCritical = pSensor.LowerNonCritical;
  118. pGetSensorInfoRes->SensorInfo.LowerCritical = pSensor.LowerCritical;
  119. pGetSensorInfoRes->SensorInfo.LowerNonRecoverable = pSensor.LowerNonRecoverable;
  120. pGetSensorInfoRes->SensorInfo.UpperNonCritical = pSensor.UpperNonCritical;
  121. pGetSensorInfoRes->SensorInfo.UpperCritical = pSensor.UpperCritical;
  122. pGetSensorInfoRes->SensorInfo.UpperNonRecoverable= pSensor.UpperNonRecoverable;
  123. pGetSensorInfoRes->SensorInfo.Settable_Readable_ThreshMask= pSensor.SettableThreshMask;
  124. pGetSensorInfoRes->SensorInfo.Flags = pSensor.EventFlags & 0xe0;
  125. if((pSensor.EventFlags & BIT5) != 0)
  126. {
  127. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  128. }
  129. SensorReading = pSensor.SensorReading;
  130. pGetSensorInfoRes->SensorInfo.SensorReading = 0;
  131. SensorIsSigned = ( 0 != (pSensor.InternalFlags & BIT1));
  132. if (THRESHOLD_SENSOR_CLASS == pSensor.EventTypeCode)
  133. {
  134. pGetSensorInfoRes->SensorInfo.SensorReading = (SensorReading & 0x00FF);
  135. pGetSensorInfoRes->SensorInfo.ComparisonStatus = 0;
  136. if((pSensor.DeassertionEventEnablesByte2 & BIT6) == BIT6 )
  137. {
  138. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonRecoverable) >= 0)
  139. {
  140. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT5;
  141. }
  142. }
  143. if((pSensor.DeassertionEventEnablesByte2 & BIT5) == BIT5 )
  144. {
  145. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperCritical) >= 0)
  146. {
  147. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT4;
  148. }
  149. }
  150. if((pSensor.DeassertionEventEnablesByte2 & BIT4) == BIT4 )
  151. {
  152. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.UpperNonCritical) >= 0)
  153. {
  154. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT3;
  155. }
  156. }
  157. if((pSensor.AssertionEventEnablesByte2 & BIT6) == BIT6 )
  158. {
  159. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonRecoverable) <= 0)
  160. {
  161. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT2;
  162. }
  163. }
  164. if((pSensor.AssertionEventEnablesByte2 & BIT5) == BIT5 )
  165. {
  166. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerCritical) <= 0)
  167. {
  168. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT1;
  169. }
  170. }
  171. if((pSensor.AssertionEventEnablesByte2 & BIT4) == BIT4 )
  172. {
  173. if (CompareValues(SensorIsSigned, pGetSensorInfoRes->SensorInfo.SensorReading, pSensor.LowerNonCritical) <= 0)
  174. {
  175. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= BIT0;
  176. }
  177. }
  178. pGetSensorInfoRes->SensorInfo.ComparisonStatus &= ((pSensor.SettableThreshMask >> 8) & 0xFF);
  179. pGetSensorInfoRes->SensorInfo.OptionalStatus = 0;
  180. // For Threshold sensor, [7:6] - reserved. Returned as 1b. Ignore on read.
  181. pGetSensorInfoRes->SensorInfo.ComparisonStatus |= THRESHOLD_RESERVED_BIT;
  182. }
  183. else
  184. {
  185. pGetSensorInfoRes->SensorInfo.ComparisonStatus = (((uint8_t) (SensorReading & 0x00FF)) & ((uint8_t) (pSensor.SettableThreshMask & 0x00FF)) );
  186. pGetSensorInfoRes->SensorInfo.OptionalStatus = (((uint8_t) (SensorReading >> 8)) & ((uint8_t) (pSensor.SettableThreshMask >> 8)) );
  187. // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read.
  188. pGetSensorInfoRes->SensorInfo.OptionalStatus |= DISCRETE_RESERVED_BIT;
  189. }
  190. if((pSensor.EventFlags & BIT7) == 0)
  191. {
  192. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = 0;
  193. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = 0;
  194. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = 0;
  195. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = 0;
  196. }
  197. if((pSensor.SensorCaps & BIT6) == 0)
  198. {
  199. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionHistoryByte1 & pSensor.AssertionEventEnablesByte1);
  200. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionHistoryByte2 & pSensor.AssertionEventEnablesByte2);
  201. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionHistoryByte1 & pSensor.DeassertionEventEnablesByte1);
  202. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionHistoryByte2 & pSensor.DeassertionEventEnablesByte2);
  203. }
  204. else
  205. {
  206. pGetSensorInfoRes->SensorInfo.AssertionEventByte1 = (pSensor.AssertionEventOccuredByte1 & pSensor.AssertionEventEnablesByte1);
  207. pGetSensorInfoRes->SensorInfo.AssertionEventByte2 = (pSensor.AssertionEventOccuredByte2 & pSensor.AssertionEventEnablesByte2);
  208. pGetSensorInfoRes->SensorInfo.DeassertionEventByte1 = (pSensor.DeassertionEventOccuredByte1 & pSensor.DeassertionEventEnablesByte1);
  209. pGetSensorInfoRes->SensorInfo.DeassertionEventByte2 = (pSensor.DeassertionEventOccuredByte2 & pSensor.DeassertionEventEnablesByte2);
  210. }
  211. pSDRRec = GetSDRRec(pSensor.SDRRec->ID);
  212. if(pSensor.SDRRec->Type == FULL_SDR_REC) /*Full SDR*/
  213. {
  214. FullSDR = (FullSensorRec_T *)pSDRRec;
  215. pGetSensorInfoRes->SensorInfo.OwnerID = FullSDR->OwnerID;
  216. pGetSensorInfoRes->SensorInfo.OwnerLUN= FullSDR->OwnerLUN;
  217. pGetSensorInfoRes->SensorInfo.MaxReading = FullSDR->MaxReading;
  218. pGetSensorInfoRes->SensorInfo.MinReading = FullSDR->MinReading;
  219. pGetSensorInfoRes->SensorInfo.Linearization = FullSDR->Linearization;
  220. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  221. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,FullSDR->IDStr, MAX_ID_STR_LEN - (sizeof(FullSensorRec_T) - sizeof(SDRRecHdr_T) - FullSDR->hdr.Len));
  222. }
  223. else if(pSensor.SDRRec->Type == COMPACT_SDR_REC) /*Compact SDR*/
  224. {
  225. CompSDR = (CompactSensorRec_T *)pSDRRec;
  226. pGetSensorInfoRes->SensorInfo.OwnerID = CompSDR->OwnerID;
  227. pGetSensorInfoRes->SensorInfo.OwnerLUN= CompSDR->OwnerLUN;
  228. pGetSensorInfoRes->SensorInfo.MaxReading = 0;
  229. pGetSensorInfoRes->SensorInfo.MinReading = 0;
  230. pGetSensorInfoRes->SensorInfo.Linearization = 0;
  231. memset(pGetSensorInfoRes->SensorInfo.SensorName,0,MAX_ID_STR_LEN);
  232. strncpy(pGetSensorInfoRes->SensorInfo.SensorName,CompSDR->IDStr, MAX_ID_STR_LEN - (sizeof(CompactSensorRec_T) - sizeof(SDRRecHdr_T) - CompSDR->hdr.Len));
  233. }
  234. //memcpy(pValidSensor,(uint8_t *)&SensorInfo,sizeof(SenInfo_T));
  235. //pValidSensor = pValidSensor + sizeof(SenInfo_T);
  236. //}
  237. pGetSensorInfoRes->CompletionCode = CC_NORMAL;
  238. //pAMIGetSensorInfoRes->Noofentries = g_BMCInfo.SenConfig.ValidSensorCnt;
  239. //totalsize = sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * 11/*g_BMCInfo.SenConfig.ValidSensorCnt*/);
  240. // printf("return %d :", totalsize);
  241. // for(i=0;i<sizeof(AMIGetSensorInfoRes_T) + (sizeof(SenInfo_T) * g_BMCInfo.SenConfig.ValidSensorCnt);i++)
  242. // printf("%#x ", pRes[i]);
  243. // printf("\n");
  244. return sizeof(StorleadGetSensorInfoRes_T);
  245. }