1 /*
2  * Copyright (C) 2003-2015 FreeIPMI Core Team
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #ifndef IPMI_SENSOR_READ_H
20 #define IPMI_SENSOR_READ_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <stdint.h>
27 #include <freeipmi/api/ipmi-api.h>
28 #include <freeipmi/sdr/ipmi-sdr.h>
29 
30 /* note: SENSOR_READING_UNAVAILABLE and SENSOR_SCANNING_DISABLED are
31  * because of configuration of a sensor.  It is "ok" to some extent.
32  * SENSOR_READING_CANNOT_BE_OBTAINED is due to a retrieval error.
33  */
34 
35 #define IPMI_SENSOR_READ_ERR_SUCCESS                                 0
36 #define IPMI_SENSOR_READ_ERR_CONTEXT_NULL                            1
37 #define IPMI_SENSOR_READ_ERR_CONTEXT_INVALID                         2
38 #define IPMI_SENSOR_READ_ERR_PARAMETERS                              3
39 #define IPMI_SENSOR_READ_ERR_OUT_OF_MEMORY                           4
40 #define IPMI_SENSOR_READ_ERR_SENSOR_READING_UNAVAILABLE              5
41 #define IPMI_SENSOR_READ_ERR_SENSOR_SCANNING_DISABLED                6
42 #define IPMI_SENSOR_READ_ERR_SENSOR_NON_ANALOG                       7
43 #define IPMI_SENSOR_READ_ERR_SENSOR_NON_LINEAR                       8
44 #define IPMI_SENSOR_READ_ERR_SENSOR_NOT_OWNED_BY_BMC                 9
45 #define IPMI_SENSOR_READ_ERR_SENSOR_IS_SYSTEM_SOFTWARE              10
46 #define IPMI_SENSOR_READ_ERR_SENSOR_CANNOT_BE_BRIDGED               11
47 #define IPMI_SENSOR_READ_ERR_SENSOR_READING_CANNOT_BE_OBTAINED      12
48 #define IPMI_SENSOR_READ_ERR_NODE_BUSY                              13
49 #define IPMI_SENSOR_READ_ERR_INVALID_SDR_RECORD_TYPE                14
50 #define IPMI_SENSOR_READ_ERR_SDR_ENTRY_ERROR                        15
51 #define IPMI_SENSOR_READ_ERR_IPMI_ERROR                             16
52 #define IPMI_SENSOR_READ_ERR_SYSTEM_ERROR                           17
53 #define IPMI_SENSOR_READ_ERR_OVERFLOW                               18
54 #define IPMI_SENSOR_READ_ERR_INTERNAL_ERROR                         19
55 #define IPMI_SENSOR_READ_ERR_ERRNUMRANGE                            20
56 
57 #define IPMI_SENSOR_READ_FLAGS_DEFAULT                              0x0000
58 #define IPMI_SENSOR_READ_FLAGS_BRIDGE_SENSORS                       0x0001
59 #define IPMI_SENSOR_READ_FLAGS_DISCRETE_READING                     0x0002
60 #define IPMI_SENSOR_READ_FLAGS_IGNORE_SCANNING_DISABLED             0x0004
61 #define IPMI_SENSOR_READ_FLAGS_ASSUME_BMC_OWNER                     0x0008
62 
63 typedef struct ipmi_sensor_read_ctx *ipmi_sensor_read_ctx_t;
64 
65 /* Sensor Read Context Functions
66  * - ipmi_ctx assumes ipmi opened and ready to go
67  */
68 ipmi_sensor_read_ctx_t ipmi_sensor_read_ctx_create (ipmi_ctx_t ipmi_ctx);
69 void ipmi_sensor_read_ctx_destroy (ipmi_sensor_read_ctx_t ctx);
70 int ipmi_sensor_read_ctx_errnum (ipmi_sensor_read_ctx_t ctx);
71 char * ipmi_sensor_read_ctx_strerror (int errnum);
72 char * ipmi_sensor_read_ctx_errormsg (ipmi_sensor_read_ctx_t ctx);
73 
74 /* Sensor read flag functions */
75 int ipmi_sensor_read_ctx_get_flags (ipmi_sensor_read_ctx_t ctx, unsigned int *flags);
76 int ipmi_sensor_read_ctx_set_flags (ipmi_sensor_read_ctx_t ctx, unsigned int flags);
77 
78 /*
79  * return 1 - reading a success (although for some sensor types, a
80  * reading may not be returned. For example with discrete sensors, a
81  * reading is not returned but a sensor_event_bitmask is.)
82  *
83  * return 0 - cannot obtain reading, but sensor_event_bitmask still
84  * returned.  This is most common because the sensor cannot be
85  * interpreted, b/c (for example) it is a non-analog or non-linear
86  * sensor.  errnum will be set appropriately.
87  *
88  * return (-1) - error, neither a reading nor sensor_event_bitmask can
89  * be returned.
90  *
91  * if reading returned, must be free'd by caller
92  *
93  * 'sensor_reading_raw' is optional and need not be specified.
94  *
95  * under return of 0 or 1, the sensor_reading_raw will be filled with the raw reading
96  *
97  * Notes:
98  *
99  * shared_sensor_number_offset used for sensor record sharing in compact
100  * records.  If not used or not available, must be set to 0.
101  */
102 int ipmi_sensor_read (ipmi_sensor_read_ctx_t ctx,
103                       const void *sdr_record,
104                       unsigned int sdr_record_len,
105                       uint8_t shared_sensor_number_offset,
106                       uint8_t *sensor_reading_raw,
107                       double **sensor_reading,
108                       uint16_t *sensor_event_bitmask);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif /* IPMI_SENSOR_READ_H */
115