blob: e0a9f146e8af4a489c55319efc8a4d14ee3326b9 [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>
6#include <cstdint>
7#include <functional>
William A. Kennington III194375f2018-12-14 02:14:33 -08008#include <ipmid/iana.hpp>
Peter Hanson4a589852017-06-07 17:40:45 -07009#include <vector>
10
Peter Hanson4a589852017-06-07 17:40:45 -070011namespace oem
12{
13constexpr size_t groupMagicSize = 3;
14
15using Group = std::array<uint8_t, groupMagicSize>;
Peter Hanson4a589852017-06-07 17:40:45 -070016
17// Handler signature includes ipmi cmd to support wildcard cmd match.
18// Buffers and lengths exclude the OemGroup bytes in the IPMI message.
19// dataLen supplies length of reqBuf upon call, and should be set to the
20// length of replyBuf upon return - conventional in this code base.
Patrick Venture0b02be92018-08-31 11:55:55 -070021using Handler = std::function<ipmi_ret_t(ipmi_cmd_t, // cmd byte
22 const uint8_t*, // reqBuf
23 uint8_t*, // replyBuf
24 size_t*)>; // dataLen
Peter Hanson4a589852017-06-07 17:40:45 -070025
26/// Router Interface class.
27/// @brief Abstract Router Interface
28class Router
29{
Patrick Venture0b02be92018-08-31 11:55:55 -070030 public:
31 virtual ~Router()
32 {
33 }
Peter Hanson4a589852017-06-07 17:40:45 -070034
Patrick Venture0b02be92018-08-31 11:55:55 -070035 /// Enable message routing to begin.
36 virtual void activate() = 0;
Peter Hanson4a589852017-06-07 17:40:45 -070037
Patrick Venture0b02be92018-08-31 11:55:55 -070038 /// Register a handler for given OEMNumber & cmd.
39 /// Use IPMI_CMD_WILDCARD to catch any unregistered cmd
40 /// for the given OEMNumber.
41 ///
42 /// @param[in] oen - the OEM Number.
43 /// @param[in] cmd - the Command.
44 /// @param[in] handler - the handler to call given that OEN and
45 /// command.
46 virtual void registerHandler(Number oen, ipmi_cmd_t cmd,
47 Handler handler) = 0;
Peter Hanson4a589852017-06-07 17:40:45 -070048};
49
50/// Expose mutable Router for configuration & activation.
51///
52/// @returns pointer to OEM Router to use.
53Router* mutableRouter();
54
55/// Convert a group to an OEN.
56///
57/// @param[in] oeg - request buffer for IPMI command.
58/// @return the OEN.
59constexpr Number toOemNumber(const uint8_t oeg[groupMagicSize])
60{
61 return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
62}
63
64/// Given a Group convert to an OEN.
65///
66/// @param[in] oeg - OEM Group reference.
67/// @return the OEN.
68constexpr Number toOemNumber(const Group& oeg)
69{
70 return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
71}
72
73/// Given an OEN, conver to the OEM Group.
74///
75/// @param[in] oen - the OEM Number.
76/// @return the OEM Group.
77constexpr Group toOemGroup(Number oen)
78{
Patrick Venture0b02be92018-08-31 11:55:55 -070079 return Group{static_cast<uint8_t>(oen), static_cast<uint8_t>(oen >> 8),
80 static_cast<uint8_t>(oen >> 16)};
Peter Hanson4a589852017-06-07 17:40:45 -070081}
82
Patrick Venture0b02be92018-08-31 11:55:55 -070083} // namespace oem