| #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> |
| #include <unordered_map> |
| |
| #define PLDM_TYPES 6 |
| #define MAX_DEV_NAME_SIZE 32 |
| #define BASE_REQUEST_RETRIES 50 |
| |
| const std::unordered_map<uint8_t, int> baseCommandRequestSize = { |
| {PLDM_GET_TID, 0}, |
| {PLDM_GET_PLDM_TYPES, 0}, |
| {PLDM_GET_PLDM_VERSION, PLDM_GET_VERSION_REQ_BYTES}, |
| {PLDM_GET_PLDM_COMMANDS, PLDM_GET_COMMANDS_REQ_BYTES}}; |
| |
| /** |
| * @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 |