blob: f8d261d1c1266903e2417bb05eab7adb5a5b28f1 [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
Varsha Kaverappabb585b22020-09-10 06:15:42 -05002#include "libpldm/platform.h"
3
Sampa Misraaea5dde2020-08-31 08:33:47 -05004#include "inband_code_update.hpp"
5#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05006#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05007#include "libpldmresponder/platform.hpp"
8
9namespace pldm
10{
Sampa Misraaea5dde2020-08-31 08:33:47 -050011namespace responder
12{
Sampa Misraaea5dde2020-08-31 08:33:47 -050013namespace oem_ibm_platform
14{
15
16#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
17#define PLDM_OEM_IBM_BOOT_STATE 32769
18
Sagar Srinivas78a225a2020-08-27 00:52:20 -050019static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
20constexpr uint16_t ENTITY_INSTANCE_0 = 0;
21constexpr uint16_t ENTITY_INSTANCE_1 = 1;
22
Varsha Kaverappabb585b22020-09-10 06:15:42 -050023enum class CodeUpdateState : uint8_t
24{
25 START = 0x1,
26 END = 0x2,
27 FAIL = 0x3,
28 ABORT = 0x4,
29 ACCEPT = 0x5,
30 REJECT = 0x6
31};
32
Sampa Misraaea5dde2020-08-31 08:33:47 -050033class Handler : public oem_platform::Handler
34{
35 public:
36 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050037 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
38 uint8_t mctp_eid, Requester& requester) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050039 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050040 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
41 mctp_eid(mctp_eid), requester(requester)
Sampa Misraaea5dde2020-08-31 08:33:47 -050042 {
43 codeUpdate->setVersions();
44 }
45
46 int getOemStateSensorReadingsHandler(
47 EntityType entityType, EntityInstance entityInstance,
48 StateSetId stateSetId, CompositeCount compSensorCnt,
49 std::vector<get_sensor_state_field>& stateField);
50
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050051 int OemSetStateEffecterStatesHandler(
52 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
53 uint8_t compEffecterCnt,
54 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050055
56 /** @brief Method to set the platform handler in the
57 * oem_ibm_handler class
58 * @param[in] handler - pointer to PLDM platform handler
59 */
60 void setPlatformHandler(pldm::responder::platform::Handler* handler);
61
Sagar Srinivas78a225a2020-08-27 00:52:20 -050062 /** @brief Method to fetch the effecter ID of the code update PDRs
63 *
64 * @return platformHandler->getNextEffecterId() - returns the
65 * effecter ID from the platform handler
66 */
67 uint16_t getNextEffecterId()
68 {
69 return platformHandler->getNextEffecterId();
70 }
71
72 /** @brief Method to fetch the sensor ID of the code update PDRs
73 *
74 * @return platformHandler->getNextSensorId() - returns the
75 * Sensor ID from the platform handler
76 */
77 uint16_t getNextSensorId()
78 {
79 return platformHandler->getNextSensorId();
80 }
81
82 /** @brief Method to Generate the OEM PDRs
83 *
84 * @param[in] repo - instance of concrete implementation of Repo
85 */
86 void buildOEMPDR(pdr_utils::Repo& repo);
87
Varsha Kaverappabb585b22020-09-10 06:15:42 -050088 /** @brief Method to send code update event to host
89 * @param[in] sensorId - sendor ID
90 * @param[in] sensorEventClass - event class of sensor
91 * @param[in] sensorOffset - sensor offset
92 * @param[in] eventState - new code update event state
93 * @param[in] prevEventState - previous code update event state
94 * @return none
95 */
96 void sendStateSensorEvent(uint16_t sensorId,
97 enum sensor_event_class_states sensorEventClass,
98 uint8_t sensorOffset, uint8_t eventState,
99 uint8_t prevEventState);
100
101 /** @brief Method to send encoded request msg of code update event to host
102 * @param[in] requestMsg - encoded request msg
103 * @return PLDM status code
104 */
105 int sendEventToHost(std::vector<uint8_t>& requestMsg);
106
Sampa Misraaea5dde2020-08-31 08:33:47 -0500107 ~Handler() = default;
108
109 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
110 pldm::responder::platform::Handler*
111 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500112
113 /** @brief fd of MCTP communications socket */
114 int mctp_fd;
115
116 /** @brief MCTP EID of host firmware */
117 uint8_t mctp_eid;
118
119 /** @brief reference to Requester object, primarily used to access API to
120 * obtain PLDM instance id.
121 */
122 Requester& requester;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500123};
124
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500125/** @brief Method to encode code update event msg
126 * @param[in] eventType - type of event
127 * @param[in] eventDataVec - vector of event data to be sent to host
128 * @param[in/out] requestMsg - request msg to be encoded
129 * @param[in] instanceId - instance ID
130 * @return PLDM status code
131 */
132int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
133 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
134
Sampa Misraaea5dde2020-08-31 08:33:47 -0500135} // namespace oem_ibm_platform
136
137} // namespace responder
138
139} // namespace pldm