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 | |
George Liu | 067d178 | 2025-07-02 14:03:54 +0800 | [diff] [blame^] | 33 | response->completionCode = ipmi::ccSuccess; |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 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 | |
Tang Yiwei | de4121c | 2022-05-17 18:21:03 +0800 | [diff] [blame] | 65 | if (session->currentPrivilege() < |
| 66 | static_cast<uint8_t>(sol::Manager::get().solMinPrivilege)) |
| 67 | { |
| 68 | response->completionCode = IPMI_CC_INSUFFICIENT_PRIVILEGE; |
| 69 | return outPayload; |
| 70 | } |
| 71 | |
Saravanan Palanisamy | 0a26904 | 2019-07-05 02:21:21 +0000 | [diff] [blame] | 72 | // Is SOL Payload enabled for this user & channel. |
| 73 | auto userId = ipmi::ipmiUserGetUserId(session->userName); |
| 74 | ipmi::PayloadAccess payloadAccess = {}; |
| 75 | if ((ipmi::ipmiUserGetUserPayloadAccess(session->channelNum(), userId, |
George Liu | 067d178 | 2025-07-02 14:03:54 +0800 | [diff] [blame^] | 76 | payloadAccess) != |
| 77 | ipmi::ccSuccess) || |
Saravanan Palanisamy | 0a26904 | 2019-07-05 02:21:21 +0000 | [diff] [blame] | 78 | !(payloadAccess.stdPayloadEnables1[static_cast<uint8_t>( |
| 79 | message::PayloadType::SOL)])) |
| 80 | { |
| 81 | response->completionCode = IPMI_CC_PAYLOAD_TYPE_DISABLED; |
| 82 | return outPayload; |
| 83 | } |
| 84 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 85 | auto status = sol::Manager::get().isPayloadActive(request->payloadInstance); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 86 | if (status) |
| 87 | { |
| 88 | response->completionCode = IPMI_CC_PAYLOAD_ALREADY_ACTIVE; |
| 89 | return outPayload; |
| 90 | } |
| 91 | |
| 92 | // Set the current command's socket channel to the session |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 93 | handler->setChannelInSession(); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 94 | |
| 95 | // Start the SOL payload |
| 96 | try |
| 97 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 98 | sol::Manager::get().startPayloadInstance(request->payloadInstance, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 99 | handler->sessionID); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 100 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 101 | catch (const std::exception& e) |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 102 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 103 | lg2::error("Failed to start SOL payload: {ERROR}", "ERROR", e); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 104 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 105 | return outPayload; |
| 106 | } |
| 107 | |
| 108 | response->inPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 109 | response->outPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 110 | response->portNum = endian::to_ipmi<uint16_t>(IPMI_STD_PORT); |
| 111 | |
| 112 | // VLAN addressing is not used |
| 113 | response->vlanNum = 0xFFFF; |
| 114 | |
| 115 | return outPayload; |
| 116 | } |
| 117 | |
Patrick Williams | 33503e2 | 2025-02-03 14:27:32 -0500 | [diff] [blame] | 118 | std::vector<uint8_t> deactivatePayload( |
| 119 | const std::vector<uint8_t>& inPayload, |
| 120 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 121 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 122 | auto request = |
| 123 | reinterpret_cast<const DeactivatePayloadRequest*>(inPayload.data()); |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 124 | if (inPayload.size() != sizeof(*request)) |
| 125 | { |
| 126 | std::vector<uint8_t> errorPayload{IPMI_CC_REQ_DATA_LEN_INVALID}; |
| 127 | return errorPayload; |
| 128 | } |
| 129 | |
| 130 | std::vector<uint8_t> outPayload(sizeof(DeactivatePayloadResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 131 | auto response = |
| 132 | reinterpret_cast<DeactivatePayloadResponse*>(outPayload.data()); |
George Liu | 067d178 | 2025-07-02 14:03:54 +0800 | [diff] [blame^] | 133 | response->completionCode = ipmi::ccSuccess; |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 134 | |
| 135 | // SOL is the payload currently supported for deactivation |
| 136 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 137 | { |
| 138 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 139 | return outPayload; |
| 140 | } |
| 141 | |
| 142 | // Only one instance of SOL is supported |
| 143 | if (request->payloadInstance != 1) |
| 144 | { |
| 145 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 146 | return outPayload; |
| 147 | } |
| 148 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 149 | auto status = sol::Manager::get().isPayloadActive(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 150 | if (!status) |
| 151 | { |
| 152 | response->completionCode = IPMI_CC_PAYLOAD_DEACTIVATED; |
| 153 | return outPayload; |
| 154 | } |
| 155 | |
Tang Yiwei | de4121c | 2022-05-17 18:21:03 +0800 | [diff] [blame] | 156 | auto currentSession = |
| 157 | session::Manager::get().getSession(handler->sessionID); |
| 158 | auto solSessionID = |
| 159 | sol::Manager::get().getContext(request->payloadInstance).sessionID; |
Jayaprakash Mutyala | 34a2c41 | 2023-09-08 10:30:28 +0000 | [diff] [blame] | 160 | auto solActiveSession = |
| 161 | sol::Manager::get().getContext(request->payloadInstance).session; |
Tang Yiwei | de4121c | 2022-05-17 18:21:03 +0800 | [diff] [blame] | 162 | // The session owner or the ADMIN could deactivate the session |
| 163 | if (currentSession->userName != solActiveSession->userName && |
| 164 | currentSession->currentPrivilege() != |
| 165 | static_cast<uint8_t>(session::Privilege::ADMIN)) |
| 166 | { |
| 167 | response->completionCode = IPMI_CC_INSUFFICIENT_PRIVILEGE; |
| 168 | return outPayload; |
| 169 | } |
| 170 | |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 171 | try |
| 172 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 173 | sol::Manager::get().stopPayloadInstance(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 174 | |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 175 | try |
| 176 | { |
Tang Yiwei | de4121c | 2022-05-17 18:21:03 +0800 | [diff] [blame] | 177 | activating(request->payloadInstance, solSessionID); |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 178 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 179 | catch (const std::exception& e) |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 180 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 181 | lg2::info("Failed to call the activating method: {ERROR}", "ERROR", |
| 182 | e); |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 183 | /* |
| 184 | * In case session has been closed (like in the case of inactivity |
| 185 | * timeout), then activating function would throw an exception, |
Jayaprakash Mutyala | 34a2c41 | 2023-09-08 10:30:28 +0000 | [diff] [blame] | 186 | * since solSessionID is not found. As session is already closed, |
| 187 | * returning IPMI status code for Payload already deactivated |
| 188 | * as BMC automatically deactivates all active payloads when |
| 189 | * session is terminated. |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 190 | */ |
Jayaprakash Mutyala | 34a2c41 | 2023-09-08 10:30:28 +0000 | [diff] [blame] | 191 | response->completionCode = IPMI_CC_PAYLOAD_DEACTIVATED; |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 192 | return outPayload; |
| 193 | } |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 194 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 195 | catch (const std::exception& e) |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 196 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 197 | lg2::error("Failed to call the getContext method: {ERROR}", "ERROR", e); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 198 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 199 | return outPayload; |
| 200 | } |
| 201 | |
| 202 | return outPayload; |
| 203 | } |
| 204 | |
Patrick Williams | 33503e2 | 2025-02-03 14:27:32 -0500 | [diff] [blame] | 205 | std::vector<uint8_t> getPayloadStatus( |
| 206 | const std::vector<uint8_t>& inPayload, |
| 207 | std::shared_ptr<message::Handler>& /* handler */) |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 208 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 209 | auto request = |
| 210 | reinterpret_cast<const GetPayloadStatusRequest*>(inPayload.data()); |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 211 | if (inPayload.size() != sizeof(*request)) |
| 212 | { |
| 213 | std::vector<uint8_t> errorPayload{IPMI_CC_REQ_DATA_LEN_INVALID}; |
| 214 | return errorPayload; |
| 215 | } |
| 216 | |
| 217 | std::vector<uint8_t> outPayload(sizeof(GetPayloadStatusResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 218 | auto response = |
| 219 | reinterpret_cast<GetPayloadStatusResponse*>(outPayload.data()); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 220 | |
| 221 | // SOL is the payload currently supported for payload status |
| 222 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 223 | { |
| 224 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 225 | return outPayload; |
| 226 | } |
| 227 | |
George Liu | 067d178 | 2025-07-02 14:03:54 +0800 | [diff] [blame^] | 228 | response->completionCode = ipmi::ccSuccess; |
Ayushi Smriti | ddba9d1 | 2019-09-13 12:03:31 +0530 | [diff] [blame] | 229 | |
| 230 | constexpr size_t maxSolPayloadInstances = 1; |
| 231 | response->capacity = maxSolPayloadInstances; |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 232 | |
| 233 | // Currently we support only one SOL session |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 234 | response->instance1 = sol::Manager::get().isPayloadActive(1); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 235 | |
| 236 | return outPayload; |
| 237 | } |
| 238 | |
Patrick Williams | 33503e2 | 2025-02-03 14:27:32 -0500 | [diff] [blame] | 239 | std::vector<uint8_t> getPayloadInfo( |
| 240 | const std::vector<uint8_t>& inPayload, |
| 241 | std::shared_ptr<message::Handler>& /* handler */) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 242 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 243 | auto request = |
| 244 | reinterpret_cast<const GetPayloadInfoRequest*>(inPayload.data()); |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 245 | |
| 246 | if (inPayload.size() != sizeof(*request)) |
| 247 | { |
| 248 | std::vector<uint8_t> errorPayload{IPMI_CC_REQ_DATA_LEN_INVALID}; |
| 249 | return errorPayload; |
| 250 | } |
| 251 | |
| 252 | std::vector<uint8_t> outPayload(sizeof(GetPayloadInfoResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 253 | auto response = |
| 254 | reinterpret_cast<GetPayloadInfoResponse*>(outPayload.data()); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 255 | |
| 256 | // SOL is the payload currently supported for payload status & only one |
| 257 | // instance of SOL is supported. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 258 | if (static_cast<uint8_t>(message::PayloadType::SOL) != |
| 259 | request->payloadType || |
| 260 | request->payloadInstance != 1) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 261 | { |
| 262 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 263 | return outPayload; |
| 264 | } |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 265 | auto status = sol::Manager::get().isPayloadActive(request->payloadInstance); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 266 | |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 267 | if (status) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 268 | { |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 269 | auto& context = |
| 270 | sol::Manager::get().getContext(request->payloadInstance); |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 271 | response->sessionID = context.sessionID; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 272 | } |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 273 | else |
| 274 | { |
| 275 | // No active payload - return session id as 0 |
| 276 | response->sessionID = 0; |
| 277 | } |
George Liu | 067d178 | 2025-07-02 14:03:54 +0800 | [diff] [blame^] | 278 | response->completionCode = ipmi::ccSuccess; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 279 | return outPayload; |
| 280 | } |
| 281 | |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 282 | } // namespace command |
| 283 | |
| 284 | } // namespace sol |