blob: bacc3f0e15abb970cd8067a3854d84f5fe163b67 [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
2
Varsha Kaverappabb585b22020-09-10 06:15:42 -05003#include "libpldm/platform.h"
4
Sampa Misraaea5dde2020-08-31 08:33:47 -05005#include "inband_code_update.hpp"
6#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05007#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05008#include "libpldmresponder/platform.hpp"
9
10namespace pldm
11{
Sampa Misraaea5dde2020-08-31 08:33:47 -050012namespace responder
13{
Sampa Misraaea5dde2020-08-31 08:33:47 -050014namespace oem_ibm_platform
15{
16
17#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
18#define PLDM_OEM_IBM_BOOT_STATE 32769
19
Sagar Srinivas78a225a2020-08-27 00:52:20 -050020static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
21constexpr uint16_t ENTITY_INSTANCE_0 = 0;
22constexpr uint16_t ENTITY_INSTANCE_1 = 1;
23
Varsha Kaverappabb585b22020-09-10 06:15:42 -050024enum class CodeUpdateState : uint8_t
25{
26 START = 0x1,
27 END = 0x2,
28 FAIL = 0x3,
29 ABORT = 0x4,
30 ACCEPT = 0x5,
31 REJECT = 0x6
32};
33
Sampa Misraaea5dde2020-08-31 08:33:47 -050034class Handler : public oem_platform::Handler
35{
36 public:
37 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050038 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
39 uint8_t mctp_eid, Requester& requester) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050040 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050041 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
42 mctp_eid(mctp_eid), requester(requester)
Sampa Misraaea5dde2020-08-31 08:33:47 -050043 {
44 codeUpdate->setVersions();
45 }
46
47 int getOemStateSensorReadingsHandler(
48 EntityType entityType, EntityInstance entityInstance,
49 StateSetId stateSetId, CompositeCount compSensorCnt,
50 std::vector<get_sensor_state_field>& stateField);
51
52 int oemSetStateEffecterStatesHandler(
53 EntityType entityType, EntityInstance entityInstance,
54 StateSetId stateSetId, CompositeCount compEffecterCnt,
55 const std::vector<set_effecter_state_field>& stateField);
56
57 /** @brief Method to set the platform handler in the
58 * oem_ibm_handler class
59 * @param[in] handler - pointer to PLDM platform handler
60 */
61 void setPlatformHandler(pldm::responder::platform::Handler* handler);
62
Sagar Srinivas78a225a2020-08-27 00:52:20 -050063 /** @brief Method to fetch the effecter ID of the code update PDRs
64 *
65 * @return platformHandler->getNextEffecterId() - returns the
66 * effecter ID from the platform handler
67 */
68 uint16_t getNextEffecterId()
69 {
70 return platformHandler->getNextEffecterId();
71 }
72
73 /** @brief Method to fetch the sensor ID of the code update PDRs
74 *
75 * @return platformHandler->getNextSensorId() - returns the
76 * Sensor ID from the platform handler
77 */
78 uint16_t getNextSensorId()
79 {
80 return platformHandler->getNextSensorId();
81 }
82
83 /** @brief Method to Generate the OEM PDRs
84 *
85 * @param[in] repo - instance of concrete implementation of Repo
86 */
87 void buildOEMPDR(pdr_utils::Repo& repo);
88
Varsha Kaverappabb585b22020-09-10 06:15:42 -050089 /** @brief Method to send code update event to host
90 * @param[in] sensorId - sendor ID
91 * @param[in] sensorEventClass - event class of sensor
92 * @param[in] sensorOffset - sensor offset
93 * @param[in] eventState - new code update event state
94 * @param[in] prevEventState - previous code update event state
95 * @return none
96 */
97 void sendStateSensorEvent(uint16_t sensorId,
98 enum sensor_event_class_states sensorEventClass,
99 uint8_t sensorOffset, uint8_t eventState,
100 uint8_t prevEventState);
101
102 /** @brief Method to send encoded request msg of code update event to host
103 * @param[in] requestMsg - encoded request msg
104 * @return PLDM status code
105 */
106 int sendEventToHost(std::vector<uint8_t>& requestMsg);
107
Sampa Misraaea5dde2020-08-31 08:33:47 -0500108 ~Handler() = default;
109
110 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
111 pldm::responder::platform::Handler*
112 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500113
114 /** @brief fd of MCTP communications socket */
115 int mctp_fd;
116
117 /** @brief MCTP EID of host firmware */
118 uint8_t mctp_eid;
119
120 /** @brief reference to Requester object, primarily used to access API to
121 * obtain PLDM instance id.
122 */
123 Requester& requester;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500124};
125
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500126/** @brief Method to encode code update event msg
127 * @param[in] eventType - type of event
128 * @param[in] eventDataVec - vector of event data to be sent to host
129 * @param[in/out] requestMsg - request msg to be encoded
130 * @param[in] instanceId - instance ID
131 * @return PLDM status code
132 */
133int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
134 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
135
Sampa Misraaea5dde2020-08-31 08:33:47 -0500136} // namespace oem_ibm_platform
137
138} // namespace responder
139
140} // namespace pldm