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