blob: ef0e697951fd25edd68c7b52e202f0986a1514b7 [file] [log] [blame]
Peter Hanson4a589852017-06-07 17:40:45 -07001#pragma once
2
William A. Kennington III194375f2018-12-14 02:14:33 -08003#include <ipmid/api.h>
Patrick Venturedd0459e2018-09-08 09:27:16 -07004
Peter Hanson4a589852017-06-07 17:40:45 -07005#include <array>
Patrick Venture082a39c2020-05-07 17:26:47 -07006#include <cstddef>
Peter Hanson4a589852017-06-07 17:40:45 -07007#include <cstdint>
8#include <functional>
William A. Kennington III194375f2018-12-14 02:14:33 -08009#include <ipmid/iana.hpp>
Peter Hanson4a589852017-06-07 17:40:45 -070010#include <vector>
11
Peter Hanson4a589852017-06-07 17:40:45 -070012namespace oem
13{
Patrick Venture082a39c2020-05-07 17:26:47 -070014constexpr std::size_t groupMagicSize = 3;
Peter Hanson4a589852017-06-07 17:40:45 -070015
Patrick Venture082a39c2020-05-07 17:26:47 -070016using Group = std::array<std::uint8_t, groupMagicSize>;
Peter Hanson4a589852017-06-07 17:40:45 -070017
18// Handler signature includes ipmi cmd to support wildcard cmd match.
19// Buffers and lengths exclude the OemGroup bytes in the IPMI message.
20// dataLen supplies length of reqBuf upon call, and should be set to the
21// length of replyBuf upon return - conventional in this code base.
Patrick Venture082a39c2020-05-07 17:26:47 -070022using Handler = std::function<ipmi_ret_t(ipmi_cmd_t, // cmd byte
23 const std::uint8_t*, // reqBuf
24 std::uint8_t*, // replyBuf
25 std::size_t*)>; // dataLen
Peter Hanson4a589852017-06-07 17:40:45 -070026
27/// Router Interface class.
28/// @brief Abstract Router Interface
29class Router
30{
Patrick Venture0b02be92018-08-31 11:55:55 -070031 public:
32 virtual ~Router()
33 {
34 }
Peter Hanson4a589852017-06-07 17:40:45 -070035
Patrick Venture0b02be92018-08-31 11:55:55 -070036 /// Enable message routing to begin.
37 virtual void activate() = 0;
Peter Hanson4a589852017-06-07 17:40:45 -070038
Patrick Venture0b02be92018-08-31 11:55:55 -070039 /// Register a handler for given OEMNumber & cmd.
40 /// Use IPMI_CMD_WILDCARD to catch any unregistered cmd
41 /// for the given OEMNumber.
42 ///
43 /// @param[in] oen - the OEM Number.
44 /// @param[in] cmd - the Command.
45 /// @param[in] handler - the handler to call given that OEN and
46 /// command.
47 virtual void registerHandler(Number oen, ipmi_cmd_t cmd,
48 Handler handler) = 0;
Peter Hanson4a589852017-06-07 17:40:45 -070049};
50
51/// Expose mutable Router for configuration & activation.
52///
53/// @returns pointer to OEM Router to use.
54Router* mutableRouter();
55
56/// Convert a group to an OEN.
57///
58/// @param[in] oeg - request buffer for IPMI command.
59/// @return the OEN.
Patrick Venture082a39c2020-05-07 17:26:47 -070060constexpr Number toOemNumber(const std::uint8_t oeg[groupMagicSize])
Peter Hanson4a589852017-06-07 17:40:45 -070061{
62 return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
63}
64
65/// Given a Group convert to an OEN.
66///
67/// @param[in] oeg - OEM Group reference.
68/// @return the OEN.
69constexpr Number toOemNumber(const Group& oeg)
70{
71 return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
72}
73
74/// Given an OEN, conver to the OEM Group.
75///
76/// @param[in] oen - the OEM Number.
77/// @return the OEM Group.
78constexpr Group toOemGroup(Number oen)
79{
Patrick Venture082a39c2020-05-07 17:26:47 -070080 return Group{static_cast<std::uint8_t>(oen),
81 static_cast<std::uint8_t>(oen >> 8),
82 static_cast<std::uint8_t>(oen >> 16)};
Peter Hanson4a589852017-06-07 17:40:45 -070083}
84
Patrick Venture0b02be92018-08-31 11:55:55 -070085} // namespace oem