diff options
author | jayaprakash Mutyala <mutyalax.jayaprakash@intel.com> | 2019-05-13 20:22:50 +0000 |
---|---|---|
committer | jayaprakash Mutyala <mutyalax.jayaprakash@intel.com> | 2019-07-30 00:06:30 +0000 |
commit | d957823e99cd30067818ceb2a32ef110a26aef35 (patch) | |
tree | 5bc3454ca10f6442fe051643dd95775e6a3011f6 /sensorhandler.cpp | |
parent | 894d022017215acceafc9e3f21379534f5396d21 (diff) | |
download | phosphor-host-ipmid-d957823e99cd30067818ceb2a32ef110a26aef35.tar.gz phosphor-host-ipmid-d957823e99cd30067818ceb2a32ef110a26aef35.zip |
Sensorhandler: move get SDR info & reserve SDR to new API
Rewrite "Get SDR info and Reserve SDR" command to
use the newly introduced IPMI provider API.
Tested:
verified using ipmitool sensor commands.
a. get SDR info
Command: ipmitool raw 0x04 0x20 0x01
Output: 02 01
Command: ipmitool raw 0x04 0x20 0x00
Output: 00 01
b. reserve sdr
Command: ipmitool raw 0x04 0x22
Output: 01 00
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Change-Id: Id1d7015cec45c5524210033e4210c710da27e9ae
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Diffstat (limited to 'sensorhandler.cpp')
-rw-r--r-- | sensorhandler.cpp | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp index 4c0fe01..f649ce7 100644 --- a/sensorhandler.cpp +++ b/sensorhandler.cpp @@ -552,50 +552,52 @@ ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return rc; } -ipmi_ret_t ipmi_sen_get_sdr_info(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 SDR Info command + * @param count - Operation + * + * @returns IPMI completion code plus response data + * - sdrCount - sensor/SDR count + * - lunsAndDynamicPopulation - static/Dynamic sensor population flag + */ +ipmi::RspType<uint8_t, // respcount + uint8_t // dynamic population flags + > + ipmiSensorGetDeviceSdrInfo(std::optional<uint8_t> count) { - auto resp = static_cast<get_sdr_info::GetSdrInfoResp*>(response); - if (request == nullptr || - get_sdr_info::request::get_count(request) == false) + uint8_t sdrCount; + // multiple LUNs not supported. + constexpr uint8_t lunsAndDynamicPopulation = 1; + constexpr uint8_t getSdrCount = 0x01; + constexpr uint8_t getSensorCount = 0x00; + + if (count.value_or(0) == getSdrCount) + { + // Get SDR count. This returns the total number of SDRs in the device. + sdrCount = sensors.size() + frus.size() + entities.size(); + } + else if (count.value_or(0) == getSensorCount) { - // Get Sensor Count - resp->count = sensors.size() + frus.size() + entities.size(); + // Get Sensor count. This returns the number of sensors + sdrCount = sensors.size(); } else { - resp->count = 1; + return ipmi::responseInvalidCommandOnLun(); } - // Multiple LUNs not supported. - namespace response = get_sdr_info::response; - response::set_lun_present(0, &(resp->luns_and_dynamic_population)); - response::set_lun_not_present(1, &(resp->luns_and_dynamic_population)); - response::set_lun_not_present(2, &(resp->luns_and_dynamic_population)); - response::set_lun_not_present(3, &(resp->luns_and_dynamic_population)); - response::set_static_population(&(resp->luns_and_dynamic_population)); - - *data_len = SDR_INFO_RESP_SIZE; - - return IPMI_CC_OK; + return ipmi::responseSuccess(sdrCount, lunsAndDynamicPopulation); } -ipmi_ret_t ipmi_sen_reserve_sdr(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 reserve SDR command + * @returns IPMI completion code plus response data + * - reservationID - reservation ID + */ +ipmi::RspType<uint16_t> ipmiSensorReserveSdr() { // A constant reservation ID is okay until we implement add/remove SDR. - const uint16_t reservation_id = 1; - *(uint16_t*)response = reservation_id; - *data_len = sizeof(uint16_t); + constexpr uint16_t reservationID = 1; - printf("Created new IPMI SDR reservation ID %d\n", *(uint16_t*)response); - return IPMI_CC_OK; + return ipmi::responseSuccess(reservationID); } void setUnitFieldsForObject(const ipmi::sensor::Info* info, @@ -1055,12 +1057,14 @@ void register_netfn_sen_functions() ipmi_sen_get_sensor_reading, PRIVILEGE_USER); // <Reserve Device SDR Repository> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_DEVICE_SDR_REPO, - nullptr, ipmi_sen_reserve_sdr, PRIVILEGE_USER); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor, + ipmi::sensor_event::cmdReserveDeviceSdrRepository, + ipmi::Privilege::User, ipmiSensorReserveSdr); // <Get Device SDR Info> - ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR_INFO, nullptr, - ipmi_sen_get_sdr_info, PRIVILEGE_USER); + ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor, + ipmi::sensor_event::cmdGetDeviceSdrInfo, + ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo); // <Get Device SDR> ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, nullptr, |