Skip to content

Commit

Permalink
Merge pull request ibm-openbmc#18 from jaypadath/cod_license_support
Browse files Browse the repository at this point in the history
Cod license support
  • Loading branch information
rfrandse authored Sep 29, 2021
2 parents ff1a489 + 69f6344 commit fa0bf01
Show file tree
Hide file tree
Showing 23 changed files with 1,368 additions and 7 deletions.
35 changes: 35 additions & 0 deletions host-bmc/custom_dbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,40 @@ void CustomDBus::implementObjectEnableIface(const std::string& path)
}
}

void CustomDBus::implementLicInterfaces(
const std::string& path, const uint32_t& authdevno, const std::string& name,
const std::string& serialno, const uint64_t& exptime,
const sdbusplus::com::ibm::License::Entry::server::LicenseEntry::Type& type,
const sdbusplus::com::ibm::License::Entry::server::LicenseEntry::
AuthorizationType& authtype)
{
if (codLic.find(path) == codLic.end())
{
codLic.emplace(
path, std::make_unique<LicIntf>(pldm::utils::DBusHandler::getBus(),
path.c_str()));
}

codLic.at(path)->authDeviceNumber(authdevno);
codLic.at(path)->name(name);
codLic.at(path)->serialNumber(serialno);
codLic.at(path)->expirationTime(exptime);
codLic.at(path)->type(type);
codLic.at(path)->authorizationType(authtype);
}

void CustomDBus::setAvailabilityState(const std::string& path,
const bool& state)
{
if (availabilityState.find(path) == availabilityState.end())
{
availabilityState.emplace(
path, std::make_unique<AvailabilityIntf>(
pldm::utils::DBusHandler::getBus(), path.c_str()));
}

availabilityState.at(path)->available(state);
}

} // namespace dbus
} // namespace pldm
45 changes: 45 additions & 0 deletions host-bmc/custom_dbus.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include "com/ibm/License/Entry/LicenseEntry/server.hpp"
#include "common/utils.hpp"

#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
#include <xyz/openbmc_project/Inventory/Item/CpuCore/server.hpp>
#include <xyz/openbmc_project/Inventory/Item/server.hpp>
#include <xyz/openbmc_project/Object/Enable/server.hpp>
#include <xyz/openbmc_project/State/Decorator/Availability/server.hpp>
#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>

#include <map>
Expand All @@ -32,6 +34,10 @@ using CoreIntf = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Inventory::Item::server::CpuCore>;
using EnableIface = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Object::server::Enable>;
using LicIntf = sdbusplus::server::object::object<
sdbusplus::com::ibm::License::Entry::server::LicenseEntry>;
using AvailabilityIntf = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::State::Decorator::server::Availability>;

/** @class CustomDBus
* @brief This is a custom D-Bus object, used to add D-Bus interface and
Expand Down Expand Up @@ -113,14 +119,53 @@ class CustomDBus
*/
void implementObjectEnableIface(const std::string& path);

/** @brief Implement the license interface properties
*
* @param[in] path - The object path
*
* @param[in] authdevno - License name
*
* @param[in] name - License name
*
* @param[in] serialno - License serial number
*
* @param[in] exptime - License expiration time
*
* @param[in] type - License type
*
* @param[in] authtype - License authorization type
*
* @note This API implements the following interface
* com.ibm.License.Entry.LicenseEntry and associated
* dbus properties.
*/
void implementLicInterfaces(
const std::string& path, const uint32_t& authdevno,
const std::string& name, const std::string& serialno,
const uint64_t& exptime,
const sdbusplus::com::ibm::License::Entry::server::LicenseEntry::Type&
type,
const sdbusplus::com::ibm::License::Entry::server::LicenseEntry::
AuthorizationType& authtype);

/** @brief Set the availability state property
*
* @param[in] path - The object path
*
* @param[in] state - Availability state
*/
void setAvailabilityState(const std::string& path, const bool& state);

private:
std::map<ObjectPath, std::unique_ptr<LocationIntf>> location;

std::map<ObjectPath, std::unique_ptr<OperationalStatusIntf>>
operationalStatus;
std::map<ObjectPath, std::unique_ptr<AvailabilityIntf>> availabilityState;

