Storlead.c 10 KB

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