diff options
author | anil kumar appana <anil.kumarx.appana@intel.com> | 2019-05-27 18:10:23 +0000 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2020-01-14 16:25:34 +0000 |
commit | 5b7c3266d3f8e49f48f1fed43caed078c8a8af8d (patch) | |
tree | 14c312f8adc6bdca11819baaed6021822ff4d731 | |
parent | c665652df4c6d05f34ae1af49b2e7756629abbe3 (diff) | |
download | phosphor-host-ipmid-5b7c3266d3f8e49f48f1fed43caed078c8a8af8d.tar.gz phosphor-host-ipmid-5b7c3266d3f8e49f48f1fed43caed078c8a8af8d.zip |
storagehandler: move read FRU data to new API
Rewrite "Read FRU Data" command to new IPMI provider API.
Tested:
1. verified Read FRU data is same both before and after the changes
ipmitool raw 0x0a 0x11 0x74 58 00 3 //request
03 32 36 31 //response
Signed-off-by: anil kumar appana <anil.kumarx.appana@intel.com>
Change-Id: I3bd497068462ee97a7b3fe648c3b0727f998bb0b
-rw-r--r-- | storagehandler.cpp | 60 | ||||
-rw-r--r-- | storagehandler.hpp | 20 |
2 files changed, 32 insertions, 48 deletions
diff --git a/storagehandler.cpp b/storagehandler.cpp index 437f858..d2bc8a5 100644 --- a/storagehandler.cpp +++ b/storagehandler.cpp @@ -662,59 +662,62 @@ ipmi::RspType<uint16_t, // FRU Inventory area size in bytes, } } -// Read FRU data -ipmi_ret_t ipmi_storage_read_fru_data(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 Read FRU Data command + * @param fruDeviceId - FRU device ID. FFh = reserved + * @param offset - FRU inventory offset to read + * @param readCount - count to read + * + * @return IPMI completion code plus response data + * - returnCount - response data count. + * - data - response data + */ +ipmi::RspType<uint8_t, // count returned + std::vector<uint8_t>> // FRU data + ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset, + uint8_t readCount) { - ipmi_ret_t rc = IPMI_CC_OK; - const ReadFruDataRequest* reqptr = - reinterpret_cast<const ReadFruDataRequest*>(request); - auto resptr = reinterpret_cast<ReadFruDataResponse*>(response); + if (fruDeviceId == 0xFF) + { + return ipmi::responseInvalidFieldRequest(); + } - auto iter = frus.find(reqptr->fruID); + auto iter = frus.find(fruDeviceId); if (iter == frus.end()) { - *data_len = 0; - return IPMI_CC_SENSOR_INVALID; + return ipmi::responseSensorInvalid(); } - auto offset = - static_cast<uint16_t>(reqptr->offsetMS << 8 | reqptr->offsetLS); try { - const auto& fruArea = getFruAreaData(reqptr->fruID); + const auto& fruArea = getFruAreaData(fruDeviceId); auto size = fruArea.size(); if (offset >= size) { - return IPMI_CC_PARM_OUT_OF_RANGE; + return ipmi::responseParmOutOfRange(); } // Write the count of response data. - if ((offset + reqptr->count) <= size) + uint8_t returnCount; + if ((offset + readCount) <= size) { - resptr->count = reqptr->count; + returnCount = readCount; } else { - resptr->count = size - offset; + returnCount = size - offset; } - std::copy((fruArea.begin() + offset), - (fruArea.begin() + offset + resptr->count), resptr->data); + std::vector<uint8_t> fruData((fruArea.begin() + offset), + (fruArea.begin() + offset + returnCount)); - *data_len = resptr->count + 1; // additional one byte for count + return ipmi::responseSuccess(returnCount, fruData); } catch (const InternalFailure& e) { - rc = IPMI_CC_UNSPECIFIED_ERROR; - *data_len = 0; log<level::ERR>(e.what()); + return ipmi::responseUnspecifiedError(); } - return rc; } ipmi::RspType<uint8_t, // SDR version @@ -789,8 +792,9 @@ void register_netfn_storage_functions() ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); // <READ FRU Data> - ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_READ_FRU_DATA, NULL, - ipmi_storage_read_fru_data, PRIVILEGE_USER); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, + ipmi::storage::cmdReadFruData, + ipmi::Privilege::Operator, ipmiStorageReadFruData); // <Get Repository Info> ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, diff --git a/storagehandler.hpp b/storagehandler.hpp index d093980..6c91905 100644 --- a/storagehandler.hpp +++ b/storagehandler.hpp @@ -21,23 +21,3 @@ enum ipmi_netfn_storage_cmds IPMI_CMD_SET_SEL_TIME = 0x49, }; - -/** - * @struct Read FRU Data command request data - */ -struct ReadFruDataRequest -{ - uint8_t fruID; ///< FRU Device ID. FFh = reserved - uint8_t offsetLS; ///< FRU Inventory Offset to read, LS Byte - uint8_t offsetMS; ///< FRU Inventory Offset ro read, MS Byte - uint8_t count; ///< Count to read -} __attribute__((packed)); - -/** - * @struct Read FRU Data command response data - */ -struct ReadFruDataResponse -{ - uint8_t count; ///< Response data Count. - uint8_t data[]; ///< Response data. -} __attribute__((packed)); |