Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 1 | #include "payload_cmds.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 2 | |
| 3 | #include "main.hpp" |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 4 | #include "sol/sol_manager.hpp" |
| 5 | #include "sol_cmds.hpp" |
| 6 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 7 | #include <host-ipmid/ipmid-api.h> |
| 8 | |
| 9 | #include <phosphor-logging/log.hpp> |
| 10 | |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 11 | namespace sol |
| 12 | { |
| 13 | |
| 14 | namespace command |
| 15 | { |
| 16 | |
| 17 | using namespace phosphor::logging; |
| 18 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 19 | std::vector<uint8_t> activatePayload(const std::vector<uint8_t>& inPayload, |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 20 | const message::Handler& handler) |
| 21 | { |
| 22 | std::vector<uint8_t> outPayload(sizeof(ActivatePayloadResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 23 | auto request = |
| 24 | reinterpret_cast<const ActivatePayloadRequest*>(inPayload.data()); |
| 25 | auto response = |
| 26 | reinterpret_cast<ActivatePayloadResponse*>(outPayload.data()); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 27 | |
| 28 | response->completionCode = IPMI_CC_OK; |
| 29 | |
| 30 | // SOL is the payload currently supported for activation. |
| 31 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 32 | { |
| 33 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 34 | return outPayload; |
| 35 | } |
| 36 | |
Tom Joseph | 96b6d81 | 2017-04-28 01:27:17 +0530 | [diff] [blame] | 37 | if (!std::get<sol::Manager&>(singletonPool).enable) |
| 38 | { |
| 39 | response->completionCode = IPMI_CC_PAYLOAD_TYPE_DISABLED; |
| 40 | return outPayload; |
| 41 | } |
| 42 | |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 43 | // Only one instance of SOL is currently supported. |
| 44 | if (request->payloadInstance != 1) |
| 45 | { |
| 46 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 47 | return outPayload; |
| 48 | } |
| 49 | |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 50 | auto session = std::get<session::Manager&>(singletonPool) |
| 51 | .getSession(handler.sessionID); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 52 | |
| 53 | if (!request->encryption && session->isCryptAlgoEnabled()) |
| 54 | { |
| 55 | response->completionCode = IPMI_CC_PAYLOAD_WITHOUT_ENCRYPTION; |
| 56 | return outPayload; |
| 57 | } |
| 58 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 59 | auto status = std::get<sol::Manager&>(singletonPool) |
| 60 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 61 | if (status) |
| 62 | { |
| 63 | response->completionCode = IPMI_CC_PAYLOAD_ALREADY_ACTIVE; |
| 64 | return outPayload; |
| 65 | } |
| 66 | |
| 67 | // Set the current command's socket channel to the session |
| 68 | handler.setChannelInSession(); |
| 69 | |
| 70 | // Start the SOL payload |
| 71 | try |
| 72 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 73 | std::get<sol::Manager&>(singletonPool) |
| 74 | .startPayloadInstance(request->payloadInstance, handler.sessionID); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 75 | } |
| 76 | catch (std::exception& e) |
| 77 | { |
| 78 | log<level::ERR>(e.what()); |
| 79 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 80 | return outPayload; |
| 81 | } |
| 82 | |
| 83 | response->inPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 84 | response->outPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 85 | response->portNum = endian::to_ipmi<uint16_t>(IPMI_STD_PORT); |
| 86 | |
| 87 | // VLAN addressing is not used |
| 88 | response->vlanNum = 0xFFFF; |
| 89 | |
| 90 | return outPayload; |
| 91 | } |
| 92 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 93 | std::vector<uint8_t> deactivatePayload(const std::vector<uint8_t>& inPayload, |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 94 | const message::Handler& handler) |
| 95 | { |
| 96 | std::vector<uint8_t> outPayload(sizeof(DeactivatePayloadResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 97 | auto request = |
| 98 | reinterpret_cast<const DeactivatePayloadRequest*>(inPayload.data()); |
| 99 | auto response = |
| 100 | reinterpret_cast<DeactivatePayloadResponse*>(outPayload.data()); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 101 | |
| 102 | response->completionCode = IPMI_CC_OK; |
| 103 | |
| 104 | // SOL is the payload currently supported for deactivation |
| 105 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 106 | { |
| 107 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 108 | return outPayload; |
| 109 | } |
| 110 | |
| 111 | // Only one instance of SOL is supported |
| 112 | if (request->payloadInstance != 1) |
| 113 | { |
| 114 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 115 | return outPayload; |
| 116 | } |
| 117 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 118 | auto status = std::get<sol::Manager&>(singletonPool) |
| 119 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 120 | if (!status) |
| 121 | { |
| 122 | response->completionCode = IPMI_CC_PAYLOAD_DEACTIVATED; |
| 123 | return outPayload; |
| 124 | } |
| 125 | |
| 126 | try |
| 127 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 128 | auto& context = std::get<sol::Manager&>(singletonPool) |
| 129 | .getContext(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 130 | auto sessionID = context.sessionID; |
| 131 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 132 | std::get<sol::Manager&>(singletonPool) |
| 133 | .stopPayloadInstance(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 134 | |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 135 | try |
| 136 | { |
| 137 | activating(request->payloadInstance, sessionID); |
| 138 | } |
| 139 | catch (std::exception& e) |
| 140 | { |
| 141 | log<level::INFO>(e.what()); |
| 142 | /* |
| 143 | * In case session has been closed (like in the case of inactivity |
| 144 | * timeout), then activating function would throw an exception, |
| 145 | * since sessionID is not found. IPMI success completion code is |
| 146 | * returned, since the session is closed. |
| 147 | */ |
| 148 | return outPayload; |
| 149 | } |
| 150 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 151 | auto check = |
| 152 | std::get<session::Manager&>(singletonPool).stopSession(sessionID); |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 153 | if (!check) |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 154 | { |
| 155 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 156 | } |
| 157 | } |
| 158 | catch (std::exception& e) |
| 159 | { |
| 160 | log<level::ERR>(e.what()); |
| 161 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 162 | return outPayload; |
| 163 | } |
| 164 | |
| 165 | return outPayload; |
| 166 | } |
| 167 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 168 | std::vector<uint8_t> getPayloadStatus(const std::vector<uint8_t>& inPayload, |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 169 | const message::Handler& handler) |
| 170 | { |
| 171 | std::vector<uint8_t> outPayload(sizeof(GetPayloadStatusResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 172 | auto request = |
| 173 | reinterpret_cast<const GetPayloadStatusRequest*>(inPayload.data()); |
| 174 | auto response = |
| 175 | reinterpret_cast<GetPayloadStatusResponse*>(outPayload.data()); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 176 | |
| 177 | // SOL is the payload currently supported for payload status |
| 178 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 179 | { |
| 180 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 181 | return outPayload; |
| 182 | } |
| 183 | |
| 184 | response->completionCode = IPMI_CC_OK; |
| 185 | response->capacity = MAX_PAYLOAD_INSTANCES; |
| 186 | |
| 187 | // Currently we support only one SOL session |
| 188 | response->instance1 = |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 189 | std::get<sol::Manager&>(singletonPool).isPayloadActive(1); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 190 | |
| 191 | return outPayload; |
| 192 | } |
| 193 | |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 194 | std::vector<uint8_t> getPayloadInfo(const std::vector<uint8_t>& inPayload, |
| 195 | const message::Handler& handler) |
| 196 | { |
| 197 | std::vector<uint8_t> outPayload(sizeof(GetPayloadInfoResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 198 | auto request = |
| 199 | reinterpret_cast<const GetPayloadInfoRequest*>(inPayload.data()); |
| 200 | auto response = |
| 201 | reinterpret_cast<GetPayloadInfoResponse*>(outPayload.data()); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 202 | |
| 203 | // SOL is the payload currently supported for payload status & only one |
| 204 | // instance of SOL is supported. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 205 | if (static_cast<uint8_t>(message::PayloadType::SOL) != |
| 206 | request->payloadType || |
| 207 | request->payloadInstance != 1) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 208 | { |
| 209 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 210 | return outPayload; |
| 211 | } |
| 212 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 213 | auto status = std::get<sol::Manager&>(singletonPool) |
| 214 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 215 | |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 216 | if (status) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 217 | { |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 218 | auto& context = std::get<sol::Manager&>(singletonPool) |
| 219 | .getContext(request->payloadInstance); |
| 220 | response->sessionID = context.sessionID; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 221 | } |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 222 | else |
| 223 | { |
| 224 | // No active payload - return session id as 0 |
| 225 | response->sessionID = 0; |
| 226 | } |
| 227 | response->completionCode = IPMI_CC_OK; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 228 | return outPayload; |
| 229 | } |
| 230 | |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 231 | } // namespace command |
| 232 | |
| 233 | } // namespace sol |