summaryrefslogtreecommitdiffstats
path: root/sensorhandler.cpp
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2017-04-05 15:09:41 -0700
committerEmily Shaffer <emilyshaffer@google.com>2017-06-06 10:55:40 -0700
commit2ae09b9a5cdcf5991b8a30688e89ab26f43a3f27 (patch)
tree7579ba68b1f2b25c8e2725b57fee126c2d7cebe7 /sensorhandler.cpp
parentfca6a4fc4baddf4880fe4d54d77a424bced21c76 (diff)
downloadphosphor-host-ipmid-2ae09b9a5cdcf5991b8a30688e89ab26f43a3f27.tar.gz
phosphor-host-ipmid-2ae09b9a5cdcf5991b8a30688e89ab26f43a3f27.zip
sensorhandler: Refactor find_openbmc_path to check sensor map first
Change-Id: I846d538643af77705d5160bf4d9127f758b5c749 Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Diffstat (limited to 'sensorhandler.cpp')
-rw-r--r--sensorhandler.cpp60
1 files changed, 50 insertions, 10 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 69f1911..9355fe3 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -108,11 +108,11 @@ final:
return r;
}
+int get_bus_for_path(const char *path, char **busname) {
+ return mapper_get_service(bus, path, busname);
+}
-// Use a lookup table to find the interface name of a specific sensor
-// This will be used until an alternative is found. this is the first
-// step for mapping IPMI
-int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) {
+int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) {
char *busname = NULL;
const char *iface = "org.openbmc.managers.System";
const char *objname = "/org/openbmc/managers/System";
@@ -122,7 +122,7 @@ int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *int
int r;
- r = mapper_get_service(bus, objname, &busname);
+ r = get_bus_for_path(objname, &busname);
if (r < 0) {
fprintf(stderr, "Failed to get %s busname: %s\n",
objname, strerror(-r));
@@ -142,7 +142,7 @@ int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *int
goto final;
}
- r = mapper_get_service(bus, str2, &str1);
+ r = get_bus_for_path(str2, &str1);
if (r < 0) {
fprintf(stderr, "Failed to get %s busname: %s\n",
str2, strerror(-r));
@@ -165,6 +165,46 @@ final:
return r;
}
+// Use a lookup table to find the interface name of a specific sensor
+// This will be used until an alternative is found. this is the first
+// step for mapping IPMI
+int find_openbmc_path(uint8_t num, dbus_interface_t *interface) {
+ int rc;
+
+ // When the sensor map does not contain the sensor requested,
+ // fall back to the legacy DBus lookup (deprecated)
+ const auto& sensor_it = sensors.find(num);
+ if (sensor_it == sensors.end())
+ {
+ return legacy_dbus_openbmc_path("SENSOR", num, interface);
+ }
+
+ const auto& info = sensor_it->second;
+
+ char* busname;
+ rc = get_bus_for_path(info.sensorPath.c_str(), &busname);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to get %s busname: %s\n",
+ info.sensorPath.c_str(),
+ busname);
+ goto final;
+ }
+
+ interface->sensortype = info.sensorType;
+ strcpy(interface->bus, busname);
+ strcpy(interface->path, info.sensorPath.c_str());
+ // Take the interface name from the beginning of the DbusInterfaceMap. This
+ // works for the Value interface but may not suffice for more complex
+ // sensors.
+ // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
+ strcpy(interface->interface, info.sensorInterfaces.begin()->first.c_str());
+ interface->sensornumber = num;
+
+final:
+ free(busname);
+ return rc;
+}
+
/////////////////////////////////////////////////////////////////////
//
@@ -182,7 +222,7 @@ int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *valu
fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n",
number, method, value);
- r = find_openbmc_path("SENSOR", number, &a);
+ r = find_openbmc_path(number, &a);
if (r < 0) {
fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
@@ -224,7 +264,7 @@ int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t va
fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n",
number, method, value);
- r = find_openbmc_path("SENSOR", number, &a);
+ r = find_openbmc_path(number, &a);
if (r < 0) {
fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
@@ -317,7 +357,7 @@ uint8_t get_type_from_interface(dbus_interface_t dbus_if) {
uint8_t find_type_for_sensor_number(uint8_t num) {
int r;
dbus_interface_t dbus_if;
- r = find_openbmc_path("SENSOR", num, &dbus_if);
+ r = find_openbmc_path(num, &dbus_if);
if (r < 0) {
fprintf(stderr, "Could not find sensor %d\n", num);
return r;
@@ -490,7 +530,7 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum);
- r = find_openbmc_path("SENSOR", reqptr->sennum, &a);
+ r = find_openbmc_path(reqptr->sennum, &a);
if (r < 0) {
fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
OpenPOWER on IntegriCloud