blob: 4fabac5450f6b1dff772648dee3e07985107ddb9 [file] [log] [blame]
Tomd700e762016-09-20 18:24:13 +05301#include <mapper.h>
Emily Shaffer1fabf222017-04-05 08:53:21 -07002#include <math.h>
Chris Austenac4604a2015-10-13 12:43:27 -05003#include <stdio.h>
4#include <string.h>
Emily Shaffercc941e12017-06-14 13:06:26 -07005#include <set>
Tom Josephbe703f72017-03-09 12:34:35 +05306#include <bitset>
Emily Shafferbbef71c2017-05-08 16:36:17 -07007#include <xyz/openbmc_project/Sensor/Value/server.hpp>
Chris Austen10ccc0f2015-12-10 18:27:04 -06008#include <systemd/sd-bus.h>
Tom Josephbe703f72017-03-09 12:34:35 +05309#include "host-ipmid/ipmid-api.h"
10#include <phosphor-logging/log.hpp>
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050011#include <phosphor-logging/elog-errors.hpp>
Ratan Guptae0cc8552018-01-22 14:23:04 +053012#include "fruread.hpp"
Tomd700e762016-09-20 18:24:13 +053013#include "ipmid.hpp"
Tom Josephbe703f72017-03-09 12:34:35 +053014#include "sensorhandler.h"
15#include "types.hpp"
16#include "utils.hpp"
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050017#include "xyz/openbmc_project/Common/error.hpp"
18
Ratan Guptae0cc8552018-01-22 14:23:04 +053019static constexpr uint8_t fruInventoryDevice = 0x10;
20static constexpr uint8_t IPMIFruInventory = 0x02;
21static constexpr uint8_t BMCSlaveAddress = 0x20;
22
Chris Austen8a45e7c2015-10-15 00:31:46 -050023extern int updateSensorRecordFromSSRAESC(const void *);
Tomd700e762016-09-20 18:24:13 +053024extern sd_bus *bus;
Tom Josephbe703f72017-03-09 12:34:35 +053025extern const ipmi::sensor::IdInfoMap sensors;
Ratan Guptae0cc8552018-01-22 14:23:04 +053026extern const FruMap frus;
27
28
Tom Josephbe703f72017-03-09 12:34:35 +053029using namespace phosphor::logging;
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050030using InternalFailure =
31 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Chris Austenac4604a2015-10-13 12:43:27 -050032
33void register_netfn_sen_functions() __attribute__((constructor));
34
Chris Austen0012e9b2015-10-22 01:37:46 -050035struct sensorTypemap_t {
36 uint8_t number;
Chris Austend7cf0e42015-11-07 14:27:12 -060037 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050038 char dbusname[32];
39} ;
40
Chris Austen0012e9b2015-10-22 01:37:46 -050041sensorTypemap_t g_SensorTypeMap[] = {
42
Chris Austend7cf0e42015-11-07 14:27:12 -060043 {0x01, 0x6F, "Temp"},
44 {0x0C, 0x6F, "DIMM"},
45 {0x0C, 0x6F, "MEMORY_BUFFER"},
46 {0x07, 0x6F, "PROC"},
47 {0x07, 0x6F, "CORE"},
48 {0x07, 0x6F, "CPU"},
49 {0x0F, 0x6F, "BootProgress"},
50 {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09
51 {0xC3, 0x6F, "BootCount"},
52 {0x1F, 0x6F, "OperatingSystemStatus"},
Chris Austen800ba712015-12-03 15:31:00 -060053 {0x12, 0x6F, "SYSTEM_EVENT"},
54 {0xC7, 0x03, "SYSTEM"},
55 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austen10ccc0f2015-12-10 18:27:04 -060056 {0xC2, 0x6F, "PowerCap"},
Tom Joseph558184e2017-09-01 13:45:05 +053057 {0x0b, 0xCA, "PowerSupplyRedundancy"},
Jayanth Othayoth0661beb2017-03-22 06:00:58 -050058 {0xDA, 0x03, "TurboAllowed"},
Tom Joseph558184e2017-09-01 13:45:05 +053059 {0xD8, 0xC8, "PowerSupplyDerating"},
Chris Austend7cf0e42015-11-07 14:27:12 -060060 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050061};
62
63
Chris Austenac4604a2015-10-13 12:43:27 -050064struct sensor_data_t {
65 uint8_t sennum;
66} __attribute__ ((packed)) ;
67
Chris Austen10ccc0f2015-12-10 18:27:04 -060068struct sensorreadingresp_t {
69 uint8_t value;
70 uint8_t operation;
71 uint8_t indication[2];
72} __attribute__ ((packed)) ;
Chris Austenac4604a2015-10-13 12:43:27 -050073
Emily Shaffer2ae09b92017-04-05 15:09:41 -070074int get_bus_for_path(const char *path, char **busname) {
75 return mapper_get_service(bus, path, busname);
76}
Tomd700e762016-09-20 18:24:13 +053077
Emily Shaffer2ae09b92017-04-05 15:09:41 -070078int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) {
Tomd700e762016-09-20 18:24:13 +053079 char *busname = NULL;
80 const char *iface = "org.openbmc.managers.System";
81 const char *objname = "/org/openbmc/managers/System";
82 char *str1 = NULL, *str2, *str3;
83 sd_bus_error error = SD_BUS_ERROR_NULL;
84 sd_bus_message *reply = NULL;
85
86
87 int r;
Emily Shaffer2ae09b92017-04-05 15:09:41 -070088 r = get_bus_for_path(objname, &busname);
Tomd700e762016-09-20 18:24:13 +053089 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -040090 fprintf(stderr, "Failed to get %s busname: %s\n",
91 objname, strerror(-r));
Tomd700e762016-09-20 18:24:13 +053092 goto final;
93 }
94
95 r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId",
96 &error, &reply, "sy", type, num);
97 if (r < 0) {
98 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
99 goto final;
100 }
101
102 r = sd_bus_message_read(reply, "(ss)", &str2, &str3);
103 if (r < 0) {
104 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
105 goto final;
106 }
107
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700108 r = get_bus_for_path(str2, &str1);
Tomd700e762016-09-20 18:24:13 +0530109 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400110 fprintf(stderr, "Failed to get %s busname: %s\n",
111 str2, strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530112 goto final;
113 }
114
115 strncpy(interface->bus, str1, MAX_DBUS_PATH);
116 strncpy(interface->path, str2, MAX_DBUS_PATH);
117 strncpy(interface->interface, str3, MAX_DBUS_PATH);
118
119 interface->sensornumber = num;
Emily Shaffer71174412017-04-05 15:10:40 -0700120 // Make sure we know that the type hasn't been set, as newer codebase will
121 // set it automatically from the YAML at this step.
122 interface->sensortype = 0;
Tomd700e762016-09-20 18:24:13 +0530123
124final:
125
126 sd_bus_error_free(&error);
127 reply = sd_bus_message_unref(reply);
128 free(busname);
129 free(str1);
130
131 return r;
132}
133
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700134// Use a lookup table to find the interface name of a specific sensor
135// This will be used until an alternative is found. this is the first
136// step for mapping IPMI
137int find_openbmc_path(uint8_t num, dbus_interface_t *interface) {
138 int rc;
139
140 // When the sensor map does not contain the sensor requested,
141 // fall back to the legacy DBus lookup (deprecated)
142 const auto& sensor_it = sensors.find(num);
143 if (sensor_it == sensors.end())
144 {
145 return legacy_dbus_openbmc_path("SENSOR", num, interface);
146 }
147
148 const auto& info = sensor_it->second;
149
Patrick Williams8451edf2017-06-13 09:01:06 -0500150 char* busname = nullptr;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700151 rc = get_bus_for_path(info.sensorPath.c_str(), &busname);
152 if (rc < 0) {
153 fprintf(stderr, "Failed to get %s busname: %s\n",
154 info.sensorPath.c_str(),
155 busname);
156 goto final;
157 }
158
159 interface->sensortype = info.sensorType;
160 strcpy(interface->bus, busname);
161 strcpy(interface->path, info.sensorPath.c_str());
162 // Take the interface name from the beginning of the DbusInterfaceMap. This
163 // works for the Value interface but may not suffice for more complex
164 // sensors.
165 // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500166 strcpy(interface->interface, info.propertyInterfaces.begin()->first.c_str());
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700167 interface->sensornumber = num;
168
169final:
170 free(busname);
171 return rc;
172}
173
Tomd700e762016-09-20 18:24:13 +0530174
175/////////////////////////////////////////////////////////////////////
176//
177// Routines used by ipmi commands wanting to interact on the dbus
178//
179/////////////////////////////////////////////////////////////////////
180int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) {
181
182
183 dbus_interface_t a;
184 int r;
185 sd_bus_error error = SD_BUS_ERROR_NULL;
186 sd_bus_message *m=NULL;
187
188 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n",
189 number, method, value);
190
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700191 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530192
193 if (r < 0) {
194 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
195 return 0;
196 }
197
198 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
199 if (r < 0) {
200 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
201 goto final;
202 }
203
204 r = sd_bus_message_append(m, "v", "s", value);
205 if (r < 0) {
206 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
207 goto final;
208 }
209
210
211 r = sd_bus_call(bus, m, 0, &error, NULL);
212 if (r < 0) {
213 fprintf(stderr, "Failed to call the method: %s", strerror(-r));
214 }
215
216final:
217 sd_bus_error_free(&error);
218 m = sd_bus_message_unref(m);
219
220 return 0;
221}
222int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) {
223
224
225 dbus_interface_t a;
226 int r;
227 sd_bus_error error = SD_BUS_ERROR_NULL;
228 sd_bus_message *m=NULL;
229
230 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n",
231 number, method, value);
232
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700233 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530234
235 if (r < 0) {
236 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
237 return 0;
238 }
239
240 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
241 if (r < 0) {
242 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
243 goto final;
244 }
245
246 r = sd_bus_message_append(m, "v", "i", value);
247 if (r < 0) {
248 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
249 goto final;
250 }
251
252
253 r = sd_bus_call(bus, m, 0, &error, NULL);
254 if (r < 0) {
255 fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
256 }
257
258final:
259 sd_bus_error_free(&error);
260 m = sd_bus_message_unref(m);
261
262 return 0;
263}
264
Chris Austen0012e9b2015-10-22 01:37:46 -0500265uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -0500266
Chris Austen0012e9b2015-10-22 01:37:46 -0500267 sensorTypemap_t *s = g_SensorTypeMap;
268 char r=0;
Chris Austen0012e9b2015-10-22 01:37:46 -0500269 while (s->number != 0xFF) {
270 if (!strcmp(s->dbusname,p)) {
Tom Joseph558184e2017-09-01 13:45:05 +0530271 r = s->typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -0500272 break;
Chris Austenac4604a2015-10-13 12:43:27 -0500273 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500274 s++;
Chris Austenac4604a2015-10-13 12:43:27 -0500275 }
276
Chris Austen0012e9b2015-10-22 01:37:46 -0500277 if (s->number == 0xFF)
278 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -0500279
Chris Austen0012e9b2015-10-22 01:37:46 -0500280 return r;
Chris Austenac4604a2015-10-13 12:43:27 -0500281}
282
Chris Austen0012e9b2015-10-22 01:37:46 -0500283
Emily Shaffer391f3302017-04-03 10:27:08 -0700284uint8_t get_type_from_interface(dbus_interface_t dbus_if) {
Chris Austen0012e9b2015-10-22 01:37:46 -0500285
Chris Austen0012e9b2015-10-22 01:37:46 -0500286 char *p;
Brad Bishop56003452016-10-05 21:49:19 -0400287 uint8_t type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500288
Chris Austen0012e9b2015-10-22 01:37:46 -0500289 // This is where sensors that do not exist in dbus but do
290 // exist in the host code stop. This should indicate it
291 // is not a supported sensor
Emily Shaffer391f3302017-04-03 10:27:08 -0700292 if (dbus_if.interface[0] == 0) { return 0;}
Chris Austen0012e9b2015-10-22 01:37:46 -0500293
Emily Shaffer71174412017-04-05 15:10:40 -0700294 // Fetch type from interface itself.
295 if (dbus_if.sensortype != 0)
296 {
297 type = dbus_if.sensortype;
Chris Austen0012e9b2015-10-22 01:37:46 -0500298 } else {
299 // Non InventoryItems
Emily Shaffer391f3302017-04-03 10:27:08 -0700300 p = strrchr (dbus_if.path, '/');
Brad Bishop56003452016-10-05 21:49:19 -0400301 type = dbus_to_sensor_type(p+1);
Chris Austen0012e9b2015-10-22 01:37:46 -0500302 }
303
Brad Bishop56003452016-10-05 21:49:19 -0400304 return type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500305 }
306
Emily Shaffer391f3302017-04-03 10:27:08 -0700307// Replaces find_sensor
308uint8_t find_type_for_sensor_number(uint8_t num) {
309 int r;
310 dbus_interface_t dbus_if;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700311 r = find_openbmc_path(num, &dbus_if);
Emily Shaffer391f3302017-04-03 10:27:08 -0700312 if (r < 0) {
313 fprintf(stderr, "Could not find sensor %d\n", num);
314 return r;
315 }
316 return get_type_from_interface(dbus_if);
317}
318
Chris Austen10ccc0f2015-12-10 18:27:04 -0600319
320
321
322
Chris Austen0012e9b2015-10-22 01:37:46 -0500323ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
324 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500325 ipmi_data_len_t data_len, ipmi_context_t context)
326{
327 sensor_data_t *reqptr = (sensor_data_t*)request;
328 ipmi_ret_t rc = IPMI_CC_OK;
329
330 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
331
332 // TODO Not sure what the System-event-sensor is suppose to return
333 // need to ask Hostboot team
334 unsigned char buf[] = {0x00,0x6F};
335
Emily Shaffer391f3302017-04-03 10:27:08 -0700336 buf[0] = find_type_for_sensor_number(reqptr->sennum);
Chris Austen0012e9b2015-10-22 01:37:46 -0500337
338 // HACK UNTIL Dbus gets updated or we find a better way
339 if (buf[0] == 0) {
Chris Austen800ba712015-12-03 15:31:00 -0600340 rc = IPMI_CC_SENSOR_INVALID;
Chris Austen0012e9b2015-10-22 01:37:46 -0500341 }
342
Chris Austenac4604a2015-10-13 12:43:27 -0500343
344 *data_len = sizeof(buf);
345 memcpy(response, &buf, *data_len);
346
Chris Austenac4604a2015-10-13 12:43:27 -0500347 return rc;
348}
349
Emily Shaffercc941e12017-06-14 13:06:26 -0700350const std::set<std::string> analogSensorInterfaces =
351{
352 "xyz.openbmc_project.Sensor.Value",
Patrick Venturee9a64052017-08-18 19:17:27 -0700353 "xyz.openbmc_project.Control.FanPwm",
Emily Shaffercc941e12017-06-14 13:06:26 -0700354};
355
356bool isAnalogSensor(const std::string& interface)
357{
358 return (analogSensorInterfaces.count(interface));
359}
360
Tom Josephbe703f72017-03-09 12:34:35 +0530361ipmi_ret_t setSensorReading(void *request)
362{
Tom Joseph816e92b2017-09-06 19:23:00 +0530363 ipmi::sensor::SetSensorReadingReq cmdData =
364 *(static_cast<ipmi::sensor::SetSensorReadingReq *>(request));
Tom Josephbe703f72017-03-09 12:34:35 +0530365
366 // Check if the Sensor Number is present
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500367 const auto iter = sensors.find(cmdData.number);
Tom Josephbe703f72017-03-09 12:34:35 +0530368 if (iter == sensors.end())
369 {
370 return IPMI_CC_SENSOR_INVALID;
371 }
372
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500373 try
374 {
375 return iter->second.updateFunc(cmdData, iter->second);
376 }
377 catch (InternalFailure& e)
378 {
379 log<level::ERR>("Set sensor failed",
380 entry("SENSOR_NUM=%d", cmdData.number));
381 commit<InternalFailure>();
382 }
Tom Joseph82024322017-09-28 20:07:29 +0530383 catch (const std::runtime_error& e)
384 {
385 log<level::ERR>(e.what());
386 }
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500387
388 return IPMI_CC_UNSPECIFIED_ERROR;
Tom Josephbe703f72017-03-09 12:34:35 +0530389}
Chris Austenac4604a2015-10-13 12:43:27 -0500390
Chris Austen0012e9b2015-10-22 01:37:46 -0500391ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
392 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500393 ipmi_data_len_t data_len, ipmi_context_t context)
394{
Chris Austenac4604a2015-10-13 12:43:27 -0500395 sensor_data_t *reqptr = (sensor_data_t*)request;
Chris Austenac4604a2015-10-13 12:43:27 -0500396
Chris Austen0012e9b2015-10-22 01:37:46 -0500397 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500398
Tom Josephbe703f72017-03-09 12:34:35 +0530399 /*
400 * This would support the Set Sensor Reading command for the presence
401 * and functional state of Processor, Core & DIMM. For the remaining
402 * sensors the existing support is invoked.
403 */
404 auto ipmiRC = setSensorReading(request);
405
406 if(ipmiRC == IPMI_CC_SENSOR_INVALID)
407 {
408 updateSensorRecordFromSSRAESC(reqptr);
409 ipmiRC = IPMI_CC_OK;
410 }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500411
Chris Austenac4604a2015-10-13 12:43:27 -0500412 *data_len=0;
Tom Josephbe703f72017-03-09 12:34:35 +0530413 return ipmiRC;
Chris Austenac4604a2015-10-13 12:43:27 -0500414}
415
Tom Joseph3ee668f2018-03-02 19:49:17 +0530416ipmi_ret_t legacyGetSensorReading(uint8_t sensorNum,
417 ipmi_response_t response,
418 ipmi_data_len_t data_len)
Chris Austen10ccc0f2015-12-10 18:27:04 -0600419{
Chris Austen10ccc0f2015-12-10 18:27:04 -0600420 int r;
421 dbus_interface_t a;
422 sd_bus *bus = ipmid_get_sd_bus_connection();
Tom Joseph3ee668f2018-03-02 19:49:17 +0530423 ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID;
424 uint8_t type = 0;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600425 sd_bus_message *reply = NULL;
Adriana Kobylak93125982016-03-01 12:48:10 -0600426 int reading = 0;
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600427 char* assertion = NULL;
Tom Joseph3ee668f2018-03-02 19:49:17 +0530428 sensorreadingresp_t *resp = (sensorreadingresp_t*) response;
429 *data_len=0;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600430
Tom Joseph3ee668f2018-03-02 19:49:17 +0530431 r = find_openbmc_path(sensorNum, &a);
Tom Joseph40c35b12017-09-07 02:04:42 +0530432 if (r < 0)
433 {
Tom Joseph3ee668f2018-03-02 19:49:17 +0530434 sd_journal_print(LOG_ERR, "Failed to find Sensor 0x%02x\n", sensorNum);
435 return IPMI_CC_SENSOR_INVALID;
Nan Li36deb762016-05-12 10:23:41 +0800436 }
Tom Joseph3ee668f2018-03-02 19:49:17 +0530437
438 type = get_type_from_interface(a);
439 if (type == 0)
Tom Joseph40c35b12017-09-07 02:04:42 +0530440 {
Tom Joseph3ee668f2018-03-02 19:49:17 +0530441 sd_journal_print(LOG_ERR, "Failed to find Sensor 0x%02x\n",
442 sensorNum);
443 return IPMI_CC_SENSOR_INVALID;
Brad Bishop56003452016-10-05 21:49:19 -0400444 }
Chris Austen10ccc0f2015-12-10 18:27:04 -0600445
Chris Austen10ccc0f2015-12-10 18:27:04 -0600446 switch(type) {
Chris Austen10ccc0f2015-12-10 18:27:04 -0600447 case 0xC2:
Dhruvaraj Subhashchandrand12ae752017-10-04 00:33:27 -0500448 case 0xC8:
Tom Joseph3ee668f2018-03-02 19:49:17 +0530449 r = sd_bus_get_property(bus,a.bus, a.path, a.interface,
450 "value", NULL, &reply, "i");
451 if (r < 0)
452 {
453 sd_journal_print(LOG_ERR, "Failed to call sd_bus_get_property:"
454 " %d, %s\n", r, strerror(-r));
455 sd_journal_print(LOG_ERR, "Bus: %s, Path: %s, Interface: %s\n",
456 a.bus, a.path, a.interface);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600457 break;
458 }
459
Adriana Kobylak93125982016-03-01 12:48:10 -0600460 r = sd_bus_message_read(reply, "i", &reading);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600461 if (r < 0) {
Tom Joseph3ee668f2018-03-02 19:49:17 +0530462 sd_journal_print(LOG_ERR, "Failed to read sensor: %s\n",
463 strerror(-r));
Chris Austen10ccc0f2015-12-10 18:27:04 -0600464 break;
465 }
466
Chris Austen10ccc0f2015-12-10 18:27:04 -0600467 rc = IPMI_CC_OK;
468 *data_len=sizeof(sensorreadingresp_t);
469
Adriana Kobylak93125982016-03-01 12:48:10 -0600470 resp->value = (uint8_t)reading;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600471 resp->operation = 0;
472 resp->indication[0] = 0;
473 resp->indication[1] = 0;
474 break;
475
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600476 //TODO openbmc/openbmc#2154 Move this sensor to right place.
477 case 0xCA:
Tom Joseph3ee668f2018-03-02 19:49:17 +0530478 r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value",
479 NULL, &reply, "s");
480 if (r < 0)
481 {
482 sd_journal_print(LOG_ERR, "Failed to call sd_bus_get_property:"
483 " %d, %s\n", r, strerror(-r));
484 sd_journal_print(LOG_ERR, "Bus: %s, Path: %s, Interface: %s\n",
485 a.bus, a.path, a.interface);
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600486 break;
487 }
488
489 r = sd_bus_message_read(reply, "s", &assertion);
Tom Joseph3ee668f2018-03-02 19:49:17 +0530490 if (r < 0)
491 {
492 sd_journal_print(LOG_ERR, "Failed to read sensor: %s\n",
493 strerror(-r));
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600494 break;
495 }
496
497 rc = IPMI_CC_OK;
498 *data_len=sizeof(sensorreadingresp_t);
499
500 resp->value = 0;
501 resp->operation = 0;
502 if (strcmp(assertion,"Enabled") == 0)
503 {
504 resp->indication[0] = 0x02;
505 }
506 else
507 {
508 resp->indication[0] = 0x1;
509 }
510 resp->indication[1] = 0;
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600511 break;
512
Chris Austen10ccc0f2015-12-10 18:27:04 -0600513 default:
Tom Joseph14c15462017-09-07 02:16:51 +0530514 {
Tom Joseph3ee668f2018-03-02 19:49:17 +0530515 return IPMI_CC_SENSOR_INVALID;
Tom Joseph14c15462017-09-07 02:16:51 +0530516 }
Chris Austen10ccc0f2015-12-10 18:27:04 -0600517 }
518
vishwa1eaea4f2016-02-26 11:57:40 -0600519 reply = sd_bus_message_unref(reply);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600520
521 return rc;
522}
523
Tom Joseph3ee668f2018-03-02 19:49:17 +0530524ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
525 ipmi_request_t request, ipmi_response_t response,
526 ipmi_data_len_t data_len, ipmi_context_t context)
527{
528 sensor_data_t *reqptr = (sensor_data_t*)request;
529 sensorreadingresp_t *resp = (sensorreadingresp_t*) response;
530 ipmi::sensor::GetSensorResponse getResponse {};
531 static constexpr auto scanningEnabledBit = 6;
532
533 const auto iter = sensors.find(reqptr->sennum);
534 if (iter == sensors.end())
535 {
536 return legacyGetSensorReading(reqptr->sennum, response, data_len);
537 }
538 if (ipmi::sensor::Mutability::Read !=
539 (iter->second.mutability & ipmi::sensor::Mutability::Read))
540 {
541 return IPMI_CC_SENSOR_INVALID;
542 }
543
544 try
545 {
546 getResponse = iter->second.getFunc(iter->second);
547 *data_len = getResponse.size();
548 memcpy(resp, getResponse.data(), *data_len);
549 resp->operation = 1 << scanningEnabledBit;
550 return IPMI_CC_OK;
551 }
552 catch (const std::exception& e)
553 {
554 *data_len = getResponse.size();
555 memcpy(resp, getResponse.data(), *data_len);
556 return IPMI_CC_OK;
557 }
558}
559
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530560void getSensorThresholds(uint8_t sensorNum,
561 get_sdr::GetSensorThresholdsResponse* response)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600562{
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530563 constexpr auto warningThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600564 "xyz.openbmc_project.Sensor.Threshold.Warning";
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530565 constexpr auto criticalThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600566 "xyz.openbmc_project.Sensor.Threshold.Critical";
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600567
568 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
569
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530570 const auto iter = sensors.find(sensorNum);
571 const auto info = iter->second;
572
573 auto service = ipmi::getService(bus, info.sensorInterface, info.sensorPath);
574
575 auto warnThresholds = ipmi::getAllDbusProperties(bus,
576 service,
577 info.sensorPath,
578 warningThreshIntf);
579
580 double warnLow = warnThresholds["WarningLow"].get<int64_t>();
581 double warnHigh = warnThresholds["WarningHigh"].get<int64_t>();
582
583 if (warnLow != 0)
584 {
585 warnLow *= pow(10, info.scale - info.exponentR);
586 response->lowerNonCritical = static_cast<uint8_t>((
587 warnLow - info.scaledOffset) / info.coefficientM);
588 response->validMask |= static_cast<uint8_t>(
589 ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK);
590 }
591
592 if (warnHigh != 0)
593 {
594 warnHigh *= pow(10, info.scale - info.exponentR);
595 response->upperNonCritical = static_cast<uint8_t>((
596 warnHigh - info.scaledOffset) / info.coefficientM);
597 response->validMask |= static_cast<uint8_t>(
598 ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK);
599 }
600
601 auto critThresholds = ipmi::getAllDbusProperties(bus,
602 service,
603 info.sensorPath,
604 criticalThreshIntf);
605 double critLow = critThresholds["CriticalLow"].get<int64_t>();
606 double critHigh = critThresholds["CriticalHigh"].get<int64_t>();
607
608 if (critLow != 0)
609 {
610 critLow *= pow(10, info.scale - info.exponentR);
611 response->lowerCritical = static_cast<uint8_t>((
612 critLow - info.scaledOffset) / info.coefficientM);
613 response->validMask |= static_cast<uint8_t>(
614 ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK);
615 }
616
617 if (critHigh != 0)
618 {
619 critHigh *= pow(10, info.scale - info.exponentR);
620 response->upperCritical = static_cast<uint8_t>((
621 critHigh - info.scaledOffset)/ info.coefficientM);
622 response->validMask |= static_cast<uint8_t>(
623 ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK);
624 }
625}
626
627ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
628 ipmi_request_t request, ipmi_response_t response,
629 ipmi_data_len_t data_len, ipmi_context_t context)
630{
631 constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
632
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600633 if (*data_len != sizeof(uint8_t))
634 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530635 *data_len = 0;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600636 return IPMI_CC_REQ_DATA_LEN_INVALID;
637 }
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600638
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530639 auto sensorNum = *(reinterpret_cast<const uint8_t *>(request));
640 *data_len = 0;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600641
642 const auto iter = sensors.find(sensorNum);
643 if (iter == sensors.end())
644 {
645 return IPMI_CC_SENSOR_INVALID;
646 }
647
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530648 const auto info = iter->second;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600649
650 //Proceed only if the sensor value interface is implemented.
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530651 if (info.propertyInterfaces.find(valueInterface) ==
652 info.propertyInterfaces.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600653 {
654 //return with valid mask as 0
655 return IPMI_CC_OK;
656 }
657
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530658 auto responseData =
659 reinterpret_cast<get_sdr::GetSensorThresholdsResponse*>(response);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600660
661 try
662 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530663 getSensorThresholds(sensorNum, responseData);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600664 }
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530665 catch (std::exception& e)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600666 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530667 //Mask if the property is not present
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600668 responseData->validMask = 0;
669 }
670
671 *data_len = sizeof(get_sdr::GetSensorThresholdsResponse);
672 return IPMI_CC_OK;
673}
674
Chris Austen0012e9b2015-10-22 01:37:46 -0500675ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
676 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500677 ipmi_data_len_t data_len, ipmi_context_t context)
678{
Nan Li70aa8d92016-08-29 00:11:10 +0800679 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenac4604a2015-10-13 12:43:27 -0500680
681 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
682 *data_len = 0;
683
684 return rc;
685}
686
Emily Shafferd06e0e72017-04-05 09:08:57 -0700687ipmi_ret_t ipmi_sen_get_sdr_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
688 ipmi_request_t request,
689 ipmi_response_t response,
690 ipmi_data_len_t data_len,
691 ipmi_context_t context)
692{
693 auto resp = static_cast<get_sdr_info::GetSdrInfoResp*>(response);
694 if (request == nullptr ||
695 get_sdr_info::request::get_count(request) == false)
696 {
697 // Get Sensor Count
Ratan Guptae0cc8552018-01-22 14:23:04 +0530698 resp->count = sensors.size() + frus.size();
Emily Shafferd06e0e72017-04-05 09:08:57 -0700699 }
700 else
701 {
702 resp->count = 1;
703 }
704
705 // Multiple LUNs not supported.
706 namespace response = get_sdr_info::response;
707 response::set_lun_present(0, &(resp->luns_and_dynamic_population));
708 response::set_lun_not_present(1, &(resp->luns_and_dynamic_population));
709 response::set_lun_not_present(2, &(resp->luns_and_dynamic_population));
710 response::set_lun_not_present(3, &(resp->luns_and_dynamic_population));
711 response::set_static_population(&(resp->luns_and_dynamic_population));
712
713 *data_len = SDR_INFO_RESP_SIZE;
714
715 return IPMI_CC_OK;
716}
717
Emily Shaffera344afc2017-04-13 15:09:39 -0700718ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
719 ipmi_request_t request,
720 ipmi_response_t response,
721 ipmi_data_len_t data_len,
722 ipmi_context_t context)
723{
724 // A constant reservation ID is okay until we implement add/remove SDR.
725 const uint16_t reservation_id = 1;
726 *(uint16_t*)response = reservation_id;
Emily Shaffer5a5a6282017-08-15 11:17:17 -0700727 *data_len = sizeof(uint16_t);
Emily Shaffera344afc2017-04-13 15:09:39 -0700728
729 printf("Created new IPMI SDR reservation ID %d\n", *(uint16_t*)response);
730 return IPMI_CC_OK;
731}
Chris Austenac4604a2015-10-13 12:43:27 -0500732
Tom Josephdc212b22018-02-16 09:59:57 +0530733void setUnitFieldsForObject(const ipmi::sensor::Info *info,
Emily Shaffercc941e12017-06-14 13:06:26 -0700734 get_sdr::SensorDataFullRecordBody *body)
735{
Tom Josephdc212b22018-02-16 09:59:57 +0530736 namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
737 try
Emily Shaffercc941e12017-06-14 13:06:26 -0700738 {
Tom Josephdc212b22018-02-16 09:59:57 +0530739 auto unit = server::Value::convertUnitFromString(info->unit);
740 // Unit strings defined in
741 // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
742 switch (unit)
Emily Shaffercc941e12017-06-14 13:06:26 -0700743 {
Tom Josephdc212b22018-02-16 09:59:57 +0530744 case server::Value::Unit::DegreesC:
745 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
746 break;
747 case server::Value::Unit::RPMS:
748 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions
749 get_sdr::body::set_rate_unit(0b100, body); // per minute
750 break;
751 case server::Value::Unit::Volts:
752 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
753 break;
754 case server::Value::Unit::Meters:
755 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
756 break;
757 case server::Value::Unit::Amperes:
758 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
759 break;
760 case server::Value::Unit::Joules:
761 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
762 break;
763 case server::Value::Unit::Watts:
764 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
765 break;
766 default:
767 // Cannot be hit.
768 fprintf(stderr, "Unknown value unit type: = %s\n",
769 info->unit.c_str());
Emily Shaffercc941e12017-06-14 13:06:26 -0700770 }
771 }
Tom Josephdc212b22018-02-16 09:59:57 +0530772 catch (sdbusplus::exception::InvalidEnumString e)
Emily Shaffercc941e12017-06-14 13:06:26 -0700773 {
Tom Josephdc212b22018-02-16 09:59:57 +0530774 log<level::WARNING>("Warning: no unit provided for sensor!");
Emily Shaffercc941e12017-06-14 13:06:26 -0700775 }
Emily Shaffercc941e12017-06-14 13:06:26 -0700776}
777
Emily Shafferbbef71c2017-05-08 16:36:17 -0700778ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body,
779 const ipmi::sensor::Info *info,
780 ipmi_data_len_t data_len)
781{
782 /* Functional sensor case */
Emily Shaffercc941e12017-06-14 13:06:26 -0700783 if (isAnalogSensor(info->propertyInterfaces.begin()->first))
Emily Shafferbbef71c2017-05-08 16:36:17 -0700784 {
Emily Shafferbbef71c2017-05-08 16:36:17 -0700785
786 body->sensor_units_1 = 0; // unsigned, no rate, no modifier, not a %
787
788 /* Unit info */
Tom Josephdc212b22018-02-16 09:59:57 +0530789 setUnitFieldsForObject(info, body);
Emily Shaffer10f49592017-05-10 12:01:10 -0700790
791 get_sdr::body::set_b(info->coefficientB, body);
792 get_sdr::body::set_m(info->coefficientM, body);
793 get_sdr::body::set_b_exp(info->exponentB, body);
Tom Josephdc212b22018-02-16 09:59:57 +0530794 get_sdr::body::set_r_exp(info->exponentR, body);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700795
Emily Shafferbbef71c2017-05-08 16:36:17 -0700796 get_sdr::body::set_id_type(0b00, body); // 00 = unicode
Emily Shafferbbef71c2017-05-08 16:36:17 -0700797 }
798
Tom Joseph96423912018-01-25 00:14:34 +0530799 /* ID string */
800 auto id_string = info->sensorNameFunc(*info);
801
802 if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
803 {
804 get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH, body);
805 }
806 else
807 {
808 get_sdr::body::set_id_strlen(id_string.length(), body);
809 }
810 strncpy(body->id_string, id_string.c_str(),
811 get_sdr::body::get_id_strlen(body));
812
Emily Shafferbbef71c2017-05-08 16:36:17 -0700813 return IPMI_CC_OK;
814};
815
Ratan Guptae0cc8552018-01-22 14:23:04 +0530816ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response,
817 ipmi_data_len_t data_len)
818{
819 auto req = reinterpret_cast<get_sdr::GetSdrReq*>(request);
820 auto resp = reinterpret_cast<get_sdr::GetSdrResp*>(response);
821 get_sdr::SensorDataFruRecord record {};
822 auto dataLength = 0;
823
824 auto fru = frus.begin();
825 uint8_t fruID {};
826 auto recordID = get_sdr::request::get_record_id(req);
827
828 fruID = recordID - FRU_RECORD_ID_START;
829 fru = frus.find(fruID);
830 if (fru == frus.end())
831 {
832 return IPMI_CC_SENSOR_INVALID;
833 }
834
835 /* Header */
836 get_sdr::header::set_record_id(recordID, &(record.header));
837 record.header.sdr_version = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
838 record.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD;
839 record.header.record_length = sizeof(record.key) + sizeof(record.body);
840
841 /* Key */
842 record.key.fruID = fruID;
843 record.key.accessLun |= IPMI_LOGICAL_FRU;
844 record.key.deviceAddress = BMCSlaveAddress;
845
846 /* Body */
847 record.body.entityID = fru->second[0].entityID;
848 record.body.entityInstance = fru->second[0].entityInstance;
849 record.body.deviceType = fruInventoryDevice;
850 record.body.deviceTypeModifier = IPMIFruInventory;
851
852 /* Device ID string */
853 auto deviceID = fru->second[0].path.substr(
854 fru->second[0].path.find_last_of('/') + 1,
855 fru->second[0].path.length());
856
857
858 if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH)
859 {
860 get_sdr::body::set_device_id_strlen(
861 get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH,
862 &(record.body));
863 }
864 else
865 {
866 get_sdr::body::set_device_id_strlen(deviceID.length(),
867 &(record.body));
868 }
869
870 strncpy(record.body.deviceID, deviceID.c_str(),
871 get_sdr::body::get_device_id_strlen(&(record.body)));
872
873 if (++fru == frus.end())
874 {
875 get_sdr::response::set_next_record_id(END_OF_RECORD, resp); // last record
876 }
877 else
878 {
879 get_sdr::response::set_next_record_id(
880 (FRU_RECORD_ID_START + fru->first), resp);
881 }
882
883 if (req->bytes_to_read > (sizeof(*resp) - req->offset))
884 {
885 dataLength = (sizeof(*resp) - req->offset);
886 }
887 else
888 {
889 dataLength = req->bytes_to_read;
890 }
891
892 if (dataLength <= 0)
893 {
894 return IPMI_CC_REQ_DATA_LEN_INVALID;
895 }
896
897 memcpy(resp->record_data,
898 reinterpret_cast<uint8_t*>(&record) + req->offset,
899 (dataLength));
900
901 *data_len = dataLength;
902 *data_len += 2; // additional 2 bytes for next record ID
903
904 return IPMI_CC_OK;
905}
906
Emily Shafferbbef71c2017-05-08 16:36:17 -0700907ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
908 ipmi_request_t request, ipmi_response_t response,
909 ipmi_data_len_t data_len, ipmi_context_t context)
910{
911 ipmi_ret_t ret = IPMI_CC_OK;
912 get_sdr::GetSdrReq *req = (get_sdr::GetSdrReq*)request;
913 get_sdr::GetSdrResp *resp = (get_sdr::GetSdrResp*)response;
914 get_sdr::SensorDataFullRecord record = {0};
915 if (req != NULL)
916 {
917 // Note: we use an iterator so we can provide the next ID at the end of
918 // the call.
919 auto sensor = sensors.begin();
Ratan Guptae0cc8552018-01-22 14:23:04 +0530920 auto recordID = get_sdr::request::get_record_id(req);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700921
922 // At the beginning of a scan, the host side will send us id=0.
Ratan Guptae0cc8552018-01-22 14:23:04 +0530923 if (recordID != 0)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700924 {
Ratan Guptae0cc8552018-01-22 14:23:04 +0530925 // recordID greater then 255,it means it is a FRU record.
926 // Currently we are supporting two record types either FULL record
927 // or FRU record.
928 if (recordID >= FRU_RECORD_ID_START)
929 {
930 return ipmi_fru_get_sdr(request, response, data_len);
931 }
932 else
933 {
934 sensor = sensors.find(recordID);
935 if (sensor == sensors.end())
936 {
937 return IPMI_CC_SENSOR_INVALID;
938 }
Emily Shafferbbef71c2017-05-08 16:36:17 -0700939 }
940 }
941
942 uint8_t sensor_id = sensor->first;
943
944 /* Header */
945 get_sdr::header::set_record_id(sensor_id, &(record.header));
946 record.header.sdr_version = 0x51; // Based on IPMI Spec v2.0 rev 1.1
947 record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD;
948 record.header.record_length = sizeof(get_sdr::SensorDataFullRecord);
949
950 /* Key */
Tom Joseph96423912018-01-25 00:14:34 +0530951 get_sdr::key::set_owner_id_bmc(&(record.key));
Emily Shafferbbef71c2017-05-08 16:36:17 -0700952 record.key.sensor_number = sensor_id;
953
954 /* Body */
Tom Joseph96423912018-01-25 00:14:34 +0530955 record.body.entity_id = sensor->second.entityType;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700956 record.body.sensor_type = sensor->second.sensorType;
957 record.body.event_reading_type = sensor->second.sensorReadingType;
Tom Joseph96423912018-01-25 00:14:34 +0530958 record.body.entity_instance = sensor->second.instance;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700959
960 // Set the type-specific details given the DBus interface
961 ret = populate_record_from_dbus(&(record.body), &(sensor->second),
962 data_len);
963
964 if (++sensor == sensors.end())
965 {
Ratan Guptae0cc8552018-01-22 14:23:04 +0530966 // we have reached till end of sensor, so assign the next record id
967 // to 256(Max Sensor ID = 255) + FRU ID(may start with 0).
968 auto next_record_id = (frus.size()) ?
969 frus.begin()->first + FRU_RECORD_ID_START :
970 END_OF_RECORD;
971
972 get_sdr::response::set_next_record_id(next_record_id, resp);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700973 }
974 else
975 {
976 get_sdr::response::set_next_record_id(sensor->first, resp);
977 }
978
979 *data_len = sizeof(get_sdr::GetSdrResp) - req->offset;
980 memcpy(resp->record_data, (char*)&record + req->offset,
981 sizeof(get_sdr::SensorDataFullRecord) - req->offset);
982 }
983
984 return ret;
985}
986
987
Chris Austenac4604a2015-10-13 12:43:27 -0500988void register_netfn_sen_functions()
989{
Tom05732372016-09-06 17:21:23 +0530990 // <Wildcard Command>
Emily Shaffera344afc2017-04-13 15:09:39 -0700991 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
992 NETFUN_SENSOR, IPMI_CMD_WILDCARD);
993 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD,
994 nullptr, ipmi_sen_wildcard,
Tom05732372016-09-06 17:21:23 +0530995 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -0500996
Tom05732372016-09-06 17:21:23 +0530997 // <Get Sensor Type>
Emily Shaffera344afc2017-04-13 15:09:39 -0700998 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
999 NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
1000 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE,
1001 nullptr, ipmi_sen_get_sensor_type,
Tom05732372016-09-06 17:21:23 +05301002 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -05001003
Tom05732372016-09-06 17:21:23 +05301004 // <Set Sensor Reading and Event Status>
Emily Shaffera344afc2017-04-13 15:09:39 -07001005 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
1006 NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
1007 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR,
1008 nullptr, ipmi_sen_set_sensor,
Tom05732372016-09-06 17:21:23 +05301009 PRIVILEGE_OPERATOR);
Chris Austen8a45e7c2015-10-15 00:31:46 -05001010
Tom05732372016-09-06 17:21:23 +05301011 // <Get Sensor Reading>
Emily Shaffera344afc2017-04-13 15:09:39 -07001012 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
1013 NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING);
1014 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING,
1015 nullptr, ipmi_sen_get_sensor_reading,
1016 PRIVILEGE_USER);
1017
Tom Joseph5ca50952018-02-22 00:33:38 +05301018 // <Reserve Device SDR Repository>
1019 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_DEVICE_SDR_REPO,
Emily Shaffera344afc2017-04-13 15:09:39 -07001020 nullptr, ipmi_sen_reserve_sdr,
1021 PRIVILEGE_USER);
Chris Austen10ccc0f2015-12-10 18:27:04 -06001022
Tom Joseph5ca50952018-02-22 00:33:38 +05301023 // <Get Device SDR Info>
1024 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR_INFO,
Emily Shaffera344afc2017-04-13 15:09:39 -07001025 nullptr, ipmi_sen_get_sdr_info,
1026 PRIVILEGE_USER);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001027
Tom Joseph5ca50952018-02-22 00:33:38 +05301028 // <Get Device SDR>
1029 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR,
Emily Shafferbbef71c2017-05-08 16:36:17 -07001030 nullptr, ipmi_sen_get_sdr,
1031 PRIVILEGE_USER);
1032
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001033 // <Get Sensor Thresholds>
1034 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_THRESHOLDS,
1035 nullptr, ipmi_sen_get_sensor_thresholds,
1036 PRIVILEGE_USER);
1037
Chris Austenac4604a2015-10-13 12:43:27 -05001038 return;
1039}