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