blob: 4e9a93a8860dd64dd9e2454ee5d8a8c9c2f477ae [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
5#include "fruread.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07006
Chris Austen10ccc0f2015-12-10 18:27:04 -06007#include <systemd/sd-bus.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07008
Vernon Mauerye08fbff2019-04-03 09:19:34 -07009#include <ipmid/api.hpp>
Vernon Mauery9cf08382023-04-28 14:00:11 -070010#include <ipmid/entity_map_json.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070011#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070012#include <ipmid/utils.hpp>
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050013#include <phosphor-logging/elog-errors.hpp>
George Liu3b1071a2024-07-17 20:26:14 +080014#include <phosphor-logging/lg2.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070015#include <sdbusplus/message/types.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070016#include <xyz/openbmc_project/Common/error.hpp>
Alexander Hansen653aec02025-11-14 13:38:08 +010017#include <xyz/openbmc_project/Sensor/Threshold/Critical/common.hpp>
18#include <xyz/openbmc_project/Sensor/Threshold/Warning/common.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070019#include <xyz/openbmc_project/Sensor/Value/server.hpp>
20
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050021#include <bitset>
22#include <cmath>
23#include <cstring>
24#include <set>
25
Ratan Guptae0cc8552018-01-22 14:23:04 +053026static constexpr uint8_t fruInventoryDevice = 0x10;
27static constexpr uint8_t IPMIFruInventory = 0x02;
Matt Simmering68d9d402023-11-09 14:22:11 -080028static constexpr uint8_t BMCTargetAddress = 0x20;
Ratan Guptae0cc8552018-01-22 14:23:04 +053029
Patrick Venture0b02be92018-08-31 11:55:55 -070030extern int updateSensorRecordFromSSRAESC(const void*);
31extern sd_bus* bus;
Patrick Venturedb0cbe62019-09-09 14:47:22 -070032
33namespace ipmi
34{
35namespace sensor
36{
37extern const IdInfoMap sensors;
38} // namespace sensor
39} // namespace ipmi
40
Ratan Guptae0cc8552018-01-22 14:23:04 +053041extern const FruMap frus;
42
Tom Josephbe703f72017-03-09 12:34:35 +053043using namespace phosphor::logging;
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050044using InternalFailure =
Willy Tu523e2d12023-09-05 11:36:48 -070045 sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
Chris Austenac4604a2015-10-13 12:43:27 -050046
Alexander Hansenf365c7f2025-11-14 12:08:34 +010047using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
Alexander Hansen653aec02025-11-14 13:38:08 +010048using SensorThresholdCritical =
49 sdbusplus::common::xyz::openbmc_project::sensor::threshold::Critical;
50using SensorThresholdWarning =
51 sdbusplus::common::xyz::openbmc_project::sensor::threshold::Warning;
Alexander Hansenf365c7f2025-11-14 12:08:34 +010052
George Liu5087b072025-03-11 19:28:17 +080053void registerNetFnSenFunctions() __attribute__((constructor));
Chris Austenac4604a2015-10-13 12:43:27 -050054
Patrick Venture0b02be92018-08-31 11:55:55 -070055struct sensorTypemap_t
56{
Chris Austen0012e9b2015-10-22 01:37:46 -050057 uint8_t number;
Chris Austend7cf0e42015-11-07 14:27:12 -060058 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050059 char dbusname[32];
Patrick Venture0b02be92018-08-31 11:55:55 -070060};
Chris Austen0012e9b2015-10-22 01:37:46 -050061
Chris Austen0012e9b2015-10-22 01:37:46 -050062sensorTypemap_t g_SensorTypeMap[] = {
63
Chris Austend7cf0e42015-11-07 14:27:12 -060064 {0x01, 0x6F, "Temp"},
65 {0x0C, 0x6F, "DIMM"},
66 {0x0C, 0x6F, "MEMORY_BUFFER"},
67 {0x07, 0x6F, "PROC"},
68 {0x07, 0x6F, "CORE"},
69 {0x07, 0x6F, "CPU"},
70 {0x0F, 0x6F, "BootProgress"},
Patrick Venture0b02be92018-08-31 11:55:55 -070071 {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor
72 // type code os 0x09
Chris Austend7cf0e42015-11-07 14:27:12 -060073 {0xC3, 0x6F, "BootCount"},
74 {0x1F, 0x6F, "OperatingSystemStatus"},
Chris Austen800ba712015-12-03 15:31:00 -060075 {0x12, 0x6F, "SYSTEM_EVENT"},
76 {0xC7, 0x03, "SYSTEM"},
77 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austen10ccc0f2015-12-10 18:27:04 -060078 {0xC2, 0x6F, "PowerCap"},
Tom Joseph558184e2017-09-01 13:45:05 +053079 {0x0b, 0xCA, "PowerSupplyRedundancy"},
Jayanth Othayoth0661beb2017-03-22 06:00:58 -050080 {0xDA, 0x03, "TurboAllowed"},
Tom Joseph558184e2017-09-01 13:45:05 +053081 {0xD8, 0xC8, "PowerSupplyDerating"},
Chris Austend7cf0e42015-11-07 14:27:12 -060082 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050083};
84
Patrick Venture0b02be92018-08-31 11:55:55 -070085struct sensor_data_t
86{
Chris Austenac4604a2015-10-13 12:43:27 -050087 uint8_t sennum;
Patrick Venture0b02be92018-08-31 11:55:55 -070088} __attribute__((packed));
Chris Austenac4604a2015-10-13 12:43:27 -050089
Lei YU14a47812021-09-17 15:58:04 +080090using SDRCacheMap = std::unordered_map<uint8_t, get_sdr::SensorDataFullRecord>;
91SDRCacheMap sdrCacheMap __attribute__((init_priority(101)));
92
93using SensorThresholdMap =
94 std::unordered_map<uint8_t, get_sdr::GetSensorThresholdsResponse>;
95SensorThresholdMap sensorThresholdMap __attribute__((init_priority(101)));
96
Lei YU962e68b2021-09-16 16:25:34 +080097#ifdef FEATURE_SENSORS_CACHE
Patrick Williams5d82f472022-07-22 19:26:53 -050098std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match_t>> sensorAddedMatches
99 __attribute__((init_priority(101)));
100std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match_t>> sensorUpdatedMatches
101 __attribute__((init_priority(101)));
102std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match_t>> sensorRemovedMatches
103 __attribute__((init_priority(101)));
104std::unique_ptr<sdbusplus::bus::match_t> sensorsOwnerMatch
Lei YU7f3a70f2021-12-07 16:40:40 +0800105 __attribute__((init_priority(101)));
Lei YUbe5c6b22021-09-16 15:46:20 +0800106
Lei YU97140502021-09-17 13:49:43 +0800107ipmi::sensor::SensorCacheMap sensorCacheMap __attribute__((init_priority(101)));
Lei YU8c2c0482021-09-16 17:28:28 +0800108
Lei YU7f3a70f2021-12-07 16:40:40 +0800109// It is needed to know which objects belong to which service, so that when a
110// service exits without interfacesRemoved signal, we could invaildate the cache
111// that is related to the service. It uses below two variables:
112// - idToServiceMap records which sensors are known to have a related service;
113// - serviceToIdMap maps a service to the sensors.
114using sensorIdToServiceMap = std::unordered_map<uint8_t, std::string>;
115sensorIdToServiceMap idToServiceMap __attribute__((init_priority(101)));
116
117using sensorServiceToIdMap = std::unordered_map<std::string, std::set<uint8_t>>;
118sensorServiceToIdMap serviceToIdMap __attribute__((init_priority(101)));
119
Willy Tu11d68892022-01-20 10:37:34 -0800120static void fillSensorIdServiceMap(const std::string&,
Lei YU7f3a70f2021-12-07 16:40:40 +0800121 const std::string& /*intf*/, uint8_t id,
122 const std::string& service)
123{
124 if (idToServiceMap.find(id) != idToServiceMap.end())
125 {
126 return;
127 }
128 idToServiceMap[id] = service;
129 serviceToIdMap[service].insert(id);
130}
131
132static void fillSensorIdServiceMap(const std::string& obj,
133 const std::string& intf, uint8_t id)
134{
135 if (idToServiceMap.find(id) != idToServiceMap.end())
136 {
137 return;
138 }
139 try
140 {
Patrick Williams5d82f472022-07-22 19:26:53 -0500141 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Lei YU7f3a70f2021-12-07 16:40:40 +0800142 auto service = ipmi::getService(bus, intf, obj);
143 idToServiceMap[id] = service;
144 serviceToIdMap[service].insert(id);
145 }
146 catch (...)
147 {
148 // Ignore
149 }
150}
151
Lei YUbe5c6b22021-09-16 15:46:20 +0800152void initSensorMatches()
153{
154 using namespace sdbusplus::bus::match::rules;
Patrick Williams5d82f472022-07-22 19:26:53 -0500155 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Lei YUbe5c6b22021-09-16 15:46:20 +0800156 for (const auto& s : ipmi::sensor::sensors)
157 {
158 sensorAddedMatches.emplace(
159 s.first,
Patrick Williams5d82f472022-07-22 19:26:53 -0500160 std::make_unique<sdbusplus::bus::match_t>(
Lei YUbe5c6b22021-09-16 15:46:20 +0800161 bus, interfacesAdded() + argNpath(0, s.second.sensorPath),
Lei YU7f3a70f2021-12-07 16:40:40 +0800162 [id = s.first, obj = s.second.sensorPath,
163 intf = s.second.propertyInterfaces.begin()->first](
164 auto& /*msg*/) { fillSensorIdServiceMap(obj, intf, id); }));
165 sensorRemovedMatches.emplace(
166 s.first,
Patrick Williams5d82f472022-07-22 19:26:53 -0500167 std::make_unique<sdbusplus::bus::match_t>(
Lei YU7f3a70f2021-12-07 16:40:40 +0800168 bus, interfacesRemoved() + argNpath(0, s.second.sensorPath),
169 [id = s.first](auto& /*msg*/) {
Patrick Williams1318a5e2024-08-16 15:19:54 -0400170 // Ideally this should work.
171 // But when a service is terminated or crashed, it does not
172 // emit interfacesRemoved signal. In that case it's handled
173 // by sensorsOwnerMatch
174 sensorCacheMap[id].reset();
175 }));
Lei YUbe5c6b22021-09-16 15:46:20 +0800176 sensorUpdatedMatches.emplace(
Patrick Williams1318a5e2024-08-16 15:19:54 -0400177 s.first,
178 std::make_unique<sdbusplus::bus::match_t>(
179 bus,
180 type::signal() + path(s.second.sensorPath) +
181 member("PropertiesChanged"s) +
182 interface("org.freedesktop.DBus.Properties"s),
183 [&s](auto& msg) {
184 fillSensorIdServiceMap(
185 s.second.sensorPath,
186 s.second.propertyInterfaces.begin()->first, s.first);
187 try
188 {
189 // This is signal callback
Patrick Williams94b23392025-11-05 00:16:19 -0500190 auto interfaceName = msg.unpack<std::string>();
191
192 auto props = msg.unpack<ipmi::PropertyMap>();
193
Patrick Williams1318a5e2024-08-16 15:19:54 -0400194 s.second.getFunc(s.first, s.second, props);
195 }
196 catch (const std::exception& e)
197 {
198 sensorCacheMap[s.first].reset();
199 }
200 }));
Lei YUbe5c6b22021-09-16 15:46:20 +0800201 }
Jian Zhang4a105cd2022-08-05 22:26:42 +0800202 sensorsOwnerMatch = std::make_unique<sdbusplus::bus::match_t>(
203 bus, nameOwnerChanged(), [](auto& msg) {
Patrick Williams1318a5e2024-08-16 15:19:54 -0400204 std::string name;
205 std::string oldOwner;
206 std::string newOwner;
207 msg.read(name, oldOwner, newOwner);
Jian Zhang4a105cd2022-08-05 22:26:42 +0800208
Patrick Williams1318a5e2024-08-16 15:19:54 -0400209 if (!name.empty() && newOwner.empty())
Jian Zhang4a105cd2022-08-05 22:26:42 +0800210 {
Patrick Williams1318a5e2024-08-16 15:19:54 -0400211 // The service exits
212 const auto it = serviceToIdMap.find(name);
213 if (it == serviceToIdMap.end())
214 {
215 return;
216 }
217 for (const auto& id : it->second)
218 {
219 // Invalidate cache
220 sensorCacheMap[id].reset();
221 }
Jian Zhang4a105cd2022-08-05 22:26:42 +0800222 }
Patrick Williams1318a5e2024-08-16 15:19:54 -0400223 });
Lei YUbe5c6b22021-09-16 15:46:20 +0800224}
Lei YU962e68b2021-09-16 16:25:34 +0800225#endif
Lei YUbe5c6b22021-09-16 15:46:20 +0800226
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700227// Use a lookup table to find the interface name of a specific sensor
228// This will be used until an alternative is found. this is the first
229// step for mapping IPMI
Patrick Venture0b02be92018-08-31 11:55:55 -0700230int find_openbmc_path(uint8_t num, dbus_interface_t* interface)
231{
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700232 const auto& sensor_it = ipmi::sensor::sensors.find(num);
233 if (sensor_it == ipmi::sensor::sensors.end())
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700234 {
Adriana Kobylakba23ff72018-09-12 12:58:43 -0500235 // The sensor map does not contain the sensor requested
236 return -EINVAL;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700237 }
238
239 const auto& info = sensor_it->second;
240
George Liua0088712024-01-30 13:03:23 +0800241 std::string serviceName{};
242 try
243 {
244 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Patrick Williams1318a5e2024-08-16 15:19:54 -0400245 serviceName =
246 ipmi::getService(bus, info.sensorInterface, info.sensorPath);
George Liua0088712024-01-30 13:03:23 +0800247 }
248 catch (const sdbusplus::exception_t&)
Patrick Venture0b02be92018-08-31 11:55:55 -0700249 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700250 std::fprintf(stderr, "Failed to get %s busname: %s\n",
George Liua0088712024-01-30 13:03:23 +0800251 info.sensorPath.c_str(), serviceName.c_str());
252 return -EINVAL;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700253 }
254
255 interface->sensortype = info.sensorType;
George Liua0088712024-01-30 13:03:23 +0800256 strcpy(interface->bus, serviceName.c_str());
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700257 strcpy(interface->path, info.sensorPath.c_str());
258 // Take the interface name from the beginning of the DbusInterfaceMap. This
259 // works for the Value interface but may not suffice for more complex
260 // sensors.
261 // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
Patrick Venture0b02be92018-08-31 11:55:55 -0700262 strcpy(interface->interface,
263 info.propertyInterfaces.begin()->first.c_str());
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700264 interface->sensornumber = num;
265
George Liua0088712024-01-30 13:03:23 +0800266 return 0;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700267}
268
Tomd700e762016-09-20 18:24:13 +0530269/////////////////////////////////////////////////////////////////////
270//
271// Routines used by ipmi commands wanting to interact on the dbus
272//
273/////////////////////////////////////////////////////////////////////
Patrick Venture0b02be92018-08-31 11:55:55 -0700274int set_sensor_dbus_state_s(uint8_t number, const char* method,
275 const char* value)
276{
Tomd700e762016-09-20 18:24:13 +0530277 dbus_interface_t a;
278 int r;
279 sd_bus_error error = SD_BUS_ERROR_NULL;
Jayanth Othayotha6fb32d2024-12-15 10:55:22 -0600280 sd_bus_message* m = nullptr;
Tomd700e762016-09-20 18:24:13 +0530281
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700282 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530283
Patrick Venture0b02be92018-08-31 11:55:55 -0700284 if (r < 0)
285 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700286 std::fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
Tomd700e762016-09-20 18:24:13 +0530287 return 0;
288 }
289
Patrick Venture0b02be92018-08-31 11:55:55 -0700290 r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface,
291 method);
292 if (r < 0)
293 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700294 std::fprintf(stderr, "Failed to create a method call: %s",
295 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530296 goto final;
297 }
298
299 r = sd_bus_message_append(m, "v", "s", value);
Patrick Venture0b02be92018-08-31 11:55:55 -0700300 if (r < 0)
301 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700302 std::fprintf(stderr, "Failed to create a input parameter: %s",
303 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530304 goto final;
305 }
306
Jayanth Othayotha6fb32d2024-12-15 10:55:22 -0600307 r = sd_bus_call(bus, m, 0, &error, nullptr);
Patrick Venture0b02be92018-08-31 11:55:55 -0700308 if (r < 0)
309 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700310 std::fprintf(stderr, "Failed to call the method: %s", strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530311 }
312
313final:
314 sd_bus_error_free(&error);
315 m = sd_bus_message_unref(m);
316
317 return 0;
318}
Patrick Venture0b02be92018-08-31 11:55:55 -0700319int set_sensor_dbus_state_y(uint8_t number, const char* method,
320 const uint8_t value)
321{
Tomd700e762016-09-20 18:24:13 +0530322 dbus_interface_t a;
323 int r;
324 sd_bus_error error = SD_BUS_ERROR_NULL;
Jayanth Othayotha6fb32d2024-12-15 10:55:22 -0600325 sd_bus_message* m = nullptr;
Tomd700e762016-09-20 18:24:13 +0530326
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700327 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530328
Patrick Venture0b02be92018-08-31 11:55:55 -0700329 if (r < 0)
330 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700331 std::fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
Tomd700e762016-09-20 18:24:13 +0530332 return 0;
333 }
334
Patrick Venture0b02be92018-08-31 11:55:55 -0700335 r = sd_bus_message_new_method_call(bus, &m, a.bus, a.path, a.interface,
336 method);
337 if (r < 0)
338 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700339 std::fprintf(stderr, "Failed to create a method call: %s",
340 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530341 goto final;
342 }
343
344 r = sd_bus_message_append(m, "v", "i", value);
Patrick Venture0b02be92018-08-31 11:55:55 -0700345 if (r < 0)
346 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700347 std::fprintf(stderr, "Failed to create a input parameter: %s",
348 strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530349 goto final;
350 }
351
Jayanth Othayotha6fb32d2024-12-15 10:55:22 -0600352 r = sd_bus_call(bus, m, 0, &error, nullptr);
Patrick Venture0b02be92018-08-31 11:55:55 -0700353 if (r < 0)
354 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700355 std::fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530356 }
357
358final:
359 sd_bus_error_free(&error);
360 m = sd_bus_message_unref(m);
361
362 return 0;
363}
364
Patrick Venture0b02be92018-08-31 11:55:55 -0700365uint8_t dbus_to_sensor_type(char* p)
366{
Patrick Venture0b02be92018-08-31 11:55:55 -0700367 sensorTypemap_t* s = g_SensorTypeMap;
368 char r = 0;
369 while (s->number != 0xFF)
370 {
371 if (!strcmp(s->dbusname, p))
372 {
Tom Joseph558184e2017-09-01 13:45:05 +0530373 r = s->typecode;
Patrick Venture0b02be92018-08-31 11:55:55 -0700374 break;
Chris Austenac4604a2015-10-13 12:43:27 -0500375 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500376 s++;
Chris Austenac4604a2015-10-13 12:43:27 -0500377 }
378
Chris Austen0012e9b2015-10-22 01:37:46 -0500379 if (s->number == 0xFF)
380 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -0500381
Chris Austen0012e9b2015-10-22 01:37:46 -0500382 return r;
Chris Austenac4604a2015-10-13 12:43:27 -0500383}
384
Patrick Venture0b02be92018-08-31 11:55:55 -0700385uint8_t get_type_from_interface(dbus_interface_t dbus_if)
386{
Brad Bishop56003452016-10-05 21:49:19 -0400387 uint8_t type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500388
Chris Austen0012e9b2015-10-22 01:37:46 -0500389 // This is where sensors that do not exist in dbus but do
390 // exist in the host code stop. This should indicate it
391 // is not a supported sensor
Patrick Venture0b02be92018-08-31 11:55:55 -0700392 if (dbus_if.interface[0] == 0)
393 {
394 return 0;
395 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500396
Emily Shaffer71174412017-04-05 15:10:40 -0700397 // Fetch type from interface itself.
398 if (dbus_if.sensortype != 0)
399 {
400 type = dbus_if.sensortype;
Patrick Venture0b02be92018-08-31 11:55:55 -0700401 }
402 else
403 {
Chris Austen0012e9b2015-10-22 01:37:46 -0500404 // Non InventoryItems
Patrick Venture4491a462018-10-13 13:00:42 -0700405 char* p = strrchr(dbus_if.path, '/');
Patrick Venture0b02be92018-08-31 11:55:55 -0700406 type = dbus_to_sensor_type(p + 1);
Chris Austen0012e9b2015-10-22 01:37:46 -0500407 }
408
Brad Bishop56003452016-10-05 21:49:19 -0400409 return type;
Patrick Venture0b02be92018-08-31 11:55:55 -0700410}
Chris Austen0012e9b2015-10-22 01:37:46 -0500411
Emily Shaffer391f3302017-04-03 10:27:08 -0700412// Replaces find_sensor
Patrick Venture0b02be92018-08-31 11:55:55 -0700413uint8_t find_type_for_sensor_number(uint8_t num)
414{
Emily Shaffer391f3302017-04-03 10:27:08 -0700415 int r;
416 dbus_interface_t dbus_if;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700417 r = find_openbmc_path(num, &dbus_if);
Patrick Venture0b02be92018-08-31 11:55:55 -0700418 if (r < 0)
419 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700420 std::fprintf(stderr, "Could not find sensor %d\n", num);
Lei YU91875f72018-04-03 15:14:49 +0800421 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700422 }
423 return get_type_from_interface(dbus_if);
424}
425
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000426/**
427 * @brief implements the get sensor type command.
428 * @param - sensorNumber
429 *
430 * @return IPMI completion code plus response data on success.
431 * - sensorType
432 * - eventType
433 **/
434
435ipmi::RspType<uint8_t, // sensorType
436 uint8_t // eventType
437 >
438 ipmiGetSensorType(uint8_t sensorNumber)
Chris Austenac4604a2015-10-13 12:43:27 -0500439{
Wang Xiaohua64b76212022-08-11 13:23:53 +0800440 const auto it = ipmi::sensor::sensors.find(sensorNumber);
441 if (it == ipmi::sensor::sensors.end())
Patrick Venture0b02be92018-08-31 11:55:55 -0700442 {
Wang Xiaohua64b76212022-08-11 13:23:53 +0800443 // The sensor map does not contain the sensor requested
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000444 return ipmi::responseSensorInvalid();
Chris Austen0012e9b2015-10-22 01:37:46 -0500445 }
446
Wang Xiaohua64b76212022-08-11 13:23:53 +0800447 const auto& info = it->second;
448 uint8_t sensorType = info.sensorType;
449 uint8_t eventType = info.sensorReadingType;
450
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +0000451 return ipmi::responseSuccess(sensorType, eventType);
Chris Austenac4604a2015-10-13 12:43:27 -0500452}
453
Patrick Venture0b02be92018-08-31 11:55:55 -0700454const std::set<std::string> analogSensorInterfaces = {
Alexander Hansenf365c7f2025-11-14 12:08:34 +0100455 SensorValue::interface,
Patrick Venturee9a64052017-08-18 19:17:27 -0700456 "xyz.openbmc_project.Control.FanPwm",
Emily Shaffercc941e12017-06-14 13:06:26 -0700457};
458
459bool isAnalogSensor(const std::string& interface)
460{
461 return (analogSensorInterfaces.count(interface));
462}
463
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000464/**
465@brief This command is used to set sensorReading.
466
467@param
468 - sensorNumber
469 - operation
470 - reading
471 - assertOffset0_7
472 - assertOffset8_14
473 - deassertOffset0_7
474 - deassertOffset8_14
475 - eventData1
476 - eventData2
477 - eventData3
478
479@return completion code on success.
480**/
481
Patrick Williams1318a5e2024-08-16 15:19:54 -0400482ipmi::RspType<> ipmiSetSensorReading(
483 uint8_t sensorNumber, uint8_t operation, uint8_t reading,
484 uint8_t assertOffset0_7, uint8_t assertOffset8_14,
485 uint8_t deassertOffset0_7, uint8_t deassertOffset8_14, uint8_t eventData1,
486 uint8_t eventData2, uint8_t eventData3)
Tom Josephbe703f72017-03-09 12:34:35 +0530487{
George Liu3b1071a2024-07-17 20:26:14 +0800488 lg2::debug("IPMI SET_SENSOR, sensorNumber: {SENSOR_NUM}", "SENSOR_NUM",
489 lg2::hex, sensorNumber);
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000490
Arun P. Mohanan0634e982021-08-30 15:21:33 +0530491 if (sensorNumber == 0xFF)
492 {
493 return ipmi::responseInvalidFieldRequest();
494 }
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000495 ipmi::sensor::SetSensorReadingReq cmdData;
496
497 cmdData.number = sensorNumber;
498 cmdData.operation = operation;
499 cmdData.reading = reading;
500 cmdData.assertOffset0_7 = assertOffset0_7;
501 cmdData.assertOffset8_14 = assertOffset8_14;
502 cmdData.deassertOffset0_7 = deassertOffset0_7;
503 cmdData.deassertOffset8_14 = deassertOffset8_14;
504 cmdData.eventData1 = eventData1;
505 cmdData.eventData2 = eventData2;
506 cmdData.eventData3 = eventData3;
Tom Josephbe703f72017-03-09 12:34:35 +0530507
508 // Check if the Sensor Number is present
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700509 const auto iter = ipmi::sensor::sensors.find(sensorNumber);
510 if (iter == ipmi::sensor::sensors.end())
Tom Josephbe703f72017-03-09 12:34:35 +0530511 {
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000512 updateSensorRecordFromSSRAESC(&sensorNumber);
513 return ipmi::responseSuccess();
Tom Josephbe703f72017-03-09 12:34:35 +0530514 }
515
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500516 try
517 {
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500518 if (ipmi::sensor::Mutability::Write !=
Patrick Venture0b02be92018-08-31 11:55:55 -0700519 (iter->second.mutability & ipmi::sensor::Mutability::Write))
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500520 {
George Liu3b1071a2024-07-17 20:26:14 +0800521 lg2::error("Sensor Set operation is not allowed, "
522 "sensorNumber: {SENSOR_NUM}",
523 "SENSOR_NUM", lg2::hex, sensorNumber);
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000524 return ipmi::responseIllegalCommand();
Jayanth Othayoth0922bde2018-04-02 07:59:34 -0500525 }
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000526 auto ipmiRC = iter->second.updateFunc(cmdData, iter->second);
527 return ipmi::response(ipmiRC);
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500528 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500529 catch (const InternalFailure& e)
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500530 {
George Liu3b1071a2024-07-17 20:26:14 +0800531 lg2::error("Set sensor failed, sensorNumber: {SENSOR_NUM}",
532 "SENSOR_NUM", lg2::hex, sensorNumber);
Patrick Venture0b02be92018-08-31 11:55:55 -0700533 commit<InternalFailure>();
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000534 return ipmi::responseUnspecifiedError();
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500535 }
Tom Joseph82024322017-09-28 20:07:29 +0530536 catch (const std::runtime_error& e)
537 {
George Liu3b1071a2024-07-17 20:26:14 +0800538 lg2::error("runtime error: {ERROR}", "ERROR", e);
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +0000539 return ipmi::responseUnspecifiedError();
Tom Joseph82024322017-09-28 20:07:29 +0530540 }
Chris Austenac4604a2015-10-13 12:43:27 -0500541}
542
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000543/** @brief implements the get sensor reading command
544 * @param sensorNum - sensor number
545 *
546 * @returns IPMI completion code plus response data
547 * - senReading - sensor reading
548 * - reserved
549 * - readState - sensor reading state enabled
550 * - senScanState - sensor scan state disabled
551 * - allEventMessageState - all Event message state disabled
552 * - assertionStatesLsb - threshold levels states
553 * - assertionStatesMsb - discrete reading sensor states
554 */
555ipmi::RspType<uint8_t, // sensor reading
Tom Joseph3ee668f2018-03-02 19:49:17 +0530556
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000557 uint5_t, // reserved
558 bool, // reading state
Sui Chen4cc42552019-09-11 10:28:35 -0700559 bool, // 0 = sensor scanning state disabled
560 bool, // 0 = all event messages disabled
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000561
562 uint8_t, // threshold levels states
563 uint8_t // discrete reading sensor states
564 >
Willy Tu11d68892022-01-20 10:37:34 -0800565 ipmiSensorGetSensorReading([[maybe_unused]] ipmi::Context::ptr& ctx,
566 uint8_t sensorNum)
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000567{
568 if (sensorNum == 0xFF)
569 {
570 return ipmi::responseInvalidFieldRequest();
571 }
572
573 const auto iter = ipmi::sensor::sensors.find(sensorNum);
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700574 if (iter == ipmi::sensor::sensors.end())
Tom Joseph3ee668f2018-03-02 19:49:17 +0530575 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000576 return ipmi::responseSensorInvalid();
Tom Joseph3ee668f2018-03-02 19:49:17 +0530577 }
578 if (ipmi::sensor::Mutability::Read !=
Patrick Venture0b02be92018-08-31 11:55:55 -0700579 (iter->second.mutability & ipmi::sensor::Mutability::Read))
Tom Joseph3ee668f2018-03-02 19:49:17 +0530580 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000581 return ipmi::responseIllegalCommand();
Tom Joseph3ee668f2018-03-02 19:49:17 +0530582 }
583
584 try
585 {
Lei YU8c2c0482021-09-16 17:28:28 +0800586#ifdef FEATURE_SENSORS_CACHE
Lei YU8e8152c2021-12-06 20:11:08 +0800587 auto& sensorData = sensorCacheMap[sensorNum];
Lei YU97140502021-09-17 13:49:43 +0800588 if (!sensorData.has_value())
589 {
Lei YUa55e9ea2021-09-18 15:15:17 +0800590 // No cached value, try read it
Lei YU8e8152c2021-12-06 20:11:08 +0800591 std::string service;
592 boost::system::error_code ec;
Lei YUa55e9ea2021-09-18 15:15:17 +0800593 const auto& sensorInfo = iter->second;
Lei YU8e8152c2021-12-06 20:11:08 +0800594 ec = ipmi::getService(ctx, sensorInfo.sensorInterface,
595 sensorInfo.sensorPath, service);
596 if (ec)
Lei YUa55e9ea2021-09-18 15:15:17 +0800597 {
Lei YU8e8152c2021-12-06 20:11:08 +0800598 return ipmi::responseUnspecifiedError();
Lei YUa55e9ea2021-09-18 15:15:17 +0800599 }
Lei YU7f3a70f2021-12-07 16:40:40 +0800600 fillSensorIdServiceMap(sensorInfo.sensorPath,
601 sensorInfo.propertyInterfaces.begin()->first,
602 iter->first, service);
Lei YU8e8152c2021-12-06 20:11:08 +0800603
604 ipmi::PropertyMap props;
605 ec = ipmi::getAllDbusProperties(
606 ctx, service, sensorInfo.sensorPath,
607 sensorInfo.propertyInterfaces.begin()->first, props);
608 if (ec)
Lei YUa55e9ea2021-09-18 15:15:17 +0800609 {
Lei YU8e8152c2021-12-06 20:11:08 +0800610 fprintf(stderr, "Failed to get sensor %s, %d: %s\n",
611 sensorInfo.sensorPath.c_str(), ec.value(),
612 ec.message().c_str());
Lei YUa55e9ea2021-09-18 15:15:17 +0800613 // Intitilizing with default values
614 constexpr uint8_t senReading = 0;
615 constexpr uint5_t reserved{0};
616 constexpr bool readState = true;
617 constexpr bool senScanState = false;
618 constexpr bool allEventMessageState = false;
619 constexpr uint8_t assertionStatesLsb = 0;
620 constexpr uint8_t assertionStatesMsb = 0;
Lei YU97140502021-09-17 13:49:43 +0800621
Patrick Williams1318a5e2024-08-16 15:19:54 -0400622 return ipmi::responseSuccess(
623 senReading, reserved, readState, senScanState,
624 allEventMessageState, assertionStatesLsb,
625 assertionStatesMsb);
Lei YUa55e9ea2021-09-18 15:15:17 +0800626 }
Lei YU8e8152c2021-12-06 20:11:08 +0800627 sensorInfo.getFunc(sensorNum, sensorInfo, props);
Lei YU97140502021-09-17 13:49:43 +0800628 }
629 return ipmi::responseSuccess(
630 sensorData->response.reading, uint5_t(0),
631 sensorData->response.readingOrStateUnavailable,
632 sensorData->response.scanningEnabled,
633 sensorData->response.allEventMessagesEnabled,
634 sensorData->response.thresholdLevelsStates,
635 sensorData->response.discreteReadingSensorStates);
636
Lei YU8c2c0482021-09-16 17:28:28 +0800637#else
Sui Chen4cc42552019-09-11 10:28:35 -0700638 ipmi::sensor::GetSensorResponse getResponse =
639 iter->second.getFunc(iter->second);
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000640
Patrick Williams1318a5e2024-08-16 15:19:54 -0400641 return ipmi::responseSuccess(
642 getResponse.reading, uint5_t(0),
643 getResponse.readingOrStateUnavailable, getResponse.scanningEnabled,
644 getResponse.allEventMessagesEnabled,
645 getResponse.thresholdLevelsStates,
646 getResponse.discreteReadingSensorStates);
Lei YU8c2c0482021-09-16 17:28:28 +0800647#endif
Tom Joseph3ee668f2018-03-02 19:49:17 +0530648 }
Brandon Kim9cf85622019-06-19 12:05:08 -0700649#ifdef UPDATE_FUNCTIONAL_ON_FAIL
650 catch (const SensorFunctionalError& e)
651 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000652 return ipmi::responseResponseError();
Brandon Kim9cf85622019-06-19 12:05:08 -0700653 }
654#endif
Tom Joseph3ee668f2018-03-02 19:49:17 +0530655 catch (const std::exception& e)
656 {
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +0000657 // Intitilizing with default values
658 constexpr uint8_t senReading = 0;
659 constexpr uint5_t reserved{0};
660 constexpr bool readState = true;
661 constexpr bool senScanState = false;
662 constexpr bool allEventMessageState = false;
663 constexpr uint8_t assertionStatesLsb = 0;
664 constexpr uint8_t assertionStatesMsb = 0;
665
666 return ipmi::responseSuccess(senReading, reserved, readState,
667 senScanState, allEventMessageState,
668 assertionStatesLsb, assertionStatesMsb);
Tom Joseph3ee668f2018-03-02 19:49:17 +0530669 }
670}
671
George Liu402024a2024-07-16 14:36:31 +0800672void updateWarningThreshold(uint8_t lowerValue, uint8_t upperValue,
673 get_sdr::GetSensorThresholdsResponse& resp)
674{
675 resp.lowerNonCritical = lowerValue;
676 resp.upperNonCritical = upperValue;
677 if (lowerValue)
678 {
679 resp.validMask |= static_cast<uint8_t>(
680 ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK);
681 }
682
683 if (upperValue)
684 {
685 resp.validMask |= static_cast<uint8_t>(
686 ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK);
687 }
688}
689
690void updateCriticalThreshold(uint8_t lowerValue, uint8_t upperValue,
691 get_sdr::GetSensorThresholdsResponse& resp)
692{
693 resp.lowerCritical = lowerValue;
694 resp.upperCritical = upperValue;
695 if (lowerValue)
696 {
697 resp.validMask |= static_cast<uint8_t>(
698 ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK);
699 }
700
701 if (upperValue)
702 {
703 resp.validMask |= static_cast<uint8_t>(
704 ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK);
705 }
706}
707
708void updateNonRecoverableThreshold(uint8_t lowerValue, uint8_t upperValue,
709 get_sdr::GetSensorThresholdsResponse& resp)
710{
711 resp.lowerNonRecoverable = lowerValue;
712 resp.upperNonRecoverable = upperValue;
713 if (lowerValue)
714 {
715 resp.validMask |= static_cast<uint8_t>(
716 ipmi::sensor::ThresholdMask::NON_RECOVERABLE_LOW_MASK);
717 }
718
719 if (upperValue)
720 {
721 resp.validMask |= static_cast<uint8_t>(
722 ipmi::sensor::ThresholdMask::NON_RECOVERABLE_HIGH_MASK);
723 }
724}
725
Patrick Williams69b4c282025-03-03 11:19:13 -0500726get_sdr::GetSensorThresholdsResponse getSensorThresholds(
727 ipmi::Context::ptr& ctx, uint8_t sensorNum)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600728{
William A. Kennington III515bc372020-10-27 16:32:32 -0700729 get_sdr::GetSensorThresholdsResponse resp{};
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700730 const auto iter = ipmi::sensor::sensors.find(sensorNum);
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530731 const auto info = iter->second;
732
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300733 std::string service;
734 boost::system::error_code ec;
735 ec = ipmi::getService(ctx, info.sensorInterface, info.sensorPath, service);
736 if (ec)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530737 {
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300738 return resp;
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530739 }
740
Willy Tu9154caa2021-12-02 02:28:54 -0800741 int32_t minClamp;
742 int32_t maxClamp;
743 int32_t rawData;
744 constexpr uint8_t sensorUnitsSignedBits = 2 << 6;
745 constexpr uint8_t signedDataFormat = 0x80;
746 if ((info.sensorUnits1 & sensorUnitsSignedBits) == signedDataFormat)
747 {
748 minClamp = std::numeric_limits<int8_t>::lowest();
749 maxClamp = std::numeric_limits<int8_t>::max();
750 }
751 else
752 {
753 minClamp = std::numeric_limits<uint8_t>::lowest();
754 maxClamp = std::numeric_limits<uint8_t>::max();
755 }
George Liu402024a2024-07-16 14:36:31 +0800756
757 static std::vector<std::string> thresholdNames{"Warning", "Critical",
758 "NonRecoverable"};
759
760 for (const auto& thresholdName : thresholdNames)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530761 {
George Liu402024a2024-07-16 14:36:31 +0800762 std::string thresholdInterface =
763 "xyz.openbmc_project.Sensor.Threshold." + thresholdName;
764 std::string thresholdLow = thresholdName + "Low";
765 std::string thresholdHigh = thresholdName + "High";
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300766
George Liu402024a2024-07-16 14:36:31 +0800767 ipmi::PropertyMap thresholds;
768 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
769 thresholdInterface, thresholds);
770 if (ec)
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300771 {
George Liu402024a2024-07-16 14:36:31 +0800772 continue;
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300773 }
774
George Liu402024a2024-07-16 14:36:31 +0800775 double lowValue = ipmi::mappedVariant<double>(
776 thresholds, thresholdLow, std::numeric_limits<double>::quiet_NaN());
777 double highValue = ipmi::mappedVariant<double>(
778 thresholds, thresholdHigh,
Hieu Huynh92079a22022-10-07 08:24:59 +0000779 std::numeric_limits<double>::quiet_NaN());
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530780
George Liu402024a2024-07-16 14:36:31 +0800781 uint8_t lowerValue = 0;
782 uint8_t upperValue = 0;
783 if (std::isfinite(lowValue))
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300784 {
George Liu402024a2024-07-16 14:36:31 +0800785 lowValue *= std::pow(10, info.scale - info.exponentR);
786 rawData = round((lowValue - info.scaledOffset) / info.coefficientM);
787 lowerValue =
Willy Tu9154caa2021-12-02 02:28:54 -0800788 static_cast<uint8_t>(std::clamp(rawData, minClamp, maxClamp));
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300789 }
790
George Liu402024a2024-07-16 14:36:31 +0800791 if (std::isfinite(highValue))
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300792 {
George Liu402024a2024-07-16 14:36:31 +0800793 highValue *= std::pow(10, info.scale - info.exponentR);
794 rawData =
795 round((highValue - info.scaledOffset) / info.coefficientM);
796 upperValue =
Willy Tu9154caa2021-12-02 02:28:54 -0800797 static_cast<uint8_t>(std::clamp(rawData, minClamp, maxClamp));
George Liu402024a2024-07-16 14:36:31 +0800798 }
799
800 if (thresholdName == "Warning")
801 {
802 updateWarningThreshold(lowerValue, upperValue, resp);
803 }
804 else if (thresholdName == "Critical")
805 {
806 updateCriticalThreshold(lowerValue, upperValue, resp);
807 }
808 else if (thresholdName == "NonRecoverable")
809 {
810 updateNonRecoverableThreshold(lowerValue, upperValue, resp);
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300811 }
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530812 }
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000813
814 return resp;
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530815}
816
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000817/** @brief implements the get sensor thresholds command
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300818 * @param ctx - IPMI context pointer
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000819 * @param sensorNum - sensor number
820 *
821 * @returns IPMI completion code plus response data
822 * - validMask - threshold mask
823 * - lower non-critical threshold - IPMI messaging state
824 * - lower critical threshold - link authentication state
825 * - lower non-recoverable threshold - callback state
826 * - upper non-critical threshold
827 * - upper critical
828 * - upper non-recoverable
829 */
830ipmi::RspType<uint8_t, // validMask
831 uint8_t, // lowerNonCritical
832 uint8_t, // lowerCritical
833 uint8_t, // lowerNonRecoverable
834 uint8_t, // upperNonCritical
835 uint8_t, // upperCritical
836 uint8_t // upperNonRecoverable
837 >
Konstantin Aladyshev89a83b62021-05-12 18:59:27 +0300838 ipmiSensorGetSensorThresholds(ipmi::Context::ptr& ctx, uint8_t sensorNum)
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530839{
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700840 const auto iter = ipmi::sensor::sensors.find(sensorNum);
841 if (iter == ipmi::sensor::sensors.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600842 {
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000843 return ipmi::responseSensorInvalid();
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600844 }
845
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530846 const auto info = iter->second;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600847
Patrick Venture0b02be92018-08-31 11:55:55 -0700848 // Proceed only if the sensor value interface is implemented.
Alexander Hansenf365c7f2025-11-14 12:08:34 +0100849 if (info.propertyInterfaces.find(SensorValue::interface) ==
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530850 info.propertyInterfaces.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600851 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700852 // return with valid mask as 0
jayaprakash Mutyala996c9792019-05-03 15:56:48 +0000853 return ipmi::responseSuccess();
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600854 }
855
Lei YU14a47812021-09-17 15:58:04 +0800856 auto it = sensorThresholdMap.find(sensorNum);
857 if (it == sensorThresholdMap.end())
858 {
George Liu7a34a6c2024-09-12 16:03:18 +0800859 auto resp = getSensorThresholds(ctx, sensorNum);
860 if (resp.validMask == 0)
861 {
862 return ipmi::responseSensorInvalid();
863 }
864 sensorThresholdMap[sensorNum] = std::move(resp);
Lei YU14a47812021-09-17 15:58:04 +0800865 }
866
867 const auto& resp = sensorThresholdMap[sensorNum];
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600868
Patrick Williams1318a5e2024-08-16 15:19:54 -0400869 return ipmi::responseSuccess(
870 resp.validMask, resp.lowerNonCritical, resp.lowerCritical,
871 resp.lowerNonRecoverable, resp.upperNonCritical, resp.upperCritical,
872 resp.upperNonRecoverable);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600873}
874
Lotus Xuf93da662021-10-18 17:20:06 +0800875/** @brief implements the Set Sensor threshold command
876 * @param sensorNumber - sensor number
877 * @param lowerNonCriticalThreshMask
878 * @param lowerCriticalThreshMask
879 * @param lowerNonRecovThreshMask
880 * @param upperNonCriticalThreshMask
881 * @param upperCriticalThreshMask
882 * @param upperNonRecovThreshMask
883 * @param reserved
884 * @param lowerNonCritical - lower non-critical threshold
885 * @param lowerCritical - Lower critical threshold
886 * @param lowerNonRecoverable - Lower non recovarable threshold
887 * @param upperNonCritical - Upper non-critical threshold
888 * @param upperCritical - Upper critical
889 * @param upperNonRecoverable - Upper Non-recoverable
890 *
891 * @returns IPMI completion code
892 */
893ipmi::RspType<> ipmiSenSetSensorThresholds(
894 ipmi::Context::ptr& ctx, uint8_t sensorNum, bool lowerNonCriticalThreshMask,
895 bool lowerCriticalThreshMask, bool lowerNonRecovThreshMask,
896 bool upperNonCriticalThreshMask, bool upperCriticalThreshMask,
897 bool upperNonRecovThreshMask, uint2_t reserved, uint8_t lowerNonCritical,
Willy Tu11d68892022-01-20 10:37:34 -0800898 uint8_t lowerCritical, uint8_t, uint8_t upperNonCritical,
899 uint8_t upperCritical, uint8_t)
Lotus Xuf93da662021-10-18 17:20:06 +0800900{
901 if (reserved)
902 {
903 return ipmi::responseInvalidFieldRequest();
904 }
905
906 // lower nc and upper nc not suppported on any sensor
907 if (lowerNonRecovThreshMask || upperNonRecovThreshMask)
908 {
909 return ipmi::responseInvalidFieldRequest();
910 }
911
912 // if none of the threshold mask are set, nothing to do
913 if (!(lowerNonCriticalThreshMask | lowerCriticalThreshMask |
914 lowerNonRecovThreshMask | upperNonCriticalThreshMask |
915 upperCriticalThreshMask | upperNonRecovThreshMask))
916 {
917 return ipmi::responseSuccess();
918 }
919
Lotus Xuf93da662021-10-18 17:20:06 +0800920 const auto iter = ipmi::sensor::sensors.find(sensorNum);
921 if (iter == ipmi::sensor::sensors.end())
922 {
923 return ipmi::responseSensorInvalid();
924 }
925
926 const auto& info = iter->second;
927
928 // Proceed only if the sensor value interface is implemented.
Alexander Hansenf365c7f2025-11-14 12:08:34 +0100929 if (info.propertyInterfaces.find(SensorValue::interface) ==
Lotus Xuf93da662021-10-18 17:20:06 +0800930 info.propertyInterfaces.end())
931 {
932 // return with valid mask as 0
933 return ipmi::responseSuccess();
934 }
935
Lotus Xuf93da662021-10-18 17:20:06 +0800936 std::string service;
937 boost::system::error_code ec;
938 ec = ipmi::getService(ctx, info.sensorInterface, info.sensorPath, service);
939 if (ec)
940 {
941 return ipmi::responseResponseError();
942 }
943 // store a vector of property name, value to set, and interface
944 std::vector<std::tuple<std::string, uint8_t, std::string>> thresholdsToSet;
945
946 // define the indexes of the tuple
947 constexpr uint8_t propertyName = 0;
948 constexpr uint8_t thresholdValue = 1;
949 constexpr uint8_t interface = 2;
950 // verifiy all needed fields are present
951 if (lowerCriticalThreshMask || upperCriticalThreshMask)
952 {
Lotus Xuf93da662021-10-18 17:20:06 +0800953 ipmi::PropertyMap findThreshold;
954 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
Alexander Hansen653aec02025-11-14 13:38:08 +0100955 SensorThresholdCritical::interface,
956 findThreshold);
Lotus Xuf93da662021-10-18 17:20:06 +0800957
958 if (!ec)
959 {
960 if (lowerCriticalThreshMask)
961 {
Alexander Hansen653aec02025-11-14 13:38:08 +0100962 auto findLower = findThreshold.find(
963 SensorThresholdCritical::property_names::critical_low);
Lotus Xuf93da662021-10-18 17:20:06 +0800964 if (findLower == findThreshold.end())
965 {
966 return ipmi::responseInvalidFieldRequest();
967 }
Alexander Hansen653aec02025-11-14 13:38:08 +0100968 thresholdsToSet.emplace_back(
969 SensorThresholdCritical::property_names::critical_low,
970 lowerCritical, SensorThresholdCritical::interface);
Lotus Xuf93da662021-10-18 17:20:06 +0800971 }
972 if (upperCriticalThreshMask)
973 {
Alexander Hansen653aec02025-11-14 13:38:08 +0100974 auto findUpper = findThreshold.find(
975 SensorThresholdCritical::property_names::critical_high);
Lotus Xuf93da662021-10-18 17:20:06 +0800976 if (findUpper == findThreshold.end())
977 {
978 return ipmi::responseInvalidFieldRequest();
979 }
Alexander Hansen653aec02025-11-14 13:38:08 +0100980 thresholdsToSet.emplace_back(
981 SensorThresholdCritical::property_names::critical_high,
982 upperCritical, SensorThresholdCritical::interface);
Lotus Xuf93da662021-10-18 17:20:06 +0800983 }
984 }
985 }
986 if (lowerNonCriticalThreshMask || upperNonCriticalThreshMask)
987 {
988 ipmi::PropertyMap findThreshold;
989 ec = ipmi::getAllDbusProperties(ctx, service, info.sensorPath,
Alexander Hansen653aec02025-11-14 13:38:08 +0100990 SensorThresholdWarning::interface,
991 findThreshold);
Lotus Xuf93da662021-10-18 17:20:06 +0800992
993 if (!ec)
994 {
995 if (lowerNonCriticalThreshMask)
996 {
Alexander Hansen653aec02025-11-14 13:38:08 +0100997 auto findLower = findThreshold.find(
998 SensorThresholdWarning::property_names::warning_low);
Lotus Xuf93da662021-10-18 17:20:06 +0800999 if (findLower == findThreshold.end())
1000 {
1001 return ipmi::responseInvalidFieldRequest();
1002 }
Alexander Hansen653aec02025-11-14 13:38:08 +01001003 thresholdsToSet.emplace_back(
1004 SensorThresholdWarning::property_names::warning_low,
1005 lowerNonCritical, SensorThresholdWarning::interface);
Lotus Xuf93da662021-10-18 17:20:06 +08001006 }
1007 if (upperNonCriticalThreshMask)
1008 {
Alexander Hansen653aec02025-11-14 13:38:08 +01001009 auto findUpper = findThreshold.find(
1010 SensorThresholdWarning::property_names::warning_high);
Lotus Xuf93da662021-10-18 17:20:06 +08001011 if (findUpper == findThreshold.end())
1012 {
1013 return ipmi::responseInvalidFieldRequest();
1014 }
Alexander Hansen653aec02025-11-14 13:38:08 +01001015 thresholdsToSet.emplace_back(
1016 SensorThresholdWarning::property_names::warning_high,
1017 upperNonCritical, SensorThresholdWarning::interface);
Lotus Xuf93da662021-10-18 17:20:06 +08001018 }
1019 }
1020 }
1021 for (const auto& property : thresholdsToSet)
1022 {
1023 // from section 36.3 in the IPMI Spec, assume all linear
1024 double valueToSet =
1025 ((info.coefficientM * std::get<thresholdValue>(property)) +
1026 (info.scaledOffset * std::pow(10.0, info.scale))) *
1027 std::pow(10.0, info.exponentR);
1028 ipmi::setDbusProperty(
1029 ctx, service, info.sensorPath, std::get<interface>(property),
1030 std::get<propertyName>(property), ipmi::Value(valueToSet));
1031 }
1032
Lei YU14a47812021-09-17 15:58:04 +08001033 // Invalidate the cache
1034 sensorThresholdMap.erase(sensorNum);
Lotus Xuf93da662021-10-18 17:20:06 +08001035 return ipmi::responseSuccess();
1036}
1037
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001038/** @brief implements the get SDR Info command
1039 * @param count - Operation
1040 *
1041 * @returns IPMI completion code plus response data
1042 * - sdrCount - sensor/SDR count
1043 * - lunsAndDynamicPopulation - static/Dynamic sensor population flag
1044 */
1045ipmi::RspType<uint8_t, // respcount
1046 uint8_t // dynamic population flags
1047 >
1048 ipmiSensorGetDeviceSdrInfo(std::optional<uint8_t> count)
Emily Shafferd06e0e72017-04-05 09:08:57 -07001049{
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001050 uint8_t sdrCount;
1051 // multiple LUNs not supported.
1052 constexpr uint8_t lunsAndDynamicPopulation = 1;
1053 constexpr uint8_t getSdrCount = 0x01;
1054 constexpr uint8_t getSensorCount = 0x00;
1055
1056 if (count.value_or(0) == getSdrCount)
Emily Shafferd06e0e72017-04-05 09:08:57 -07001057 {
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001058 // Get SDR count. This returns the total number of SDRs in the device.
Patrick Venture87fd2cd2019-08-19 12:07:18 -07001059 const auto& entityRecords =
1060 ipmi::sensor::EntityInfoMapContainer::getContainer()
1061 ->getIpmiEntityRecords();
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001062 sdrCount = ipmi::sensor::sensors.size() + frus.size() +
1063 entityRecords.size();
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001064 }
1065 else if (count.value_or(0) == getSensorCount)
1066 {
1067 // Get Sensor count. This returns the number of sensors
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001068 sdrCount = ipmi::sensor::sensors.size();
Emily Shafferd06e0e72017-04-05 09:08:57 -07001069 }
1070 else
1071 {
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001072 return ipmi::responseInvalidCommandOnLun();
Emily Shafferd06e0e72017-04-05 09:08:57 -07001073 }
1074
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001075 return ipmi::responseSuccess(sdrCount, lunsAndDynamicPopulation);
Emily Shafferd06e0e72017-04-05 09:08:57 -07001076}
1077
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001078/** @brief implements the reserve SDR command
1079 * @returns IPMI completion code plus response data
1080 * - reservationID - reservation ID
1081 */
1082ipmi::RspType<uint16_t> ipmiSensorReserveSdr()
Emily Shaffera344afc2017-04-13 15:09:39 -07001083{
1084 // A constant reservation ID is okay until we implement add/remove SDR.
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001085 constexpr uint16_t reservationID = 1;
Emily Shaffera344afc2017-04-13 15:09:39 -07001086
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001087 return ipmi::responseSuccess(reservationID);
Emily Shaffera344afc2017-04-13 15:09:39 -07001088}
Chris Austenac4604a2015-10-13 12:43:27 -05001089
George Liue6b2be52025-08-19 13:57:43 +08001090void setUnitFieldsForObject(const ipmi::sensor::Info& info,
1091 get_sdr::SensorDataFullRecordBody& body)
Emily Shaffercc941e12017-06-14 13:06:26 -07001092{
Willy Tu523e2d12023-09-05 11:36:48 -07001093 namespace server = sdbusplus::server::xyz::openbmc_project::sensor;
George Liu42247d22025-08-19 10:24:47 +08001094 body.sensorUnits1 = info.sensorUnits1; // default is 0. unsigned, no rate,
1095 // no modifier, not a %
Tom Josephdc212b22018-02-16 09:59:57 +05301096 try
Emily Shaffercc941e12017-06-14 13:06:26 -07001097 {
George Liue6b2be52025-08-19 13:57:43 +08001098 auto unit = server::Value::convertUnitFromString(info.unit);
Tom Josephdc212b22018-02-16 09:59:57 +05301099 // Unit strings defined in
1100 // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
1101 switch (unit)
Emily Shaffercc941e12017-06-14 13:06:26 -07001102 {
Tom Josephdc212b22018-02-16 09:59:57 +05301103 case server::Value::Unit::DegreesC:
George Liu42247d22025-08-19 10:24:47 +08001104 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_DEGREES_C;
Tom Josephdc212b22018-02-16 09:59:57 +05301105 break;
1106 case server::Value::Unit::RPMS:
George Liu42247d22025-08-19 10:24:47 +08001107 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_RPM;
Tom Josephdc212b22018-02-16 09:59:57 +05301108 break;
1109 case server::Value::Unit::Volts:
George Liu42247d22025-08-19 10:24:47 +08001110 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_VOLTS;
Tom Josephdc212b22018-02-16 09:59:57 +05301111 break;
1112 case server::Value::Unit::Meters:
George Liu42247d22025-08-19 10:24:47 +08001113 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_METERS;
Tom Josephdc212b22018-02-16 09:59:57 +05301114 break;
1115 case server::Value::Unit::Amperes:
George Liu42247d22025-08-19 10:24:47 +08001116 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_AMPERES;
Tom Josephdc212b22018-02-16 09:59:57 +05301117 break;
1118 case server::Value::Unit::Joules:
George Liu42247d22025-08-19 10:24:47 +08001119 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_JOULES;
Tom Josephdc212b22018-02-16 09:59:57 +05301120 break;
1121 case server::Value::Unit::Watts:
George Liu42247d22025-08-19 10:24:47 +08001122 body.sensorUnits2Base = get_sdr::SENSOR_UNIT_WATTS;
Tom Josephdc212b22018-02-16 09:59:57 +05301123 break;
Konstantin Aladyshev0ab84792025-05-05 17:02:43 +03001124 case server::Value::Unit::Percent:
George Liuf60be692025-08-19 11:28:42 +08001125 get_sdr::body::setPercentage(body);
Konstantin Aladyshev0ab84792025-05-05 17:02:43 +03001126 break;
Tom Josephdc212b22018-02-16 09:59:57 +05301127 default:
1128 // Cannot be hit.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -07001129 std::fprintf(stderr, "Unknown value unit type: = %s\n",
George Liue6b2be52025-08-19 13:57:43 +08001130 info.unit.c_str());
Emily Shaffercc941e12017-06-14 13:06:26 -07001131 }
1132 }
Patrick Venture64678b82018-10-13 13:11:32 -07001133 catch (const sdbusplus::exception::InvalidEnumString& e)
Emily Shaffercc941e12017-06-14 13:06:26 -07001134 {
George Liu3b1071a2024-07-17 20:26:14 +08001135 lg2::warning("Warning: no unit provided for sensor!");
Emily Shaffercc941e12017-06-14 13:06:26 -07001136 }
Emily Shaffercc941e12017-06-14 13:06:26 -07001137}
1138
George Liuf60be692025-08-19 11:28:42 +08001139ipmi::Cc populateRecordFromDbus(const ipmi::sensor::Info& info,
1140 get_sdr::SensorDataFullRecordBody& body)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001141{
1142 /* Functional sensor case */
George Liue6b2be52025-08-19 13:57:43 +08001143 if (isAnalogSensor(info.propertyInterfaces.begin()->first))
Emily Shafferbbef71c2017-05-08 16:36:17 -07001144 {
Emily Shafferbbef71c2017-05-08 16:36:17 -07001145 /* Unit info */
Tom Josephdc212b22018-02-16 09:59:57 +05301146 setUnitFieldsForObject(info, body);
Emily Shaffer10f49592017-05-10 12:01:10 -07001147
George Liuf60be692025-08-19 11:28:42 +08001148 get_sdr::body::setB(info.coefficientB, body);
1149 get_sdr::body::setM(info.coefficientM, body);
1150 get_sdr::body::setBexp(info.exponentB, body);
1151 get_sdr::body::setRexp(info.exponentR, body);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001152 }
1153
Tom Joseph96423912018-01-25 00:14:34 +05301154 /* ID string */
George Liu42247d22025-08-19 10:24:47 +08001155 auto idString = info.sensorName;
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +08001156
George Liu42247d22025-08-19 10:24:47 +08001157 if (idString.empty())
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +08001158 {
George Liu42247d22025-08-19 10:24:47 +08001159 idString = info.sensorNameFunc(info);
Jeremy Kerrbe4ffa82020-08-10 16:17:37 +08001160 }
Tom Joseph96423912018-01-25 00:14:34 +05301161
George Liu42247d22025-08-19 10:24:47 +08001162 if (idString.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
Tom Joseph96423912018-01-25 00:14:34 +05301163 {
George Liuf60be692025-08-19 11:28:42 +08001164 get_sdr::body::setIdStrLen(FULL_RECORD_ID_STR_MAX_LENGTH, body);
Tom Joseph96423912018-01-25 00:14:34 +05301165 }
1166 else
1167 {
George Liuf60be692025-08-19 11:28:42 +08001168 get_sdr::body::setIdStrLen(idString.length(), body);
Tom Joseph96423912018-01-25 00:14:34 +05301169 }
George Liuf60be692025-08-19 11:28:42 +08001170 get_sdr::body::setIdType(3, body); // "8-bit ASCII + Latin 1"
1171 strncpy(body.idString, idString.c_str(), get_sdr::body::getIdStrLen(body));
Tom Joseph96423912018-01-25 00:14:34 +05301172
George Liue8a97bd2024-12-05 17:26:46 +08001173 return ipmi::ccSuccess;
Emily Shafferbbef71c2017-05-08 16:36:17 -07001174};
1175
George Liuc7a4da52025-08-19 16:20:31 +08001176ipmi::RspType<uint16_t, // nextRecordId
1177 std::vector<uint8_t> // recordData
1178 >
1179 ipmiFruGetSdr(uint16_t recordID, uint8_t offset, uint8_t bytesToRead)
Ratan Guptae0cc8552018-01-22 14:23:04 +05301180{
Ratan Guptae0cc8552018-01-22 14:23:04 +05301181 auto fru = frus.begin();
Patrick Venture0b02be92018-08-31 11:55:55 -07001182 uint8_t fruID{};
Ratan Guptae0cc8552018-01-22 14:23:04 +05301183
1184 fruID = recordID - FRU_RECORD_ID_START;
1185 fru = frus.find(fruID);
1186 if (fru == frus.end())
1187 {
George Liuc7a4da52025-08-19 16:20:31 +08001188 return ipmi::responseSensorInvalid();
Ratan Guptae0cc8552018-01-22 14:23:04 +05301189 }
1190
George Liuc7a4da52025-08-19 16:20:31 +08001191 get_sdr::SensorDataFruRecord record{};
Ratan Guptae0cc8552018-01-22 14:23:04 +05301192 /* Header */
George Liuc7a4da52025-08-19 16:20:31 +08001193 record.header.recordId = recordID;
George Liu42247d22025-08-19 10:24:47 +08001194 record.header.sdrVersion = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
1195 record.header.recordType = get_sdr::SENSOR_DATA_FRU_RECORD;
1196 record.header.recordLength = sizeof(record.key) + sizeof(record.body);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301197
1198 /* Key */
1199 record.key.fruID = fruID;
1200 record.key.accessLun |= IPMI_LOGICAL_FRU;
Matt Simmering68d9d402023-11-09 14:22:11 -08001201 record.key.deviceAddress = BMCTargetAddress;
Ratan Guptae0cc8552018-01-22 14:23:04 +05301202
1203 /* Body */
1204 record.body.entityID = fru->second[0].entityID;
1205 record.body.entityInstance = fru->second[0].entityInstance;
1206 record.body.deviceType = fruInventoryDevice;
1207 record.body.deviceTypeModifier = IPMIFruInventory;
1208
1209 /* Device ID string */
Patrick Venture0b02be92018-08-31 11:55:55 -07001210 auto deviceID =
1211 fru->second[0].path.substr(fru->second[0].path.find_last_of('/') + 1,
1212 fru->second[0].path.length());
Ratan Guptae0cc8552018-01-22 14:23:04 +05301213
1214 if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH)
1215 {
George Liuf60be692025-08-19 11:28:42 +08001216 get_sdr::body::setDeviceIdStrLen(
George Liue6b2be52025-08-19 13:57:43 +08001217 get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, record.body);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301218 }
1219 else
1220 {
George Liuf60be692025-08-19 11:28:42 +08001221 get_sdr::body::setDeviceIdStrLen(deviceID.length(), record.body);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301222 }
1223
George Liuc7a4da52025-08-19 16:20:31 +08001224 uint16_t nextRecordId{};
Ratan Guptae0cc8552018-01-22 14:23:04 +05301225 strncpy(record.body.deviceID, deviceID.c_str(),
George Liuf60be692025-08-19 11:28:42 +08001226 get_sdr::body::getDeviceIdStrLen(record.body));
Ratan Guptae0cc8552018-01-22 14:23:04 +05301227
1228 if (++fru == frus.end())
1229 {
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001230 // we have reached till end of fru, so assign the next record id to
1231 // 512(Max fru ID = 511) + Entity Record ID(may start with 0).
Patrick Venture87fd2cd2019-08-19 12:07:18 -07001232 const auto& entityRecords =
1233 ipmi::sensor::EntityInfoMapContainer::getContainer()
1234 ->getIpmiEntityRecords();
George Liuc7a4da52025-08-19 16:20:31 +08001235 nextRecordId =
Patrick Williams1318a5e2024-08-16 15:19:54 -04001236 (entityRecords.size())
1237 ? entityRecords.begin()->first + ENTITY_RECORD_ID_START
1238 : END_OF_RECORD;
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001239 }
1240 else
1241 {
George Liuc7a4da52025-08-19 16:20:31 +08001242 nextRecordId = FRU_RECORD_ID_START + fru->first;
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001243 }
1244
1245 // Check for invalid offset size
George Liuc7a4da52025-08-19 16:20:31 +08001246 if (offset > sizeof(record))
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001247 {
George Liuc7a4da52025-08-19 16:20:31 +08001248 return ipmi::responseParmOutOfRange();
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001249 }
1250
George Liuc7a4da52025-08-19 16:20:31 +08001251 size_t dataLen =
1252 std::min(static_cast<size_t>(bytesToRead), sizeof(record) - offset);
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001253
George Liuc7a4da52025-08-19 16:20:31 +08001254 std::vector<uint8_t> recordData(dataLen);
1255 std::memcpy(recordData.data(),
1256 reinterpret_cast<const uint8_t*>(&record) + offset, dataLen);
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001257
George Liuc7a4da52025-08-19 16:20:31 +08001258 return ipmi::responseSuccess(nextRecordId, recordData);
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001259}
1260
George Liuc7a4da52025-08-19 16:20:31 +08001261ipmi::RspType<uint16_t, // nextRecordId
1262 std::vector<uint8_t> // recordData
1263 >
1264 ipmiEntityGetSdr(uint16_t recordID, uint8_t offset, uint8_t bytesToRead)
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001265{
Patrick Venture87fd2cd2019-08-19 12:07:18 -07001266 const auto& entityRecords =
1267 ipmi::sensor::EntityInfoMapContainer::getContainer()
1268 ->getIpmiEntityRecords();
Patrick Venture83a0b842019-07-19 18:37:15 -07001269 auto entity = entityRecords.begin();
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001270 uint8_t entityRecordID;
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001271
1272 entityRecordID = recordID - ENTITY_RECORD_ID_START;
Patrick Venture83a0b842019-07-19 18:37:15 -07001273 entity = entityRecords.find(entityRecordID);
1274 if (entity == entityRecords.end())
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001275 {
George Liuc7a4da52025-08-19 16:20:31 +08001276 return ipmi::responseSensorInvalid();
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001277 }
1278
George Liuc7a4da52025-08-19 16:20:31 +08001279 get_sdr::SensorDataEntityRecord record{};
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001280 /* Header */
George Liuc7a4da52025-08-19 16:20:31 +08001281 record.header.recordId = recordID;
George Liu42247d22025-08-19 10:24:47 +08001282 record.header.sdrVersion = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
1283 record.header.recordType = get_sdr::SENSOR_DATA_ENTITY_RECORD;
1284 record.header.recordLength = sizeof(record.key) + sizeof(record.body);
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001285
1286 /* Key */
1287 record.key.containerEntityId = entity->second.containerEntityId;
1288 record.key.containerEntityInstance = entity->second.containerEntityInstance;
George Liuf60be692025-08-19 11:28:42 +08001289 get_sdr::key::setFlags(entity->second.isList, entity->second.isLinked,
1290 record.key);
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001291 record.key.entityId1 = entity->second.containedEntities[0].first;
1292 record.key.entityInstance1 = entity->second.containedEntities[0].second;
1293
1294 /* Body */
1295 record.body.entityId2 = entity->second.containedEntities[1].first;
1296 record.body.entityInstance2 = entity->second.containedEntities[1].second;
1297 record.body.entityId3 = entity->second.containedEntities[2].first;
1298 record.body.entityInstance3 = entity->second.containedEntities[2].second;
1299 record.body.entityId4 = entity->second.containedEntities[3].first;
1300 record.body.entityInstance4 = entity->second.containedEntities[3].second;
1301
George Liuc7a4da52025-08-19 16:20:31 +08001302 uint16_t nextRecordId{};
Patrick Venture83a0b842019-07-19 18:37:15 -07001303 if (++entity == entityRecords.end())
Jaghathiswari Rankappagounder Natarajan9c118942019-02-12 13:22:55 -08001304 {
George Liuc7a4da52025-08-19 16:20:31 +08001305 nextRecordId = END_OF_RECORD;
Ratan Guptae0cc8552018-01-22 14:23:04 +05301306 }
1307 else
1308 {
George Liuc7a4da52025-08-19 16:20:31 +08001309 nextRecordId = entity->first + ENTITY_RECORD_ID_START;
Ratan Guptae0cc8552018-01-22 14:23:04 +05301310 }
1311
Emily Shaffer0fbdbce2018-09-27 09:30:41 -07001312 // Check for invalid offset size
George Liuc7a4da52025-08-19 16:20:31 +08001313 if (offset > sizeof(record))
Ratan Guptae0cc8552018-01-22 14:23:04 +05301314 {
George Liuc7a4da52025-08-19 16:20:31 +08001315 return ipmi::responseParmOutOfRange();
Ratan Guptae0cc8552018-01-22 14:23:04 +05301316 }
1317
George Liuc7a4da52025-08-19 16:20:31 +08001318 size_t dataLen =
1319 std::min(static_cast<size_t>(bytesToRead), sizeof(record) - offset);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301320
George Liuc7a4da52025-08-19 16:20:31 +08001321 std::vector<uint8_t> recordData(dataLen);
1322 std::memcpy(recordData.data(),
1323 reinterpret_cast<const uint8_t*>(&record) + offset, dataLen);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301324
George Liuc7a4da52025-08-19 16:20:31 +08001325 return ipmi::responseSuccess(nextRecordId, recordData);
Ratan Guptae0cc8552018-01-22 14:23:04 +05301326}
1327
George Liuc7a4da52025-08-19 16:20:31 +08001328ipmi::RspType<uint16_t, // nextRecordId
1329 std::vector<uint8_t> // recordData
1330 >
1331 ipmiSensorGetSdr(uint16_t /* reservationId */, uint16_t recordID,
1332 uint8_t offset, uint8_t bytesToRead)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001333{
Patrick Venture38426dd2019-07-30 15:22:29 -07001334 // Note: we use an iterator so we can provide the next ID at the end of
1335 // the call.
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001336 auto sensor = ipmi::sensor::sensors.begin();
Patrick Venture38426dd2019-07-30 15:22:29 -07001337
1338 // At the beginning of a scan, the host side will send us id=0.
1339 if (recordID != 0)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001340 {
Patrick Venture38426dd2019-07-30 15:22:29 -07001341 // recordID 0 to 255 means it is a FULL record.
1342 // recordID 256 to 511 means it is a FRU record.
1343 // recordID greater then 511 means it is a Entity Association
1344 // record. Currently we are supporting three record types: FULL
1345 // record, FRU record and Enttiy Association record.
1346 if (recordID >= ENTITY_RECORD_ID_START)
Emily Shafferbbef71c2017-05-08 16:36:17 -07001347 {
George Liuc7a4da52025-08-19 16:20:31 +08001348 return ipmiEntityGetSdr(recordID, offset, bytesToRead);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001349 }
Patrick Venture38426dd2019-07-30 15:22:29 -07001350 else if (recordID >= FRU_RECORD_ID_START &&
1351 recordID < ENTITY_RECORD_ID_START)
Jaghathiswari Rankappagounder Natarajan0780df12019-02-06 15:29:24 -08001352 {
George Liuc7a4da52025-08-19 16:20:31 +08001353 return ipmiFruGetSdr(recordID, offset, bytesToRead);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001354 }
1355 else
1356 {
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001357 sensor = ipmi::sensor::sensors.find(recordID);
1358 if (sensor == ipmi::sensor::sensors.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001359 {
George Liuc7a4da52025-08-19 16:20:31 +08001360 return ipmi::responseSensorInvalid();
Patrick Venture38426dd2019-07-30 15:22:29 -07001361 }
Emily Shafferbbef71c2017-05-08 16:36:17 -07001362 }
Emily Shafferbbef71c2017-05-08 16:36:17 -07001363 }
1364
George Liu42247d22025-08-19 10:24:47 +08001365 uint8_t sensorId = sensor->first;
Patrick Venture38426dd2019-07-30 15:22:29 -07001366
George Liu42247d22025-08-19 10:24:47 +08001367 auto it = sdrCacheMap.find(sensorId);
Lei YU14a47812021-09-17 15:58:04 +08001368 if (it == sdrCacheMap.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001369 {
Lei YU14a47812021-09-17 15:58:04 +08001370 /* Header */
Willy Tu11d68892022-01-20 10:37:34 -08001371 get_sdr::SensorDataFullRecord record = {};
George Liu42247d22025-08-19 10:24:47 +08001372 record.header.recordId = sensorId;
1373 record.header.sdrVersion = 0x51; // Based on IPMI Spec v2.0 rev 1.1
1374 record.header.recordType = get_sdr::SENSOR_DATA_FULL_RECORD;
1375 record.header.recordLength = sizeof(record.key) + sizeof(record.body);
Lei YU14a47812021-09-17 15:58:04 +08001376
1377 /* Key */
George Liuf60be692025-08-19 11:28:42 +08001378 get_sdr::key::setOwnerIdBmc(record.key);
George Liu42247d22025-08-19 10:24:47 +08001379 record.key.sensorNumber = sensorId;
Lei YU14a47812021-09-17 15:58:04 +08001380
1381 /* Body */
George Liu42247d22025-08-19 10:24:47 +08001382 record.body.entityId = sensor->second.entityType;
1383 record.body.sensorType = sensor->second.sensorType;
1384 record.body.eventReadingType = sensor->second.sensorReadingType;
1385 record.body.entityInstance = sensor->second.instance;
Lei YU14a47812021-09-17 15:58:04 +08001386 if (ipmi::sensor::Mutability::Write ==
1387 (sensor->second.mutability & ipmi::sensor::Mutability::Write))
1388 {
George Liuf60be692025-08-19 11:28:42 +08001389 get_sdr::body::initSettableState(true, record.body);
Lei YU14a47812021-09-17 15:58:04 +08001390 }
1391
1392 // Set the type-specific details given the DBus interface
George Liuf60be692025-08-19 11:28:42 +08001393 populateRecordFromDbus(sensor->second, record.body);
George Liu42247d22025-08-19 10:24:47 +08001394 sdrCacheMap[sensorId] = std::move(record);
Patrick Venture38426dd2019-07-30 15:22:29 -07001395 }
1396
George Liuc7a4da52025-08-19 16:20:31 +08001397 uint16_t nextRecordId{};
George Liu42247d22025-08-19 10:24:47 +08001398 const auto& record = sdrCacheMap[sensorId];
Patrick Venture38426dd2019-07-30 15:22:29 -07001399
Patrick Venturedb0cbe62019-09-09 14:47:22 -07001400 if (++sensor == ipmi::sensor::sensors.end())
Patrick Venture38426dd2019-07-30 15:22:29 -07001401 {
1402 // we have reached till end of sensor, so assign the next record id
1403 // to 256(Max Sensor ID = 255) + FRU ID(may start with 0).
George Liuc7a4da52025-08-19 16:20:31 +08001404 nextRecordId = (frus.size()) ? frus.begin()->first + FRU_RECORD_ID_START
1405 : END_OF_RECORD;
Patrick Venture38426dd2019-07-30 15:22:29 -07001406 }
1407 else
1408 {
George Liuc7a4da52025-08-19 16:20:31 +08001409 nextRecordId = sensor->first;
Patrick Venture38426dd2019-07-30 15:22:29 -07001410 }
1411
George Liuc7a4da52025-08-19 16:20:31 +08001412 if (offset > sizeof(record))
Patrick Venture38426dd2019-07-30 15:22:29 -07001413 {
George Liuc7a4da52025-08-19 16:20:31 +08001414 return ipmi::responseParmOutOfRange();
Patrick Venture38426dd2019-07-30 15:22:29 -07001415 }
1416
George Liuc7a4da52025-08-19 16:20:31 +08001417 size_t dataLen =
1418 std::min(static_cast<size_t>(bytesToRead), sizeof(record) - offset);
Patrick Venture38426dd2019-07-30 15:22:29 -07001419
George Liuc7a4da52025-08-19 16:20:31 +08001420 std::vector<uint8_t> recordData(dataLen);
1421 std::memcpy(recordData.data(),
1422 reinterpret_cast<const uint8_t*>(&record) + offset, dataLen);
Patrick Venture38426dd2019-07-30 15:22:29 -07001423
George Liuc7a4da52025-08-19 16:20:31 +08001424 return ipmi::responseSuccess(nextRecordId, recordData);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001425}
1426
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001427static bool isFromSystemChannel()
1428{
1429 // TODO we could not figure out where the request is from based on IPMI
1430 // command handler parameters. because of it, we can not differentiate
1431 // request from SMS/SMM or IPMB channel
1432 return true;
1433}
1434
George Liu6b47d5a2025-08-18 10:40:17 +08001435ipmi::RspType<> ipmicmdPlatformEvent(ipmi::Context::ptr& ctx,
1436 const std::vector<uint8_t>& data)
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001437{
George Liu6b47d5a2025-08-18 10:40:17 +08001438 size_t paraLen = data.size();
1439 if (paraLen < selSystemEventSizeWith1Bytes ||
1440 paraLen > selSystemEventSizeWith3Bytes)
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001441 {
George Liu6b47d5a2025-08-18 10:40:17 +08001442 return ipmi::responseReqDataLenInvalid();
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001443 }
1444
George Liu6b47d5a2025-08-18 10:40:17 +08001445 uint16_t generatorID = 0xff;
1446 std::string sensorPath = "IPMB";
1447 const uint8_t* raw = data.data();
1448 const PlatformEventRequest* req = nullptr;
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001449 if (isFromSystemChannel())
George Liu6b47d5a2025-08-18 10:40:17 +08001450 {
1451 // first byte for SYSTEM Interface is Generator ID +1 to get common
1452 // struct
1453 req = reinterpret_cast<const PlatformEventRequest*>(raw + 1);
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001454 // Capture the generator ID
George Liu6b47d5a2025-08-18 10:40:17 +08001455 generatorID = *raw;
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001456 // Platform Event usually comes from other firmware, like BIOS.
1457 // Unlike BMC sensor, it does not have BMC DBUS sensor path.
1458 sensorPath = "System";
1459 }
1460 else
1461 {
George Liu6b47d5a2025-08-18 10:40:17 +08001462 req = reinterpret_cast<const PlatformEventRequest*>(raw);
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001463 // TODO GenratorID for IPMB is combination of RqSA and RqLUN
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001464 }
George Liu6b47d5a2025-08-18 10:40:17 +08001465
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001466 // Content of event data field depends on sensor class.
1467 // When data0 bit[5:4] is non-zero, valid data counts is 3.
1468 // When data0 bit[7:6] is non-zero, valid data counts is 2.
1469 if (((req->data[0] & byte3EnableMask) != 0 &&
1470 paraLen < selSystemEventSizeWith3Bytes) ||
1471 ((req->data[0] & byte2EnableMask) != 0 &&
1472 paraLen < selSystemEventSizeWith2Bytes))
1473 {
George Liu6b47d5a2025-08-18 10:40:17 +08001474 return ipmi::responseReqDataLenInvalid();
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001475 }
1476
1477 // Count bytes of Event Data
George Liu6b47d5a2025-08-18 10:40:17 +08001478 size_t count;
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001479 if ((req->data[0] & byte3EnableMask) != 0)
1480 {
1481 count = 3;
1482 }
1483 else if ((req->data[0] & byte2EnableMask) != 0)
1484 {
1485 count = 2;
1486 }
1487 else
1488 {
1489 count = 1;
1490 }
George Liu6b47d5a2025-08-18 10:40:17 +08001491 bool assert = req->eventDirectionType & directionMask ? false : true;
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001492 std::vector<uint8_t> eventData(req->data, req->data + count);
1493
George Liu6b47d5a2025-08-18 10:40:17 +08001494 auto ec = ipmi::callDbusMethod(
1495 ctx, ipmiSELObject, ipmiSELPath, ipmiSELAddInterface, "IpmiSelAdd",
1496 ipmiSELAddMessage, sensorPath, eventData, assert, generatorID);
1497 if (ec)
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001498 {
George Liu6b47d5a2025-08-18 10:40:17 +08001499 lg2::error("IpmiSelAdd call failed: {ERROR}", "ERROR", ec.message());
1500 return ipmi::responseUnspecifiedError();
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001501 }
George Liu6b47d5a2025-08-18 10:40:17 +08001502
1503 return ipmi::responseSuccess();
Jia, Chunhui3342a8e2018-12-29 13:32:26 +08001504}
1505
George Liu5087b072025-03-11 19:28:17 +08001506void registerNetFnSenFunctions()
Chris Austenac4604a2015-10-13 12:43:27 -05001507{
Willy Tud351a722021-08-12 14:33:40 -07001508 // Handlers with dbus-sdr handler implementation.
1509 // Do not register the hander if it dynamic sensors stack is used.
Deepak Kumar Sahua8be7dc2019-05-07 14:26:53 +00001510
Willy Tud351a722021-08-12 14:33:40 -07001511#ifndef FEATURE_DYNAMIC_SENSORS
Lei YUbe5c6b22021-09-16 15:46:20 +08001512
Lei YU962e68b2021-09-16 16:25:34 +08001513#ifdef FEATURE_SENSORS_CACHE
Lei YUbe5c6b22021-09-16 15:46:20 +08001514 // Initialize the sensor matches
1515 initSensorMatches();
Lei YU962e68b2021-09-16 16:25:34 +08001516#endif
Lei YUbe5c6b22021-09-16 15:46:20 +08001517
Tom05732372016-09-06 17:21:23 +05301518 // <Set Sensor Reading and Event Status>
Deepak Kumar Sahu9da3a752019-05-21 00:45:14 +00001519 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1520 ipmi::sensor_event::cmdSetSensorReadingAndEvtSts,
1521 ipmi::Privilege::Operator, ipmiSetSensorReading);
Tom05732372016-09-06 17:21:23 +05301522 // <Get Sensor Reading>
jayaprakash Mutyala4c3feba2019-07-16 00:14:35 +00001523 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1524 ipmi::sensor_event::cmdGetSensorReading,
1525 ipmi::Privilege::User, ipmiSensorGetSensorReading);
Emily Shaffera344afc2017-04-13 15:09:39 -07001526
Tom Joseph5ca50952018-02-22 00:33:38 +05301527 // <Reserve Device SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001528 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1529 ipmi::sensor_event::cmdReserveDeviceSdrRepository,
1530 ipmi::Privilege::User, ipmiSensorReserveSdr);
Chris Austen10ccc0f2015-12-10 18:27:04 -06001531
Tom Joseph5ca50952018-02-22 00:33:38 +05301532 // <Get Device SDR Info>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +00001533 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1534 ipmi::sensor_event::cmdGetDeviceSdrInfo,
1535 ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001536
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001537 // <Get Sensor Thresholds>
jayaprakash Mutyala996c9792019-05-03 15:56:48 +00001538 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1539 ipmi::sensor_event::cmdGetSensorThreshold,
1540 ipmi::Privilege::User, ipmiSensorGetSensorThresholds);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001541
Lotus Xuf93da662021-10-18 17:20:06 +08001542 // <Set Sensor Thresholds>
1543 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1544 ipmi::sensor_event::cmdSetSensorThreshold,
1545 ipmi::Privilege::User, ipmiSenSetSensorThresholds);
Vivekanand Veeracholand3d2fe22021-11-12 19:40:42 -08001546
1547 // <Get Device SDR>
George Liuc7a4da52025-08-19 16:20:31 +08001548 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1549 ipmi::sensor_event::cmdGetDeviceSdr,
1550 ipmi::Privilege::User, ipmiSensorGetSdr);
Vivekanand Veeracholand3d2fe22021-11-12 19:40:42 -08001551
Willy Tud351a722021-08-12 14:33:40 -07001552#endif
1553
1554 // Common Handers used by both implementation.
1555
1556 // <Platform Event Message>
George Liu6b47d5a2025-08-18 10:40:17 +08001557 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1558 ipmi::sensor_event::cmdPlatformEvent,
1559 ipmi::Privilege::Operator, ipmicmdPlatformEvent);
Willy Tud351a722021-08-12 14:33:40 -07001560
1561 // <Get Sensor Type>
1562 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
1563 ipmi::sensor_event::cmdGetSensorType,
1564 ipmi::Privilege::User, ipmiGetSensorType);
1565
Chris Austenac4604a2015-10-13 12:43:27 -05001566 return;
1567}