summaryrefslogtreecommitdiffstats
path: root/command/sol_cmds.cpp
blob: f475c032448c445027214a679327196b3d6a9900 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <phosphor-logging/log.hpp>
#include "main.hpp"
#include "sol/sol_context.hpp"
#include "sol/sol_manager.hpp"
#include "sol_cmds.hpp"

namespace sol
{

namespace command
{

using namespace phosphor::logging;

std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload,
                                    const message::Handler& handler)
{
    auto request = reinterpret_cast<const Payload*>(inPayload.data());
    auto solDataSize = inPayload.size() - sizeof(Payload);

    Buffer charData(solDataSize);
    if( solDataSize > 0)
    {
        std::copy_n(inPayload.data() + sizeof(Payload),
                    solDataSize,
                    charData.begin());
    }

    try
    {
        auto& context = std::get<sol::Manager&>(singletonPool).
                getContext(handler.sessionID);

        context.processInboundPayload(request->packetSeqNum,
                                      request->packetAckSeqNum,
                                      request->acceptedCharCount,
                                      request->inOperation.ack,
                                      charData);
    }
    catch (std::exception& e)
    {
        log<level::ERR>(e.what());
        return std::vector<uint8_t>();
    }

    return std::vector<uint8_t>();
}

void activating(uint8_t payloadInstance, uint32_t sessionID)
{
    std::vector<uint8_t> outPayload(sizeof(ActivatingRequest));

    auto request = reinterpret_cast<ActivatingRequest*>
                    (outPayload.data());

    request->sessionState = 0;
    request->payloadInstance = payloadInstance;
    request->majorVersion = MAJOR_VERSION;
    request->minorVersion = MINOR_VERSION;

    auto session = (std::get<session::Manager&>(singletonPool).getSession(
            sessionID)).lock();

    message::Handler msgHandler(session->channelPtr, sessionID);

    msgHandler.sendUnsolicitedIPMIPayload(netfnTransport,
                                          solActivatingCmd,
                                          outPayload);
}

std::vector<uint8_t> setConfParams(const std::vector<uint8_t>& inPayload,
                                   const message::Handler& handler)
{
    std::vector<uint8_t> outPayload(sizeof(SetConfParamsResponse));
    auto request = reinterpret_cast<const SetConfParamsRequest*>
                   (inPayload.data());
    auto response = reinterpret_cast<SetConfParamsResponse*>
                    (outPayload.data());
    response->completionCode = IPMI_CC_OK;

    switch (static_cast<Parameter>(request->paramSelector))
    {
        case Parameter::PROGRESS:
        {
            uint8_t progress = request->value & progressMask;
            std::get<sol::Manager&>(singletonPool).progress = progress;
            break;
        }
        case Parameter::ENABLE:
        {
            bool enable = request->value & enableMask;
            std::get<sol::Manager&>(singletonPool).enable = enable;
            break;
        }
        case Parameter::AUTHENTICATION:
        {
            if (!request->auth.auth || !request->auth.encrypt)
            {
                response->completionCode = ipmiCCWriteReadParameter;
            }
            else if (request->auth.privilege <
                     static_cast<uint8_t>(session::Privilege::USER) ||
                     request->auth.privilege >
                     static_cast<uint8_t>(session::Privilege::OEM))
            {
                response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
            }
            else
            {
                std::get<sol::Manager&>(singletonPool).solMinPrivilege =
                       static_cast<session::Privilege>(request->auth.privilege);
            }
            break;
        }
        case Parameter::ACCUMULATE:
        {
            using namespace std::chrono_literals;

            if (request->acc.threshold == 0)
            {
                response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
                break;
            }

            std::get<sol::Manager&>(singletonPool).accumulateInterval =
                    request->acc.interval * sol::accIntervalFactor * 1ms;
            std::get<sol::Manager&>(singletonPool).sendThreshold =
                    request->acc.threshold;
            break;
        }
        case Parameter::RETRY:
        {
            using namespace std::chrono_literals;

            std::get<sol::Manager&>(singletonPool).retryCount =
                    request->retry.count;
            std::get<sol::Manager&>(singletonPool).retryInterval =
                    request->retry.interval * sol::retryIntervalFactor * 1ms;
            break;
        }
        case Parameter::PORT:
        {
            response->completionCode = ipmiCCWriteReadParameter;
            break;
        }
        case Parameter::NVBITRATE:
        case Parameter::VBITRATE:
        case Parameter::CHANNEL:
        default:
            response->completionCode = ipmiCCParamNotSupported;
    }

    return outPayload;
}

std::vector<uint8_t> getConfParams(const std::vector<uint8_t>& inPayload,
                                   const message::Handler& handler)
{
    std::vector<uint8_t> outPayload(sizeof(GetConfParamsResponse));
    auto request = reinterpret_cast<const GetConfParamsRequest*>
                   (inPayload.data());
    auto response = reinterpret_cast<GetConfParamsResponse*>
                    (outPayload.data());
    response->completionCode = IPMI_CC_OK;
    response->paramRev = parameterRevision;

    if (request->getParamRev)
    {
        return outPayload;
    }

    switch (static_cast<Parameter>(request->paramSelector))
    {
        case Parameter::PROGRESS:
        {
            outPayload.push_back(std::get<sol::Manager&>
                    (singletonPool).progress);
            break;
        }
        case Parameter::ENABLE:
        {
            outPayload.push_back(std::get<sol::Manager&>
                    (singletonPool).enable);
            break;
        }
        case Parameter::AUTHENTICATION:
        {
            Auth value {0};

            value.encrypt = std::get<sol::Manager&>(singletonPool).forceEncrypt;
            value.auth = std::get<sol::Manager&>(singletonPool).forceAuth;
            value.privilege  = static_cast<uint8_t>(std::get<sol::Manager&>
                    (singletonPool).solMinPrivilege);
            auto buffer = reinterpret_cast<const uint8_t *>(&value);

            std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
            break;
        }
        case Parameter::ACCUMULATE:
        {
            Accumulate value {0};

            value.interval = std::get<sol::Manager&>(singletonPool)
                            .accumulateInterval.count()/sol::accIntervalFactor;
            value.threshold = std::get<sol::Manager&>
                            (singletonPool).sendThreshold;
            auto buffer = reinterpret_cast<const uint8_t *>(&value);

            std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
            break;
        }
        case Parameter::RETRY:
        {
            Retry value {0};

            value.count = std::get<sol::Manager&>(singletonPool).retryCount;
            value.interval = std::get<sol::Manager&>(singletonPool)
                    .retryInterval.count()/sol::retryIntervalFactor;
            auto buffer = reinterpret_cast<const uint8_t *>(&value);

            std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
            break;
        }
        case Parameter::PORT:
        {
            auto port = endian::to_ipmi<uint16_t>(IPMI_STD_PORT);
            auto buffer = reinterpret_cast<const uint8_t *>(&port);

            std::copy_n(buffer, sizeof(port), std::back_inserter(outPayload));
            break;
        }
        case Parameter::NVBITRATE:
        case Parameter::VBITRATE:
        case Parameter::CHANNEL:
        default:
            response->completionCode = ipmiCCParamNotSupported;
    }

    return outPayload;
}

} // namespace command

} // namespace sol
OpenPOWER on IntegriCloud