diff options
author | jayaprakash Mutyala <mutyalax.jayaprakash@intel.com> | 2019-05-03 01:38:01 +0000 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-05-28 17:47:38 +0000 |
commit | db2e8c45727ba98e26778b8c754b92e093e6921c (patch) | |
tree | 05d55aec086f08bd4dce34bc7cf2f6a52662188e /storagehandler.cpp | |
parent | f4e385155ec28c45c70742e19b00cb515ae76783 (diff) | |
download | phosphor-host-ipmid-db2e8c45727ba98e26778b8c754b92e093e6921c.tar.gz phosphor-host-ipmid-db2e8c45727ba98e26778b8c754b92e093e6921c.zip |
storagehandler: move get & set SEL time to new API
Rewrite "Get & Set SEL time" command to use the newly
introduced IPMI provider API.
Tested:
Verified using ipmitool sel time get/set behavior before and
after the changes.
Change-Id: I856ac92356e4472a67bf0e354fff6c3e2ced0cdb
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Diffstat (limited to 'storagehandler.cpp')
-rw-r--r-- | storagehandler.cpp | 87 |
1 files changed, 30 insertions, 57 deletions
diff --git a/storagehandler.cpp b/storagehandler.cpp index 88a0aa1..3923621 100644 --- a/storagehandler.cpp +++ b/storagehandler.cpp @@ -37,13 +37,6 @@ constexpr auto HOST_TIME_PATH = "/xyz/openbmc_project/time/host"; constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; constexpr auto PROPERTY_ELAPSED = "Elapsed"; -const char* getTimeString(const uint64_t& usecSinceEpoch) -{ - using namespace std::chrono; - system_clock::time_point tp{microseconds(usecSinceEpoch)}; - auto t = system_clock::to_time_t(tp); - return std::ctime(&t); -} } // namespace namespace cache @@ -467,21 +460,15 @@ ipmi::RspType<uint8_t // erase status static_cast<uint8_t>(ipmi::sel::eraseComplete)); } -ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, - ipmi_response_t response, - ipmi_data_len_t data_len, - ipmi_context_t context) +/** @brief implements the get SEL time command + * @returns IPMI completion code plus response data + * -current time + */ +ipmi::RspType<uint32_t> // current time + ipmiStorageGetSelTime() { - if (*data_len != 0) - { - *data_len = 0; - return IPMI_CC_REQ_DATA_LEN_INVALID; - } - using namespace std::chrono; uint64_t host_time_usec = 0; - uint32_t resp = 0; std::stringstream hostTime; try @@ -501,7 +488,7 @@ ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, log<level::ERR>("Error getting time", entry("SERVICE=%s", service.c_str()), entry("PATH=%s", HOST_TIME_PATH)); - return IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } reply.read(value); host_time_usec = std::get<uint64_t>(value); @@ -509,50 +496,34 @@ ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, catch (InternalFailure& e) { log<level::ERR>(e.what()); - return IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } catch (const std::runtime_error& e) { log<level::ERR>(e.what()); - return IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } - hostTime << "Host time:" << getTimeString(host_time_usec); + hostTime << "Host time:" + << duration_cast<seconds>(microseconds(host_time_usec)).count(); log<level::DEBUG>(hostTime.str().c_str()); // Time is really long int but IPMI wants just uint32. This works okay until // the number of seconds since 1970 overflows uint32 size.. Still a whole // lot of time here to even think about that. - resp = duration_cast<seconds>(microseconds(host_time_usec)).count(); - resp = htole32(resp); - - // From the IPMI Spec 2.0, response should be a 32-bit value - *data_len = sizeof(resp); - - // Pack the actual response - std::memcpy(response, &resp, *data_len); - - return IPMI_CC_OK; + return ipmi::responseSuccess( + duration_cast<seconds>(microseconds(host_time_usec)).count()); } -ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, - ipmi_response_t response, - ipmi_data_len_t data_len, - ipmi_context_t context) +/** @brief implements the set SEL time command + * @param selDeviceTime - epoch time + * -local time as the number of seconds from 00:00:00, January 1, 1970 + * @returns IPMI completion code + */ +ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime) { - if (*data_len != sizeof(uint32_t)) - { - *data_len = 0; - return IPMI_CC_REQ_DATA_LEN_INVALID; - } using namespace std::chrono; - ipmi_ret_t rc = IPMI_CC_OK; - uint32_t secs = *static_cast<uint32_t*>(request); - *data_len = 0; - - secs = le32toh(secs); - microseconds usec{seconds(secs)}; + microseconds usec{seconds(selDeviceTime)}; try { @@ -571,21 +542,21 @@ ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, log<level::ERR>("Error setting time", entry("SERVICE=%s", service.c_str()), entry("PATH=%s", HOST_TIME_PATH)); - rc = IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } } catch (InternalFailure& e) { log<level::ERR>(e.what()); - rc = IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } catch (const std::runtime_error& e) { log<level::ERR>(e.what()); - rc = IPMI_CC_UNSPECIFIED_ERROR; + return ipmi::responseUnspecifiedError(); } - return rc; + return ipmi::responseSuccess(); } ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, @@ -773,12 +744,14 @@ void register_netfn_storage_functions() getSELInfo, PRIVILEGE_USER); // <Get SEL Time> - ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, - ipmi_storage_get_sel_time, PRIVILEGE_USER); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, + ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, + ipmiStorageGetSelTime); // <Set SEL Time> - ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, - ipmi_storage_set_sel_time, PRIVILEGE_OPERATOR); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, + ipmi::storage::cmdSetSelTime, + ipmi::Privilege::Operator, ipmiStorageSetSelTime); // <Reserve SEL> ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, |