std::unordered_map<ObjectPath, std::unique_ptr<ItemIntf>> presentStatus;
std::unordered_map<ObjectPath, std::unique_ptr<CoreIntf>> cpuCore;
std::unordered_map<ObjectPath, std::unique_ptr<LicIntf>> codLic;

/** @brief Used to hold the objects which will contain EnableIface */
std::unordered_map<ObjectPath, std::unique_ptr<EnableIface>> _enabledStatus;
Expand Down
1 change: 1 addition & 0 deletions libpldmresponder/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if get_option('oem-ibm').enabled()
'../oem/ibm/libpldmresponder/collect_slot_vpd.cpp',
'../oem/ibm/requester/dbus_to_file_handler.cpp',
'../oem/ibm/libpldmresponder/file_io_type_progress_src.cpp',
'../oem/ibm/libpldmresponder/file_io_type_lic.cpp',
]
endif

Expand Down
103 changes: 103 additions & 0 deletions oem/ibm/libpldm/file_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,106 @@ int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,

return PLDM_SUCCESS;
}

int encode_file_ack_with_meta_data_req(
uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
uint8_t file_status, uint32_t file_meta_data_1, uint32_t file_meta_data_2,
uint32_t file_meta_data_3, uint32_t file_meta_data_4, struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}

struct pldm_header_info header = {0};
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_FILE_ACK_WITH_META_DATA;
uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
if (rc != PLDM_SUCCESS) {
return rc;
}

struct pldm_file_ack_with_meta_data_req *req =
(struct pldm_file_ack_with_meta_data_req *)msg->payload;
req->file_type = htole16(file_type);
req->file_handle = htole32(file_handle);
req->file_status = file_status;
req->file_meta_data_1 = htole32(file_meta_data_1);
req->file_meta_data_2 = htole32(file_meta_data_2);
req->file_meta_data_3 = htole32(file_meta_data_3);
req->file_meta_data_4 = htole32(file_meta_data_4);

return PLDM_SUCCESS;
}

int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg,
size_t payload_length,
uint8_t *completion_code)
{
if (msg == NULL || completion_code == NULL) {
return PLDM_ERROR_INVALID_DATA;
}

if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}

struct pldm_file_ack_with_meta_data_resp *response =
(struct pldm_file_ack_with_meta_data_resp *)msg->payload;
*completion_code = response->completion_code;

return PLDM_SUCCESS;
}

int decode_file_ack_with_meta_data_req(
const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1,
uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
uint32_t *file_meta_data_4)
{
if (msg == NULL || file_type == NULL || file_handle == NULL) {
return PLDM_ERROR_INVALID_DATA;
}

if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}

struct pldm_file_ack_with_meta_data_req *request =
(struct pldm_file_ack_with_meta_data_req *)msg->payload;
*file_type = le16toh(request->file_type);
*file_handle = le32toh(request->file_handle);
*file_status = request->file_status;
*file_meta_data_1 = le32toh(request->file_meta_data_1);
*file_meta_data_2 = le32toh(request->file_meta_data_2);
*file_meta_data_3 = le32toh(request->file_meta_data_3);
*file_meta_data_4 = le32toh(request->file_meta_data_4);

return PLDM_SUCCESS;
}

int encode_file_ack_with_meta_data_resp(uint8_t instance_id,
uint8_t completion_code,
struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
}

struct pldm_header_info header = {0};
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_OEM;
header.command = PLDM_FILE_ACK_WITH_META_DATA;
uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
if (rc != PLDM_SUCCESS) {
return rc;
}

struct pldm_file_ack_with_meta_data_resp *response =
(struct pldm_file_ack_with_meta_data_resp *)msg->payload;
response->completion_code = completion_code;

return PLDM_SUCCESS;
}
91 changes: 91 additions & 0 deletions oem/ibm/libpldm/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum pldm_fileio_commands {
PLDM_READ_FILE_BY_TYPE = 0xB,
PLDM_WRITE_FILE_BY_TYPE = 0xC,
PLDM_FILE_ACK = 0xD,
PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA = 0xE,
PLDM_FILE_ACK_WITH_META_DATA = 0xF,
};

