Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 1 | #include "sol_cmds.hpp" |
| 2 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 3 | #include "sessions_manager.hpp" |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 4 | #include "sol/sol_context.hpp" |
| 5 | #include "sol/sol_manager.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 6 | |
| 7 | #include <phosphor-logging/log.hpp> |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 8 | |
| 9 | namespace sol |
| 10 | { |
| 11 | |
| 12 | namespace command |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
| 16 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 17 | std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 18 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 19 | { |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 20 | // Check inPayload size is at least Payload |
| 21 | if (inPayload.size() < sizeof(Payload)) |
| 22 | { |
| 23 | return std::vector<uint8_t>(); |
| 24 | } |
| 25 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 26 | auto request = reinterpret_cast<const Payload*>(inPayload.data()); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 27 | auto solDataSize = inPayload.size() - sizeof(Payload); |
| 28 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 29 | std::vector<uint8_t> charData(solDataSize); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 30 | if (solDataSize > 0) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 31 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 32 | std::copy_n(inPayload.data() + sizeof(Payload), solDataSize, |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 33 | charData.begin()); |
| 34 | } |
| 35 | |
| 36 | try |
| 37 | { |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 38 | auto& context = sol::Manager::get().getContext(handler->sessionID); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 39 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 40 | context.processInboundPayload( |
| 41 | request->packetSeqNum, request->packetAckSeqNum, |
| 42 | request->acceptedCharCount, request->inOperation.ack, charData); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 43 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 44 | catch (const std::exception& e) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 45 | { |
| 46 | log<level::ERR>(e.what()); |
| 47 | return std::vector<uint8_t>(); |
| 48 | } |
| 49 | |
| 50 | return std::vector<uint8_t>(); |
| 51 | } |
| 52 | |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 53 | void activating(uint8_t payloadInstance, uint32_t sessionID) |
| 54 | { |
| 55 | std::vector<uint8_t> outPayload(sizeof(ActivatingRequest)); |
| 56 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 57 | auto request = reinterpret_cast<ActivatingRequest*>(outPayload.data()); |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 58 | |
| 59 | request->sessionState = 0; |
| 60 | request->payloadInstance = payloadInstance; |
| 61 | request->majorVersion = MAJOR_VERSION; |
| 62 | request->minorVersion = MINOR_VERSION; |
| 63 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 64 | auto session = session::Manager::get().getSession(sessionID); |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 65 | |
| 66 | message::Handler msgHandler(session->channelPtr, sessionID); |
| 67 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 68 | msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd, |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 69 | outPayload); |
| 70 | } |
| 71 | |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 72 | std::vector<uint8_t> getConfParams(const std::vector<uint8_t>& inPayload, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 73 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 74 | { |
| 75 | std::vector<uint8_t> outPayload(sizeof(GetConfParamsResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 76 | auto request = |
| 77 | reinterpret_cast<const GetConfParamsRequest*>(inPayload.data()); |
| 78 | auto response = reinterpret_cast<GetConfParamsResponse*>(outPayload.data()); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 79 | response->completionCode = IPMI_CC_OK; |
| 80 | response->paramRev = parameterRevision; |
| 81 | |
| 82 | if (request->getParamRev) |
| 83 | { |
| 84 | return outPayload; |
| 85 | } |
| 86 | |
| 87 | switch (static_cast<Parameter>(request->paramSelector)) |
| 88 | { |
| 89 | case Parameter::PROGRESS: |
| 90 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 91 | outPayload.push_back(sol::Manager::get().progress); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 92 | break; |
| 93 | } |
| 94 | case Parameter::ENABLE: |
| 95 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 96 | outPayload.push_back(sol::Manager::get().enable); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 97 | break; |
| 98 | } |
| 99 | case Parameter::AUTHENTICATION: |
| 100 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 101 | Auth value{0}; |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 102 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 103 | value.encrypt = sol::Manager::get().forceEncrypt; |
| 104 | value.auth = sol::Manager::get().forceAuth; |
| 105 | value.privilege = |
| 106 | static_cast<uint8_t>(sol::Manager::get().solMinPrivilege); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 107 | auto buffer = reinterpret_cast<const uint8_t*>(&value); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 108 | |
| 109 | std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); |
| 110 | break; |
| 111 | } |
| 112 | case Parameter::ACCUMULATE: |
| 113 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 114 | Accumulate value{0}; |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 115 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 116 | value.interval = sol::Manager::get().accumulateInterval.count() / |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 117 | sol::accIntervalFactor; |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 118 | value.threshold = sol::Manager::get().sendThreshold; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 119 | auto buffer = reinterpret_cast<const uint8_t*>(&value); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 120 | |
| 121 | std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); |
| 122 | break; |
| 123 | } |
| 124 | case Parameter::RETRY: |
| 125 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 126 | Retry value{0}; |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 127 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 128 | value.count = sol::Manager::get().retryCount; |
| 129 | value.interval = sol::Manager::get().retryInterval.count() / |
| 130 | sol::retryIntervalFactor; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 131 | auto buffer = reinterpret_cast<const uint8_t*>(&value); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 132 | |
| 133 | std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload)); |
| 134 | break; |
| 135 | } |
| 136 | case Parameter::PORT: |
| 137 | { |
| 138 | auto port = endian::to_ipmi<uint16_t>(IPMI_STD_PORT); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 139 | auto buffer = reinterpret_cast<const uint8_t*>(&port); |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 140 | |
| 141 | std::copy_n(buffer, sizeof(port), std::back_inserter(outPayload)); |
| 142 | break; |
| 143 | } |
Tom Joseph | 6f83cbc | 2018-03-27 03:01:58 +0530 | [diff] [blame] | 144 | case Parameter::CHANNEL: |
| 145 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 146 | outPayload.push_back(sol::Manager::get().channel); |
Tom Joseph | 6f83cbc | 2018-03-27 03:01:58 +0530 | [diff] [blame] | 147 | break; |
| 148 | } |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 149 | case Parameter::NVBITRATE: |
| 150 | case Parameter::VBITRATE: |
Tom Joseph | 20aef33 | 2017-04-28 01:34:10 +0530 | [diff] [blame] | 151 | default: |
| 152 | response->completionCode = ipmiCCParamNotSupported; |
| 153 | } |
| 154 | |
| 155 | return outPayload; |
| 156 | } |
| 157 | |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 158 | } // namespace command |
| 159 | |
| 160 | } // namespace sol |