libipmi_sensor.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. /*****************************************************************
  2. ******************************************************************
  3. *** ***
  4. *** (C)Copyright 2008, American Megatrends Inc. ***
  5. *** ***
  6. *** All Rights Reserved ***
  7. *** ***
  8. *** 5555 Oakbrook Parkway, Norcross, GA 30093, USA ***
  9. *** ***
  10. *** Phone 770.246.8600 ***
  11. *** ***
  12. ******************************************************************
  13. ******************************************************************
  14. ******************************************************************
  15. *
  16. * Filename: libipmi_sensor.c
  17. *
  18. ******************************************************************/
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include "libipmi_session.h"
  24. #include "libipmi_errorcodes.h"
  25. #include "libipmi_sensor.h"
  26. #include "libipmi_AppDevice.h"
  27. #include "libipmi_storlead_OEM.h"
  28. #include "com_BmcType.h"
  29. #include "com_IPMIDefs.h"
  30. #include "com_IPMI_Storlead.h"
  31. #define PACKED __attribute__ ((packed))
  32. #include "com_IPMI_SDRRecord.h"
  33. #include "com_IPMI_SensorEvent.h"
  34. /* 35.2 Get Device SDR Info Command */
  35. uint16_t IPMICMD_GetSDRInfo( IPMI20_UDS_SESSION_T *pUDSSession,
  36. uint8_t *pReqGetSDRInfo,
  37. GetSDRInfoRes_T *pResGetSDRInfo,
  38. int timeout)
  39. {
  40. uint16_t wRet;
  41. uint32_t dwResLen;
  42. dwResLen = MAX_RESPONSE_SIZE;
  43. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  44. NETFNLUN_IPMI_SENSOR, CMD_GET_DEV_SDR_INFO,
  45. (uint8_t*)pReqGetSDRInfo, sizeof(uint8_t),
  46. (uint8_t *)pResGetSDRInfo, &dwResLen,
  47. timeout);
  48. return wRet;
  49. }
  50. /* 35.3 Get Device SDR Command */
  51. uint16_t IPMICMD_GetDevSDR( IPMI20_UDS_SESSION_T *pUDSSession,
  52. GetDevSDRReq_T *pReqDevSDR,
  53. GetDevSDRRes_T *pResDevSDR,
  54. uint32_t *pOutBuffLen,
  55. int timeout)
  56. {
  57. uint16_t wRet;
  58. uint32_t dwResLen;
  59. dwResLen = sizeof(GetDevSDRRes_T);
  60. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  61. NETFNLUN_IPMI_SENSOR, CMD_GET_DEV_SDR,
  62. (uint8_t*)pReqDevSDR, sizeof(GetDevSDRReq_T),
  63. (uint8_t *)pResDevSDR, &dwResLen,
  64. timeout);
  65. *pOutBuffLen = dwResLen;
  66. return wRet;
  67. }
  68. /* 35.4 Reserve Device SDR Repository Command */
  69. uint16_t IPMICMD_ReserveDevSDR( IPMI20_UDS_SESSION_T *pUDSSession,
  70. ReserveDevSDRRes_T *pResReserveDevSDR,
  71. int timeout)
  72. {
  73. char Req[20];
  74. uint16_t wRet;
  75. uint32_t dwResLen;
  76. dwResLen = sizeof(ReserveDevSDRRes_T);
  77. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  78. NETFNLUN_IPMI_SENSOR, CMD_RESERVE_DEV_SDR_REPOSITORY,
  79. (uint8_t*)Req, 0,
  80. (uint8_t *)pResReserveDevSDR, &dwResLen,
  81. timeout);
  82. return wRet;
  83. }
  84. /* 35.5 Get Sensor Reading Factors Command */
  85. uint16_t IPMICMD_GetSensorReadingFactor( IPMI20_UDS_SESSION_T *pUDSSession,
  86. GetSensorReadingFactorReq_T *pReqGetSensorReadingFactor,
  87. GetSensorReadingFactorRes_T *pResGetSensorReadingFactor,
  88. int timeout)
  89. {
  90. uint16_t wRet;
  91. uint32_t dwResLen;
  92. dwResLen = sizeof(GetSensorReadingFactorRes_T);
  93. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  94. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_READING_FACTORS,
  95. (uint8_t*)pReqGetSensorReadingFactor, sizeof(GetSensorReadingFactorReq_T),
  96. (uint8_t *)pResGetSensorReadingFactor, &dwResLen,
  97. timeout);
  98. return wRet;
  99. }
  100. /* 35.6 Set Sensor Hysteresis Command */
  101. uint16_t IPMICMD_SetSensorHysterisis( IPMI20_UDS_SESSION_T *pUDSSession,
  102. SetSensorHysterisisReq_T *pReqSetSensorHysterisis,
  103. SetSensorHysterisisRes_T *pResSetSensorHysterisis,
  104. int timeout)
  105. {
  106. uint16_t wRet;
  107. uint32_t dwResLen;
  108. dwResLen = sizeof(SetSensorHysterisisRes_T);
  109. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  110. NETFNLUN_IPMI_SENSOR, CMD_SET_SENSOR_HYSTERISIS,
  111. (uint8_t*)pReqSetSensorHysterisis, sizeof(SetSensorHysterisisReq_T),
  112. (uint8_t *)pResSetSensorHysterisis, &dwResLen,
  113. timeout);
  114. return wRet;
  115. }
  116. /* 35.7 Get Sensor Hysteresis Command */
  117. uint16_t IPMICMD_GetSensorHysterisis( IPMI20_UDS_SESSION_T *pUDSSession,
  118. GetSensorHysterisisReq_T *pReqGetSensorHysterisis,
  119. GetSensorHysterisisRes_T *pResGetSensorHysterisis,
  120. int timeout)
  121. {
  122. uint16_t wRet;
  123. uint32_t dwResLen;
  124. dwResLen = sizeof(GetSensorHysterisisRes_T);
  125. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  126. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_HYSTERISIS,
  127. (uint8_t*)pReqGetSensorHysterisis, sizeof(GetSensorHysterisisReq_T),
  128. (uint8_t *)pResGetSensorHysterisis, &dwResLen,
  129. timeout);
  130. return wRet;
  131. }
  132. /* 35.8 Set Sensor Thresholds Command */
  133. uint16_t IPMICMD_SetSensorThreshold( IPMI20_UDS_SESSION_T *pUDSSession,
  134. SetSensorThresholdReq_T *pReqSetSensorThreshold,
  135. SetSensorThresholdRes_T *pResSetSensorThreshold,
  136. int timeout)
  137. {
  138. uint16_t wRet;
  139. uint32_t dwResLen;
  140. dwResLen = sizeof(SetSensorThresholdRes_T);
  141. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  142. NETFNLUN_IPMI_SENSOR, CMD_SET_SENSOR_THRESHOLDS,
  143. (uint8_t*)pReqSetSensorThreshold, sizeof(SetSensorThresholdReq_T),
  144. (uint8_t *)pResSetSensorThreshold, &dwResLen,
  145. timeout);
  146. return wRet;
  147. }
  148. /* 35.9 Get Sensor Thresholds Command */
  149. uint16_t IPMICMD_GetSensorThreshold( IPMI20_UDS_SESSION_T *pUDSSession,
  150. GetSensorThresholdReq_T *pReqGetSensorThreshold,
  151. GetSensorThresholdRes_T *pResGetSensorThreshold,
  152. int timeout)
  153. {
  154. uint16_t wRet;
  155. uint32_t dwResLen;
  156. dwResLen = sizeof(GetSensorThresholdRes_T);
  157. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  158. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_THRESHOLDS,
  159. (uint8_t*)pReqGetSensorThreshold, sizeof(GetSensorThresholdReq_T),
  160. (uint8_t *)pResGetSensorThreshold, &dwResLen,
  161. timeout);
  162. return wRet;
  163. }
  164. /* 35.10 Set Sensor Event Enable Command */
  165. uint16_t IPMICMD_SetSensorEventEnable( IPMI20_UDS_SESSION_T *pUDSSession,
  166. SetSensorEventEnableReq_T *pReqSetSensorEventEnable,
  167. SetSensorEventEnableRes_T *pResSetSensorEventEnable,
  168. int timeout)
  169. {
  170. uint16_t wRet;
  171. uint32_t dwResLen;
  172. dwResLen = sizeof(SetSensorEventEnableRes_T);
  173. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  174. NETFNLUN_IPMI_SENSOR, CMD_SET_SENSOR_EVENT_ENABLE,
  175. (uint8_t*)pReqSetSensorEventEnable, sizeof(SetSensorEventEnableReq_T),
  176. (uint8_t *)pResSetSensorEventEnable, &dwResLen,
  177. timeout);
  178. return wRet;
  179. }
  180. /* 35.11 Get Sensor Event Enable Command */
  181. uint16_t IPMICMD_GetSensorEventEnable( IPMI20_UDS_SESSION_T *pUDSSession,
  182. GetSensorEventEnableReq_T *pReqGetSensorEventEnable,
  183. GetSensorEventEnableRes_T *pResGetSensorEventEnable,
  184. int timeout)
  185. {
  186. uint16_t wRet;
  187. uint32_t dwResLen;
  188. dwResLen = sizeof(GetSensorEventEnableRes_T);
  189. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  190. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_EVENT_ENABLE,
  191. (uint8_t*)pReqGetSensorEventEnable, sizeof(GetSensorEventEnableReq_T),
  192. (uint8_t *)pResGetSensorEventEnable, &dwResLen,
  193. timeout);
  194. return wRet;
  195. }
  196. /* 35.12 ReArm Sensor Events Command */
  197. uint16_t IPMICMD_ReArmSensorEvents( IPMI20_UDS_SESSION_T *pUDSSession,
  198. ReArmSensorReq_T *pReArmSensorReq,
  199. ReArmSensorRes_T *pReArmSensorRes,
  200. int timeout)
  201. {
  202. uint16_t wRet;
  203. uint32_t dwResLen;
  204. dwResLen = sizeof(ReArmSensorRes_T);
  205. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  206. NETFNLUN_IPMI_SENSOR, CMD_REARM_SENSOR_EVENTS,
  207. (uint8_t*)pReArmSensorReq, sizeof(ReArmSensorReq_T),
  208. (uint8_t *)pReArmSensorRes, &dwResLen,
  209. timeout);
  210. return wRet;
  211. }
  212. /* 35.13 Get Sensor Event Status Command */
  213. uint16_t IPMICMD_GetSensorEventStatus( IPMI20_UDS_SESSION_T *pUDSSession,
  214. GetSensorEventStatusReq_T *pReqGetSensorEventStatus,
  215. GetSensorEventStatusRes_T *pResGetSensorEventStatus,
  216. int timeout)
  217. {
  218. uint16_t wRet;
  219. uint32_t dwResLen;
  220. dwResLen = sizeof(GetSensorEventStatusRes_T);
  221. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  222. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_EVENT_STATUS,
  223. (uint8_t*)pReqGetSensorEventStatus, sizeof(GetSensorEventEnableReq_T),
  224. (uint8_t *)pResGetSensorEventStatus, &dwResLen,
  225. timeout);
  226. return wRet;
  227. }
  228. /* 35.14 Get Sensor Reading Command */
  229. uint16_t IPMICMD_GetSensorReading( IPMI20_UDS_SESSION_T *pUDSSession,
  230. GetSensorReadingReq_T *pReqGetSensorReading,
  231. GetSensorReadingRes_T *pResGetSensorReading,
  232. int timeout)
  233. {
  234. uint16_t wRet;
  235. uint32_t dwResLen;
  236. dwResLen = sizeof(GetSensorReadingRes_T);
  237. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  238. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_READING,
  239. (uint8_t*)pReqGetSensorReading, sizeof(GetSensorReadingReq_T),
  240. (uint8_t *)pResGetSensorReading, &dwResLen,
  241. timeout);
  242. return wRet;
  243. }
  244. /* 35.15 Set Sensor Type Command */
  245. uint16_t IPMICMD_SetSensorType( IPMI20_UDS_SESSION_T *pUDSSession,
  246. SetSensorTypeReq_T *pReqSetSensorType,
  247. SetSensorTypeRes_T *pResSetSensorType,
  248. int timeout)
  249. {
  250. uint16_t wRet;
  251. uint32_t dwResLen;
  252. dwResLen = sizeof(SetSensorTypeRes_T);
  253. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  254. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_READING,
  255. (uint8_t*)pReqSetSensorType, sizeof(SetSensorTypeReq_T),
  256. (uint8_t *)pResSetSensorType, &dwResLen,
  257. timeout);
  258. return wRet;
  259. }
  260. /* 35.16 Get Sensor Type Command */
  261. uint16_t IPMICMD_GetSensorType( IPMI20_UDS_SESSION_T *pUDSSession,
  262. GetSensorTypeReq_T *pReqGetSensorType,
  263. GetSensorTypeRes_T *pResGetSensorType,
  264. int timeout)
  265. {
  266. uint16_t wRet;
  267. uint32_t dwResLen;
  268. dwResLen = sizeof(GetSensorTypeRes_T);
  269. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  270. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_READING,
  271. (uint8_t*)pReqGetSensorType, sizeof(GetSensorTypeReq_T),
  272. (uint8_t *)pResGetSensorType, &dwResLen,
  273. timeout);
  274. return wRet;
  275. }
  276. uint16_t IPMICMD_SetSensorReading( IPMI20_UDS_SESSION_T *pUDSSession,
  277. SetSensorReadingReq_T *pReqSetSensorReading,
  278. SetSensorReadingRes_T *pResSetSensorReading,
  279. int timeout)
  280. {
  281. uint16_t wRet;
  282. uint32_t dwResLen;
  283. dwResLen = sizeof(SetSensorReadingRes_T);
  284. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  285. NETFNLUN_IPMI_SENSOR,CMD_SET_SENSOR_READING,
  286. (uint8_t*)pReqSetSensorReading, sizeof(SetSensorReadingReq_T),
  287. (uint8_t *)pResSetSensorReading , &dwResLen,
  288. timeout);
  289. return wRet;
  290. }
  291. /* ------------------ High level functions ------------------ */
  292. //#define SDR_FILE_PATH "/tmp/sdr_data"
  293. uint16_t
  294. LIBIPMI_HL_ReadSensorFromSDR( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t *sdr_buffer,
  295. uint8_t *raw_reading, float *reading,
  296. uint8_t *discrete, int timeout )
  297. {
  298. // SDRRecHdr_T *header = (SDRRecHdr_T *)sdr_buffer;
  299. // uint8_t SendMsg= FALSE;
  300. // GetSensorReadingReq_T get_reading_req;
  301. // GetSensorReadingRes_T get_reading_res;
  302. // AMIGetChNumRes_T pAMIGetChNumRes;
  303. // uint8_t SendMsgReq[5];
  304. // uint32_t SendMsgReqLen = 0;
  305. // uint8_t record_type;
  306. // uint16_t wRet;
  307. // *discrete = (u8)0;
  308. // record_type = header->Type;
  309. // if( record_type == 0x01 )
  310. // {
  311. // FullSensorRec_T *record;
  312. // /* Determine if sensor is discrete, and pull out the sensor number */
  313. // record = (FullSensorRec_T *)sdr_buffer;
  314. // if( record->EventTypeCode > 0x01 )
  315. // *discrete = record->EventTypeCode;
  316. // if(record->OwnerID != 0x20)
  317. // {
  318. // wRet = IPMICMD_AMIGetChNum (pUDSSession,&pAMIGetChNumRes,
  319. // timeout);
  320. // SendMsg = TRUE;
  321. // SendMsgReq[0] = 0x40 | pAMIGetChNumRes.ChannelNum;
  322. // SendMsgReq[1] = record->OwnerID;
  323. // SendMsgReq[2] = NETFN_SENSOR;
  324. // SendMsgReq[3] = CMD_GET_SENSOR_READING;
  325. // SendMsgReq[4] = record->SensorNum;
  326. // SendMsgReqLen = 5;
  327. // }
  328. // else
  329. // {
  330. // get_reading_req.SensorNum = record->SensorNum;
  331. // }
  332. // }
  333. // else if( record_type == 0x02 )
  334. // {
  335. // CompactSensorRec_T *record;
  336. // /* Determine if sensor is discrete, and pull out the sensor number */
  337. // record = (CompactSensorRec_T *)sdr_buffer;
  338. // if( record->EventTypeCode > 0x01 )
  339. // *discrete = record->EventTypeCode;
  340. // if(record->OwnerID != 0x20)
  341. // {
  342. // wRet = IPMICMD_AMIGetChNum (pUDSSession,&pAMIGetChNumRes,
  343. // timeout);
  344. // SendMsg = TRUE;
  345. // SendMsgReq[0] = 0x40 | pAMIGetChNumRes.ChannelNum;
  346. // SendMsgReq[1] = record->OwnerID;
  347. // SendMsgReq[2] = NETFN_SENSOR;
  348. // SendMsgReq[3] = CMD_GET_SENSOR_READING;
  349. // SendMsgReq[4] = record->SensorNum;
  350. // SendMsgReqLen = 5;
  351. // }
  352. // else
  353. // {
  354. // get_reading_req.SensorNum = record->SensorNum;
  355. // }
  356. // }
  357. // else
  358. // {
  359. // /* We only know how to read sensors with records */
  360. // /* of type full or compact */
  361. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_INVALID_SDR_ENTRY ) );
  362. // }
  363. // if(SendMsg == TRUE)
  364. // {
  365. // /*SendMessage Command to Get Sensor Reading when sensor Owner ID is not 0x20 */
  366. // wRet = IPMICMD_SendMessage(pUDSSession,SendMsgReq,(uint8_t *)&get_reading_res,
  367. // SendMsgReqLen,timeout);
  368. // if(get_reading_res.CompletionCode == CC_TIMEOUT)
  369. // {
  370. // get_reading_res.Flags &= 0x20;
  371. // }
  372. // else if( wRet != LIBIPMI_E_SUCCESS)
  373. // {
  374. // return( wRet );
  375. // }
  376. // }
  377. // else
  378. // {
  379. // /* Get the sensor reading */
  380. // wRet = IPMICMD_GetSensorReading( pUDSSession, &get_reading_req,
  381. // &get_reading_res, timeout );
  382. // if( wRet != LIBIPMI_E_SUCCESS )
  383. // {
  384. // //printf("falied when readinf sensor no %d\n",get_reading_req.SensorNum);
  385. // return( wRet );
  386. // }
  387. // }
  388. // /* Pass the raw reading out to the caller. */
  389. // /* We need this for discrete sensors. */
  390. // *raw_reading = get_reading_res.SensorReading;
  391. // /* If sensor scanning is disabled or the reading is unavailable... */
  392. // if( !( get_reading_res.Flags & 0x40 ) || ( get_reading_res.Flags & 0x20) )
  393. // {
  394. // /* Return an error code to let the caller know */
  395. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_SENSOR_DISABLED ) );
  396. // }
  397. // if( *discrete )
  398. // {
  399. // /* Pass the discrete state information back in the reading variable */
  400. // *reading = (float)( get_reading_res.ComparisonStatus |
  401. // ( get_reading_res.OptionalStatus << 8 ) );
  402. // }
  403. // else
  404. // {
  405. // /* Convert raw sensor reading to final form */
  406. // ipmi_convert_reading( sdr_buffer, *raw_reading, reading );
  407. // }
  408. return( LIBIPMI_E_SUCCESS );
  409. }
  410. uint16_t
  411. LIBIPMI_HL_LoadSensorSDRs( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t **sdr_buffer,
  412. int *count, int timeout )
  413. {
  414. // FILE *sdrfile;
  415. // uint8_t *local_sdr_buffer = NULL;
  416. // /* Open the SDR file */
  417. // sdrfile = fopen( SDR_FILE_PATH, "r" );
  418. // if( sdrfile == NULL )
  419. // {
  420. // /* If sdr file does not exist... */
  421. // if( errno == ENOENT )
  422. // {
  423. // /* ...create it */
  424. // sdrfile = fopen( SDR_FILE_PATH, "w+" );
  425. // if( sdrfile == NULL )
  426. // {
  427. // /* Uh-oh, something bad happened. */
  428. // printf( "Cannot create SDR file: %s\n", strerror( errno ) );
  429. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  430. // }
  431. // /* Read the SDRs from the BMC (Note: this function calls malloc) */
  432. // *count = read_sensor_sdrs( pUDSSession,
  433. // (struct sensor_info **)&local_sdr_buffer,
  434. // timeout );
  435. // if( *count < 0 )
  436. // {
  437. // printf( "Cannot read SDRs from BMC: %s\n", strerror( errno ) );
  438. // fclose( sdrfile );
  439. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  440. // }
  441. // /* Write the SDR data to file */
  442. // if( fwrite( local_sdr_buffer, (size_t)1,
  443. // sizeof( struct sensor_info ) * *count, sdrfile ) < 0 )
  444. // {
  445. // printf( "Cannot write to SDR file: %s\n", strerror( errno ) );
  446. // fclose( sdrfile );
  447. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  448. // }
  449. // fclose( sdrfile );
  450. // }
  451. // else
  452. // {
  453. // /* Uh-oh, something bad happened. */
  454. // printf( "Cannot open SDR file: %s\n", strerror( errno ) );
  455. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  456. // }
  457. // }
  458. // else
  459. // {
  460. // int retval;
  461. // size_t filelen;
  462. // /* Determine the length of the file */
  463. // retval = fseek( sdrfile, 0, SEEK_END );
  464. // if( retval < 0 )
  465. // {
  466. // printf( "Cannot seek SDR file: %s\n", strerror( errno ) );
  467. // fclose( sdrfile );
  468. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  469. // }
  470. // filelen = (size_t)ftell( sdrfile );
  471. // /* If the caller actually wants the sdrs... */
  472. // if( sdr_buffer != NULL )
  473. // {
  474. // /* Allocate some memory for 'em, and copy them in */
  475. // local_sdr_buffer = malloc( filelen );
  476. // if( local_sdr_buffer == NULL )
  477. // {
  478. // printf( "Cannot allocate memory for SDR file: %s\n", strerror( errno ) );
  479. // fclose( sdrfile );
  480. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_NOMEM ) );
  481. // }
  482. // /* Back to the beginning of the file (after seeking to the end above) */
  483. // retval = fseek( sdrfile, 0, SEEK_SET );
  484. // if( retval < 0 )
  485. // {
  486. // printf( "Cannot seek SDR file: %s\n", strerror( errno ) );
  487. // fclose( sdrfile );
  488. // free( local_sdr_buffer );
  489. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  490. // }
  491. // /* Read the entire file into the buffer we allocated */
  492. // if( fread( local_sdr_buffer, (size_t)1, filelen, sdrfile ) != filelen )
  493. // {
  494. // printf( "Cannot read from SDR file: %s\n", strerror( errno ) );
  495. // fclose( sdrfile );
  496. // free( local_sdr_buffer );
  497. // return( STATUS_CODE( IPMI_ERROR_FLAG, OEMCC_FILE_ERR ) );
  498. // }
  499. // }
  500. // fclose( sdrfile );
  501. // /* Size of sensor info structs is regular, so it's easy to */
  502. // /* calculate the number of SDRs in the file */
  503. // *count = filelen / sizeof( struct sensor_info );
  504. // }
  505. // /* If sdr_buffer is not null, pass a pointer to the allocated */
  506. // /* storage that contains the sdr data. */
  507. // if( sdr_buffer != NULL )
  508. // *sdr_buffer = local_sdr_buffer;
  509. // else
  510. // {
  511. // if( local_sdr_buffer != NULL )
  512. // free( local_sdr_buffer );
  513. // }
  514. return( LIBIPMI_E_SUCCESS );
  515. }
  516. uint16_t
  517. LIBIPMI_HL_GetSensorCount( IPMI20_UDS_SESSION_T *pUDSSession, int *sdr_count, int timeout )
  518. {
  519. uint16_t wRet;
  520. SDRRepositoryInfo_T pResSDRRepoInfo;
  521. wRet = IPMICMD_GetSDRRepositoryInfo( pUDSSession,
  522. &pResSDRRepoInfo,
  523. timeout);
  524. if(wRet != LIBIPMI_E_SUCCESS)
  525. {
  526. printf("Error in Getting Num of Sensor infon\n");
  527. return wRet;
  528. }
  529. *sdr_count = pResSDRRepoInfo.RecCt;
  530. return wRet;
  531. }
  532. #if 0
  533. uint16_t
  534. LIBIPMI_HL_GetAllSensorReadings( IPMI20_UDS_SESSION_T *pUDSSession,
  535. struct sensor_data *sensor_list, int timeout )
  536. {
  537. uint16_t wRet;
  538. uint8_t *sdr_buffer;
  539. int sdr_count;
  540. int i;
  541. GetSensorThresholdReq_T * pReqGetSensorThreshold;
  542. GetSensorThresholdRes_T * pResGetSensorThreshold;
  543. /* Load the SDRs related to sensors into memory */
  544. wRet = LIBIPMI_HL_LoadSensorSDRs( pUDSSession, &sdr_buffer, &sdr_count, timeout );
  545. if( wRet != LIBIPMI_E_SUCCESS )
  546. {
  547. printf( "Cannot load sensor SDRs\n" );
  548. return( wRet );
  549. }
  550. /* For each SDR entry... */
  551. for( i = 0; i < sdr_count; i++ )
  552. {
  553. uint8_t raw_reading;
  554. float reading;
  555. uint8_t discrete;
  556. struct sensor_info *sensor = &( ( (struct sensor_info *)sdr_buffer )[ i ] );
  557. FullSensorRec_T *record = (FullSensorRec_T *)( sensor->sdr_buffer );
  558. /* Get the reading from this sensor */
  559. wRet = LIBIPMI_HL_ReadSensorFromSDR( pUDSSession, sensor->sdr_buffer,
  560. &raw_reading, &reading, &discrete, 15 );
  561. //assume sensor is accessible till we find out otherwise
  562. sensor_list[i].SensorAccessibleFlags = 0;
  563. if( wRet != LIBIPMI_E_SUCCESS )
  564. {
  565. if(GET_ERROR_CODE(wRet) == 0xD5)
  566. {
  567. //sensor is not accessbile
  568. printf("Sensor is not accessible..server maybe powered off\n");
  569. sensor_list[i].SensorAccessibleFlags = GET_ERROR_CODE(wRet);
  570. }
  571. else if(GET_ERROR_CODE(wRet) == OEMCC_SENSOR_DISABLED)
  572. {
  573. sensor_list[i].SensorAccessibleFlags = 0xD5;
  574. }
  575. raw_reading = 0x00;
  576. reading = 0x00;
  577. discrete = 0x00;
  578. }
  579. /*Get Updated Threshold Values*/
  580. pReqGetSensorThreshold = malloc(sizeof(GetSensorThresholdReq_T));
  581. if(NULL == pReqGetSensorThreshold)
  582. return -1;
  583. pResGetSensorThreshold = malloc(sizeof(GetSensorThresholdRes_T));
  584. if(NULL == pResGetSensorThreshold)
  585. {
  586. free(pReqGetSensorThreshold);
  587. return -1;
  588. }
  589. memset(pResGetSensorThreshold, 0, sizeof(GetSensorThresholdRes_T));
  590. pReqGetSensorThreshold->SensorNum = record->SensorNum;
  591. wRet = IPMICMD_GetSensorThreshold(pUDSSession, pReqGetSensorThreshold,
  592. pResGetSensorThreshold, 15);
  593. if( wRet == LIBIPMI_E_SUCCESS )
  594. {
  595. record->UpperNonRecoverable = pResGetSensorThreshold->UpperNonRecoverable;
  596. record->UpperNonCritical = pResGetSensorThreshold->UpperNonCritical;
  597. record->UpperCritical= pResGetSensorThreshold->UpperCritical;
  598. record->LowerNonRecoverable = pResGetSensorThreshold->LowerNonRecoverable;
  599. record->LowerNonCritical = pResGetSensorThreshold->LowerNonCritical;
  600. record->LowerCritical = pResGetSensorThreshold->LowerCritical;
  601. }
  602. /* Copy the relevant sensor data into caller's array */
  603. strcpy( sensor_list[ i ].sensor_name, sensor->description );
  604. sensor_list[ i ].sensor_num = record->SensorNum;
  605. sensor_list[ i ].owner_id = record->OwnerID;
  606. sensor_list[ i ].owner_lun = record->OwnerLUN;
  607. sensor_list[ i ].sensor_type = record->SensorType;
  608. sensor_list[ i ].sensor_units[ 0 ] = record->Units1;
  609. sensor_list[ i ].sensor_units[ 1 ] = record->Units2;
  610. sensor_list[ i ].sensor_units[ 2 ] = record->Units3;
  611. sensor_list[ i ].sensor_reading = reading;
  612. sensor_list[ i ].raw_reading = raw_reading;
  613. /* If we have a discrete sensor... */
  614. if( discrete )
  615. {
  616. /* ...copy just the discrete state */
  617. sensor_list[ i ].sensor_state = 0;
  618. sensor_list[ i ].discrete_state = discrete;
  619. }
  620. else
  621. {
  622. int retval;
  623. /* ...if we have thresholds, get the threshold state and copy */
  624. /* all the threshold information to the caller's array. */
  625. retval = GetSensorState( pUDSSession, raw_reading, sensor->sdr_buffer, & (sensor_list[ i ].sensor_state) , 15);
  626. if( retval < 0 )
  627. printf( "get_sdr_sensor_state failed\n" );
  628. sensor_list[ i ].discrete_state = 0;
  629. ipmi_convert_reading(sensor->sdr_buffer,
  630. pResGetSensorThreshold->LowerNonRecoverable,
  631. &sensor_list[ i ].low_non_recov_thresh);
  632. ipmi_convert_reading(sensor->sdr_buffer,
  633. pResGetSensorThreshold->LowerCritical,
  634. &sensor_list[ i ].low_crit_thresh);
  635. ipmi_convert_reading(sensor->sdr_buffer,
  636. pResGetSensorThreshold->LowerNonCritical,
  637. &sensor_list[ i ].low_non_crit_thresh);
  638. ipmi_convert_reading(sensor->sdr_buffer,
  639. pResGetSensorThreshold->UpperNonCritical,
  640. &sensor_list[ i ].high_non_crit_thresh);
  641. ipmi_convert_reading(sensor->sdr_buffer,
  642. pResGetSensorThreshold->UpperCritical,
  643. &sensor_list[ i ].high_crit_thresh);
  644. ipmi_convert_reading(sensor->sdr_buffer,
  645. pResGetSensorThreshold->UpperNonRecoverable,
  646. &sensor_list[ i ].high_non_recov_thresh);
  647. }
  648. free(pReqGetSensorThreshold);
  649. free(pResGetSensorThreshold);
  650. }
  651. /* The sdr list was allocated by sdr_load, and we must free it */
  652. free( sdr_buffer );
  653. return( 0 );
  654. }
  655. #endif
  656. uint16_t LIBIPMI_HL_GetSensorReadingFactors( IPMI20_UDS_SESSION_T *pUDSSession,
  657. GetSensorReadingFactorReq_T *pReqGetSensorReadingFactor,
  658. GetSensorReadingFactorRes_T *pResGetSensorReadingFactor,
  659. uint32_t* nNumSensor,
  660. int timeout)
  661. {
  662. uint16_t wRet;
  663. uint32_t dwResLen;
  664. dwResLen = sizeof(GetSensorReadingFactorRes_T);
  665. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  666. NETFNLUN_IPMI_SENSOR,
  667. CMD_GET_SENSOR_READING_FACTORS,
  668. (uint8_t*)pReqGetSensorReadingFactor,
  669. sizeof(GetSensorReadingFactorReq_T),
  670. (uint8_t *)pResGetSensorReadingFactor,
  671. &dwResLen,
  672. timeout);
  673. #if 0
  674. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  675. NetFnLunBladeSts,
  676. CMD_GET_BLADE_STS,
  677. (uint8_t*)&ReqData,
  678. (uint32_t)1,
  679. (uint8_t*)pResBladeSts, &dwResLen,
  680. timeout);
  681. uint16_t wRet;
  682. uint32_t dwResLen;
  683. dwResLen = sizeof(GetSensorReadingFactorRes_T);
  684. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  685. NETFNLUN_IPMI_SENSOR, CMD_GET_SENSOR_READING_FACTORS,
  686. (uint8_t*)pReqGetSensorReadingFactor,
  687. sizeof(GetSensorReadingFactorReq_T),
  688. (uint8_t *)pResGetSensorReadingFactor, &dwResLen,
  689. timeout);
  690. #endif
  691. return wRet;
  692. }
  693. //
  694. // uint16_t LIBIPMI_HL_GetSensorHistoryReadingData( IPMI20_UDS_SESSION_T *pUDSSession, SensorhistoryData_T *pHistoryData, uint8_t nNumSensor, int timeout)
  695. //{
  696. // uint8_t nReq;
  697. // uint16_t wRet;
  698. // uint32_t dwResLen;
  699. // int i;
  700. //
  701. // nReq = nNumSensor;
  702. // printf("LIBIPMI_HL_GetSensorHistoryReadingData: nReq=%d\n",nReq);
  703. // dwResLen = sizeof(SensorhistoryData_T);
  704. // wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  705. //
  706. // NETFN_OEM<<2,
  707. // 0x0A,
  708. // (uint8_t*)&nReq,
  709. // 1,
  710. // (uint8_t *)pHistoryData,
  711. // &dwResLen,
  712. // timeout);
  713. //
  714. // for(i=1; i<=481; i++)
  715. // { printf("pHistoryData=%d", pHistoryData->records[i]);
  716. // pHistoryData->records[i]= i+1;
  717. // }
  718. // printf("\n");
  719. // return wRet;
  720. //}
  721. /**
  722. * @fn LIBIPMI_HL_GetAllSensorReadings
  723. * @brief High Level API to get all the sensor Info
  724. * @params Session, sensor_list, nNumSensor, timout
  725. * @return proper completion code on success
  726. */
  727. uint16_t
  728. LIBIPMI_HL_GetAllSensorReadings( IPMI20_UDS_SESSION_T *pUDSSession, struct sensor_data *sensor_list, uint32_t nNumSensor, int timeout )
  729. {
  730. uint16_t wRet;
  731. int sdr_count;
  732. int i ;
  733. uint8_t Req[20];
  734. StorleadGetSensorInfoRes_T GetSensorInfoRes;
  735. uint32_t dwResLen;
  736. SenInfo_T *pSensorBuff;
  737. float tmp_float;
  738. uint16_t tmp_hw;
  739. for(i = 0; i < nNumSensor; i++)
  740. {
  741. Req[0] = i;
  742. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession, //notice!
  743. (NETFN_STORLEAD << 2), CMD_GET_SENSOR_INFO,
  744. Req, 1,
  745. (uint8_t*)&GetSensorInfoRes, &dwResLen,
  746. timeout);
  747. if(wRet == LIBIPMI_E_SUCCESS)
  748. {
  749. pSensorBuff = &GetSensorInfoRes.SensorInfo;
  750. sensor_list[ i ].sensor_num = pSensorBuff->SensorNumber;
  751. sensor_list[ i ].owner_id = pSensorBuff->OwnerID;
  752. sensor_list[ i ].owner_lun = pSensorBuff->OwnerLUN;
  753. sensor_list[ i ].sensor_type = pSensorBuff->SensorTypeCode;
  754. sensor_list[ i ].sensor_units[ 0 ] = pSensorBuff->Units1;
  755. sensor_list[ i ].sensor_units[ 1 ] = pSensorBuff->Units2;
  756. sensor_list[ i ].sensor_units[ 2 ] = pSensorBuff->Units3;
  757. sensor_list[ i ].raw_reading = pSensorBuff->SensorReading;
  758. strncpy(sensor_list[ i ].sensor_name,pSensorBuff->SensorName,MAX_ID_STR_LEN);
  759. sensor_list[i].SensorAccessibleFlags = 0;
  760. if(pSensorBuff->EventTypeCode > 1)
  761. {
  762. /*Updating the discrete sensor details*/
  763. sensor_list[i].discrete_state = pSensorBuff->EventTypeCode;
  764. sensor_list[i].sensor_state = 0;
  765. sensor_list[ i ].sensor_reading = (float)(pSensorBuff->ComparisonStatus | (pSensorBuff->OptionalStatus << 8));
  766. }
  767. else
  768. {
  769. sensor_list[ i ].discrete_state = 0;
  770. sensor_list[ i ].Settable_Readable_ThreshMask=pSensorBuff->Settable_Readable_ThreshMask;
  771. if(pSensorBuff->SensorReading>0)
  772. /*Convert Sensor Reading*/
  773. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->SensorReading, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  774. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  775. sensor_list[i].sensor_reading = tmp_float;
  776. /*Convert LowerNonRecoverable*/
  777. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT2)
  778. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->LowerNonRecoverable, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  779. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  780. sensor_list[i].low_non_recov_thresh = tmp_float;
  781. /*Convert LowerCritical*/
  782. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT1)
  783. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->LowerCritical, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  784. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  785. sensor_list[i].low_crit_thresh = tmp_float;
  786. /*Convert LowerNonCritical*/
  787. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT0)
  788. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->LowerNonCritical, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  789. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  790. sensor_list[i].low_non_crit_thresh = tmp_float;
  791. /*Convert UpperNonCritical*/
  792. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT3)
  793. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->UpperNonCritical, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  794. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  795. sensor_list[i].high_non_crit_thresh = tmp_float;
  796. /*Convert UpperCritical*/
  797. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT4)
  798. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->UpperCritical, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  799. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  800. sensor_list[i].high_crit_thresh = tmp_float;
  801. /*Convert UpperNonRecoverable*/
  802. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT5)
  803. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->UpperNonRecoverable, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  804. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  805. sensor_list[i].high_non_recov_thresh = tmp_float;
  806. //MAX reading
  807. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT5)
  808. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->MaxReading, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  809. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  810. sensor_list[i].max_reading = tmp_float;
  811. //MIN reading
  812. if(sensor_list[ i ].Settable_Readable_ThreshMask & BIT5)
  813. ipmi_conv_reading(pSensorBuff->hdr.Type,pSensorBuff->MinReading, &tmp_float, pSensorBuff->MinReading, pSensorBuff->MaxReading, pSensorBuff->Units1,
  814. pSensorBuff->Linearization, pSensorBuff->M_LSB, pSensorBuff->B_LSB, pSensorBuff->M_MSB_Tolerance, pSensorBuff->B_MSB_Accuracy,pSensorBuff->RExp_BExp);
  815. sensor_list[i].min_reading = tmp_float;
  816. /*Get the Sensor state*/
  817. SensorState(pSensorBuff->SensorReading,&tmp_hw,pSensorBuff->hdr.Type,pSensorBuff->Linearization,pSensorBuff->Units1,pSensorBuff->EventTypeCode,pSensorBuff->AssertionEventByte1,pSensorBuff->AssertionEventByte2,pSensorBuff->DeassertionEventByte1,pSensorBuff->DeassertionEventByte2);
  818. sensor_list[i].sensor_state = tmp_hw;
  819. }
  820. /* If sensor scanning is disabled or the reading is unavailable... */
  821. if( !( pSensorBuff->Flags & SENSOR_SCANNING_BIT) || (pSensorBuff->Flags & UNABLE_TO_READ_SENSOR) )
  822. {
  823. /* Return an error code to let the caller know */
  824. sensor_list[i].SensorAccessibleFlags = SENSOR_NOT_AVAILABLE;
  825. sensor_list[i].sensor_reading = 0;
  826. sensor_list[i].discrete_state = 0;
  827. sensor_list[i].raw_reading = 0;
  828. }
  829. //printf("sensor_list[%d]: SensorNum %d, SensorName %s, SensorReading = %f\n", i, sensor_list[i].sensor_num, sensor_list[i].sensor_name, sensor_list[i].sensor_reading);
  830. }
  831. else
  832. {
  833. printf("error getting sensor info %d\n",wRet);
  834. }
  835. }
  836. return wRet ;
  837. }