summaryrefslogtreecommitdiffstats
path: root/apphandler.cpp
diff options
context:
space:
mode:
authorDavid Cobbley <david.j.cobbley@linux.intel.com>2017-11-21 15:58:13 -0800
committerDavid Cobbley <david.j.cobbley@linux.intel.com>2018-01-04 15:27:45 -0800
commita1adb0777e370103ab9f3e7f8788f74975c69897 (patch)
treedca82cfd0f5fe7b06024c0b2a8fbf4bdeed8103f /apphandler.cpp
parent5bfbde351aabe2096de99ee959a8a2e50edcf84c (diff)
downloadphosphor-host-ipmid-a1adb0777e370103ab9f3e7f8788f74975c69897.tar.gz
phosphor-host-ipmid-a1adb0777e370103ab9f3e7f8788f74975c69897.zip
Get Device ID - JSON
This reads in all the get device ID parameters via a JSON file in the rootfs. Using a file in the rootfs will give much more flexibility to consumers of openbmc. Each ODM can simply bbappend their dev_id.json with their own specific get device ID info in. Now you can compile in the required info at build time, or modify during run time if needed. It also does not require any additional compilers/scripts to generate a yaml file. Change-Id: I44dfda54fa1762f88973ad709bf7a50bf32e492d Signed-off-by: David Cobbley <david.j.cobbley@linux.intel.com>
Diffstat (limited to 'apphandler.cpp')
-rw-r--r--apphandler.cpp128
1 files changed, 69 insertions, 59 deletions
diff --git a/apphandler.cpp b/apphandler.cpp
index 048219e..4b00065 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -3,9 +3,11 @@
#include "app/watchdog.hpp"
#include "host-ipmid/ipmid-api.h"
#include "ipmid.hpp"
+#include "nlohmann/json.hpp"
#include "types.hpp"
#include "utils.hpp"
+#include <fstream>
#include <stdio.h>
#include <stdint.h>
#include <systemd/sd-bus.h>
@@ -59,7 +61,6 @@ ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return rc;
}
-
typedef struct
{
char major;
@@ -164,73 +165,82 @@ ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
char *busname = NULL;
int r;
rev_t rev = {0};
- ipmi_device_id_t dev_id{};
+ static ipmi_device_id_t dev_id{};
+ static bool dev_id_initialized = false;
+ const char* filename = "/usr/share/ipmi-providers/dev_id.json";
// Data length
*data_len = sizeof(dev_id);
- // From IPMI spec, controller that have different application commands, or different
- // definitions of OEM fields, are expected to have different Device ID values.
- // Set to 0 now.
+ if (!dev_id_initialized)
+ {
+ // Firmware revision is already implemented,
+ // so get it from appropriate position.
+ r = mapper_get_service(bus, objname, &busname);
+ if (r < 0) {
+ fprintf(stderr, "Failed to get %s bus name: %s\n",
+ objname, strerror(-r));
+ goto finish;
+ }
+ r = sd_bus_get_property_string(bus,busname,objname,iface,"version",
+ NULL, &ver);
+ if ( r < 0 ) {
+ fprintf(stderr, "Failed to obtain version property: %s\n",
+ strerror(-r));
+ } else {
+ r = convert_version(ver, &rev);
+ if( r >= 0 ) {
+ // bit7 identifies if the device is available
+ // 0=normal operation
+ // 1=device firmware, SDR update,
+ // or self-initialization in progress.
+ // our SDR is normal working condition, so mask:
+ dev_id.fw[0] = 0x7F & rev.major;
+
+ rev.minor = (rev.minor > 99 ? 99 : rev.minor);
+ dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
+ memcpy(&dev_id.aux, rev.d, 4);
+ }
+ }
- // Device Revision is set to 0 now.
- // Bit7 identifies if device provide Device SDRs, obmc don't have SDR,we use ipmi to
- // simulate SDR, hence the value:
- dev_id.revision = 0x80;
+ // IPMI Spec version 2.0
+ dev_id.ipmi_ver = 2;
- // Firmware revision is already implemented, so get it from appropriate position.
- r = mapper_get_service(bus, objname, &busname);
- if (r < 0) {
- fprintf(stderr, "Failed to get %s bus name: %s\n",
- objname, strerror(-r));
- goto finish;
- }
- r = sd_bus_get_property_string(bus,busname,objname,iface,"version", NULL, &ver);
- if ( r < 0 ) {
- fprintf(stderr, "Failed to obtain version property: %s\n", strerror(-r));
- } else {
- r = convert_version(ver, &rev);
- if( r >= 0 ) {
- // bit7 identifies if the device is available, 0=normal operation,
- // 1=device firmware, SDR update or self-initialization in progress.
- // our SDR is normal working condition, so mask:
- dev_id.fw[0] = 0x7F & rev.major;
-
- rev.minor = (rev.minor > 99 ? 99 : rev.minor);
- dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
- memcpy(&dev_id.aux, rev.d, 4);
+ std::ifstream dev_id_file(filename);
+ if (dev_id_file.is_open())
+ {
+ auto data = nlohmann::json::parse(dev_id_file, nullptr, false);
+ if (!data.is_discarded())
+ {
+ dev_id.id = data.value("id", 0);
+ dev_id.revision = data.value("revision", 0);
+ dev_id.addn_dev_support = data.value("addn_dev_support", 0);
+ dev_id.manuf_id[2] = data.value("manuf_id", 0) >> 16;
+ dev_id.manuf_id[1] = data.value("manuf_id", 0) >> 8;
+ dev_id.manuf_id[0] = data.value("manuf_id", 0);
+ dev_id.prod_id[1] = data.value("prod_id", 0) >> 8;
+ dev_id.prod_id[0] = data.value("prod_id", 0);
+ dev_id.aux[3] = data.value("aux", 0) >> 24;
+ dev_id.aux[2] = data.value("aux", 0) >> 16;
+ dev_id.aux[1] = data.value("aux", 0) >> 8;
+ dev_id.aux[0] = data.value("aux", 0);
+
+ //Don't read the file every time if successful
+ dev_id_initialized = true;
+ }
+ else
+ {
+ log<level::ERR>("Device ID JSON parser failure");
+ rc = IPMI_CC_UNSPECIFIED_ERROR;
+ }
+ }
+ else
+ {
+ log<level::ERR>("Device ID file not found");
+ rc = IPMI_CC_UNSPECIFIED_ERROR;
}
}
- // IPMI Spec version 2.0
- dev_id.ipmi_ver = 2;
-
- // Additional device Support.
- // List the 'logical device' commands and functions that the controller supports
- // that are in addition to the mandatory IPM and Application commands.
- // [7] Chassis Device (device functions as chassis device per ICMB spec.)
- // [6] Bridge (device responds to Bridge NetFn commands)
- // [5] IPMB Event Generator
- // [4] IPMB Event Receiver
- // [3] FRU Inventory Device
- // [2] SEL Device
- // [1] SDR Repository Device
- // [0] Sensor Device
- // We support FRU/SEL/Sensor now:
- dev_id.addn_dev_support = 0x8D;
-
- // This value is the IANA number assigned to "IBM Platform Firmware
- // Division", which is also used by our service processor. We may want
- // a different number or at least a different version?
- dev_id.manuf_id[0] = 0x41;
- dev_id.manuf_id[1] = 0xA7;
- dev_id.manuf_id[2] = 0x00;
-
- // Witherspoon's product ID is hardcoded to 4F42(ASCII 'OB').
- // TODO: openbmc/openbmc#495
- dev_id.prod_id[0] = 0x4F;
- dev_id.prod_id[1] = 0x42;
-
// Pack the actual response
memcpy(response, &dev_id, *data_len);
finish:
OpenPOWER on IntegriCloud