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