#include #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 payloadHandler(const std::vector& inPayload, const message::Handler& handler) { auto request = reinterpret_cast(inPayload.data()); auto solDataSize = inPayload.size() - sizeof(Payload); std::vector charData(solDataSize); if( solDataSize > 0) { std::copy_n(inPayload.data() + sizeof(Payload), solDataSize, charData.begin()); } try { auto& context = std::get(singletonPool). getContext(handler.sessionID); context.processInboundPayload(request->packetSeqNum, request->packetAckSeqNum, request->acceptedCharCount, request->inOperation.ack, charData); } catch (std::exception& e) { log(e.what()); return std::vector(); } return std::vector(); } void activating(uint8_t payloadInstance, uint32_t sessionID) { std::vector outPayload(sizeof(ActivatingRequest)); auto request = reinterpret_cast (outPayload.data()); request->sessionState = 0; request->payloadInstance = payloadInstance; request->majorVersion = MAJOR_VERSION; request->minorVersion = MINOR_VERSION; auto session = (std::get(singletonPool).getSession( sessionID)).lock(); message::Handler msgHandler(session->channelPtr, sessionID); msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd, outPayload); } std::vector setConfParams(const std::vector& inPayload, const message::Handler& handler) { std::vector outPayload(sizeof(SetConfParamsResponse)); auto request = reinterpret_cast (inPayload.data()); auto response = reinterpret_cast (outPayload.data()); response->completionCode = IPMI_CC_OK; switch (static_cast(request->paramSelector)) { case Parameter::PROGRESS: { uint8_t progress = request->value & progressMask; std::get(singletonPool).progress = progress; break; } case Parameter::ENABLE: { bool enable = request->value & enableMask; std::get(singletonPool).enable = enable; break; } case Parameter::AUTHENTICATION: { if (!request->auth.auth || !request->auth.encrypt) { response->completionCode = ipmiCCWriteReadParameter; } else if (request->auth.privilege < static_cast(session::Privilege::USER) || request->auth.privilege > static_cast(session::Privilege::OEM)) { response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; } else { std::get(singletonPool).solMinPrivilege = static_cast(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(singletonPool).accumulateInterval = request->acc.interval * sol::accIntervalFactor * 1ms; std::get(singletonPool).sendThreshold = request->acc.threshold; break; } case Parameter::RETRY: { using namespace std::chrono_literals; std::get(singletonPool).retryCount = request->retry.count; std::get(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 getConfParams(const std::vector& inPayload, const message::Handler& handler) { std::vector outPayload(sizeof(GetConfParamsResponse)); auto request = reinterpret_cast (inPayload.data()); auto response = reinterpret_cast (outPayload.data()); response->completionCode = IPMI_CC_OK; response->paramRev = parameterRevision; if (request->getParamRev) { return outPayload; } switch (static_cast(request->paramSelector)) { case Parameter::PROGRESS: { outPayload.push_back(std::get (singletonPool).progress); break; } case Parameter::ENABLE: { outPayload.push_back(std::get (singletonPool).enable); break; } case Parameter::AUTHENTICATION: { Auth value {0}; value.encrypt = std::get(singletonPool).forceEncrypt; value.auth = std::get(singletonPool).forceAuth; value.privilege = static_cast(std::get (singletonPool).solMinPrivilege); auto buffer = reinterpret_cast(&value); std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); break; } case Parameter::ACCUMULATE: { Accumulate value {0}; value.interval = std::get(singletonPool) .accumulateInterval.count()/sol::accIntervalFactor; value.threshold = std::get (singletonPool).sendThreshold; auto buffer = reinterpret_cast(&value); std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); break; } case Parameter::RETRY: { Retry value {0}; value.count = std::get(singletonPool).retryCount; value.interval = std::get(singletonPool) .retryInterval.count()/sol::retryIntervalFactor; auto buffer = reinterpret_cast(&value); std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); break; } case Parameter::PORT: { auto port = endian::to_ipmi(IPMI_STD_PORT); auto buffer = reinterpret_cast(&port); std::copy_n(buffer, sizeof(port), std::back_inserter(outPayload)); break; } case Parameter::CHANNEL: { outPayload.push_back(std::get (singletonPool).channel); break; } case Parameter::NVBITRATE: case Parameter::VBITRATE: default: response->completionCode = ipmiCCParamNotSupported; } return outPayload; } } // namespace command } // namespace sol