Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 1 | #pragma once |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 2 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 3 | #include "occ_events.hpp" |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 4 | #include "occ_status.hpp" |
| 5 | #include "utils.hpp" |
| 6 | |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 7 | #include <libpldm/instance-id.h> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 8 | #include <libpldm/pldm.h> |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 9 | #include <libpldm/transport.h> |
Lakshmi Yadlapati | 6213f19 | 2024-07-01 11:50:09 -0500 | [diff] [blame] | 10 | #include <libpldm/transport/af-mctp.h> |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 11 | #include <libpldm/transport/mctp-demux.h> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 12 | |
| 13 | #include <sdbusplus/bus/match.hpp> |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 14 | #include <sdeventplus/event.hpp> |
| 15 | #include <sdeventplus/utility/timer.hpp> |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 16 | |
| 17 | namespace pldm |
| 18 | { |
| 19 | |
| 20 | namespace MatchRules = sdbusplus::bus::match::rules; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 21 | using namespace open_power::occ; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 22 | |
| 23 | using CompositeEffecterCount = uint8_t; |
| 24 | using EffecterID = uint16_t; |
| 25 | using EntityType = uint16_t; |
| 26 | using EntityInstance = uint16_t; |
| 27 | using EventState = uint8_t; |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 28 | using InstanceToEffecter = std::map<open_power::occ::instanceID, EffecterID>; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 29 | using PdrList = std::vector<std::vector<uint8_t>>; |
| 30 | using SensorID = uint16_t; |
| 31 | using SensorOffset = uint8_t; |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 32 | using SensorToInstance = std::map<SensorID, open_power::occ::instanceID>; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 33 | using TerminusID = uint8_t; |
| 34 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 35 | /** @brief OCC instance starts with 0 for example "occ0" */ |
| 36 | constexpr open_power::occ::instanceID start = 0; |
| 37 | |
| 38 | /** @brief Hardcoded mctpEid for HBRT */ |
| 39 | constexpr mctp_eid_t mctpEid = 10; |
| 40 | |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 41 | /** @brief Hardcoded TID */ |
| 42 | constexpr TerminusID tid = mctpEid; |
| 43 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 44 | /** @class Interface |
| 45 | * |
| 46 | * @brief Abstracts the PLDM details related to the OCC |
| 47 | */ |
| 48 | class Interface |
| 49 | { |
| 50 | public: |
| 51 | Interface() = delete; |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 52 | //~Interface() = default; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 53 | Interface(const Interface&) = delete; |
| 54 | Interface& operator=(const Interface&) = delete; |
| 55 | Interface(Interface&&) = delete; |
| 56 | Interface& operator=(Interface&&) = delete; |
| 57 | |
| 58 | /** @brief Constructs the PLDM Interface object for OCC functions |
| 59 | * |
| 60 | * @param[in] callBack - callBack handler to invoke when the OCC state |
| 61 | * changes. |
| 62 | */ |
| 63 | explicit Interface( |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 64 | std::function<bool(open_power::occ::instanceID, bool)> callBack, |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 65 | std::function<void(open_power::occ::instanceID, bool)> sbeCallBack, |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 66 | std::function<void(bool)> safeModeCallBack, EventPtr& event) : |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 67 | callBack(callBack), sbeCallBack(sbeCallBack), |
| 68 | safeModeCallBack(safeModeCallBack), event(event), |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 69 | pldmEventSignal( |
| 70 | open_power::occ::utils::getBus(), |
| 71 | MatchRules::type::signal() + |
| 72 | MatchRules::member("StateSensorEvent") + |
| 73 | MatchRules::path("/xyz/openbmc_project/pldm") + |
| 74 | MatchRules::interface("xyz.openbmc_project.PLDM.Event"), |
| 75 | std::bind(std::mem_fn(&Interface::sensorEvent), this, |
| 76 | std::placeholders::_1)), |
Chris Cain | 157467d | 2022-06-24 11:25:23 -0500 | [diff] [blame] | 77 | hostStateSignal( |
| 78 | open_power::occ::utils::getBus(), |
| 79 | MatchRules::propertiesChanged("/xyz/openbmc_project/state/host0", |
| 80 | "xyz.openbmc_project.State.Host"), |
| 81 | std::bind(std::mem_fn(&Interface::hostStateEvent), this, |
| 82 | std::placeholders::_1)), |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 83 | sdpEvent(sdeventplus::Event::get_default()), |
| 84 | pldmRspTimer( |
| 85 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>( |
| 86 | sdpEvent, std::bind(&Interface::pldmRspExpired, this))) |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 87 | { |
| 88 | int rc = pldm_instance_db_init_default(&pldmInstanceIdDb); |
| 89 | if (rc) |
| 90 | { |
| 91 | throw std::system_category().default_error_condition(rc); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | ~Interface() |
| 96 | { |
| 97 | int rc = pldm_instance_db_destroy(pldmInstanceIdDb); |
| 98 | if (rc) |
| 99 | { |
| 100 | std::cout << "pldm_instance_db_destroy failed, rc =" << rc << "\n"; |
| 101 | } |
| 102 | } |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 103 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 104 | /** @brief Fetch the state sensor PDRs and populate the cache with |
| 105 | * sensorId to OCC/SBE instance mapping information and the sensor |
| 106 | * offset for the relevent state set. |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 107 | * |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 108 | * @param[in] stateSetId - the state set ID to look for |
| 109 | * @param[out] sensorInstanceMap - map of sensorID to instance |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 110 | * @param[out] sensorOffset - sensor offset of interested state set ID |
| 111 | */ |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 112 | void fetchSensorInfo(uint16_t stateSetId, |
| 113 | SensorToInstance& sensorInstanceMap, |
| 114 | SensorOffset& sensorOffset); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 115 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 116 | /** @brief Fetch the OCC/SBE state effecter PDRs and populate the cache |
| 117 | * with OCC/SBE instance to EffecterID information. |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 118 | * |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 119 | * @param[in] stateSetId - the state set ID to look for |
| 120 | * @param[out] instanceToEffecterMap - map of instance to effecterID |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 121 | * @param[out] count - sensor offset of interested state set ID |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 122 | * @param[out] stateIdPos - position of the stateSetID |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 123 | */ |
Eddie James | 432dc48 | 2021-11-19 15:29:31 -0600 | [diff] [blame] | 124 | void fetchEffecterInfo(uint16_t stateSetId, |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 125 | InstanceToEffecter& instanceToEffecterMap, |
| 126 | CompositeEffecterCount& count, uint8_t& stateIdPos); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 127 | |
| 128 | /** @brief Prepare the request for SetStateEffecterStates command |
| 129 | * |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 130 | * @param[in] effecterId - the instance effecter ID |
| 131 | * @param[in] effecterCount - compositeEffecterCount for the effecter PDR |
| 132 | * @param[in] stateIdPos - position of the stateSetID |
| 133 | * @param[in] stateSetValue - the value to set the state set to |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 134 | * |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 135 | * @return PLDM request message to be sent to host for OCC reset or SBE |
| 136 | * HRESET, empty response in the case of failure. |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 137 | */ |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 138 | std::vector<uint8_t> prepareSetEffecterReq( |
| 139 | EffecterID effecterId, CompositeEffecterCount effecterCount, |
| 140 | uint8_t stateIdPos, uint8_t stateSetValue); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 141 | |
| 142 | /** @brief Send the PLDM message to reset the OCC |
| 143 | * |
| 144 | * @param[in] instanceId - OCC instance to reset |
| 145 | * |
| 146 | */ |
| 147 | void resetOCC(open_power::occ::instanceID occInstanceId); |
| 148 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 149 | /** @brief Send the PLDM message to perform the HRESET |
| 150 | * |
| 151 | * @param[in] instanceID - SBE instance to HRESET |
| 152 | */ |
| 153 | void sendHRESET(open_power::occ::instanceID sbeInstanceId); |
| 154 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 155 | /** @brief Check if the OCC active sensor is available |
| 156 | * On successful read, the Manager callback will be called to update |
| 157 | * the status |
| 158 | * |
| 159 | * @param[in] instance - OCC instance to check |
| 160 | */ |
| 161 | void checkActiveSensor(uint8_t instance); |
| 162 | |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 163 | /** @brief Set the throttleTraces flag |
| 164 | * |
| 165 | * @param[in] throttle - Flag to indicate if traces should be throttled |
| 166 | */ |
| 167 | void setTraceThrottle(const bool throttle); |
| 168 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 169 | private: |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 170 | /** @brief PLDM instance ID database object used to get instance IDs |
| 171 | */ |
| 172 | pldm_instance_db* pldmInstanceIdDb = nullptr; |
| 173 | |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 174 | /** @brief PLDM instance number used in PLDM requests |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 175 | */ |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 176 | std::optional<uint8_t> pldmInstanceID; |
Chris Cain | 8b508bf | 2022-05-26 14:01:31 -0500 | [diff] [blame] | 177 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 178 | /** @brief Callback handler to be invoked when the state of the OCC |
| 179 | * changes |
| 180 | */ |
| 181 | std::function<bool(open_power::occ::instanceID, bool)> callBack = nullptr; |
| 182 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 183 | /** @brief Callback handler to be invoked when the maintenance state of the |
| 184 | * SBE changes |
| 185 | */ |
| 186 | std::function<void(open_power::occ::instanceID, bool)> sbeCallBack = |
| 187 | nullptr; |
| 188 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 189 | /** @brief Callback handler to be invoked when the OCC is in SAFE Mode = |
| 190 | * true or when OCCs are in_service = false. |
| 191 | */ |
| 192 | std::function<void(bool)> safeModeCallBack = nullptr; |
| 193 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 194 | /** @brief reference to sd_event wrapped in unique_ptr */ |
| 195 | EventPtr& event; |
| 196 | |
| 197 | /** @brief event source wrapped in unique_ptr */ |
| 198 | EventSourcePtr eventSource; |
| 199 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 200 | /** @brief Used to subscribe to D-Bus PLDM StateSensorEvent signal and |
| 201 | * processes if the event corresponds to OCC state change. |
| 202 | */ |
| 203 | sdbusplus::bus::match_t pldmEventSignal; |
| 204 | |
Chris Cain | 157467d | 2022-06-24 11:25:23 -0500 | [diff] [blame] | 205 | /** @brief Used to subscribe for host state change signal */ |
| 206 | sdbusplus::bus::match_t hostStateSignal; |
| 207 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 208 | /** @brief PLDM Sensor ID to OCC Instance mapping |
| 209 | */ |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 210 | SensorToInstance sensorToOCCInstance; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 211 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 212 | /** @brief PLDM Sensor ID to SBE Instance mapping |
| 213 | */ |
| 214 | SensorToInstance sensorToSBEInstance; |
| 215 | |
| 216 | /** @brief Sensor offset of OCC state set ID |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 217 | * PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS in state sensor PDR. |
| 218 | */ |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 219 | SensorOffset OCCSensorOffset = 0; |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 220 | |
| 221 | /** @brief Sensor offset of the SBE state set ID |
| 222 | * PLDM_OEM_IBM_SBE_HRESET_STATE in state sensor PDR. |
| 223 | */ |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 224 | SensorOffset SBESensorOffset = 0; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 225 | |
| 226 | /** @brief OCC Instance mapping to PLDM Effecter ID |
| 227 | */ |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 228 | InstanceToEffecter occInstanceToEffecter; |
| 229 | |
| 230 | /** @brief SBE instance mapping to PLDM Effecter ID |
| 231 | */ |
| 232 | InstanceToEffecter sbeInstanceToEffecter; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 233 | |
| 234 | /** @brief compositeEffecterCount for OCC reset state effecter PDR */ |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 235 | CompositeEffecterCount OCCEffecterCount = 0; |
| 236 | |
| 237 | /** @brief compositeEffecterCount for SBE HRESET state effecter PDR */ |
| 238 | CompositeEffecterCount SBEEffecterCount = 0; |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 239 | |
| 240 | /** @brief Position of Boot/Restart Cause stateSetID in OCC state |
| 241 | * effecter PDR |
| 242 | */ |
| 243 | uint8_t bootRestartPosition = 0; |
| 244 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 245 | /** @brief Position of the SBE maintenance stateSetID in the state |
| 246 | * effecter PDR |
| 247 | */ |
| 248 | uint8_t sbeMaintenanceStatePosition = 0; |
| 249 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 250 | /** @brief OCC instance number for the PLDM message */ |
| 251 | uint8_t pldmResponseOcc = 0; |
| 252 | |
| 253 | /** @brief File descriptor for PLDM messages */ |
| 254 | int pldmFd = -1; |
| 255 | |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 256 | /** pldm transport instance */ |
| 257 | struct pldm_transport* pldmTransport = NULL; |
| 258 | |
Lakshmi Yadlapati | 6213f19 | 2024-07-01 11:50:09 -0500 | [diff] [blame] | 259 | union TransportImpl |
| 260 | { |
| 261 | struct pldm_transport_mctp_demux* mctpDemux; |
| 262 | struct pldm_transport_af_mctp* afMctp; |
| 263 | }; |
| 264 | |
| 265 | TransportImpl impl; |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 266 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 267 | /** @brief The response for the PLDM request msg is received flag. |
| 268 | */ |
| 269 | bool pldmResponseReceived = false; |
| 270 | |
| 271 | /** @brief The response for the PLDM request has timed out. |
| 272 | */ |
| 273 | bool pldmResponseTimeout = false; |
| 274 | |
| 275 | /** @brief timer event */ |
| 276 | sdeventplus::Event sdpEvent; |
| 277 | |
| 278 | /** @brief Timer that is started when PLDM command is sent |
| 279 | */ |
| 280 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> pldmRspTimer; |
| 281 | |
Chris Cain | 12d0b82 | 2022-04-22 17:29:18 -0500 | [diff] [blame] | 282 | std::set<uint8_t> outstandingHResets; |
| 283 | |
Chris Cain | 755af10 | 2024-02-27 16:09:51 -0600 | [diff] [blame] | 284 | /** @brief Flag to indicate that traces should be throttled. |
| 285 | Used to limit traces when there are issues getting OCC status. |
| 286 | */ |
| 287 | static bool throttleTraces; |
| 288 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 289 | /** @brief Callback when PLDM response has not been received within the |
| 290 | * timeout period. |
| 291 | */ |
| 292 | void pldmRspExpired(); |
| 293 | |
| 294 | /** @brief Close the MCTP file */ |
| 295 | void pldmClose(); |
| 296 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 297 | /** @brief When the OCC state changes host sends PlatformEventMessage |
| 298 | * StateSensorEvent, this function processes the D-Bus signal |
| 299 | * with the sensor event information and invokes the callback |
| 300 | * to change the OCC state. |
| 301 | * |
| 302 | * @param[in] msg - data associated with the subscribed signal |
| 303 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 304 | void sensorEvent(sdbusplus::message_t& msg); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 305 | |
Chris Cain | 157467d | 2022-06-24 11:25:23 -0500 | [diff] [blame] | 306 | /** @brief When the host state changes and if the CurrentHostState is |
| 307 | * xyz.openbmc_project.State.Host.HostState.Off then |
| 308 | * the cache of OCC sensors and effecters mapping is cleared. |
| 309 | * |
| 310 | * @param[in] msg - data associated with the subscribed signal |
| 311 | */ |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 312 | void hostStateEvent(sdbusplus::message_t& msg); |
Chris Cain | 157467d | 2022-06-24 11:25:23 -0500 | [diff] [blame] | 313 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 314 | /** @brief Called when it is determined that the Host is not running. |
| 315 | * The cache of OCC sensors and effecters mapping is cleared. |
| 316 | */ |
| 317 | void clearData(); |
| 318 | |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 319 | /** @brief Check if the PDR cache for PLDM OCC sensors is valid |
| 320 | * |
| 321 | * @return true if cache is populated and false if the cache is not |
| 322 | * populated. |
| 323 | */ |
| 324 | auto isOCCSensorCacheValid() |
| 325 | { |
| 326 | return (sensorToOCCInstance.empty() ? false : true); |
| 327 | } |
| 328 | |
| 329 | /** @brief Check if the PDR cache for PLDM OCC effecters is valid |
| 330 | * |
| 331 | * @return true if cache is populated and false if the cache is not |
| 332 | * populated. |
| 333 | */ |
| 334 | auto isPDREffecterCacheValid() |
| 335 | { |
| 336 | return (occInstanceToEffecter.empty() ? false : true); |
| 337 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 338 | |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 339 | /** @brief Get a PLDM requester instance id |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 340 | * |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 341 | * @return true if the id was found and false if not |
| 342 | */ |
Rashmica Gupta | aeba51c | 2023-02-17 12:30:46 +1100 | [diff] [blame] | 343 | bool getPldmInstanceId(); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 344 | |
Rashmica Gupta | db38e91 | 2023-05-25 10:33:46 +1000 | [diff] [blame] | 345 | /** @brief Free PLDM requester instance id */ |
| 346 | void freePldmInstanceId(); |
| 347 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 348 | /** @brief Encode a GetStateSensor command into a PLDM request |
| 349 | * @param[in] instance - OCC instance number |
| 350 | * @param[in] sensorId - OCC Active sensor ID number |
| 351 | * |
| 352 | * @return request - The encoded PLDM messsage to be sent |
| 353 | */ |
Patrick Williams | d7542c8 | 2024-08-16 15:20:28 -0400 | [diff] [blame] | 354 | std::vector<uint8_t> |
| 355 | encodeGetStateSensorRequest(uint8_t instance, uint16_t sensorId); |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 356 | |
| 357 | /** @brief setup PLDM transport for sending and receiving PLDM messages. |
| 358 | * |
| 359 | * @return true on success, otherwise return false |
| 360 | */ |
| 361 | int pldmOpen(void); |
| 362 | |
| 363 | /** @brief Opens the MCTP socket for sending and receiving messages. |
| 364 | * |
Lakshmi Yadlapati | 6213f19 | 2024-07-01 11:50:09 -0500 | [diff] [blame] | 365 | * @return 0 on success, otherwise returns a negative error code |
Rashmica Gupta | 52328cb | 2023-02-15 10:38:16 +1100 | [diff] [blame] | 366 | */ |
| 367 | int openMctpDemuxTransport(); |
| 368 | |
Lakshmi Yadlapati | 6213f19 | 2024-07-01 11:50:09 -0500 | [diff] [blame] | 369 | /** @brief Opens the MCTP AF_MCTP for sending and receiving messages. |
| 370 | * |
| 371 | * @return 0 on success, otherwise returns a negative error code |
| 372 | */ |
| 373 | int openAfMctpTransport(); |
| 374 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 375 | /** @brief Send the PLDM request |
| 376 | * |
Chris Cain | d1b6826 | 2022-02-28 09:56:50 -0600 | [diff] [blame] | 377 | * @param[in] request - the request data |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 378 | * @param[in] rspExpected - false: no need to wait for the response |
| 379 | * true: will need to process response in callback |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 380 | */ |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 381 | void sendPldm(const std::vector<uint8_t>& request, const uint8_t instance, |
| 382 | const bool rspExpected = false); |
| 383 | |
| 384 | /** @brief Register a callback function to handle the PLDM response */ |
| 385 | void registerPldmRspCallback(); |
| 386 | |
| 387 | /** @brief callback for the PLDM response event |
| 388 | * |
| 389 | * @param[in] es - Populated event source |
| 390 | * @param[in] fd - Associated File descriptor |
| 391 | * @param[in] revents - Type of event |
| 392 | * @param[in] userData - User data that was passed during registration |
| 393 | * |
| 394 | * @return - 0 or positive number on success and negative |
| 395 | * errno otherwise |
| 396 | */ |
| 397 | static int pldmRspCallback(sd_event_source* es, int fd, uint32_t revents, |
| 398 | void* userData); |
Patrick Williams | 05e9559 | 2021-09-02 09:28:14 -0500 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | } // namespace pldm |