summaryrefslogtreecommitdiffstats
path: root/host-ipmid/oemrouter.hpp
blob: fb1275058e325124c6d345ed928815ae80d94101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once

#include <host-ipmid/ipmid-api.h>

#include <array>
#include <cstdint>
#include <functional>
#include <host-ipmid/iana.hpp>
#include <vector>

namespace oem
{
constexpr size_t groupMagicSize = 3;

using Group = std::array<uint8_t, groupMagicSize>;

// Handler signature includes ipmi cmd to support wildcard cmd match.
// Buffers and lengths exclude the OemGroup bytes in the IPMI message.
// dataLen supplies length of reqBuf upon call, and should be set to the
// length of replyBuf upon return - conventional in this code base.
using Handler = std::function<ipmi_ret_t(ipmi_cmd_t,     // cmd byte
                                         const uint8_t*, // reqBuf
                                         uint8_t*,       // replyBuf
                                         size_t*)>;      // dataLen

/// Router Interface class.
/// @brief Abstract Router Interface
class Router
{
  public:
    virtual ~Router()
    {
    }

    /// Enable message routing to begin.
    virtual void activate() = 0;

    /// Register a handler for given OEMNumber & cmd.
    /// Use IPMI_CMD_WILDCARD to catch any unregistered cmd
    /// for the given OEMNumber.
    ///
    /// @param[in] oen - the OEM Number.
    /// @param[in] cmd - the Command.
    /// @param[in] handler - the handler to call given that OEN and
    ///                      command.
    virtual void registerHandler(Number oen, ipmi_cmd_t cmd,
                                 Handler handler) = 0;
};

/// Expose mutable Router for configuration & activation.
///
/// @returns pointer to OEM Router to use.
Router* mutableRouter();

/// Convert a group to an OEN.
///
/// @param[in] oeg - request buffer for IPMI command.
/// @return the OEN.
constexpr Number toOemNumber(const uint8_t oeg[groupMagicSize])
{
    return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
}

/// Given a Group convert to an OEN.
///
/// @param[in] oeg - OEM Group reference.
/// @return the OEN.
constexpr Number toOemNumber(const Group& oeg)
{
    return (oeg[2] << 16) | (oeg[1] << 8) | oeg[0];
}

/// Given an OEN, conver to the OEM Group.
///
/// @param[in] oen - the OEM Number.
/// @return the OEM Group.
constexpr Group toOemGroup(Number oen)
{
    return Group{static_cast<uint8_t>(oen), static_cast<uint8_t>(oen >> 8),
                 static_cast<uint8_t>(oen >> 16)};
}

} // namespace oem
OpenPOWER on IntegriCloud