1 #pragma once 2 3 #include "libpldm/platform.h" 4 5 #include "common/types.hpp" 6 #include "requester/handler.hpp" 7 8 #include <sdbusplus/server/object.hpp> 9 #include <sdeventplus/event.hpp> 10 #include <xyz/openbmc_project/Inventory/Item/Board/server.hpp> 11 12 #include <algorithm> 13 #include <bitset> 14 #include <vector> 15 16 namespace pldm 17 { 18 namespace platform_mc 19 { 20 21 /** 22 * @brief Terminus 23 * 24 * Terminus class holds the TID, supported PLDM Type or PDRs which are needed by 25 * other manager class for sensor monitoring and control. 26 */ 27 class Terminus 28 { 29 public: 30 Terminus(pldm_tid_t tid, uint64_t supportedPLDMTypes); 31 32 /** @brief Check if the terminus supports the PLDM type message 33 * 34 * @param[in] type - PLDM Type 35 * @return support state - True if support, otherwise False 36 */ 37 bool doesSupportType(uint8_t type); 38 39 /** @brief Check if the terminus supports the PLDM command message 40 * 41 * @param[in] type - PLDM Type 42 * @param[in] command - PLDM command 43 * @return support state - True if support, otherwise False 44 */ 45 bool doesSupportCommand(uint8_t type, uint8_t command); 46 47 /** @brief Set the supported PLDM commands for terminus 48 * 49 * @param[in] cmds - bit mask of the supported PLDM commands 50 * @return success state - True if success, otherwise False 51 */ setSupportedCommands(const std::vector<uint8_t> & cmds)52 bool setSupportedCommands(const std::vector<uint8_t>& cmds) 53 { 54 const size_t expectedSize = PLDM_MAX_TYPES * 55 (PLDM_MAX_CMDS_PER_TYPE / 8); 56 if (cmds.empty() || cmds.size() != expectedSize) 57 { 58 lg2::error( 59 "setSupportedCommands received invalid bit mask size. Expected: {EXPECTED}, Received: {RECEIVED}", 60 "EXPECTED", expectedSize, "RECEIVED", cmds.size()); 61 return false; 62 } 63 64 /* Assign Vector supportedCmds by Vector cmds */ 65 supportedCmds.resize(cmds.size()); 66 std::copy(cmds.begin(), cmds.begin() + cmds.size(), 67 supportedCmds.begin()); 68 69 return true; 70 } 71 /** @brief The getter to return terminus's TID */ getTid()72 pldm_tid_t getTid() 73 { 74 return tid; 75 } 76 77 /** @brief A list of PDRs fetched from Terminus */ 78 std::vector<std::vector<uint8_t>> pdrs{}; 79 80 /** @brief A flag to indicate if terminus has been initialized */ 81 bool initialized = false; 82 83 private: 84 /* @brief The terminus's TID */ 85 pldm_tid_t tid; 86 87 /* @brief The supported PLDM command types of the terminus */ 88 std::bitset<64> supportedTypes; 89 90 /** @brief Store supported PLDM commands of a terminus 91 * Maximum number of PLDM Type is PLDM_MAX_TYPES 92 * Maximum number of PLDM command for each type is 93 * PLDM_MAX_CMDS_PER_TYPE. 94 * Each uint8_t can store the supported state of 8 PLDM commands. 95 * Size of supportedCmds will be 96 * PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8). 97 */ 98 std::vector<uint8_t> supportedCmds; 99 }; 100 } // namespace platform_mc 101 } // namespace pldm 102