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 | |
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 | |
| 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 | |
Saravanan Palanisamy | 0a26904 | 2019-07-05 02:21:21 +0000 | [diff] [blame^] | 59 | // Is SOL Payload enabled for this user & channel. |
| 60 | auto userId = ipmi::ipmiUserGetUserId(session->userName); |
| 61 | ipmi::PayloadAccess payloadAccess = {}; |
| 62 | if ((ipmi::ipmiUserGetUserPayloadAccess(session->channelNum(), userId, |
| 63 | payloadAccess) != IPMI_CC_OK) || |
| 64 | !(payloadAccess.stdPayloadEnables1[static_cast<uint8_t>( |
| 65 | message::PayloadType::SOL)])) |
| 66 | { |
| 67 | response->completionCode = IPMI_CC_PAYLOAD_TYPE_DISABLED; |
| 68 | return outPayload; |
| 69 | } |
| 70 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 71 | auto status = std::get<sol::Manager&>(singletonPool) |
| 72 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 73 | if (status) |
| 74 | { |
| 75 | response->completionCode = IPMI_CC_PAYLOAD_ALREADY_ACTIVE; |
| 76 | return outPayload; |
| 77 | } |
| 78 | |
| 79 | // Set the current command's socket channel to the session |
| 80 | handler.setChannelInSession(); |
| 81 | |
| 82 | // Start the SOL payload |
| 83 | try |
| 84 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 85 | std::get<sol::Manager&>(singletonPool) |
| 86 | .startPayloadInstance(request->payloadInstance, handler.sessionID); |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 87 | } |
| 88 | catch (std::exception& e) |
| 89 | { |
| 90 | log<level::ERR>(e.what()); |
| 91 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 92 | return outPayload; |
| 93 | } |
| 94 | |
| 95 | response->inPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 96 | response->outPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE); |
| 97 | response->portNum = endian::to_ipmi<uint16_t>(IPMI_STD_PORT); |
| 98 | |
| 99 | // VLAN addressing is not used |
| 100 | response->vlanNum = 0xFFFF; |
| 101 | |
| 102 | return outPayload; |
| 103 | } |
| 104 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 105 | std::vector<uint8_t> deactivatePayload(const std::vector<uint8_t>& inPayload, |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 106 | const message::Handler& handler) |
| 107 | { |
| 108 | std::vector<uint8_t> outPayload(sizeof(DeactivatePayloadResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 109 | auto request = |
| 110 | reinterpret_cast<const DeactivatePayloadRequest*>(inPayload.data()); |
| 111 | auto response = |
| 112 | reinterpret_cast<DeactivatePayloadResponse*>(outPayload.data()); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 113 | |
| 114 | response->completionCode = IPMI_CC_OK; |
| 115 | |
Sumanth Bhat | b9631f8 | 2019-03-07 11:51:53 +0530 | [diff] [blame] | 116 | if (inPayload.size() != sizeof(DeactivatePayloadRequest)) |
| 117 | { |
| 118 | response->completionCode = IPMI_CC_REQ_DATA_LEN_INVALID; |
| 119 | return outPayload; |
| 120 | } |
| 121 | |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 122 | // SOL is the payload currently supported for deactivation |
| 123 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 124 | { |
| 125 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 126 | return outPayload; |
| 127 | } |
| 128 | |
| 129 | // Only one instance of SOL is supported |
| 130 | if (request->payloadInstance != 1) |
| 131 | { |
| 132 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 133 | return outPayload; |
| 134 | } |
| 135 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 136 | auto status = std::get<sol::Manager&>(singletonPool) |
| 137 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 138 | if (!status) |
| 139 | { |
| 140 | response->completionCode = IPMI_CC_PAYLOAD_DEACTIVATED; |
| 141 | return outPayload; |
| 142 | } |
| 143 | |
| 144 | try |
| 145 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 146 | auto& context = std::get<sol::Manager&>(singletonPool) |
| 147 | .getContext(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 148 | auto sessionID = context.sessionID; |
| 149 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 150 | std::get<sol::Manager&>(singletonPool) |
| 151 | .stopPayloadInstance(request->payloadInstance); |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 152 | |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 153 | try |
| 154 | { |
| 155 | activating(request->payloadInstance, sessionID); |
| 156 | } |
| 157 | catch (std::exception& e) |
| 158 | { |
| 159 | log<level::INFO>(e.what()); |
| 160 | /* |
| 161 | * In case session has been closed (like in the case of inactivity |
| 162 | * timeout), then activating function would throw an exception, |
| 163 | * since sessionID is not found. IPMI success completion code is |
| 164 | * returned, since the session is closed. |
| 165 | */ |
| 166 | return outPayload; |
| 167 | } |
| 168 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 169 | auto check = |
| 170 | std::get<session::Manager&>(singletonPool).stopSession(sessionID); |
Tom Joseph | 6516cef | 2017-07-31 18:48:34 +0530 | [diff] [blame] | 171 | if (!check) |
Tom Joseph | e2f0a8e | 2017-04-03 02:01:49 +0530 | [diff] [blame] | 172 | { |
| 173 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 174 | } |
| 175 | } |
| 176 | catch (std::exception& e) |
| 177 | { |
| 178 | log<level::ERR>(e.what()); |
| 179 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 180 | return outPayload; |
| 181 | } |
| 182 | |
| 183 | return outPayload; |
| 184 | } |
| 185 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 186 | std::vector<uint8_t> getPayloadStatus(const std::vector<uint8_t>& inPayload, |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 187 | const message::Handler& handler) |
| 188 | { |
| 189 | std::vector<uint8_t> outPayload(sizeof(GetPayloadStatusResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 190 | auto request = |
| 191 | reinterpret_cast<const GetPayloadStatusRequest*>(inPayload.data()); |
| 192 | auto response = |
| 193 | reinterpret_cast<GetPayloadStatusResponse*>(outPayload.data()); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 194 | |
| 195 | // SOL is the payload currently supported for payload status |
| 196 | if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType) |
| 197 | { |
| 198 | response->completionCode = IPMI_CC_UNSPECIFIED_ERROR; |
| 199 | return outPayload; |
| 200 | } |
| 201 | |
| 202 | response->completionCode = IPMI_CC_OK; |
| 203 | response->capacity = MAX_PAYLOAD_INSTANCES; |
| 204 | |
| 205 | // Currently we support only one SOL session |
| 206 | response->instance1 = |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 207 | std::get<sol::Manager&>(singletonPool).isPayloadActive(1); |
Tom Joseph | e1ae56c | 2017-04-03 02:03:41 +0530 | [diff] [blame] | 208 | |
| 209 | return outPayload; |
| 210 | } |
| 211 | |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 212 | std::vector<uint8_t> getPayloadInfo(const std::vector<uint8_t>& inPayload, |
| 213 | const message::Handler& handler) |
| 214 | { |
| 215 | std::vector<uint8_t> outPayload(sizeof(GetPayloadInfoResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 216 | auto request = |
| 217 | reinterpret_cast<const GetPayloadInfoRequest*>(inPayload.data()); |
| 218 | auto response = |
| 219 | reinterpret_cast<GetPayloadInfoResponse*>(outPayload.data()); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 220 | |
| 221 | // SOL is the payload currently supported for payload status & only one |
| 222 | // instance of SOL is supported. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 223 | if (static_cast<uint8_t>(message::PayloadType::SOL) != |
| 224 | request->payloadType || |
| 225 | request->payloadInstance != 1) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 226 | { |
| 227 | response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; |
| 228 | return outPayload; |
| 229 | } |
| 230 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 231 | auto status = std::get<sol::Manager&>(singletonPool) |
| 232 | .isPayloadActive(request->payloadInstance); |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 233 | |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 234 | if (status) |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 235 | { |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 236 | auto& context = std::get<sol::Manager&>(singletonPool) |
| 237 | .getContext(request->payloadInstance); |
| 238 | response->sessionID = context.sessionID; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 239 | } |
Richard Marian Thomaiyar | 5f1dd31 | 2019-01-22 15:55:41 +0530 | [diff] [blame] | 240 | else |
| 241 | { |
| 242 | // No active payload - return session id as 0 |
| 243 | response->sessionID = 0; |
| 244 | } |
| 245 | response->completionCode = IPMI_CC_OK; |
Tom Joseph | 8093849 | 2018-03-22 10:05:20 +0530 | [diff] [blame] | 246 | return outPayload; |
| 247 | } |
| 248 | |
Tom Joseph | 5c846a8 | 2017-04-03 01:59:39 +0530 | [diff] [blame] | 249 | } // namespace command |
| 250 | |
| 251 | } // namespace sol |