summaryrefslogtreecommitdiffstats
path: root/dcmihandler.cpp
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-07-12 19:54:44 +0530
committerPatrick Williams <patrick@stwcx.xyz>2017-07-18 21:21:28 +0000
commitbe5eaa10b211fd3116762fee5e1b86475bed092f (patch)
tree370341e430cc4843764d9aef8d0078759cef16f3 /dcmihandler.cpp
parent10f4959a020f33d40e7387d93fdab9bba46963d7 (diff)
downloadphosphor-host-ipmid-be5eaa10b211fd3116762fee5e1b86475bed092f.tar.gz
phosphor-host-ipmid-be5eaa10b211fd3116762fee5e1b86475bed092f.zip
dcmi: asset-tag: Add API to read asset tag from dbus
Change-Id: I00958d4bb54896ea7d13aaffd7e0ebf3c20ef3de Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'dcmihandler.cpp')
-rw-r--r--dcmihandler.cpp78
1 files changed, 77 insertions, 1 deletions
diff --git a/dcmihandler.cpp b/dcmihandler.cpp
index 19187ba..c7497f0 100644
--- a/dcmihandler.cpp
+++ b/dcmihandler.cpp
@@ -1,8 +1,15 @@
-#include "dcmihandler.h"
+#include "dcmihandler.hpp"
#include "host-ipmid/ipmid-api.h"
+#include <phosphor-logging/elog-errors.hpp>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include "utils.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+using namespace phosphor::logging;
+using InternalFailure =
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
void register_netfn_dcmi_functions() __attribute__((constructor));
@@ -30,6 +37,75 @@ ipmi_ret_t ipmi_dcmi_get_power_limit(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return rc;
}
+namespace dcmi
+{
+
+void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree)
+{
+ static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
+ static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
+ static constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper";
+ static constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory/";
+
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+ auto depth = 0;
+
+ auto mapperCall = bus.new_method_call(mapperBusName,
+ mapperObjPath,
+ mapperIface,
+ "GetSubTree");
+
+ mapperCall.append(inventoryRoot);
+ mapperCall.append(depth);
+ mapperCall.append(std::vector<std::string>({dcmi::assetTagIntf}));
+
+ auto mapperReply = bus.call(mapperCall);
+ if (mapperReply.is_method_error())
+ {
+ log<level::ERR>("Error in mapper call");
+ elog<InternalFailure>();
+ }
+
+ mapperReply.read(objectTree);
+
+ if (objectTree.empty())
+ {
+ log<level::ERR>("AssetTag property is not populated");
+ elog<InternalFailure>();
+ }
+}
+
+std::string readAssetTag()
+{
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+ dcmi::assettag::ObjectTree objectTree;
+
+ // Read the object tree with the inventory root to figure out the object
+ // that has implemented the Asset tag interface.
+ readAssetTagObjectTree(objectTree);
+
+ auto method = bus.new_method_call(
+ (objectTree.begin()->second.begin()->first).c_str(),
+ (objectTree.begin()->first).c_str(),
+ dcmi::propIntf,
+ "Get");
+ method.append(dcmi::assetTagIntf);
+ method.append(dcmi::assetTagProp);
+
+ auto reply = bus.call(method);
+ if (reply.is_method_error())
+ {
+ log<level::ERR>("Error in reading asset tag");
+ elog<InternalFailure>();
+ }
+
+ sdbusplus::message::variant<std::string> assetTag;
+ reply.read(assetTag);
+
+ return assetTag.get<std::string>();
+}
+
+} // namespace dcmi
void register_netfn_dcmi_functions()
{
OpenPOWER on IntegriCloud