Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 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> |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 14 | #include <string> |
| 15 | #include <tuple> |
| 16 | #include <utility> |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| 19 | namespace pldm |
| 20 | { |
| 21 | namespace platform_mc |
| 22 | { |
| 23 | |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 24 | using SensorId = uint16_t; |
| 25 | using SensorCnt = uint8_t; |
| 26 | using NameLanguageTag = std::string; |
| 27 | using SensorName = std::string; |
| 28 | using SensorAuxiliaryNames = std::tuple< |
| 29 | SensorId, SensorCnt, |
| 30 | std::vector<std::vector<std::pair<NameLanguageTag, SensorName>>>>; |
| 31 | |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 32 | /** |
| 33 | * @brief Terminus |
| 34 | * |
| 35 | * Terminus class holds the TID, supported PLDM Type or PDRs which are needed by |
| 36 | * other manager class for sensor monitoring and control. |
| 37 | */ |
| 38 | class Terminus |
| 39 | { |
| 40 | public: |
| 41 | Terminus(pldm_tid_t tid, uint64_t supportedPLDMTypes); |
| 42 | |
| 43 | /** @brief Check if the terminus supports the PLDM type message |
| 44 | * |
| 45 | * @param[in] type - PLDM Type |
| 46 | * @return support state - True if support, otherwise False |
| 47 | */ |
| 48 | bool doesSupportType(uint8_t type); |
| 49 | |
| 50 | /** @brief Check if the terminus supports the PLDM command message |
| 51 | * |
| 52 | * @param[in] type - PLDM Type |
| 53 | * @param[in] command - PLDM command |
| 54 | * @return support state - True if support, otherwise False |
| 55 | */ |
| 56 | bool doesSupportCommand(uint8_t type, uint8_t command); |
| 57 | |
| 58 | /** @brief Set the supported PLDM commands for terminus |
| 59 | * |
| 60 | * @param[in] cmds - bit mask of the supported PLDM commands |
| 61 | * @return success state - True if success, otherwise False |
| 62 | */ |
| 63 | bool setSupportedCommands(const std::vector<uint8_t>& cmds) |
| 64 | { |
| 65 | const size_t expectedSize = PLDM_MAX_TYPES * |
| 66 | (PLDM_MAX_CMDS_PER_TYPE / 8); |
| 67 | if (cmds.empty() || cmds.size() != expectedSize) |
| 68 | { |
| 69 | lg2::error( |
| 70 | "setSupportedCommands received invalid bit mask size. Expected: {EXPECTED}, Received: {RECEIVED}", |
| 71 | "EXPECTED", expectedSize, "RECEIVED", cmds.size()); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | /* Assign Vector supportedCmds by Vector cmds */ |
| 76 | supportedCmds.resize(cmds.size()); |
| 77 | std::copy(cmds.begin(), cmds.begin() + cmds.size(), |
| 78 | supportedCmds.begin()); |
| 79 | |
| 80 | return true; |
| 81 | } |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 82 | |
| 83 | /** @brief Parse the PDRs stored in the member variable, pdrs. |
| 84 | */ |
| 85 | void parseTerminusPDRs(); |
| 86 | |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 87 | /** @brief The getter to return terminus's TID */ |
| 88 | pldm_tid_t getTid() |
| 89 | { |
| 90 | return tid; |
| 91 | } |
| 92 | |
| 93 | /** @brief A list of PDRs fetched from Terminus */ |
| 94 | std::vector<std::vector<uint8_t>> pdrs{}; |
| 95 | |
| 96 | /** @brief A flag to indicate if terminus has been initialized */ |
| 97 | bool initialized = false; |
| 98 | |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 99 | /** @brief Get Sensor Auxiliary Names by sensorID |
| 100 | * |
| 101 | * @param[in] id - sensor ID |
| 102 | * @return sensor auxiliary names |
| 103 | */ |
| 104 | std::shared_ptr<SensorAuxiliaryNames> getSensorAuxiliaryNames(SensorId id); |
| 105 | |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 106 | private: |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 107 | /** @brief Parse the numeric sensor PDRs |
| 108 | * |
| 109 | * @param[in] pdrData - the response PDRs from GetPDR command |
| 110 | * @return pointer to numeric sensor info struct |
| 111 | */ |
| 112 | std::shared_ptr<pldm_numeric_sensor_value_pdr> |
| 113 | parseNumericSensorPDR(const std::vector<uint8_t>& pdrData); |
| 114 | |
| 115 | /** @brief Parse the sensor Auxiliary name PDRs |
| 116 | * |
| 117 | * @param[in] pdrData - the response PDRs from GetPDR command |
| 118 | * @return pointer to sensor Auxiliary name info struct |
| 119 | */ |
| 120 | std::shared_ptr<SensorAuxiliaryNames> |
| 121 | parseSensorAuxiliaryNamesPDR(const std::vector<uint8_t>& pdrData); |
| 122 | |
| 123 | /** @brief Parse the compact numeric sensor PDRs |
| 124 | * |
| 125 | * @param[in] pdrData - the response PDRs from GetPDR command |
| 126 | * @return pointer to compact numeric sensor info struct |
| 127 | */ |
| 128 | std::shared_ptr<pldm_compact_numeric_sensor_pdr> |
| 129 | parseCompactNumericSensorPDR(const std::vector<uint8_t>& pdrData); |
| 130 | |
| 131 | /** @brief Parse the sensor Auxiliary name from compact numeric sensor PDRs |
| 132 | * |
| 133 | * @param[in] pdrData - the response PDRs from GetPDR command |
| 134 | * @return pointer to sensor Auxiliary name info struct |
| 135 | */ |
| 136 | std::shared_ptr<SensorAuxiliaryNames> |
| 137 | parseCompactNumericSensorNames(const std::vector<uint8_t>& pdrData); |
| 138 | |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 139 | /* @brief The terminus's TID */ |
| 140 | pldm_tid_t tid; |
| 141 | |
| 142 | /* @brief The supported PLDM command types of the terminus */ |
| 143 | std::bitset<64> supportedTypes; |
| 144 | |
| 145 | /** @brief Store supported PLDM commands of a terminus |
| 146 | * Maximum number of PLDM Type is PLDM_MAX_TYPES |
| 147 | * Maximum number of PLDM command for each type is |
| 148 | * PLDM_MAX_CMDS_PER_TYPE. |
| 149 | * Each uint8_t can store the supported state of 8 PLDM commands. |
| 150 | * Size of supportedCmds will be |
| 151 | * PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8). |
| 152 | */ |
| 153 | std::vector<uint8_t> supportedCmds; |
Gilbert Chen | de2a132 | 2022-05-24 15:35:21 +0100 | [diff] [blame^] | 154 | |
| 155 | /* @brief Sensor Auxiliary Name list */ |
| 156 | std::vector<std::shared_ptr<SensorAuxiliaryNames>> |
| 157 | sensorAuxiliaryNamesTbl{}; |
Gilbert Chen | 6c7fed4 | 2022-02-22 15:40:17 +0000 | [diff] [blame] | 158 | }; |
| 159 | } // namespace platform_mc |
| 160 | } // namespace pldm |