blob: dc632d0288b0eb2e18b0cad3892b19e8d83e3973 [file] [log] [blame]
Brandon Kim9cf85622019-06-19 12:05:08 -07001#include "config.h"
2
Patrick Venture46470a32018-09-07 19:26:25 -07003#include "sensorhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Patrick Venture99bf1c42019-08-23 09:02:13 -07005#include "entity_map_json.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07006#include "fruread.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07007
Tomd700e762016-09-20 18:24:13 +05308#include <mapper.h>
Chris Austen10ccc0f2015-12-10 18:27:04 -06009#include <systemd/sd-bus.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070010
11#include <bitset>
Patrick Venture586d35b2018-09-07 19:56:18 -070012#include <cmath>
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070013#include <cstring>
Vernon Mauerye08fbff2019-04-03 09:19:34 -070014#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070015#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070016#include <ipmid/utils.hpp>
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050017#include <phosphor-logging/elog-errors.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070018#include <phosphor-logging/log.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070019#include <sdbusplus/message/types.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070020#include <set>
21#include <xyz/openbmc_project/Common/error.hpp>
22#include <xyz/openbmc_project/Sensor/Value/server.hpp>
23
Ratan Guptae0cc8552018-01-22 14:23:04 +053024static constexpr uint8_t fruInventoryDevice = 0x10;
25static constexpr uint8_t IPMIFruInventory = 0x02;
26static constexpr uint8_t BMCSlaveAddress = 0x20;
27
Patrick Venture0b02be92018-08-31 11:55:55 -070028extern int updateSensorRecordFromSSRAESC(const void*);
29extern sd_bus* bus;
Patrick Venturedb0cbe62019-09-09 14:47:22 -070030
31namespace ipmi
32{
33namespace sensor
34{
35extern const IdInfoMap sensors;
36} // namespace sensor
37} // namespace ipmi
38
Ratan Guptae0cc8552018-01-22 14:23:04 +053039extern const FruMap frus;
40
Tom Josephbe703f72017-03-09 12:34:35 +053041using namespace phosphor::logging;
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050042using InternalFailure =
43 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Chris Austenac4604a2015-10-13 12:43:27 -050044
Patrick Venture0b02be92018-08-31 11:55:55 -070045void register_netfn_sen_functions() __attribute__((constructor));
Chris Austenac4604a2015-10-13 12:43:27 -050046
Patrick Venture0b02be92018-08-31 11:55:55 -070047struct sensorTypemap_t
48{
Chris Austen0012e9b2015-10-22 01:37:46 -050049 uint8_t number;
Chris Austend7cf0e42015-11-07 14:27:12 -060050 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050051 char dbusname[32];
Patrick Venture0b02be92018-08-31 11:55:55 -070052};
Chris Austen0012e9b2015-10-22 01:37:46 -050053
Chris Austen0012e9b2015-10-22 01:37:46 -050054sensorTypemap_t g_SensorTypeMap[] = {
55
Chris Austend7cf0e42015-11-07 14:27:12 -060056 {0x01, 0x6F, "Temp"},
57 {0x0C, 0x6F, "DIMM"},
58 {0x0C, 0x6F, "MEMORY_BUFFER"},
59 {0x07, 0x6F, "PROC"},
60 {0x07, 0x6F, "CORE"},
61 {0x07, 0x6F, "CPU"},
62 {0x0F, 0x6F, "BootProgress"},
Patrick Venture0b02be92018-08-31 11:55:55 -070063 {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor
64 // type code os 0x09
Chris Austend7cf0e42015-11-07 14:27:12 -060065 {0xC3, 0x6F, "BootCount"},
66 {0x1F, 0x6F, "OperatingSystemStatus"},
Chris Austen800ba712015-12-03 15:31:00 -060067 {0x12, 0x6F, "SYSTEM_EVENT"},
68 {0xC7, 0x03, "SYSTEM"},
69 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austen10ccc0f2015-12-10 18:27:04 -060070 {0xC2, 0x6F, "PowerCap"},
Tom Joseph558184e2017-09-01 13:45:05 +053071 {0x0b, 0xCA, "PowerSupplyRedundancy"},
Jayanth Othayoth0661beb2017-03-22 06:00:58 -050072 {0xDA, 0x03, "TurboAllowed"},
Tom Joseph558184e2017-09-01 13:45:05 +053073 {0xD8, 0xC8, "PowerSupplyDerating"},
Chris Austend7cf0e42015-11-07 14:27:12 -060074 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050075};
76
Patrick Venture0b02be92018-08-31 11:55:55 -070077struct sensor_data_t
78{
Chris Austenac4604a2015-10-13 12:43:27 -050079 uint8_t sennum;
Patrick Venture0b02be92018-08-31 11:55:55 -070080} __attribute__((packed));
Chris Austenac4604a2015-10-13 12:43:27 -050081
Lei YU14a47812021-09-17 15:58:04 +080082using SDRCacheMap = std::unordered_map<uint8_t, get_sdr::SensorDataFullRecord>;
83SDRCacheMap sdrCacheMap __attribute__((init_priority(101)));
84
85using SensorThresholdMap =
86 std::unordered_map<uint8_t, get_sdr::GetSensorThresholdsResponse>;
87SensorThresholdMap sensorThresholdMap __attribute__((init_priority(101)));
88
Lei YU962e68b2021-09-16 16:25:34 +080089#ifdef FEATURE_SENSORS_CACHE
Lei YUbe5c6b22021-09-16 15:46:20 +080090std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match::match>>
91 sensorAddedMatches __attribute__((init_priority(101)));
92std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match::match>>
93 sensorUpdatedMatches __attribute__((init_priority(101)));
94
95void initSensorMatches()
96{
97 using namespace sdbusplus::bus::match::rules;
98 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
99 for (const auto& s : ipmi::sensor::sensors)
100 {
101 sensorAddedMatches.emplace(
102 s.first,
103 std::make_unique<sdbusplus::bus::match::match>(
104 bus, interfacesAdded() + argNpath(0, s.second.sensorPath),
105 [id = s.first, obj = s.second.sensorPath](auto& /*msg*/) {
106 // TODO
107 }));
108 sensorUpdatedMatches.emplace(
109 s.first,
110 std::make_unique<sdbusplus::bus::match::match>(
111 bus,
112 type::signal() + path(s.second.sensorPath) +
113 member("PropertiesChanged"s) +
114 interface("org.freedesktop.DBus.Properties"s),
115 [id = s.first, obj = s.second.sensorPath](auto& /*msg*/) {
116 // TODO
117 }));
118 }
119}
Lei YU962e68b2021-09-16 16:25:34 +0800120#endif
Lei YUbe5c6b22021-09-16 15:46:20 +0800121
Patrick Venture0b02be92018-08-31 11:55:55 -0700122int get_bus_for_path(const char* path, char** busname)
123{
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700124 return mapper_get_service(bus, path, busname);
125}
Tomd700e762016-09-20 18:24:13 +0530126
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700127// Use a lookup table to find the interface name of a specific sensor
128// This will be used until an alternative is found. this is the first
129// step for mapping IPMI
Patrick Venture0b02be92018-08-31 11:55:55 -0700130int find_openbmc_path(uint8_t num, dbus_interface_t* interface)
131{
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700132 int rc;
133
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700134 const auto& sensor_it = ipmi::sensor::sensors.find(num);
135 if (sensor_it == ipmi::sensor::sensors.end())
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700136 {
Adriana Kobylakba23ff72018-09-12 12:58:43 -0500137 // The sensor map does not contain the sensor requested
138 return -EINVAL;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700139 }
140
141 const auto& info = sensor_it->second;
142
Patrick Williams8451edf2017-06-13 09:01:06 -0500143 char* busname = nullptr;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700144 rc = get_bus_for_path(info.sensorPath.c_str(), &busname);
Patrick Venture0b02be92018-08-31 11:55:55 -0700145 if (rc < 0)
146 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700147 std::fprintf(stderr, "Failed to get %s busname: %s\n",
148 info.sensorPath.c_str(), busname);
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700149 goto final;
150 }
151
152 interface->sensortype = info.sensorType;
153 strcpy(interface->bus, busname);
154 strcpy(interface->path, info.sensorPath.c_str());
155 // Take the interface name from the beginning of the DbusInterfaceMap. This
156 // works for the Value interface but may not suffice for more complex
157 // sensors.
158 // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
Patrick Venture0b02be92018-08-31 11:55:55 -0700159 strcpy(interface->interface,
160 info.propertyInterfaces.begin()->first.c_str());
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700161 interface->sensornumber = num;
162
163final:
164 free(busname);
165 return rc;
166}
167
Tomd700e762016-09-20 18:24:13 +0530168/////////////////////////////////////////////////////////////////////
169//
170// Routines used by ipmi commands wanting to interact on the dbus
171//
172/////////////////////////////////////////////////////////////////////
Patrick Venture0b02be92018-08-31 11:55:55 -0700173int set_sensor_dbus_state_s(uint8_t number, const char* method,
174 const char* value)
175{
Tomd700e762016-09-20 18:24:13 +0530176
177 dbus_interface_t a;
178 int r;
179 sd_bus_error error = SD_BUS_ERROR_NULL;
Patrick Venture0b02be92018-08-31 11:55:55 -0700180 sd_bus_message* m = NULL;
Tomd700e762016-09-20 18:24:13 +0530181
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700182 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530183
Patrick Venture0b02be92018-08-31 11:55:55 -0700184 if (r < 0)
185 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700186 std::fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
Tomd700e762016-09-20 18:24:13 +0530187 return 0;
188 }
189
Patrick Venture0b02be92018-08-31 11:55:55 -0700190 r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface,
191 method);
192 if (r < 0)
193 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700194 std::fprintf(stderr, "Failed to create a method call: %s",
195 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530196 goto final;
197 }
198
199 r = sd_bus_message_append(m, "v", "s", value);
Patrick Venture0b02be92018-08-31 11:55:55 -0700200 if (r < 0)
201 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700202 std::fprintf(stderr, "Failed to create a input parameter: %s",
203 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530204 goto final;
205 }
206
Tomd700e762016-09-20 18:24:13 +0530207 r = sd_bus_call(bus, m, 0, &error, NULL);
Patrick Venture0b02be92018-08-31 11:55:55 -0700208 if (r < 0)
209 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700210 std::fprintf(stderr, "Failed to call the method: %s", strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530211 }
212
213final:
214 sd_bus_error_free(&error);
215 m = sd_bus_message_unref(m);
216
217 return 0;
218}
Patrick Venture0b02be92018-08-31 11:55:55 -0700219int set_sensor_dbus_state_y(uint8_t number, const char* method,
220 const uint8_t value)
221{
Tomd700e762016-09-20 18:24:13 +0530222
223 dbus_interface_t a;
224 int r;
225 sd_bus_error error = SD_BUS_ERROR_NULL;
Patrick Venture0b02be92018-08-31 11:55:55 -0700226 sd_bus_message* m = NULL;
Tomd700e762016-09-20 18:24:13 +0530227
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700228 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530229
Patrick Venture0b02be92018-08-31 11:55:55 -0700230 if (r < 0)
231 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700232 std::fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
Tomd700e762016-09-20 18:24:13 +0530233 return 0;
234 }
235
Patrick Venture0b02be92018-08-31 11:55:55 -0700236 r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface,
237 method);
238 if (r < 0)
239 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700240 std::fprintf(stderr, "Failed to create a method call: %s",
241 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530242 goto final;
243 }
244
245 r = sd_bus_message_append(m, "v", "i", value);
Patrick Venture0b02be92018-08-31 11:55:55 -0700246 if (r < 0)
247 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700248 std::fprintf(stderr, "Failed to create a input parameter: %s",
249 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530250 goto final;
251 }
252
Tomd700e762016-09-20 18:24:13 +0530253 r = sd_bus_call(bus, m, 0, &error, NULL);
Patrick Venture0b02be92018-08-31 11:55:55 -0700254 if (r < 0)
255 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700256 std::fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530257 }
258
259final:
260 sd_bus_error_free(&error);
261 m = sd_bus_message_unref(m);
262
263 return 0;
264}
265
Patrick Venture0b02be92018-08-31 11:55:55 -0700266uint8_t dbus_to_sensor_type(char* p)
267{
Chris Austenac4604a2015-10-13 12:43:27 -0500268
Patrick Venture0b02be92018-08-31 11:55:55 -0700269 sensorTypemap_t* s = g_SensorTypeMap;
270 char r = 0;
271 while (s->number != 0xFF)
272 {
273 if (!strcmp(s->dbusname, p))
274 {
Tom Joseph558184e2017-09-01 13:45:05 +0530275 r = s->typecode;
Patrick Venture0b02be92018-08-31 11:55:55 -0700276 break;
Chris Austenac4604a2015-10-13 12:43:27 -0500277 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500278 s++;
Chris Austenac4604a2015-10-13 12:43:27 -0500279 }
280
Chris Austen0012e9b2015-10-22 01:37:46 -0500281 if (s->number == 0xFF)
282 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -0500283
Chris Austen0012e9b2015-10-22 01:37:46 -0500284 return r;
Chris Austenac4604a2015-10-13 12:43:27 -0500285}
286
Patrick Venture0b02be92018-08-31 11:55:55 -0700287uint8_t get_type_from_interface(dbus_interface_t dbus_if)
288{
Chris Austen0012e9b2015-10-22 01:37:46 -0500289
Brad Bishop56003452016-10-05 21:49:19 -0400290 uint8_t type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500291
Chris Austen0012e9b2015-10-22 01:37:46 -0500292 // This is where sensors that do not exist in dbus but do
293 // exist in the host code stop. This should indicate it
294 // is not a supported sensor
Patrick Venture0b02be92018-08-31 11:55:55 -0700295 if (dbus_if.interface[0] == 0)
296 {
297 return 0;
298 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500299
Emily Shaffer71174412017-04-05 15:10:40 -0700300 // Fetch type from interface itself.
301 if (dbus_if.sensortype != 0)
302 {
303 type = dbus_if.sensortype;
Patrick Venture0b02be92018-08-31 11:55:55 -0700304 }
305 else
306 {
Chris Austen0012e9b2015-10-22 01:37:46 -0500307 // Non InventoryItems
Patrick Venture4491a462018-10-13 13:00:42 -0700308 char* p = strrchr(dbus_if.path, '/');
Patrick Venture0b02be92018-08-31 11:55:55 -0700309 type = dbus_to_sensor_type(p + 1);
Chris Austen0012e9b2015-10-22 01:37:46 -0500310 }
311
Brad Bishop56003452016-10-05 21:49:19 -0400312 return type;
Patrick Venture0b02be92018-08-31 11:55:55 -0700313}
Chris Austen0012e9b2015-10-22 01:37:46 -0500314
Emily Shaffer391f3302017-04-03 10:27:08 -0700315// Replaces find_sensor
Patrick Venture0b02be92018-08-31 11:55:55 -0700316uint8_t find_type_for_sensor_number(uint8_t num)
317{
Emily Shaffer391f3302017-04-03 10:27:08 -0700318 int r;
319 dbus_interface_t dbus_if;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700320 r = find_openbmc_path(num, &dbus_if);
Patrick Venture0b02be92018-08-31 11:55:55 -0700321 if (r < 0)
322 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700323 std::fprintf(stderr, "Could not find sensor %d\n", num);
Lei YU91875f72018-04-03 15:14:49 +0800324 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700325 }
326 return get_type_from_interface(dbus_if);
327}
328
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000329/**
330 * @brief implements the get sensor type command.
331 * @param - sensorNumber
332 *
333 * @return IPMI completion code plus response data on success.
334 * - sensorType
335 * - eventType
336 **/
337
338ipmi::RspType<uint8_t, // sensorType
339 uint8_t // eventType
340 >
341 ipmiGetSensorType(uint8_t sensorNumber)
Chris Austenac4604a2015-10-13 12:43:27 -0500342{
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000343 uint8_t sensorType = find_type_for_sensor_number(sensorNumber);
Chris Austenac4604a2015-10-13 12:43:27 -0500344
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000345 if (sensorType == 0)
Patrick Venture0b02be92018-08-31 11:55:55 -0700346 {
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000347 return ipmi::responseSensorInvalid();
Chris Austen0012e9b2015-10-22 01:37:46 -0500348 }
349
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000350 constexpr uint8_t eventType = 0x6F;
351 return ipmi::responseSuccess(sensorType, eventType);
Chris Austenac4604a2015-10-13 12:43:27 -0500352}
353
Patrick Venture0b02be92018-08-31 11:55:55 -0700354const std::set<std::string> analogSensorInterfaces = {
Emily Shaffercc941e12017-06-14 13:06:26 -0700355 "xyz.openbmc_project.Sensor.Value",
Patrick Venturee9a64052017-08-18 19:17:27 -0700356 "xyz.openbmc_project.Control.FanPwm",
Emily Shaffercc941e12017-06-14 13:06:26 -0700357};
358
359bool isAnalogSensor(const std::string& interface)
360{
361 return (analogSensorInterfaces.count(interface));
362}
363
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000364/**
365@brief This command is used to set sensorReading.
366
367@param
368 - sensorNumber
369 - operation
370 - reading
371 - assertOffset0_7
372 - assertOffset8_14
373 - deassertOffset0_7
374 - deassertOffset8_14
375 - eventData1
376 - eventData2
377 - eventData3
378
379@return completion code on success.
380**/
381
382ipmi::RspType<> ipmiSetSensorReading(uint8_t sensorNumber, uint8_t operation,
383 uint8_t reading, uint8_t assertOffset0_7,
384 uint8_t assertOffset8_14,
385 uint8_t deassertOffset0_7,
386 uint8_t deassertOffset8_14,
387 uint8_t eventData1, uint8_t eventData2,
388 uint8_t eventData3)
Tom Josephbe703f72017-03-09 12:34:35 +0530389{
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000390 log<level::DEBUG>("IPMI SET_SENSOR",
391 entry("SENSOR_NUM=0x%02x", sensorNumber));
392
Arun P. Mohanan0634e982021-08-30 15:21:33 +0530393 if (sensorNumber == 0xFF)
394 {
395 return ipmi::responseInvalidFieldRequest();
396 }
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000397 ipmi::sensor::SetSensorReadingReq cmdData;
398
399 cmdData.number = sensorNumber;
400 cmdData.operation = operation;
401 cmdData.reading = reading;
402 cmdData.assertOffset0_7 = assertOffset0_7;
403 cmdData.assertOffset8_14 = assertOffset8_14;
404 cmdData.deassertOffset0_7 = deassertOffset0_7;
405 cmdData.deassertOffset8_14 = deassertOffset8_14;
406 cmdData.eventData1 = eventData1;
407 cmdData.eventData2 = eventData2;
408 cmdData.eventData3 = eventData3;
Tom Josephbe703f72017-03-09 12:34:35 +0530409
410 // Check if the Sensor Number is present
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700411 const auto iter = ipmi::sensor::sensors.find(sensorNumber);
412 if (iter == ipmi::sensor::sensors.end())
Tom Josephbe703f72017-03-09 12:34:35 +0530413 {
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000414 updateSensorRecordFromSSRAESC(&sensorNumber);
415 return ipmi::responseSuccess();
Tom Josephbe703f72017-03-09 12:34:35 +0530416 }
417
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500418 try
419 {
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500420 if (ipmi::sensor::Mutability::Write !=
Patrick Venture0b02be92018-08-31 11:55:55 -0700421 (iter->second.mutability & ipmi::sensor::Mutability::Write))
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500422 {
423 log<level::ERR>("Sensor Set operation is not allowed",
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000424 entry("SENSOR_NUM=%d", sensorNumber));
425 return ipmi::responseIllegalCommand();
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500426 }
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000427 auto ipmiRC = iter->second.updateFunc(cmdData, iter->second);
428 return ipmi::response(ipmiRC);
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500429 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500430 catch (const InternalFailure& e)
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500431 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700432 log<level::ERR>("Set sensor failed",
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000433 entry("SENSOR_NUM=%d", sensorNumber));
Patrick Venture0b02be92018-08-31 11:55:55 -0700434 commit<InternalFailure>();
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000435 return ipmi::responseUnspecifiedError();
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500436 }
Tom Joseph82024322017-09-28 20:07:29 +0530437 catch (const std::runtime_error& e)
438 {
439 log<level::ERR>(e.what());
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000440 return ipmi::responseUnspecifiedError();
Tom Joseph82024322017-09-28 20:07:29 +0530441 }
Chris Austenac4604a2015-10-13 12:43:27 -0500442}
443
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000444/** @brief implements the get sensor reading command
445 * @param sensorNum - sensor number
446 *
447 * @returns IPMI completion code plus response data
448 * - senReading - sensor reading
449 * - reserved
450 * - readState - sensor reading state enabled
451 * - senScanState - sensor scan state disabled
452 * - allEventMessageState - all Event message state disabled
453 * - assertionStatesLsb - threshold levels states
454 * - assertionStatesMsb - discrete reading sensor states
455 */
456ipmi::RspType<uint8_t, // sensor reading
Tom Joseph3ee668f2018-03-02 19:49:17 +0530457
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000458 uint5_t, // reserved
459 bool, // reading state
Sui Chen4cc42552019-09-11 10:28:35 -0700460 bool, // 0 = sensor scanning state disabled
461 bool, // 0 = all event messages disabled
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000462
463 uint8_t, // threshold levels states
464 uint8_t // discrete reading sensor states
465 >
466 ipmiSensorGetSensorReading(uint8_t sensorNum)
467{
468 if (sensorNum == 0xFF)
469 {
470 return ipmi::responseInvalidFieldRequest();
471 }
472
473 const auto iter = ipmi::sensor::sensors.find(sensorNum);
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700474 if (iter == ipmi::sensor::sensors.end())
Tom Joseph3ee668f2018-03-02 19:49:17 +0530475 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000476 return ipmi::responseSensorInvalid();
Tom Joseph3ee668f2018-03-02 19:49:17 +0530477 }
478 if (ipmi::sensor::Mutability::Read !=
Patrick Venture0b02be92018-08-31 11:55:55 -0700479 (iter->second.mutability & ipmi::sensor::Mutability::Read))
Tom Joseph3ee668f2018-03-02 19:49:17 +0530480 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000481 return ipmi::responseIllegalCommand();
Tom Joseph3ee668f2018-03-02 19:49:17 +0530482 }
483
484 try
485 {
Sui Chen4cc42552019-09-11 10:28:35 -0700486 ipmi::sensor::GetSensorResponse getResponse =
487 iter->second.getFunc(iter->second);
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000488
Sui Chen4cc42552019-09-11 10:28:35 -0700489 return ipmi::responseSuccess(getResponse.reading, uint5_t(0),
490 getResponse.readingOrStateUnavailable,
491 getResponse.scanningEnabled,
492 getResponse.allEventMessagesEnabled,
493 getResponse.thresholdLevelsStates,
494 getResponse.discreteReadingSensorStates);
Tom Joseph3ee668f2018-03-02 19:49:17 +0530495 }
Brandon Kim9cf85622019-06-19 12:05:08 -0700496#ifdef UPDATE_FUNCTIONAL_ON_FAIL
497 catch (const SensorFunctionalError& e)
498 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000499 return ipmi::responseResponseError();
Brandon Kim9cf85622019-06-19 12:05:08 -0700500 }
501#endif
Tom Joseph3ee668f2018-03-02 19:49:17 +0530502 catch (const std::exception& e)
503 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000504 // Intitilizing with default values
505 constexpr uint8_t senReading = 0;
506 constexpr uint5_t reserved{0};
507 constexpr bool readState = true;
508 constexpr bool senScanState = false;
509 constexpr bool allEventMessageState = false;
510 constexpr uint8_t assertionStatesLsb = 0;
511 constexpr uint8_t assertionStatesMsb = 0;
512
513 return ipmi::responseSuccess(senReading, reserved, readState,
514 senScanState, allEventMessageState,
515 assertionStatesLsb, assertionStatesMsb);
Tom Joseph3ee668f2018-03-02 19:49:17 +0530516 }
517}
518
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300519get_sdr::GetSensorThresholdsResponse
520 getSensorThresholds(ipmi::Context::ptr& ctx, uint8_t sensorNum)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600521{
William A. Kennington III515bc372020-10-27 16:32:32 -0700522 get_sdr::GetSensorThresholdsResponse resp{};
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530523 constexpr auto warningThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600524 "xyz.openbmc_project.Sensor.Threshold.Warning";
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530525 constexpr auto criticalThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600526 "xyz.openbmc_project.Sensor.Threshold.Critical";
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600527
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700528 const auto iter = ipmi::sensor::sensors.find(sensorNum);
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530529 const auto info = iter->second;
530
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300531 std::string service;
532 boost::system::error_code ec;
533 ec = ipmi::getService(ctx, info.sensorInterface, info.sensorPath, service);
534 if (ec)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530535 {
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300536 return resp;
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530537 }
538
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300539 ipmi::PropertyMap warnThresholds;
540 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
541 warningThreshIntf, warnThresholds);
542 if (!ec)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530543 {
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300544 double warnLow = std::visit(ipmi::VariantToDoubleVisitor(),
545 warnThresholds["WarningLow"]);
546 double warnHigh = std::visit(ipmi::VariantToDoubleVisitor(),
547 warnThresholds["WarningHigh"]);
548
549 if (std::isfinite(warnLow))
550 {
551 warnLow *= std::pow(10, info.scale - info.exponentR);
552 resp.lowerNonCritical = static_cast<uint8_t>(
553 (warnLow - info.scaledOffset) / info.coefficientM);
554 resp.validMask |= static_cast<uint8_t>(
555 ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK);
556 }
557
558 if (std::isfinite(warnHigh))
559 {
560 warnHigh *= std::pow(10, info.scale - info.exponentR);
561 resp.upperNonCritical = static_cast<uint8_t>(
562 (warnHigh - info.scaledOffset) / info.coefficientM);
563 resp.validMask |= static_cast<uint8_t>(
564 ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK);
565 }
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530566 }
567
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300568 ipmi::PropertyMap critThresholds;
569 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
570 criticalThreshIntf, critThresholds);
571 if (!ec)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530572 {
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300573 double critLow = std::visit(ipmi::VariantToDoubleVisitor(),
574 critThresholds["CriticalLow"]);
575 double critHigh = std::visit(ipmi::VariantToDoubleVisitor(),
576 critThresholds["CriticalHigh"]);
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530577
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300578 if (std::isfinite(critLow))
579 {
580 critLow *= std::pow(10, info.scale - info.exponentR);
581 resp.lowerCritical = static_cast<uint8_t>(
582 (critLow - info.scaledOffset) / info.coefficientM);
583 resp.validMask |= static_cast<uint8_t>(
584 ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK);
585 }
586
587 if (std::isfinite(critHigh))
588 {
589 critHigh *= std::pow(10, info.scale - info.exponentR);
590 resp.upperCritical = static_cast<uint8_t>(
591 (critHigh - info.scaledOffset) / info.coefficientM);
592 resp.validMask |= static_cast<uint8_t>(
593 ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK);
594 }
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530595 }
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000596
597 return resp;
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530598}
599
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000600/** @brief implements the get sensor thresholds command
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300601 * @param ctx - IPMI context pointer
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000602 * @param sensorNum - sensor number
603 *
604 * @returns IPMI completion code plus response data
605 * - validMask - threshold mask
606 * - lower non-critical threshold - IPMI messaging state
607 * - lower critical threshold - link authentication state
608 * - lower non-recoverable threshold - callback state
609 * - upper non-critical threshold
610 * - upper critical
611 * - upper non-recoverable
612 */
613ipmi::RspType<uint8_t, // validMask
614 uint8_t, // lowerNonCritical
615 uint8_t, // lowerCritical
616 uint8_t, // lowerNonRecoverable
617 uint8_t, // upperNonCritical
618 uint8_t, // upperCritical
619 uint8_t // upperNonRecoverable
620 >
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300621 ipmiSensorGetSensorThresholds(ipmi::Context::ptr& ctx, uint8_t sensorNum)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530622{
623 constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
624
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700625 const auto iter = ipmi::sensor::sensors.find(sensorNum);
626 if (iter == ipmi::sensor::sensors.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600627 {
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000628 return ipmi::responseSensorInvalid();
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600629 }
630
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530631 const auto info = iter->second;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600632
Patrick Venture0b02be92018-08-31 11:55:55 -0700633 // Proceed only if the sensor value interface is implemented.
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530634 if (info.propertyInterfaces.find(valueInterface) ==
635 info.propertyInterfaces.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600636 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700637 // return with valid mask as 0
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000638 return ipmi::responseSuccess();
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600639 }
640
Lei YU14a47812021-09-17 15:58:04 +0800641 auto it = sensorThresholdMap.find(sensorNum);
642 if (it == sensorThresholdMap.end())
643 {
644 sensorThresholdMap[sensorNum] = getSensorThresholds(ctx, sensorNum);
645 }
646
647 const auto& resp = sensorThresholdMap[sensorNum];
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600648
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000649 return ipmi::responseSuccess(resp.validMask, resp.lowerNonCritical,
650 resp.lowerCritical, resp.lowerNonRecoverable,
651 resp.upperNonCritical, resp.upperCritical,
652 resp.upperNonRecoverable);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600653}
654
Lotus Xuf93da662021-10-18 17:20:06 +0800655/** @brief implements the Set Sensor threshold command
656 * @param sensorNumber - sensor number
657 * @param lowerNonCriticalThreshMask
658 * @param lowerCriticalThreshMask
659 * @param lowerNonRecovThreshMask
660 * @param upperNonCriticalThreshMask
661 * @param upperCriticalThreshMask
662 * @param upperNonRecovThreshMask
663 * @param reserved
664 * @param lowerNonCritical - lower non-critical threshold
665 * @param lowerCritical - Lower critical threshold
666 * @param lowerNonRecoverable - Lower non recovarable threshold
667 * @param upperNonCritical - Upper non-critical threshold
668 * @param upperCritical - Upper critical
669 * @param upperNonRecoverable - Upper Non-recoverable
670 *
671 * @returns IPMI completion code
672 */
673ipmi::RspType<> ipmiSenSetSensorThresholds(
674 ipmi::Context::ptr& ctx, uint8_t sensorNum, bool lowerNonCriticalThreshMask,
675 bool lowerCriticalThreshMask, bool lowerNonRecovThreshMask,
676 bool upperNonCriticalThreshMask, bool upperCriticalThreshMask,
677 bool upperNonRecovThreshMask, uint2_t reserved, uint8_t lowerNonCritical,
678 uint8_t lowerCritical, uint8_t lowerNonRecoverable,
679 uint8_t upperNonCritical, uint8_t upperCritical,
680 uint8_t upperNonRecoverable)
681{
682 if (reserved)
683 {
684 return ipmi::responseInvalidFieldRequest();
685 }
686
687 // lower nc and upper nc not suppported on any sensor
688 if (lowerNonRecovThreshMask || upperNonRecovThreshMask)
689 {
690 return ipmi::responseInvalidFieldRequest();
691 }
692
693 // if none of the threshold mask are set, nothing to do
694 if (!(lowerNonCriticalThreshMask | lowerCriticalThreshMask |
695 lowerNonRecovThreshMask | upperNonCriticalThreshMask |
696 upperCriticalThreshMask | upperNonRecovThreshMask))
697 {
698 return ipmi::responseSuccess();
699 }
700
701 constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
702
703 const auto iter = ipmi::sensor::sensors.find(sensorNum);
704 if (iter == ipmi::sensor::sensors.end())
705 {
706 return ipmi::responseSensorInvalid();
707 }
708
709 const auto& info = iter->second;
710
711 // Proceed only if the sensor value interface is implemented.
712 if (info.propertyInterfaces.find(valueInterface) ==
713 info.propertyInterfaces.end())
714 {
715 // return with valid mask as 0
716 return ipmi::responseSuccess();
717 }
718
719 constexpr auto warningThreshIntf =
720 "xyz.openbmc_project.Sensor.Threshold.Warning";
721 constexpr auto criticalThreshIntf =
722 "xyz.openbmc_project.Sensor.Threshold.Critical";
723
724 std::string service;
725 boost::system::error_code ec;
726 ec = ipmi::getService(ctx, info.sensorInterface, info.sensorPath, service);
727 if (ec)
728 {
729 return ipmi::responseResponseError();
730 }
731 // store a vector of property name, value to set, and interface
732 std::vector<std::tuple<std::string, uint8_t, std::string>> thresholdsToSet;
733
734 // define the indexes of the tuple
735 constexpr uint8_t propertyName = 0;
736 constexpr uint8_t thresholdValue = 1;
737 constexpr uint8_t interface = 2;
738 // verifiy all needed fields are present
739 if (lowerCriticalThreshMask || upperCriticalThreshMask)
740 {
741
742 ipmi::PropertyMap findThreshold;
743 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
744 criticalThreshIntf, findThreshold);
745
746 if (!ec)
747 {
748 if (lowerCriticalThreshMask)
749 {
750 auto findLower = findThreshold.find("CriticalLow");
751 if (findLower == findThreshold.end())
752 {
753 return ipmi::responseInvalidFieldRequest();
754 }
755 thresholdsToSet.emplace_back("CriticalLow", lowerCritical,
756 criticalThreshIntf);
757 }
758 if (upperCriticalThreshMask)
759 {
760 auto findUpper = findThreshold.find("CriticalHigh");
761 if (findUpper == findThreshold.end())
762 {
763 return ipmi::responseInvalidFieldRequest();
764 }
765 thresholdsToSet.emplace_back("CriticalHigh", upperCritical,
766 criticalThreshIntf);
767 }
768 }
769 }
770 if (lowerNonCriticalThreshMask || upperNonCriticalThreshMask)
771 {
772 ipmi::PropertyMap findThreshold;
773 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
774 warningThreshIntf, findThreshold);
775
776 if (!ec)
777 {
778 if (lowerNonCriticalThreshMask)
779 {
780 auto findLower = findThreshold.find("WarningLow");
781 if (findLower == findThreshold.end())
782 {
783 return ipmi::responseInvalidFieldRequest();
784 }
785 thresholdsToSet.emplace_back("WarningLow", lowerNonCritical,
786 warningThreshIntf);
787 }
788 if (upperNonCriticalThreshMask)
789 {
790 auto findUpper = findThreshold.find("WarningHigh");
791 if (findUpper == findThreshold.end())
792 {
793 return ipmi::responseInvalidFieldRequest();
794 }
795 thresholdsToSet.emplace_back("WarningHigh", upperNonCritical,
796 warningThreshIntf);
797 }
798 }
799 }
800 for (const auto& property : thresholdsToSet)
801 {
802 // from section 36.3 in the IPMI Spec, assume all linear
803 double valueToSet =
804 ((info.coefficientM * std::get<thresholdValue>(property)) +
805 (info.scaledOffset * std::pow(10.0, info.scale))) *
806 std::pow(10.0, info.exponentR);
807 ipmi::setDbusProperty(
808 ctx, service, info.sensorPath, std::get<interface>(property),
809 std::get<propertyName>(property), ipmi::Value(valueToSet));
810 }
811
Lei YU14a47812021-09-17 15:58:04 +0800812 // Invalidate the cache
813 sensorThresholdMap.erase(sensorNum);
Lotus Xuf93da662021-10-18 17:20:06 +0800814 return ipmi::responseSuccess();
815}
816
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000817/** @brief implements the get SDR Info command
818 * @param count - Operation
819 *
820 * @returns IPMI completion code plus response data
821 * - sdrCount - sensor/SDR count
822 * - lunsAndDynamicPopulation - static/Dynamic sensor population flag
823 */
824ipmi::RspType<uint8_t, // respcount
825 uint8_t // dynamic population flags
826 >
827 ipmiSensorGetDeviceSdrInfo(std::optional<uint8_t> count)
Emily Shafferd06e0e72017-04-05 09:08:57 -0700828{
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000829 uint8_t sdrCount;
830 // multiple LUNs not supported.
831 constexpr uint8_t lunsAndDynamicPopulation = 1;
832 constexpr uint8_t getSdrCount = 0x01;
833 constexpr uint8_t getSensorCount = 0x00;
834
835 if (count.value_or(0) == getSdrCount)
Emily Shafferd06e0e72017-04-05 09:08:57 -0700836 {
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000837 // Get SDR count. This returns the total number of SDRs in the device.
Patrick Venture87fd2cd2019-08-19 12:07:18 -0700838 const auto& entityRecords =
839 ipmi::sensor::EntityInfoMapContainer::getContainer()
840 ->getIpmiEntityRecords();
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700841 sdrCount =
842 ipmi::sensor::sensors.size() + frus.size() + entityRecords.size();
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000843 }
844 else if (count.value_or(0) == getSensorCount)
845 {
846 // Get Sensor count. This returns the number of sensors
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700847 sdrCount = ipmi::sensor::sensors.size();
Emily Shafferd06e0e72017-04-05 09:08:57 -0700848 }
849 else
850 {
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000851 return ipmi::responseInvalidCommandOnLun();
Emily Shafferd06e0e72017-04-05 09:08:57 -0700852 }
853
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000854 return ipmi::responseSuccess(sdrCount, lunsAndDynamicPopulation);
Emily Shafferd06e0e72017-04-05 09:08:57 -0700855}
856
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000857/** @brief implements the reserve SDR command
858 * @returns IPMI completion code plus response data
859 * - reservationID - reservation ID
860 */
861ipmi::RspType<uint16_t> ipmiSensorReserveSdr()
Emily Shaffera344afc2017-04-13 15:09:39 -0700862{
863 // A constant reservation ID is okay until we implement add/remove SDR.
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000864 constexpr uint16_t reservationID = 1;
Emily Shaffera344afc2017-04-13 15:09:39 -0700865
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000866 return ipmi::responseSuccess(reservationID);
Emily Shaffera344afc2017-04-13 15:09:39 -0700867}
Chris Austenac4604a2015-10-13 12:43:27 -0500868
Patrick Venture0b02be92018-08-31 11:55:55 -0700869void setUnitFieldsForObject(const ipmi::sensor::Info* info,
870 get_sdr::SensorDataFullRecordBody* body)
Emily Shaffercc941e12017-06-14 13:06:26 -0700871{
Tom Josephdc212b22018-02-16 09:59:57 +0530872 namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
873 try
Emily Shaffercc941e12017-06-14 13:06:26 -0700874 {
Tom Josephdc212b22018-02-16 09:59:57 +0530875 auto unit = server::Value::convertUnitFromString(info->unit);
876 // Unit strings defined in
877 // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
878 switch (unit)
Emily Shaffercc941e12017-06-14 13:06:26 -0700879 {
Tom Josephdc212b22018-02-16 09:59:57 +0530880 case server::Value::Unit::DegreesC:
881 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
882 break;
883 case server::Value::Unit::RPMS:
Kirill Pakhomov812e44c2018-10-22 16:25:35 +0300884 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_RPM;
Tom Josephdc212b22018-02-16 09:59:57 +0530885 break;
886 case server::Value::Unit::Volts:
887 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
888 break;
889 case server::Value::Unit::Meters:
890 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
891 break;
892 case server::Value::Unit::Amperes:
893 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
894 break;
895 case server::Value::Unit::Joules:
896 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
897 break;
898 case server::Value::Unit::Watts:
899 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
900 break;
901 default:
902 // Cannot be hit.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700903 std::fprintf(stderr, "Unknown value unit type: = %s\n",
904 info->unit.c_str());
Emily Shaffercc941e12017-06-14 13:06:26 -0700905 }
906 }
Patrick Venture64678b82018-10-13 13:11:32 -0700907 catch (const sdbusplus::exception::InvalidEnumString& e)
Emily Shaffercc941e12017-06-14 13:06:26 -0700908 {
Tom Josephdc212b22018-02-16 09:59:57 +0530909 log<level::WARNING>("Warning: no unit provided for sensor!");
Emily Shaffercc941e12017-06-14 13:06:26 -0700910 }
Emily Shaffercc941e12017-06-14 13:06:26 -0700911}
912
Patrick Venture0b02be92018-08-31 11:55:55 -0700913ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody* body,
914 const ipmi::sensor::Info* info,
Emily Shafferbbef71c2017-05-08 16:36:17 -0700915 ipmi_data_len_t data_len)
916{
917 /* Functional sensor case */
Emily Shaffercc941e12017-06-14 13:06:26 -0700918 if (isAnalogSensor(info->propertyInterfaces.begin()->first))
Emily Shafferbbef71c2017-05-08 16:36:17 -0700919 {
Tony Leec5324252019-10-31 17:24:16 +0800920 body->sensor_units_1 = info->sensorUnits1; // default is 0. unsigned, no
921 // rate, no modifier, not a %
Emily Shafferbbef71c2017-05-08 16:36:17 -0700922 /* Unit info */
Tom Josephdc212b22018-02-16 09:59:57 +0530923 setUnitFieldsForObject(info, body);
Emily Shaffer10f49592017-05-10 12:01:10 -0700924
925 get_sdr::body::set_b(info->coefficientB, body);
926 get_sdr::body::set_m(info->coefficientM, body);
927 get_sdr::body::set_b_exp(info->exponentB, body);
Tom Josephdc212b22018-02-16 09:59:57 +0530928 get_sdr::body::set_r_exp(info->exponentR, body);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700929
Emily Shafferbbef71c2017-05-08 16:36:17 -0700930 get_sdr::body::set_id_type(0b00, body); // 00 = unicode
Emily Shafferbbef71c2017-05-08 16:36:17 -0700931 }
932
Tom Joseph96423912018-01-25 00:14:34 +0530933 /* ID string */
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +0800934 auto id_string = info->sensorName;
935
936 if (id_string.empty())
937 {
938 id_string = info->sensorNameFunc(*info);
939 }
Tom Joseph96423912018-01-25 00:14:34 +0530940
941 if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
942 {
943 get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH, body);
944 }
945 else
946 {
947 get_sdr::body::set_id_strlen(id_string.length(), body);
948 }
949 strncpy(body->id_string, id_string.c_str(),
950 get_sdr::body::get_id_strlen(body));
951
Emily Shafferbbef71c2017-05-08 16:36:17 -0700952 return IPMI_CC_OK;
953};
954
Ratan Guptae0cc8552018-01-22 14:23:04 +0530955ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response,
956 ipmi_data_len_t data_len)
957{
958 auto req = reinterpret_cast<get_sdr::GetSdrReq*>(request);
959 auto resp = reinterpret_cast<get_sdr::GetSdrResp*>(response);
Patrick Venture0b02be92018-08-31 11:55:55 -0700960 get_sdr::SensorDataFruRecord record{};
Ratan Guptae0cc8552018-01-22 14:23:04 +0530961 auto dataLength = 0;
962
963 auto fru = frus.begin();
Patrick Venture0b02be92018-08-31 11:55:55 -0700964 uint8_t fruID{};
Ratan Guptae0cc8552018-01-22 14:23:04 +0530965 auto recordID = get_sdr::request::get_record_id(req);
966
967 fruID = recordID - FRU_RECORD_ID_START;
968 fru = frus.find(fruID);
969 if (fru == frus.end())
970 {
971 return IPMI_CC_SENSOR_INVALID;
972 }
973
974 /* Header */
975 get_sdr::header::set_record_id(recordID, &(record.header));
976 record.header.sdr_version = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
977 record.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD;
978 record.header.record_length = sizeof(record.key) + sizeof(record.body);
979
980 /* Key */
981 record.key.fruID = fruID;
982 record.key.accessLun |= IPMI_LOGICAL_FRU;
983 record.key.deviceAddress = BMCSlaveAddress;
984
985 /* Body */
986 record.body.entityID = fru->second[0].entityID;
987 record.body.entityInstance = fru->second[0].entityInstance;
988 record.body.deviceType = fruInventoryDevice;
989 record.body.deviceTypeModifier = IPMIFruInventory;
990
991 /* Device ID string */
Patrick Venture0b02be92018-08-31 11:55:55 -0700992 auto deviceID =
993 fru->second[0].path.substr(fru->second[0].path.find_last_of('/') + 1,
994 fru->second[0].path.length());
Ratan Guptae0cc8552018-01-22 14:23:04 +0530995
996 if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH)
997 {
998 get_sdr::body::set_device_id_strlen(
Patrick Venture0b02be92018-08-31 11:55:55 -0700999 get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, &(record.body));
Ratan Guptae0cc8552018-01-22 14:23:04 +05301000 }
1001 else
1002 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001003 get_sdr::body::set_device_id_strlen(deviceID.length(), &(record.body));
Ratan Guptae0cc8552018-01-22 14:23:04 +05301004 }
1005
1006 strncpy(record.body.deviceID, deviceID.c_str(),
1007 get_sdr::body::get_device_id_strlen(&(record.body)));
1008
1009 if (++fru == frus.end())
1010 {
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001011 // we have reached till end of fru, so assign the next record id to
1012 // 512(Max fru ID = 511) + Entity Record ID(may start with 0).
Patrick Venture87fd2cd2019-08-19 12:07:18 -07001013 const auto& entityRecords =
1014 ipmi::sensor::EntityInfoMapContainer::getContainer()
1015 ->getIpmiEntityRecords();
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001016 auto next_record_id =
Patrick Venture83a0b842019-07-19 18:37:15 -07001017 (entityRecords.size())
1018 ? entityRecords.begin()->first + ENTITY_RECORD_ID_START
1019 : END_OF_RECORD;
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001020 get_sdr::response::set_next_record_id(next_record_id, resp);
1021 }
1022 else
1023 {
1024 get_sdr::response::set_next_record_id(
1025 (FRU_RECORD_ID_START + fru->first), resp);
1026 }
1027
1028 // Check for invalid offset size
1029 if (req->offset > sizeof(record))
1030 {
1031 return IPMI_CC_PARM_OUT_OF_RANGE;
1032 }
1033
1034 dataLength = std::min(static_cast<size_t>(req->bytes_to_read),
1035 sizeof(record) - req->offset);
1036
1037 std::memcpy(resp->record_data,
1038 reinterpret_cast<uint8_t*>(&record) + req->offset, dataLength);
1039
1040 *data_len = dataLength;
1041 *data_len += 2; // additional 2 bytes for next record ID
1042
1043 return IPMI_CC_OK;
1044}
1045
1046ipmi_ret_t ipmi_entity_get_sdr(ipmi_request_t request, ipmi_response_t response,
1047 ipmi_data_len_t data_len)
1048{
1049 auto req = reinterpret_cast<get_sdr::GetSdrReq*>(request);
1050 auto resp = reinterpret_cast<get_sdr::GetSdrResp*>(response);
1051 get_sdr::SensorDataEntityRecord record{};
1052 auto dataLength = 0;
1053
Patrick Venture87fd2cd2019-08-19 12:07:18 -07001054 const auto& entityRecords =
1055 ipmi::sensor::EntityInfoMapContainer::getContainer()
1056 ->getIpmiEntityRecords();
Patrick Venture83a0b842019-07-19 18:37:15 -07001057 auto entity = entityRecords.begin();
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001058 uint8_t entityRecordID;
1059 auto recordID = get_sdr::request::get_record_id(req);
1060
1061 entityRecordID = recordID - ENTITY_RECORD_ID_START;
Patrick Venture83a0b842019-07-19 18:37:15 -07001062 entity = entityRecords.find(entityRecordID);
1063 if (entity == entityRecords.end())
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001064 {
1065 return IPMI_CC_SENSOR_INVALID;
1066 }
1067
1068 /* Header */
1069 get_sdr::header::set_record_id(recordID, &(record.header));
1070 record.header.sdr_version = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
1071 record.header.record_type = get_sdr::SENSOR_DATA_ENTITY_RECORD;
1072 record.header.record_length = sizeof(record.key) + sizeof(record.body);
1073
1074 /* Key */
1075 record.key.containerEntityId = entity->second.containerEntityId;
1076 record.key.containerEntityInstance = entity->second.containerEntityInstance;
1077 get_sdr::key::set_flags(entity->second.isList, entity->second.isLinked,
1078 &(record.key));
1079 record.key.entityId1 = entity->second.containedEntities[0].first;
1080 record.key.entityInstance1 = entity->second.containedEntities[0].second;
1081
1082 /* Body */
1083 record.body.entityId2 = entity->second.containedEntities[1].first;
1084 record.body.entityInstance2 = entity->second.containedEntities[1].second;
1085 record.body.entityId3 = entity->second.containedEntities[2].first;
1086 record.body.entityInstance3 = entity->second.containedEntities[2].second;
1087 record.body.entityId4 = entity->second.containedEntities[3].first;
1088 record.body.entityInstance4 = entity->second.containedEntities[3].second;
1089
Patrick Venture83a0b842019-07-19 18:37:15 -07001090 if (++entity == entityRecords.end())
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001091 {
Patrick Venture0b02be92018-08-31 11:55:55 -07001092 get_sdr::response::set_next_record_id(END_OF_RECORD,
1093 resp); // last record
Ratan Guptae0cc8552018-01-22 14:23:04 +05301094 }
1095 else
1096 {
1097 get_sdr::response::set_next_record_id(
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001098 (ENTITY_RECORD_ID_START + entity->first), resp);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301099 }
1100
Emily Shaffer0fbdbce2018-09-27 09:30:41 -07001101 // Check for invalid offset size
1102 if (req->offset > sizeof(record))
Ratan Guptae0cc8552018-01-22 14:23:04 +05301103 {
Emily Shaffer0fbdbce2018-09-27 09:30:41 -07001104 return IPMI_CC_PARM_OUT_OF_RANGE;
Ratan Guptae0cc8552018-01-22 14:23:04 +05301105 }
1106
Emily Shaffer0fbdbce2018-09-27 09:30:41 -07001107 dataLength = std::min(static_cast<size_t>(req->bytes_to_read),
1108 sizeof(record) - req->offset);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301109
Patrick Ventureb51bf9c2018-09-10 15:53:14 -07001110 std::memcpy(resp->record_data,
Jason M. Bills1cd85962018-10-05 12:04:01 -07001111 reinterpret_cast<uint8_t*>(&record) + req->offset, dataLength);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301112
1113 *data_len = dataLength;
1114 *data_len += 2; // additional 2 bytes for next record ID
1115
1116 return IPMI_CC_OK;
1117}
1118
Emily Shafferbbef71c2017-05-08 16:36:17 -07001119ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1120 ipmi_request_t request, ipmi_response_t response,
1121 ipmi_data_len_t data_len, ipmi_context_t context)
1122{
1123 ipmi_ret_t ret = IPMI_CC_OK;
Patrick Venture0b02be92018-08-31 11:55:55 -07001124 get_sdr::GetSdrReq* req = (get_sdr::GetSdrReq*)request;
1125 get_sdr::GetSdrResp* resp = (get_sdr::GetSdrResp*)response;
Patrick Venture38426dd2019-07-30 15:22:29 -07001126
1127 // Note: we use an iterator so we can provide the next ID at the end of
1128 // the call.
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001129 auto sensor = ipmi::sensor::sensors.begin();
Patrick Venture38426dd2019-07-30 15:22:29 -07001130 auto recordID = get_sdr::request::get_record_id(req);
1131
1132 // At the beginning of a scan, the host side will send us id=0.
1133 if (recordID != 0)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001134 {
Patrick Venture38426dd2019-07-30 15:22:29 -07001135 // recordID 0 to 255 means it is a FULL record.
1136 // recordID 256 to 511 means it is a FRU record.
1137 // recordID greater then 511 means it is a Entity Association
1138 // record. Currently we are supporting three record types: FULL
1139 // record, FRU record and Enttiy Association record.
1140 if (recordID >= ENTITY_RECORD_ID_START)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001141 {
Patrick Venture38426dd2019-07-30 15:22:29 -07001142 return ipmi_entity_get_sdr(request, response, data_len);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001143 }
Patrick Venture38426dd2019-07-30 15:22:29 -07001144 else if (recordID >= FRU_RECORD_ID_START &&
1145 recordID < ENTITY_RECORD_ID_START)
Jaghathiswari Rankappagounder Natarajan0780df12019-02-06 15:29:24 -08001146 {
Patrick Venture38426dd2019-07-30 15:22:29 -07001147 return ipmi_fru_get_sdr(request, response, data_len);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001148 }
1149 else
1150 {
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001151 sensor = ipmi::sensor::sensors.find(recordID);
1152 if (sensor == ipmi::sensor::sensors.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001153 {
1154 return IPMI_CC_SENSOR_INVALID;
1155 }
Emily Shafferbbef71c2017-05-08 16:36:17 -07001156 }
Emily Shafferbbef71c2017-05-08 16:36:17 -07001157 }
1158
Patrick Venture38426dd2019-07-30 15:22:29 -07001159 uint8_t sensor_id = sensor->first;
1160
Lei YU14a47812021-09-17 15:58:04 +08001161 auto it = sdrCacheMap.find(sensor_id);
1162 if (it == sdrCacheMap.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001163 {
Lei YU14a47812021-09-17 15:58:04 +08001164 /* Header */
1165 get_sdr::SensorDataFullRecord record = {0};
1166 get_sdr::header::set_record_id(sensor_id, &(record.header));
1167 record.header.sdr_version = 0x51; // Based on IPMI Spec v2.0 rev 1.1
1168 record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD;
1169 record.header.record_length = sizeof(record.key) + sizeof(record.body);
1170
1171 /* Key */
1172 get_sdr::key::set_owner_id_bmc(&(record.key));
1173 record.key.sensor_number = sensor_id;
1174
1175 /* Body */
1176 record.body.entity_id = sensor->second.entityType;
1177 record.body.sensor_type = sensor->second.sensorType;
1178 record.body.event_reading_type = sensor->second.sensorReadingType;
1179 record.body.entity_instance = sensor->second.instance;
1180 if (ipmi::sensor::Mutability::Write ==
1181 (sensor->second.mutability & ipmi::sensor::Mutability::Write))
1182 {
1183 get_sdr::body::init_settable_state(true, &(record.body));
1184 }
1185
1186 // Set the type-specific details given the DBus interface
1187 populate_record_from_dbus(&(record.body), &(sensor->second), data_len);
1188 sdrCacheMap[sensor_id] = std::move(record);
Patrick Venture38426dd2019-07-30 15:22:29 -07001189 }
1190
Lei YU14a47812021-09-17 15:58:04 +08001191 const auto& record = sdrCacheMap[sensor_id];
Patrick Venture38426dd2019-07-30 15:22:29 -07001192
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001193 if (++sensor == ipmi::sensor::sensors.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001194 {
1195 // we have reached till end of sensor, so assign the next record id
1196 // to 256(Max Sensor ID = 255) + FRU ID(may start with 0).
1197 auto next_record_id = (frus.size())
1198 ? frus.begin()->first + FRU_RECORD_ID_START
1199 : END_OF_RECORD;
1200
1201 get_sdr::response::set_next_record_id(next_record_id, resp);
1202 }
1203 else
1204 {
1205 get_sdr::response::set_next_record_id(sensor->first, resp);
1206 }
1207
1208 if (req->offset > sizeof(record))
1209 {
1210 return IPMI_CC_PARM_OUT_OF_RANGE;
1211 }
1212
1213 // data_len will ultimately be the size of the record, plus
1214 // the size of the next record ID:
1215 *data_len = std::min(static_cast<size_t>(req->bytes_to_read),
1216 sizeof(record) - req->offset);
1217
1218 std::memcpy(resp->record_data,
Lei YU14a47812021-09-17 15:58:04 +08001219 reinterpret_cast<const uint8_t*>(&record) + req->offset,
1220 *data_len);
Patrick Venture38426dd2019-07-30 15:22:29 -07001221
1222 // data_len should include the LSB and MSB:
1223 *data_len +=
1224 sizeof(resp->next_record_id_lsb) + sizeof(resp->next_record_id_msb);
1225
Emily Shafferbbef71c2017-05-08 16:36:17 -07001226 return ret;
1227}
1228
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001229static bool isFromSystemChannel()
1230{
1231 // TODO we could not figure out where the request is from based on IPMI
1232 // command handler parameters. because of it, we can not differentiate
1233 // request from SMS/SMM or IPMB channel
1234 return true;
1235}
1236
1237ipmi_ret_t ipmicmdPlatformEvent(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1238 ipmi_request_t request,
1239 ipmi_response_t response,
1240 ipmi_data_len_t dataLen, ipmi_context_t context)
1241{
1242 uint16_t generatorID;
1243 size_t count;
1244 bool assert = true;
1245 std::string sensorPath;
1246 size_t paraLen = *dataLen;
1247 PlatformEventRequest* req;
1248 *dataLen = 0;
1249
1250 if ((paraLen < selSystemEventSizeWith1Bytes) ||
1251 (paraLen > selSystemEventSizeWith3Bytes))
1252 {
1253 return IPMI_CC_REQ_DATA_LEN_INVALID;
1254 }
1255
1256 if (isFromSystemChannel())
1257 { // first byte for SYSTEM Interface is Generator ID
1258 // +1 to get common struct
1259 req = reinterpret_cast<PlatformEventRequest*>((uint8_t*)request + 1);
1260 // Capture the generator ID
1261 generatorID = *reinterpret_cast<uint8_t*>(request);
1262 // Platform Event usually comes from other firmware, like BIOS.
1263 // Unlike BMC sensor, it does not have BMC DBUS sensor path.
1264 sensorPath = "System";
1265 }
1266 else
1267 {
1268 req = reinterpret_cast<PlatformEventRequest*>(request);
1269 // TODO GenratorID for IPMB is combination of RqSA and RqLUN
1270 generatorID = 0xff;
1271 sensorPath = "IPMB";
1272 }
1273 // Content of event data field depends on sensor class.
1274 // When data0 bit[5:4] is non-zero, valid data counts is 3.
1275 // When data0 bit[7:6] is non-zero, valid data counts is 2.
1276 if (((req->data[0] & byte3EnableMask) != 0 &&
1277 paraLen < selSystemEventSizeWith3Bytes) ||
1278 ((req->data[0] & byte2EnableMask) != 0 &&
1279 paraLen < selSystemEventSizeWith2Bytes))
1280 {
1281 return IPMI_CC_REQ_DATA_LEN_INVALID;
1282 }
1283
1284 // Count bytes of Event Data
1285 if ((req->data[0] & byte3EnableMask) != 0)
1286 {
1287 count = 3;
1288 }
1289 else if ((req->data[0] & byte2EnableMask) != 0)
1290 {
1291 count = 2;
1292 }
1293 else
1294 {
1295 count = 1;
1296 }
1297 assert = req->eventDirectionType & directionMask ? false : true;
1298 std::vector<uint8_t> eventData(req->data, req->data + count);
1299
1300 sdbusplus::bus::bus dbus(bus);
1301 std::string service =
1302 ipmi::getService(dbus, ipmiSELAddInterface, ipmiSELPath);
1303 sdbusplus::message::message writeSEL = dbus.new_method_call(
1304 service.c_str(), ipmiSELPath, ipmiSELAddInterface, "IpmiSelAdd");
1305 writeSEL.append(ipmiSELAddMessage, sensorPath, eventData, assert,
1306 generatorID);
1307 try
1308 {
1309 dbus.call(writeSEL);
1310 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001311 catch (const sdbusplus::exception_t& e)
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001312 {
1313 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1314 return IPMI_CC_UNSPECIFIED_ERROR;
1315 }
1316 return IPMI_CC_OK;
1317}
1318
Chris Austenac4604a2015-10-13 12:43:27 -05001319void register_netfn_sen_functions()
1320{
Willy Tud351a722021-08-12 14:33:40 -07001321 // Handlers with dbus-sdr handler implementation.
1322 // Do not register the hander if it dynamic sensors stack is used.
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +00001323
Willy Tud351a722021-08-12 14:33:40 -07001324#ifndef FEATURE_DYNAMIC_SENSORS
Lei YUbe5c6b22021-09-16 15:46:20 +08001325
Lei YU962e68b2021-09-16 16:25:34 +08001326#ifdef FEATURE_SENSORS_CACHE
Lei YUbe5c6b22021-09-16 15:46:20 +08001327 // Initialize the sensor matches
1328 initSensorMatches();
Lei YU962e68b2021-09-16 16:25:34 +08001329#endif
Lei YUbe5c6b22021-09-16 15:46:20 +08001330
Tom05732372016-09-06 17:21:23 +05301331 // <Set Sensor Reading and Event Status>
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +00001332 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1333 ipmi::sensor_event::cmdSetSensorReadingAndEvtSts,
1334 ipmi::Privilege::Operator, ipmiSetSensorReading);
Tom05732372016-09-06 17:21:23 +05301335 // <Get Sensor Reading>
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +00001336 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1337 ipmi::sensor_event::cmdGetSensorReading,
1338 ipmi::Privilege::User, ipmiSensorGetSensorReading);
Emily Shaffera344afc2017-04-13 15:09:39 -07001339
Tom Joseph5ca50952018-02-22 00:33:38 +05301340 // <Reserve Device SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001341 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1342 ipmi::sensor_event::cmdReserveDeviceSdrRepository,
1343 ipmi::Privilege::User, ipmiSensorReserveSdr);
Chris Austen10ccc0f2015-12-10 18:27:04 -06001344
Tom Joseph5ca50952018-02-22 00:33:38 +05301345 // <Get Device SDR Info>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001346 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1347 ipmi::sensor_event::cmdGetDeviceSdrInfo,
1348 ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001349
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001350 // <Get Sensor Thresholds>
jayaprakash Mutyala996c9792019-05-03 15:56:48 +00001351 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1352 ipmi::sensor_event::cmdGetSensorThreshold,
1353 ipmi::Privilege::User, ipmiSensorGetSensorThresholds);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001354
Lotus Xuf93da662021-10-18 17:20:06 +08001355 // <Set Sensor Thresholds>
1356 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1357 ipmi::sensor_event::cmdSetSensorThreshold,
1358 ipmi::Privilege::User, ipmiSenSetSensorThresholds);
Willy Tud351a722021-08-12 14:33:40 -07001359#endif
1360
1361 // Common Handers used by both implementation.
1362
1363 // <Platform Event Message>
1364 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_PLATFORM_EVENT, nullptr,
1365 ipmicmdPlatformEvent, PRIVILEGE_OPERATOR);
1366
1367 // <Get Sensor Type>
1368 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1369 ipmi::sensor_event::cmdGetSensorType,
1370 ipmi::Privilege::User, ipmiGetSensorType);
1371
1372 // <Get Device SDR>
1373 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, nullptr,
1374 ipmi_sen_get_sdr, PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -05001375 return;
1376}