Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "account_service.hpp" |
| 19 | #include "app.hpp" |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 20 | #include "async_resp.hpp" |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 21 | #include "credential_pipe.hpp" |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 22 | #include "dbus_utility.hpp" |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 23 | #include "generated/enums/virtual_media.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 24 | #include "query.hpp" |
| 25 | #include "registries/privilege_registry.hpp" |
| 26 | #include "utils/json_utils.hpp" |
| 27 | |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 28 | #include <boost/process/async_pipe.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 29 | #include <boost/url/format.hpp> |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 30 | #include <boost/url/url_view.hpp> |
Ed Tanous | 4a7fbef | 2024-04-06 16:03:49 -0700 | [diff] [blame] | 31 | #include <boost/url/url_view_base.hpp> |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 32 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 33 | #include <array> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 34 | #include <ranges> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 35 | #include <string_view> |
| 36 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 37 | namespace redfish |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 38 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 39 | |
| 40 | enum class VmMode |
| 41 | { |
| 42 | Invalid, |
| 43 | Legacy, |
| 44 | Proxy |
| 45 | }; |
| 46 | |
| 47 | inline VmMode |
| 48 | parseObjectPathAndGetMode(const sdbusplus::message::object_path& itemPath, |
| 49 | const std::string& resName) |
| 50 | { |
| 51 | std::string thisPath = itemPath.filename(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 52 | BMCWEB_LOG_DEBUG("Filename: {}, ThisPath: {}", itemPath.str, thisPath); |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 53 | |
| 54 | if (thisPath.empty()) |
| 55 | { |
| 56 | return VmMode::Invalid; |
| 57 | } |
| 58 | |
| 59 | if (thisPath != resName) |
| 60 | { |
| 61 | return VmMode::Invalid; |
| 62 | } |
| 63 | |
| 64 | auto mode = itemPath.parent_path(); |
| 65 | auto type = mode.parent_path(); |
| 66 | |
| 67 | if (mode.filename().empty() || type.filename().empty()) |
| 68 | { |
| 69 | return VmMode::Invalid; |
| 70 | } |
| 71 | |
| 72 | if (type.filename() != "VirtualMedia") |
| 73 | { |
| 74 | return VmMode::Invalid; |
| 75 | } |
| 76 | std::string modeStr = mode.filename(); |
| 77 | if (modeStr == "Legacy") |
| 78 | { |
| 79 | return VmMode::Legacy; |
| 80 | } |
| 81 | if (modeStr == "Proxy") |
| 82 | { |
| 83 | return VmMode::Proxy; |
| 84 | } |
| 85 | return VmMode::Invalid; |
| 86 | } |
| 87 | |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 88 | using CheckItemHandler = |
| 89 | std::function<void(const std::string& service, const std::string& resName, |
| 90 | const std::shared_ptr<bmcweb::AsyncResp>&, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 91 | const std::pair<sdbusplus::message::object_path, |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 92 | dbus::utility::DBusInterfacesMap>&)>; |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 93 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 94 | inline void |
| 95 | findAndParseObject(const std::string& service, const std::string& resName, |
| 96 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 97 | CheckItemHandler&& handler) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 98 | { |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 99 | sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia"); |
| 100 | dbus::utility::getManagedObjects( |
| 101 | service, path, |
Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 102 | [service, resName, asyncResp, handler = std::move(handler)]( |
| 103 | const boost::system::error_code& ec, |
| 104 | const dbus::utility::ManagedObjectType& subtree) { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 105 | if (ec) |
| 106 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 107 | BMCWEB_LOG_DEBUG("DBUS response error"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 108 | |
| 109 | return; |
| 110 | } |
| 111 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 112 | for (const auto& item : subtree) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 113 | { |
| 114 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 115 | if (mode != VmMode::Invalid) |
| 116 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 117 | handler(service, resName, asyncResp, item); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | } |
| 121 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 122 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 123 | asyncResp->res.result(boost::beast::http::status::not_found); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 124 | }); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 127 | /** |
| 128 | * @brief Function extracts transfer protocol name from URI. |
| 129 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 130 | inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri) |
| 131 | { |
Ed Tanous | 6fd2955 | 2023-10-04 09:40:14 -0700 | [diff] [blame] | 132 | boost::system::result<boost::urls::url_view> url = |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 133 | boost::urls::parse_uri(imageUri); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 134 | if (!url) |
| 135 | { |
| 136 | return "None"; |
| 137 | } |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 138 | std::string_view scheme = url->scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 139 | if (scheme == "smb") |
| 140 | { |
| 141 | return "CIFS"; |
| 142 | } |
| 143 | if (scheme == "https") |
| 144 | { |
| 145 | return "HTTPS"; |
| 146 | } |
| 147 | |
| 148 | return "None"; |
| 149 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * @brief Read all known properties from VM object interfaces |
| 153 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 154 | inline void |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 155 | vmParseInterfaceObject(const dbus::utility::DBusInterfacesMap& interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 156 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 157 | { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 158 | for (const auto& [interface, values] : interfaces) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 159 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 160 | if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 161 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 162 | for (const auto& [property, value] : values) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 163 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 164 | if (property == "EndpointId") |
| 165 | { |
| 166 | const std::string* endpointIdValue = |
| 167 | std::get_if<std::string>(&value); |
| 168 | if (endpointIdValue == nullptr) |
| 169 | { |
| 170 | continue; |
| 171 | } |
| 172 | if (!endpointIdValue->empty()) |
| 173 | { |
| 174 | // Proxy mode |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 175 | asyncResp->res |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 176 | .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] = |
| 177 | *endpointIdValue; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 178 | asyncResp->res.jsonValue["TransferProtocolType"] = |
| 179 | "OEM"; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | if (property == "ImageURL") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 183 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 184 | const std::string* imageUrlValue = |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 185 | std::get_if<std::string>(&value); |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 186 | if (imageUrlValue != nullptr && !imageUrlValue->empty()) |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 187 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 188 | std::filesystem::path filePath = *imageUrlValue; |
| 189 | if (!filePath.has_filename()) |
| 190 | { |
| 191 | // this will handle https share, which not |
| 192 | // necessarily has to have filename given. |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 193 | asyncResp->res.jsonValue["ImageName"] = ""; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 194 | } |
| 195 | else |
| 196 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 197 | asyncResp->res.jsonValue["ImageName"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 198 | filePath.filename(); |
| 199 | } |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 200 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 201 | asyncResp->res.jsonValue["Image"] = *imageUrlValue; |
| 202 | asyncResp->res.jsonValue["TransferProtocolType"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 203 | getTransferProtocolTypeFromUri(*imageUrlValue); |
| 204 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 205 | asyncResp->res.jsonValue["ConnectedVia"] = |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 206 | virtual_media::ConnectedVia::URI; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 207 | } |
| 208 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 209 | if (property == "WriteProtected") |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 210 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 211 | const bool* writeProtectedValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 212 | if (writeProtectedValue != nullptr) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 213 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 214 | asyncResp->res.jsonValue["WriteProtected"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 215 | *writeProtectedValue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 220 | if (interface == "xyz.openbmc_project.VirtualMedia.Process") |
| 221 | { |
| 222 | for (const auto& [property, value] : values) |
| 223 | { |
| 224 | if (property == "Active") |
| 225 | { |
| 226 | const bool* activeValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 227 | if (activeValue == nullptr) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 228 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 229 | BMCWEB_LOG_DEBUG("Value Active not found"); |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 230 | return; |
| 231 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 232 | asyncResp->res.jsonValue["Inserted"] = *activeValue; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 233 | |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 234 | if (*activeValue) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 235 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 236 | asyncResp->res.jsonValue["ConnectedVia"] = |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 237 | virtual_media::ConnectedVia::Applet; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * @brief Fill template for Virtual Media Item. |
| 247 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 248 | inline nlohmann::json vmItemTemplate(const std::string& name, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 249 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 250 | { |
| 251 | nlohmann::json item; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 252 | item["@odata.id"] = boost::urls::format( |
| 253 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, resName); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 254 | |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 255 | item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia"; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 256 | item["Name"] = "Virtual Removable Media"; |
| 257 | item["Id"] = resName; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 258 | item["WriteProtected"] = true; |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 259 | item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 260 | item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"}); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 261 | item["TransferMethod"] = "Stream"; |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 262 | item["Oem"]["OpenBMC"]["@odata.type"] = |
| 263 | "#OemVirtualMedia.v1_0_0.VirtualMedia"; |
V-Sanjana | 15b8972 | 2023-05-11 16:27:03 +0530 | [diff] [blame] | 264 | item["Oem"]["OpenBMC"]["@odata.id"] = boost::urls::format( |
| 265 | "/redfish/v1/Managers/{}/VirtualMedia/{}#/Oem/OpenBMC", name, resName); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 266 | |
| 267 | return item; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @brief Fills collection data |
| 272 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 273 | inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 274 | const std::string& service, |
| 275 | const std::string& name) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 276 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 277 | BMCWEB_LOG_DEBUG("Get available Virtual Media resources."); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 278 | sdbusplus::message::object_path objPath( |
| 279 | "/xyz/openbmc_project/VirtualMedia"); |
| 280 | dbus::utility::getManagedObjects( |
| 281 | service, objPath, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 282 | [name, asyncResp{std::move(asyncResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 283 | const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 284 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 285 | if (ec) |
| 286 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 287 | BMCWEB_LOG_DEBUG("DBUS response error"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 288 | return; |
| 289 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 290 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 291 | members = nlohmann::json::array(); |
| 292 | |
| 293 | for (const auto& object : subtree) |
| 294 | { |
| 295 | nlohmann::json item; |
| 296 | std::string path = object.first.filename(); |
| 297 | if (path.empty()) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 298 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 299 | continue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 300 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 301 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 302 | item["@odata.id"] = boost::urls::format( |
| 303 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, path); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 304 | members.emplace_back(std::move(item)); |
| 305 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 306 | asyncResp->res.jsonValue["Members@odata.count"] = members.size(); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 307 | }); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 308 | } |
| 309 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 310 | inline void |
| 311 | afterGetVmData(const std::string& name, const std::string& /*service*/, |
| 312 | const std::string& resName, |
| 313 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 314 | const std::pair<sdbusplus::message::object_path, |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 315 | dbus::utility::DBusInterfacesMap>& item) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 316 | { |
| 317 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 318 | if (mode == VmMode::Invalid) |
| 319 | { |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | asyncResp->res.jsonValue = vmItemTemplate(name, resName); |
| 324 | |
| 325 | // Check if dbus path is Legacy type |
| 326 | if (mode == VmMode::Legacy) |
| 327 | { |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 328 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"] |
| 329 | ["target"] = boost::urls::format( |
| 330 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.InsertMedia", |
| 331 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | vmParseInterfaceObject(item.second, asyncResp); |
| 335 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 336 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"] |
| 337 | ["target"] = boost::urls::format( |
| 338 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.EjectMedia", |
| 339 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 342 | /** |
| 343 | * @brief Fills data for specific resource |
| 344 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 345 | inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 346 | const std::string& service, const std::string& name, |
| 347 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 348 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 349 | BMCWEB_LOG_DEBUG("Get Virtual Media resource data."); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 350 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 351 | findAndParseObject(service, resName, asyncResp, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 352 | std::bind_front(afterGetVmData, name)); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 355 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 356 | * @brief Transfer protocols supported for InsertMedia action. |
| 357 | * |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 358 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 359 | enum class TransferProtocol |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 360 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 361 | https, |
| 362 | smb, |
| 363 | invalid |
| 364 | }; |
| 365 | |
| 366 | /** |
| 367 | * @brief Function extracts transfer protocol type from URI. |
| 368 | * |
| 369 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 370 | inline std::optional<TransferProtocol> |
Ed Tanous | 4a7fbef | 2024-04-06 16:03:49 -0700 | [diff] [blame] | 371 | getTransferProtocolFromUri(const boost::urls::url_view_base& imageUri) |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 372 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 373 | std::string_view scheme = imageUri.scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 374 | if (scheme == "smb") |
| 375 | { |
| 376 | return TransferProtocol::smb; |
| 377 | } |
| 378 | if (scheme == "https") |
| 379 | { |
| 380 | return TransferProtocol::https; |
| 381 | } |
| 382 | if (!scheme.empty()) |
| 383 | { |
| 384 | return TransferProtocol::invalid; |
| 385 | } |
| 386 | |
| 387 | return {}; |
| 388 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 389 | |
| 390 | /** |
| 391 | * @brief Function convert transfer protocol from string param. |
| 392 | * |
| 393 | */ |
| 394 | inline std::optional<TransferProtocol> getTransferProtocolFromParam( |
| 395 | const std::optional<std::string>& transferProtocolType) |
| 396 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 397 | if (!transferProtocolType) |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 398 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 399 | return {}; |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 402 | if (*transferProtocolType == "CIFS") |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 403 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 404 | return TransferProtocol::smb; |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 407 | if (*transferProtocolType == "HTTPS") |
| 408 | { |
| 409 | return TransferProtocol::https; |
| 410 | } |
| 411 | |
| 412 | return TransferProtocol::invalid; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * @brief Function extends URI with transfer protocol type. |
| 417 | * |
| 418 | */ |
| 419 | inline std::string |
| 420 | getUriWithTransferProtocol(const std::string& imageUri, |
| 421 | const TransferProtocol& transferProtocol) |
| 422 | { |
| 423 | if (transferProtocol == TransferProtocol::smb) |
| 424 | { |
| 425 | return "smb://" + imageUri; |
| 426 | } |
| 427 | |
| 428 | if (transferProtocol == TransferProtocol::https) |
| 429 | { |
| 430 | return "https://" + imageUri; |
| 431 | } |
| 432 | |
| 433 | return imageUri; |
| 434 | } |
| 435 | |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 436 | struct InsertMediaActionParams |
| 437 | { |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 438 | std::optional<std::string> imageUrl; |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 439 | std::optional<std::string> userName; |
| 440 | std::optional<std::string> password; |
| 441 | std::optional<std::string> transferMethod; |
| 442 | std::optional<std::string> transferProtocolType; |
| 443 | std::optional<bool> writeProtected = true; |
| 444 | std::optional<bool> inserted; |
| 445 | }; |
| 446 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 447 | /** |
| 448 | * @brief Function transceives data with dbus directly. |
| 449 | * |
| 450 | * All BMC state properties will be retrieved before sending reset request. |
| 451 | */ |
| 452 | inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 453 | const std::string& service, const std::string& name, |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 454 | const std::string& imageUrl, bool rw, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 455 | std::string&& userName, std::string&& password) |
| 456 | { |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 457 | int fd = -1; |
| 458 | std::shared_ptr<CredentialsPipe> secretPipe; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 459 | if (!userName.empty() || !password.empty()) |
| 460 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 461 | // Payload must contain data + NULL delimiters |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 462 | constexpr const size_t secretLimit = 1024; |
| 463 | if (userName.size() + password.size() + 2 > secretLimit) |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 464 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 465 | BMCWEB_LOG_ERROR("Credentials too long to handle"); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 466 | messages::unrecognizedRequestBody(asyncResp->res); |
| 467 | return; |
| 468 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 469 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 470 | // Open pipe |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 471 | secretPipe = std::make_shared<CredentialsPipe>( |
| 472 | crow::connections::systemBus->get_io_context()); |
| 473 | fd = secretPipe->fd(); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 474 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 475 | // Pass secret over pipe |
| 476 | secretPipe->asyncWrite( |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 477 | std::move(userName), std::move(password), |
| 478 | [asyncResp, secretPipe](const boost::system::error_code& ec, |
| 479 | std::size_t) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 480 | if (ec) |
| 481 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 482 | BMCWEB_LOG_ERROR("Failed to pass secret: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 483 | messages::internalError(asyncResp->res); |
| 484 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 485 | }); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 486 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 487 | |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 488 | dbus::utility::DbusVariantType unixFd( |
| 489 | std::in_place_type<sdbusplus::message::unix_fd>, fd); |
| 490 | |
| 491 | sdbusplus::message::object_path path( |
| 492 | "/xyz/openbmc_project/VirtualMedia/Legacy"); |
| 493 | path /= name; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 494 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 495 | [asyncResp, secretPipe](const boost::system::error_code& ec, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 496 | bool success) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 497 | if (ec) |
| 498 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 499 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 500 | messages::internalError(asyncResp->res); |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 501 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 502 | } |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 503 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 504 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 505 | BMCWEB_LOG_ERROR("Service responded with error"); |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 506 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 507 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 508 | }, |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame] | 509 | service, path.str, "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", |
| 510 | imageUrl, rw, unixFd); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 514 | * @brief Function validate parameters of insert media request. |
| 515 | * |
| 516 | */ |
| 517 | inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 518 | const std::string& service, |
| 519 | const std::string& resName, |
| 520 | InsertMediaActionParams& actionParams) |
| 521 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 522 | BMCWEB_LOG_DEBUG("Validation started"); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 523 | // required param imageUrl must not be empty |
| 524 | if (!actionParams.imageUrl) |
| 525 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 526 | BMCWEB_LOG_ERROR("Request action parameter Image is empty."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 527 | |
| 528 | messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image"); |
| 529 | |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | // optional param inserted must be true |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 534 | if (actionParams.inserted && !*actionParams.inserted) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 535 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 536 | BMCWEB_LOG_ERROR( |
| 537 | "Request action optional parameter Inserted must be true."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 538 | |
| 539 | messages::actionParameterNotSupported(asyncResp->res, "Inserted", |
| 540 | "InsertMedia"); |
| 541 | |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | // optional param transferMethod must be stream |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 546 | if (actionParams.transferMethod && |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 547 | (*actionParams.transferMethod != "Stream")) |
| 548 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 549 | BMCWEB_LOG_ERROR("Request action optional parameter " |
| 550 | "TransferMethod must be Stream."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 551 | |
| 552 | messages::actionParameterNotSupported(asyncResp->res, "TransferMethod", |
| 553 | "InsertMedia"); |
| 554 | |
| 555 | return; |
| 556 | } |
Ed Tanous | 6fd2955 | 2023-10-04 09:40:14 -0700 | [diff] [blame] | 557 | boost::system::result<boost::urls::url_view> url = |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 558 | boost::urls::parse_uri(*actionParams.imageUrl); |
| 559 | if (!url) |
| 560 | { |
| 561 | messages::actionParameterValueFormatError( |
| 562 | asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia"); |
| 563 | return; |
| 564 | } |
| 565 | std::optional<TransferProtocol> uriTransferProtocolType = |
| 566 | getTransferProtocolFromUri(*url); |
| 567 | |
| 568 | std::optional<TransferProtocol> paramTransferProtocolType = |
| 569 | getTransferProtocolFromParam(actionParams.transferProtocolType); |
| 570 | |
| 571 | // ImageUrl does not contain valid protocol type |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 572 | if (uriTransferProtocolType && |
| 573 | *uriTransferProtocolType == TransferProtocol::invalid) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 574 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 575 | BMCWEB_LOG_ERROR("Request action parameter ImageUrl must " |
| 576 | "contain specified protocol type from list: " |
| 577 | "(smb, https)."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 578 | |
| 579 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 580 | |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | // transferProtocolType should contain value from list |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 585 | if (paramTransferProtocolType && |
| 586 | *paramTransferProtocolType == TransferProtocol::invalid) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 587 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 588 | BMCWEB_LOG_ERROR("Request action parameter TransferProtocolType " |
| 589 | "must be provided with value from list: " |
| 590 | "(CIFS, HTTPS)."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 591 | |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 592 | messages::propertyValueNotInList( |
| 593 | asyncResp->res, actionParams.transferProtocolType.value_or(""), |
| 594 | "TransferProtocolType"); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 595 | return; |
| 596 | } |
| 597 | |
| 598 | // valid transfer protocol not provided either with URI nor param |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 599 | if (!uriTransferProtocolType && !paramTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 600 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 601 | BMCWEB_LOG_ERROR("Request action parameter ImageUrl must " |
| 602 | "contain specified protocol type or param " |
| 603 | "TransferProtocolType must be provided."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 604 | |
| 605 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 606 | |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | // valid transfer protocol provided both with URI and param |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 611 | if (paramTransferProtocolType && uriTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 612 | { |
| 613 | // check if protocol is the same for URI and param |
| 614 | if (*paramTransferProtocolType != *uriTransferProtocolType) |
| 615 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 616 | BMCWEB_LOG_ERROR("Request action parameter " |
| 617 | "TransferProtocolType must contain the " |
| 618 | "same protocol type as protocol type " |
| 619 | "provided with param imageUrl."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 620 | |
| 621 | messages::actionParameterValueTypeError( |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 622 | asyncResp->res, actionParams.transferProtocolType.value_or(""), |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 623 | "TransferProtocolType", "InsertMedia"); |
| 624 | |
| 625 | return; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | // validation passed, add protocol to URI if needed |
Boleslaw Ogonczyk Makowski | 7ead48e | 2023-09-01 15:57:10 +0200 | [diff] [blame] | 630 | if (!uriTransferProtocolType && paramTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 631 | { |
| 632 | actionParams.imageUrl = getUriWithTransferProtocol( |
| 633 | *actionParams.imageUrl, *paramTransferProtocolType); |
| 634 | } |
| 635 | |
Jayaprakash Mutyala | 452bd8d | 2023-04-18 12:28:38 +0000 | [diff] [blame] | 636 | if (!actionParams.userName) |
| 637 | { |
| 638 | actionParams.userName = ""; |
| 639 | } |
| 640 | |
| 641 | if (!actionParams.password) |
| 642 | { |
| 643 | actionParams.password = ""; |
| 644 | } |
| 645 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 646 | doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl, |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 647 | !(actionParams.writeProtected.value_or(false)), |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 648 | std::move(*actionParams.userName), |
| 649 | std::move(*actionParams.password)); |
| 650 | } |
| 651 | |
| 652 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 653 | * @brief Function transceives data with dbus directly. |
| 654 | * |
| 655 | * All BMC state properties will be retrieved before sending reset request. |
| 656 | */ |
Ed Tanous | 24e740a | 2023-02-24 12:08:58 -0800 | [diff] [blame] | 657 | inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 658 | const std::string& service, const std::string& name, |
| 659 | bool legacy) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 660 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 661 | // Legacy mount requires parameter with image |
| 662 | if (legacy) |
| 663 | { |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 664 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 665 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 666 | if (ec) |
| 667 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 668 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 669 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 670 | messages::internalError(asyncResp->res); |
| 671 | return; |
| 672 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 673 | }, |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 674 | service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 675 | "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount"); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 676 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 677 | else // proxy |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 678 | { |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 679 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 680 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 681 | if (ec) |
| 682 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 683 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 684 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 685 | messages::internalError(asyncResp->res); |
| 686 | return; |
| 687 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 688 | }, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 689 | service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name, |
| 690 | "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount"); |
| 691 | } |
| 692 | } |
| 693 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 694 | inline void handleManagersVirtualMediaActionInsertPost( |
| 695 | crow::App& app, const crow::Request& req, |
| 696 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 697 | const std::string& name, const std::string& resName) |
| 698 | { |
| 699 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 700 | { |
| 701 | return; |
| 702 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 703 | |
| 704 | constexpr std::string_view action = "VirtualMedia.InsertMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 705 | if (name != "bmc") |
| 706 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 707 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 708 | |
| 709 | return; |
| 710 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 711 | InsertMediaActionParams actionParams; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 712 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 713 | // Read obligatory parameters (url of image) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 714 | if (!json_util::readJsonAction( |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 715 | req, asyncResp->res, "Image", actionParams.imageUrl, |
| 716 | "WriteProtected", actionParams.writeProtected, "UserName", |
| 717 | actionParams.userName, "Password", actionParams.password, |
| 718 | "Inserted", actionParams.inserted, "TransferMethod", |
| 719 | actionParams.transferMethod, "TransferProtocolType", |
| 720 | actionParams.transferProtocolType)) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 721 | { |
| 722 | return; |
| 723 | } |
| 724 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 725 | dbus::utility::getDbusObject( |
| 726 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 727 | [asyncResp, action, actionParams, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 728 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 729 | const dbus::utility::MapperGetObject& getObjectType) mutable { |
| 730 | if (ec) |
| 731 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 732 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 733 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 734 | |
| 735 | return; |
| 736 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 737 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 738 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 739 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 740 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 741 | sdbusplus::message::object_path path( |
| 742 | "/xyz/openbmc_project/VirtualMedia"); |
| 743 | dbus::utility::getManagedObjects( |
| 744 | service, path, |
| 745 | [service, resName, action, actionParams, asyncResp]( |
| 746 | const boost::system::error_code& ec2, |
| 747 | const dbus::utility::ManagedObjectType& subtree) mutable { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 748 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 749 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 750 | // Not possible in proxy mode |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 751 | BMCWEB_LOG_DEBUG("InsertMedia not " |
| 752 | "allowed in proxy mode"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 753 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 754 | |
| 755 | return; |
| 756 | } |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 757 | for (const auto& object : subtree) |
| 758 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 759 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 760 | if (mode == VmMode::Legacy) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 761 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 762 | validateParams(asyncResp, service, resName, actionParams); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 763 | |
| 764 | return; |
| 765 | } |
| 766 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 767 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 768 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 769 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 770 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | inline void handleManagersVirtualMediaActionEject( |
| 774 | crow::App& app, const crow::Request& req, |
| 775 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 776 | const std::string& managerName, const std::string& resName) |
| 777 | { |
| 778 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 779 | { |
| 780 | return; |
| 781 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 782 | |
| 783 | constexpr std::string_view action = "VirtualMedia.EjectMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 784 | if (managerName != "bmc") |
| 785 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 786 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 787 | |
| 788 | return; |
| 789 | } |
| 790 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 791 | dbus::utility::getDbusObject( |
| 792 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 793 | [asyncResp, action, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 794 | resName](const boost::system::error_code& ec2, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 795 | const dbus::utility::MapperGetObject& getObjectType) { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 796 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 797 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 798 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec2); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 799 | messages::internalError(asyncResp->res); |
| 800 | |
| 801 | return; |
| 802 | } |
| 803 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 804 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 805 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 806 | sdbusplus::message::object_path path( |
| 807 | "/xyz/openbmc_project/VirtualMedia"); |
| 808 | dbus::utility::getManagedObjects( |
| 809 | service, path, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 810 | [resName, service, action, |
| 811 | asyncResp](const boost::system::error_code& ec, |
| 812 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 813 | if (ec) |
| 814 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 815 | BMCWEB_LOG_ERROR("ObjectMapper : No Service found"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 816 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
| 820 | for (const auto& object : subtree) |
| 821 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 822 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
| 823 | if (mode != VmMode::Invalid) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 824 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 825 | doEjectAction(asyncResp, service, resName, |
| 826 | mode == VmMode::Legacy); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 827 | return; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 828 | } |
| 829 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 830 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 831 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 832 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 833 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | inline void handleManagersVirtualMediaCollectionGet( |
| 837 | crow::App& app, const crow::Request& req, |
| 838 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 839 | const std::string& name) |
| 840 | { |
| 841 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 842 | { |
| 843 | return; |
| 844 | } |
| 845 | if (name != "bmc") |
| 846 | { |
| 847 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", name); |
| 848 | |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | asyncResp->res.jsonValue["@odata.type"] = |
| 853 | "#VirtualMediaCollection.VirtualMediaCollection"; |
| 854 | asyncResp->res.jsonValue["Name"] = "Virtual Media Services"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 855 | asyncResp->res.jsonValue["@odata.id"] = |
| 856 | boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", name); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 857 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 858 | dbus::utility::getDbusObject( |
| 859 | "/xyz/openbmc_project/VirtualMedia", {}, |
| 860 | [asyncResp, name](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 861 | const dbus::utility::MapperGetObject& getObjectType) { |
| 862 | if (ec) |
| 863 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 864 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 865 | messages::internalError(asyncResp->res); |
| 866 | |
| 867 | return; |
| 868 | } |
| 869 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 870 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 871 | |
| 872 | getVmResourceList(asyncResp, service, name); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 873 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | inline void |
| 877 | handleVirtualMediaGet(crow::App& app, const crow::Request& req, |
| 878 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 879 | const std::string& name, const std::string& resName) |
| 880 | { |
| 881 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 882 | { |
| 883 | return; |
| 884 | } |
| 885 | if (name != "bmc") |
| 886 | { |
| 887 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
| 888 | |
| 889 | return; |
| 890 | } |
| 891 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 892 | dbus::utility::getDbusObject( |
| 893 | "/xyz/openbmc_project/VirtualMedia", {}, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 894 | [asyncResp, name, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 895 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 896 | const dbus::utility::MapperGetObject& getObjectType) { |
| 897 | if (ec) |
| 898 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 899 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 900 | messages::internalError(asyncResp->res); |
| 901 | |
| 902 | return; |
| 903 | } |
| 904 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 905 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 906 | |
| 907 | getVmData(asyncResp, service, name, resName); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 908 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 911 | inline void requestNBDVirtualMediaRoutes(App& app) |
| 912 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 913 | BMCWEB_ROUTE( |
| 914 | app, |
| 915 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 916 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 917 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 918 | handleManagersVirtualMediaActionInsertPost, std::ref(app))); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 919 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 920 | BMCWEB_ROUTE( |
| 921 | app, |
| 922 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 923 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 924 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 925 | handleManagersVirtualMediaActionEject, std::ref(app))); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 926 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 927 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 928 | .privileges(redfish::privileges::getVirtualMediaCollection) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 929 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 930 | handleManagersVirtualMediaCollectionGet, std::ref(app))); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 931 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 932 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 933 | .privileges(redfish::privileges::getVirtualMedia) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 934 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 935 | std::bind_front(handleVirtualMediaGet, std::ref(app))); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 936 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 937 | |
| 938 | } // namespace redfish |