blob: a6bf4c422db8fdbbaa8975bc818c1fd6c2002ca4 [file] [log] [blame]
#ifndef BASE_DISC_STATE_MACHINE_HPP
#define BASE_DISC_STATE_MACHINE_HPP
#include "libpldm/base.h"
#include "libpldm/pldm.h"
#include "state_machine_factory.hpp"
#include <array>
#include <optional>
#define PLDM_TYPES 6
#define MAX_DEV_NAME_SIZE 32
#define BASE_REQUEST_RETRIES 50
/**
* @brief Perform base discovery
*/
class BaseDiscoveryStateMachine : public StateMachineFactory
{
public:
BaseDiscoveryStateMachine(int fd, const std::string& deviceName, int netId);
OperationStatus run() override;
OperationStatus triggerNextCommand() override;
OperationStatus pushCommandResponse(struct pldm_msg* respMsg,
size_t respSize) override;
void printState() override;
private:
/**
* @brief PLDM Get TID Handler
*/
OperationStatus processGetTidRequest();
/**
* @brief PLDM Get PLDM Types Handler
*/
OperationStatus processGetPldmTypesRequest();
/**
* @brief PLDM Get PLDM Version Handler
*/
OperationStatus processGetPldmVersionRequest();
/**
* @brief PLDM Get PLDM Commands Handler
*/
OperationStatus processGetPldmCommandsRequest();
/**
* @brief Gets the next PLDM Type in queue for performing GetPLDMCommands or
* GetPLDMVersion
*/
std::optional<uint8_t> getNextPldmTypeToBeProcessed(uint8_t currentType);
// State parameters capturing/required during base discovery
int fd;
uint8_t eid;
int instanceId;
bool initialized;
int nextCommand;
StateMachineStatus requesterStatus;
uint8_t commandPldmType;
uint8_t tid;
std::string deviceName;
// MCTP network id
int netId;
std::array<bitfield8_t, PLDM_MAX_TYPES / 8> pldmTypes;
std::array<std::array<uint8_t, PLDM_MAX_CMDS_PER_TYPE>, PLDM_MAX_TYPES>
pldmCommands;
std::array<ver32_t, PLDM_MAX_TYPES> pldmVersions;
};
#endif // BASE_DISC_STATE_MACHINE_HPP