/** @brief PLDM Command specific codes
Expand Down Expand Up @@ -57,6 +59,10 @@ enum pldm_fileio_file_type {
PLDM_FILE_TYPE_RESOURCE_DUMP_PARMS = 0x8,
PLDM_FILE_TYPE_RESOURCE_DUMP = 0x9,
PLDM_FILE_TYPE_PROGRESS_SRC = 0xA,
PLDM_FILE_TYPE_ADJUNCT_DUMP = 0xB,
PLDM_FILE_TYPE_DEVICE_DUMP = 0xC,
PLDM_FILE_TYPE_COD_LICENSE_KEY = 0xD,
PLDM_FILE_TYPE_COD_LICENSED_RESOURCES = 0xE,
};

#define PLDM_RW_FILE_MEM_REQ_BYTES 20
Expand All @@ -75,6 +81,8 @@ enum pldm_fileio_file_type {
#define PLDM_RW_FILE_BY_TYPE_RESP_BYTES 5
#define PLDM_FILE_ACK_REQ_BYTES 7
#define PLDM_FILE_ACK_RESP_BYTES 1
#define PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES 26
#define PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES 1

/** @struct pldm_read_write_file_memory_req
*
Expand Down Expand Up @@ -718,6 +726,89 @@ int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
uint8_t *completion_code);

/* FileAckWithMetadata */

/** @struct pldm_file_ack_with_meta_data_req
*
* Structure representing FileAckWithMetadata request
*/
struct pldm_file_ack_with_meta_data_req {
uint16_t file_type; //!< Type of file
uint32_t file_handle; //!< Handle to file
uint8_t file_status; //!< Status of file processing
uint32_t file_meta_data_1; //!< Meta data specific to file type 1
uint32_t file_meta_data_2; //!< Meta data specific to file type 2
uint32_t file_meta_data_3; //!< Meta data specific to file type 3
uint32_t file_meta_data_4; //!< meta data specific to file type 4
} __attribute__((packed));

/** @struct pldm_file_ack_with_meta_data_resp
*
* Structure representing FileAckWithMetadata response
*/
struct pldm_file_ack_with_meta_data_resp {
uint8_t completion_code; //!< Completion code
} __attribute__((packed));

/** @brief Encode FileAckWithMetadata request data
*
* @param[in] instance_id - Message's instance id
* @param[in] file_type - Type of the file
* @param[in] file_handle - A handle to the file
* @param[in] file_status - Status of file processing
* @param[in] file_meta_data_1 - meta data specific to file type 1
* @param[in] file_meta_data_2 - meta data specific to file type 2
* @param[in] file_meta_data_3 - meta data specific to file type 3
* @param[in] file_meta_data_4 - Meta data specific to file type 4
* @param[out] msg - Message will be written to this
* @return pldm_completion_codes
*/
int encode_file_ack_with_meta_data_req(
uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
uint8_t file_status, uint32_t file_meta_data_1, uint32_t file_meta_data_2,
uint32_t file_meta_data_3, uint32_t file_meta_data_4, struct pldm_msg *msg);

/** @brief Decode FileAckWithMetadata command response data
*
* @param[in] msg - pointer to PLDM response message
* @param[in] payload_length - Length of response payload
* @param[out] completion_code - PLDM completion code
* @return pldm_completion_codes
*/
int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg,
size_t payload_length,
uint8_t *completion_code);

/** @brief Decode FileAckWithMetadata request data
*
* @param[in] msg - Pointer to PLDM request message
* @param[in] payload_length - Length of request payload
* @param[out] file_type - Type of the file
* @param[out] file_handle - A handle to the file
* @param[out] file_status - Status of file processing
* @param[out] file_meta_data_1 - meta data specific to file type 1
* @param[out] file_meta_data_2 - meta data specific to file type 2
* @param[out] file_meta_data_3 - meta data specific to file type 3
* @param[out] file_meta_data_4 - Meta data specific to file type 4
* @return pldm_completion_codes
*/
int decode_file_ack_with_meta_data_req(
const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1,
uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
uint32_t *file_meta_data_4);

/** @brief Create a PLDM response message for FileAckWithMetadata
*
* @param[in] instance_id - Message's instance id
* @param[in] completion_code - PLDM completion code
* @param[in,out] msg - Message will be written to this
* @return pldm_completion_codes
*/
int encode_file_ack_with_meta_data_resp(uint8_t instance_id,
uint8_t completion_code,
struct pldm_msg *msg);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit fa0bf01

Please sign in to comment.