xref: /openbmc/bmcweb/features/redfish/lib/virtual_media.hpp (revision 62598e31d0988d589506d5091bd38f72d61faf5e)
1107077deSPrzemyslaw Czarnowski /*
2107077deSPrzemyslaw Czarnowski // Copyright (c) 2018 Intel Corporation
3107077deSPrzemyslaw Czarnowski //
4107077deSPrzemyslaw Czarnowski // Licensed under the Apache License, Version 2.0 (the "License");
5107077deSPrzemyslaw Czarnowski // you may not use this file except in compliance with the License.
6107077deSPrzemyslaw Czarnowski // You may obtain a copy of the License at
7107077deSPrzemyslaw Czarnowski //
8107077deSPrzemyslaw Czarnowski //      http://www.apache.org/licenses/LICENSE-2.0
9107077deSPrzemyslaw Czarnowski //
10107077deSPrzemyslaw Czarnowski // Unless required by applicable law or agreed to in writing, software
11107077deSPrzemyslaw Czarnowski // distributed under the License is distributed on an "AS IS" BASIS,
12107077deSPrzemyslaw Czarnowski // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13107077deSPrzemyslaw Czarnowski // See the License for the specific language governing permissions and
14107077deSPrzemyslaw Czarnowski // limitations under the License.
15107077deSPrzemyslaw Czarnowski */
16107077deSPrzemyslaw Czarnowski #pragma once
17107077deSPrzemyslaw Czarnowski 
183ccb3adbSEd Tanous #include "account_service.hpp"
193ccb3adbSEd Tanous #include "app.hpp"
2079fdf63eSPrzemyslaw Czarnowski #include "async_resp.hpp"
212b73119cSGeorge Liu #include "dbus_utility.hpp"
22739b87efSEd Tanous #include "generated/enums/virtual_media.hpp"
233ccb3adbSEd Tanous #include "query.hpp"
243ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
253ccb3adbSEd Tanous #include "utils/json_utils.hpp"
263ccb3adbSEd Tanous 
27988fb7b2SAdrian Ambrożewicz #include <boost/process/async_pipe.hpp>
28ef4c65b7SEd Tanous #include <boost/url/format.hpp>
299e319cf0SAnna Platash #include <boost/url/url_view.hpp>
30107077deSPrzemyslaw Czarnowski 
312b73119cSGeorge Liu #include <array>
322b73119cSGeorge Liu #include <string_view>
332b73119cSGeorge Liu 
34107077deSPrzemyslaw Czarnowski namespace redfish
35107077deSPrzemyslaw Czarnowski {
36365a73f4SEd Tanous 
37365a73f4SEd Tanous enum class VmMode
38365a73f4SEd Tanous {
39365a73f4SEd Tanous     Invalid,
40365a73f4SEd Tanous     Legacy,
41365a73f4SEd Tanous     Proxy
42365a73f4SEd Tanous };
43365a73f4SEd Tanous 
44365a73f4SEd Tanous inline VmMode
45365a73f4SEd Tanous     parseObjectPathAndGetMode(const sdbusplus::message::object_path& itemPath,
46365a73f4SEd Tanous                               const std::string& resName)
47365a73f4SEd Tanous {
48365a73f4SEd Tanous     std::string thisPath = itemPath.filename();
49*62598e31SEd Tanous     BMCWEB_LOG_DEBUG("Filename: {}, ThisPath: {}", itemPath.str, thisPath);
50365a73f4SEd Tanous 
51365a73f4SEd Tanous     if (thisPath.empty())
52365a73f4SEd Tanous     {
53365a73f4SEd Tanous         return VmMode::Invalid;
54365a73f4SEd Tanous     }
55365a73f4SEd Tanous 
56365a73f4SEd Tanous     if (thisPath != resName)
57365a73f4SEd Tanous     {
58365a73f4SEd Tanous         return VmMode::Invalid;
59365a73f4SEd Tanous     }
60365a73f4SEd Tanous 
61365a73f4SEd Tanous     auto mode = itemPath.parent_path();
62365a73f4SEd Tanous     auto type = mode.parent_path();
63365a73f4SEd Tanous 
64365a73f4SEd Tanous     if (mode.filename().empty() || type.filename().empty())
65365a73f4SEd Tanous     {
66365a73f4SEd Tanous         return VmMode::Invalid;
67365a73f4SEd Tanous     }
68365a73f4SEd Tanous 
69365a73f4SEd Tanous     if (type.filename() != "VirtualMedia")
70365a73f4SEd Tanous     {
71365a73f4SEd Tanous         return VmMode::Invalid;
72365a73f4SEd Tanous     }
73365a73f4SEd Tanous     std::string modeStr = mode.filename();
74365a73f4SEd Tanous     if (modeStr == "Legacy")
75365a73f4SEd Tanous     {
76365a73f4SEd Tanous         return VmMode::Legacy;
77365a73f4SEd Tanous     }
78365a73f4SEd Tanous     if (modeStr == "Proxy")
79365a73f4SEd Tanous     {
80365a73f4SEd Tanous         return VmMode::Proxy;
81365a73f4SEd Tanous     }
82365a73f4SEd Tanous     return VmMode::Invalid;
83365a73f4SEd Tanous }
84365a73f4SEd Tanous 
8579fdf63eSPrzemyslaw Czarnowski using CheckItemHandler =
8679fdf63eSPrzemyslaw Czarnowski     std::function<void(const std::string& service, const std::string& resName,
8779fdf63eSPrzemyslaw Czarnowski                        const std::shared_ptr<bmcweb::AsyncResp>&,
8870cbdf53SGeorge Liu                        const std::pair<sdbusplus::message::object_path,
8979fdf63eSPrzemyslaw Czarnowski                                        dbus::utility::DBusInteracesMap>&)>;
9079fdf63eSPrzemyslaw Czarnowski 
91ac106bf6SEd Tanous inline void
92ac106bf6SEd Tanous     findAndParseObject(const std::string& service, const std::string& resName,
93ac106bf6SEd Tanous                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
9479fdf63eSPrzemyslaw Czarnowski                        CheckItemHandler&& handler)
9579fdf63eSPrzemyslaw Czarnowski {
965eb468daSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia");
975eb468daSGeorge Liu     dbus::utility::getManagedObjects(
985eb468daSGeorge Liu         service, path,
99ac106bf6SEd Tanous         [service, resName, asyncResp,
100746c5b8aSLakshmi Yadlapati          handler](const boost::system::error_code& ec,
10170cbdf53SGeorge Liu                   const dbus::utility::ManagedObjectType& subtree) {
10279fdf63eSPrzemyslaw Czarnowski         if (ec)
10379fdf63eSPrzemyslaw Czarnowski         {
104*62598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error");
10579fdf63eSPrzemyslaw Czarnowski 
10679fdf63eSPrzemyslaw Czarnowski             return;
10779fdf63eSPrzemyslaw Czarnowski         }
10879fdf63eSPrzemyslaw Czarnowski 
10970cbdf53SGeorge Liu         for (const auto& item : subtree)
11079fdf63eSPrzemyslaw Czarnowski         {
11179fdf63eSPrzemyslaw Czarnowski             VmMode mode = parseObjectPathAndGetMode(item.first, resName);
11279fdf63eSPrzemyslaw Czarnowski             if (mode != VmMode::Invalid)
11379fdf63eSPrzemyslaw Czarnowski             {
114ac106bf6SEd Tanous                 handler(service, resName, asyncResp, item);
11579fdf63eSPrzemyslaw Czarnowski                 return;
11679fdf63eSPrzemyslaw Czarnowski             }
11779fdf63eSPrzemyslaw Czarnowski         }
11879fdf63eSPrzemyslaw Czarnowski 
119*62598e31SEd Tanous         BMCWEB_LOG_DEBUG("Parent item not found");
120ac106bf6SEd Tanous         asyncResp->res.result(boost::beast::http::status::not_found);
1215eb468daSGeorge Liu         });
12279fdf63eSPrzemyslaw Czarnowski }
12379fdf63eSPrzemyslaw Czarnowski 
1249e319cf0SAnna Platash /**
1259e319cf0SAnna Platash  * @brief Function extracts transfer protocol name from URI.
1269e319cf0SAnna Platash  */
12767df073bSEd Tanous inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri)
12867df073bSEd Tanous {
12967df073bSEd Tanous     boost::urls::result<boost::urls::url_view> url =
130079360aeSEd Tanous         boost::urls::parse_uri(imageUri);
13167df073bSEd Tanous     if (!url)
13267df073bSEd Tanous     {
13367df073bSEd Tanous         return "None";
13467df073bSEd Tanous     }
135079360aeSEd Tanous     std::string_view scheme = url->scheme();
13667df073bSEd Tanous     if (scheme == "smb")
13767df073bSEd Tanous     {
13867df073bSEd Tanous         return "CIFS";
13967df073bSEd Tanous     }
14067df073bSEd Tanous     if (scheme == "https")
14167df073bSEd Tanous     {
14267df073bSEd Tanous         return "HTTPS";
14367df073bSEd Tanous     }
14467df073bSEd Tanous 
14567df073bSEd Tanous     return "None";
14667df073bSEd Tanous }
147107077deSPrzemyslaw Czarnowski 
148107077deSPrzemyslaw Czarnowski /**
149107077deSPrzemyslaw Czarnowski  * @brief Read all known properties from VM object interfaces
150107077deSPrzemyslaw Czarnowski  */
15122db1728SEd Tanous inline void
1528a592810SEd Tanous     vmParseInterfaceObject(const dbus::utility::DBusInteracesMap& interfaces,
153ac106bf6SEd Tanous                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
154107077deSPrzemyslaw Czarnowski {
1558a592810SEd Tanous     for (const auto& [interface, values] : interfaces)
156107077deSPrzemyslaw Czarnowski     {
157711ac7a9SEd Tanous         if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint")
158107077deSPrzemyslaw Czarnowski         {
159711ac7a9SEd Tanous             for (const auto& [property, value] : values)
160107077deSPrzemyslaw Czarnowski             {
161711ac7a9SEd Tanous                 if (property == "EndpointId")
162107077deSPrzemyslaw Czarnowski                 {
163107077deSPrzemyslaw Czarnowski                     const std::string* endpointIdValue =
164711ac7a9SEd Tanous                         std::get_if<std::string>(&value);
165711ac7a9SEd Tanous                     if (endpointIdValue == nullptr)
166107077deSPrzemyslaw Czarnowski                     {
167711ac7a9SEd Tanous                         continue;
168711ac7a9SEd Tanous                     }
169107077deSPrzemyslaw Czarnowski                     if (!endpointIdValue->empty())
170107077deSPrzemyslaw Czarnowski                     {
171107077deSPrzemyslaw Czarnowski                         // Proxy mode
172ac106bf6SEd Tanous                         asyncResp->res
173711ac7a9SEd Tanous                             .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] =
174d04ba325SPrzemyslaw Czarnowski                             *endpointIdValue;
175ac106bf6SEd Tanous                         asyncResp->res.jsonValue["TransferProtocolType"] =
176ac106bf6SEd Tanous                             "OEM";
177107077deSPrzemyslaw Czarnowski                     }
178107077deSPrzemyslaw Czarnowski                 }
179711ac7a9SEd Tanous                 if (property == "ImageURL")
180107077deSPrzemyslaw Czarnowski                 {
181107077deSPrzemyslaw Czarnowski                     const std::string* imageUrlValue =
182711ac7a9SEd Tanous                         std::get_if<std::string>(&value);
18326f6976fSEd Tanous                     if (imageUrlValue != nullptr && !imageUrlValue->empty())
184107077deSPrzemyslaw Czarnowski                     {
185da4784d8SPrzemyslaw Czarnowski                         std::filesystem::path filePath = *imageUrlValue;
186da4784d8SPrzemyslaw Czarnowski                         if (!filePath.has_filename())
187da4784d8SPrzemyslaw Czarnowski                         {
1889e319cf0SAnna Platash                             // this will handle https share, which not
1899e319cf0SAnna Platash                             // necessarily has to have filename given.
190ac106bf6SEd Tanous                             asyncResp->res.jsonValue["ImageName"] = "";
191da4784d8SPrzemyslaw Czarnowski                         }
192da4784d8SPrzemyslaw Czarnowski                         else
193da4784d8SPrzemyslaw Czarnowski                         {
194ac106bf6SEd Tanous                             asyncResp->res.jsonValue["ImageName"] =
1959e319cf0SAnna Platash                                 filePath.filename();
196da4784d8SPrzemyslaw Czarnowski                         }
197da4784d8SPrzemyslaw Czarnowski 
198ac106bf6SEd Tanous                         asyncResp->res.jsonValue["Image"] = *imageUrlValue;
199ac106bf6SEd Tanous                         asyncResp->res.jsonValue["TransferProtocolType"] =
2009e319cf0SAnna Platash                             getTransferProtocolTypeFromUri(*imageUrlValue);
2019e319cf0SAnna Platash 
202ac106bf6SEd Tanous                         asyncResp->res.jsonValue["ConnectedVia"] =
203739b87efSEd Tanous                             virtual_media::ConnectedVia::URI;
204107077deSPrzemyslaw Czarnowski                     }
205107077deSPrzemyslaw Czarnowski                 }
206711ac7a9SEd Tanous                 if (property == "WriteProtected")
2079e319cf0SAnna Platash                 {
208711ac7a9SEd Tanous                     const bool* writeProtectedValue = std::get_if<bool>(&value);
209e662eae8SEd Tanous                     if (writeProtectedValue != nullptr)
2109e319cf0SAnna Platash                     {
211ac106bf6SEd Tanous                         asyncResp->res.jsonValue["WriteProtected"] =
2129e319cf0SAnna Platash                             *writeProtectedValue;
2139e319cf0SAnna Platash                     }
2149e319cf0SAnna Platash                 }
2159e319cf0SAnna Platash             }
216107077deSPrzemyslaw Czarnowski         }
217711ac7a9SEd Tanous         if (interface == "xyz.openbmc_project.VirtualMedia.Process")
218711ac7a9SEd Tanous         {
219711ac7a9SEd Tanous             for (const auto& [property, value] : values)
220711ac7a9SEd Tanous             {
221711ac7a9SEd Tanous                 if (property == "Active")
222711ac7a9SEd Tanous                 {
223711ac7a9SEd Tanous                     const bool* activeValue = std::get_if<bool>(&value);
224e662eae8SEd Tanous                     if (activeValue == nullptr)
225711ac7a9SEd Tanous                     {
226*62598e31SEd Tanous                         BMCWEB_LOG_DEBUG("Value Active not found");
227711ac7a9SEd Tanous                         return;
228711ac7a9SEd Tanous                     }
229ac106bf6SEd Tanous                     asyncResp->res.jsonValue["Inserted"] = *activeValue;
230711ac7a9SEd Tanous 
231e05aec50SEd Tanous                     if (*activeValue)
232711ac7a9SEd Tanous                     {
233ac106bf6SEd Tanous                         asyncResp->res.jsonValue["ConnectedVia"] =
234739b87efSEd Tanous                             virtual_media::ConnectedVia::Applet;
235711ac7a9SEd Tanous                     }
236711ac7a9SEd Tanous                 }
237711ac7a9SEd Tanous             }
238711ac7a9SEd Tanous         }
239107077deSPrzemyslaw Czarnowski     }
240107077deSPrzemyslaw Czarnowski }
241107077deSPrzemyslaw Czarnowski 
242107077deSPrzemyslaw Czarnowski /**
243107077deSPrzemyslaw Czarnowski  * @brief Fill template for Virtual Media Item.
244107077deSPrzemyslaw Czarnowski  */
24522db1728SEd Tanous inline nlohmann::json vmItemTemplate(const std::string& name,
246107077deSPrzemyslaw Czarnowski                                      const std::string& resName)
247107077deSPrzemyslaw Czarnowski {
248107077deSPrzemyslaw Czarnowski     nlohmann::json item;
249ef4c65b7SEd Tanous     item["@odata.id"] = boost::urls::format(
250ef4c65b7SEd Tanous         "/redfish/v1/Managers/{}/VirtualMedia/{}", name, resName);
25122db1728SEd Tanous 
252d04ba325SPrzemyslaw Czarnowski     item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia";
253107077deSPrzemyslaw Czarnowski     item["Name"] = "Virtual Removable Media";
254107077deSPrzemyslaw Czarnowski     item["Id"] = resName;
255107077deSPrzemyslaw Czarnowski     item["WriteProtected"] = true;
256739b87efSEd Tanous     item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected;
257613dabeaSEd Tanous     item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"});
258107077deSPrzemyslaw Czarnowski     item["TransferMethod"] = "Stream";
259d04ba325SPrzemyslaw Czarnowski     item["Oem"]["OpenBMC"]["@odata.type"] =
260d04ba325SPrzemyslaw Czarnowski         "#OemVirtualMedia.v1_0_0.VirtualMedia";
26115b89725SV-Sanjana     item["Oem"]["OpenBMC"]["@odata.id"] = boost::urls::format(
26215b89725SV-Sanjana         "/redfish/v1/Managers/{}/VirtualMedia/{}#/Oem/OpenBMC", name, resName);
263107077deSPrzemyslaw Czarnowski 
264107077deSPrzemyslaw Czarnowski     return item;
265107077deSPrzemyslaw Czarnowski }
266107077deSPrzemyslaw Czarnowski 
267107077deSPrzemyslaw Czarnowski /**
268107077deSPrzemyslaw Czarnowski  *  @brief Fills collection data
269107077deSPrzemyslaw Czarnowski  */
270ac106bf6SEd Tanous inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
271107077deSPrzemyslaw Czarnowski                               const std::string& service,
272107077deSPrzemyslaw Czarnowski                               const std::string& name)
273107077deSPrzemyslaw Czarnowski {
274*62598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get available Virtual Media resources.");
2755eb468daSGeorge Liu     sdbusplus::message::object_path objPath(
2765eb468daSGeorge Liu         "/xyz/openbmc_project/VirtualMedia");
2775eb468daSGeorge Liu     dbus::utility::getManagedObjects(
2785eb468daSGeorge Liu         service, objPath,
279ac106bf6SEd Tanous         [name, asyncResp{std::move(asyncResp)}](
2805e7e2dc5SEd Tanous             const boost::system::error_code& ec,
28102cad96eSEd Tanous             const dbus::utility::ManagedObjectType& subtree) {
282107077deSPrzemyslaw Czarnowski         if (ec)
283107077deSPrzemyslaw Czarnowski         {
284*62598e31SEd Tanous             BMCWEB_LOG_DEBUG("DBUS response error");
285107077deSPrzemyslaw Czarnowski             return;
286107077deSPrzemyslaw Czarnowski         }
287ac106bf6SEd Tanous         nlohmann::json& members = asyncResp->res.jsonValue["Members"];
288107077deSPrzemyslaw Czarnowski         members = nlohmann::json::array();
289107077deSPrzemyslaw Czarnowski 
290107077deSPrzemyslaw Czarnowski         for (const auto& object : subtree)
291107077deSPrzemyslaw Czarnowski         {
292107077deSPrzemyslaw Czarnowski             nlohmann::json item;
2932dfd18efSEd Tanous             std::string path = object.first.filename();
2942dfd18efSEd Tanous             if (path.empty())
295107077deSPrzemyslaw Czarnowski             {
296107077deSPrzemyslaw Czarnowski                 continue;
297107077deSPrzemyslaw Czarnowski             }
298107077deSPrzemyslaw Czarnowski 
299ef4c65b7SEd Tanous             item["@odata.id"] = boost::urls::format(
300ef4c65b7SEd Tanous                 "/redfish/v1/Managers/{}/VirtualMedia/{}", name, path);
301107077deSPrzemyslaw Czarnowski             members.emplace_back(std::move(item));
302107077deSPrzemyslaw Czarnowski         }
303ac106bf6SEd Tanous         asyncResp->res.jsonValue["Members@odata.count"] = members.size();
3045eb468daSGeorge Liu         });
305107077deSPrzemyslaw Czarnowski }
306107077deSPrzemyslaw Czarnowski 
30770cbdf53SGeorge Liu inline void
30870cbdf53SGeorge Liu     afterGetVmData(const std::string& name, const std::string& /*service*/,
30979fdf63eSPrzemyslaw Czarnowski                    const std::string& resName,
31079fdf63eSPrzemyslaw Czarnowski                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
31170cbdf53SGeorge Liu                    const std::pair<sdbusplus::message::object_path,
31279fdf63eSPrzemyslaw Czarnowski                                    dbus::utility::DBusInteracesMap>& item)
31379fdf63eSPrzemyslaw Czarnowski {
31479fdf63eSPrzemyslaw Czarnowski     VmMode mode = parseObjectPathAndGetMode(item.first, resName);
31579fdf63eSPrzemyslaw Czarnowski     if (mode == VmMode::Invalid)
31679fdf63eSPrzemyslaw Czarnowski     {
31779fdf63eSPrzemyslaw Czarnowski         return;
31879fdf63eSPrzemyslaw Czarnowski     }
31979fdf63eSPrzemyslaw Czarnowski 
32079fdf63eSPrzemyslaw Czarnowski     asyncResp->res.jsonValue = vmItemTemplate(name, resName);
32179fdf63eSPrzemyslaw Czarnowski 
32279fdf63eSPrzemyslaw Czarnowski     // Check if dbus path is Legacy type
32379fdf63eSPrzemyslaw Czarnowski     if (mode == VmMode::Legacy)
32479fdf63eSPrzemyslaw Czarnowski     {
325ef4c65b7SEd Tanous         asyncResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"]
326ef4c65b7SEd Tanous                                 ["target"] = boost::urls::format(
327ef4c65b7SEd Tanous             "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.InsertMedia",
328ef4c65b7SEd Tanous             name, resName);
32979fdf63eSPrzemyslaw Czarnowski     }
33079fdf63eSPrzemyslaw Czarnowski 
33179fdf63eSPrzemyslaw Czarnowski     vmParseInterfaceObject(item.second, asyncResp);
33279fdf63eSPrzemyslaw Czarnowski 
333ef4c65b7SEd Tanous     asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"]
334ef4c65b7SEd Tanous                             ["target"] = boost::urls::format(
335ef4c65b7SEd Tanous         "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.EjectMedia",
336ef4c65b7SEd Tanous         name, resName);
33779fdf63eSPrzemyslaw Czarnowski }
33879fdf63eSPrzemyslaw Czarnowski 
339107077deSPrzemyslaw Czarnowski /**
340107077deSPrzemyslaw Czarnowski  *  @brief Fills data for specific resource
341107077deSPrzemyslaw Czarnowski  */
342ac106bf6SEd Tanous inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
343107077deSPrzemyslaw Czarnowski                       const std::string& service, const std::string& name,
344107077deSPrzemyslaw Czarnowski                       const std::string& resName)
345107077deSPrzemyslaw Czarnowski {
346*62598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get Virtual Media resource data.");
347107077deSPrzemyslaw Czarnowski 
348ac106bf6SEd Tanous     findAndParseObject(service, resName, asyncResp,
34970cbdf53SGeorge Liu                        std::bind_front(afterGetVmData, name));
350107077deSPrzemyslaw Czarnowski }
351107077deSPrzemyslaw Czarnowski 
352e13c2760SPrzemyslaw Czarnowski /**
353c6f4e017SAgata Olender  * @brief Transfer protocols supported for InsertMedia action.
354c6f4e017SAgata Olender  *
355c6f4e017SAgata Olender  */
356c6f4e017SAgata Olender enum class TransferProtocol
357c6f4e017SAgata Olender {
358c6f4e017SAgata Olender     https,
359c6f4e017SAgata Olender     smb,
360c6f4e017SAgata Olender     invalid
361c6f4e017SAgata Olender };
362c6f4e017SAgata Olender 
363c6f4e017SAgata Olender /**
364c6f4e017SAgata Olender  * @brief Function extracts transfer protocol type from URI.
365c6f4e017SAgata Olender  *
366c6f4e017SAgata Olender  */
36767df073bSEd Tanous inline std::optional<TransferProtocol>
368d9f466b3SEd Tanous     getTransferProtocolFromUri(boost::urls::url_view imageUri)
36967df073bSEd Tanous {
370079360aeSEd Tanous     std::string_view scheme = imageUri.scheme();
37167df073bSEd Tanous     if (scheme == "smb")
37267df073bSEd Tanous     {
37367df073bSEd Tanous         return TransferProtocol::smb;
37467df073bSEd Tanous     }
37567df073bSEd Tanous     if (scheme == "https")
37667df073bSEd Tanous     {
37767df073bSEd Tanous         return TransferProtocol::https;
37867df073bSEd Tanous     }
37967df073bSEd Tanous     if (!scheme.empty())
38067df073bSEd Tanous     {
38167df073bSEd Tanous         return TransferProtocol::invalid;
38267df073bSEd Tanous     }
38367df073bSEd Tanous 
38467df073bSEd Tanous     return {};
38567df073bSEd Tanous }
386c6f4e017SAgata Olender 
387c6f4e017SAgata Olender /**
388c6f4e017SAgata Olender  * @brief Function convert transfer protocol from string param.
389c6f4e017SAgata Olender  *
390c6f4e017SAgata Olender  */
39122db1728SEd Tanous inline std::optional<TransferProtocol> getTransferProtocolFromParam(
392c6f4e017SAgata Olender     const std::optional<std::string>& transferProtocolType)
393c6f4e017SAgata Olender {
394c6f4e017SAgata Olender     if (transferProtocolType == std::nullopt)
395c6f4e017SAgata Olender     {
396c6f4e017SAgata Olender         return {};
397c6f4e017SAgata Olender     }
398c6f4e017SAgata Olender 
399c6f4e017SAgata Olender     if (*transferProtocolType == "CIFS")
400c6f4e017SAgata Olender     {
401c6f4e017SAgata Olender         return TransferProtocol::smb;
402c6f4e017SAgata Olender     }
403c6f4e017SAgata Olender 
404c6f4e017SAgata Olender     if (*transferProtocolType == "HTTPS")
405c6f4e017SAgata Olender     {
406c6f4e017SAgata Olender         return TransferProtocol::https;
407c6f4e017SAgata Olender     }
408c6f4e017SAgata Olender 
409c6f4e017SAgata Olender     return TransferProtocol::invalid;
410c6f4e017SAgata Olender }
411c6f4e017SAgata Olender 
412c6f4e017SAgata Olender /**
413c6f4e017SAgata Olender  * @brief Function extends URI with transfer protocol type.
414c6f4e017SAgata Olender  *
415c6f4e017SAgata Olender  */
41622db1728SEd Tanous inline std::string
417c6f4e017SAgata Olender     getUriWithTransferProtocol(const std::string& imageUri,
418c6f4e017SAgata Olender                                const TransferProtocol& transferProtocol)
419c6f4e017SAgata Olender {
420c6f4e017SAgata Olender     if (transferProtocol == TransferProtocol::smb)
421c6f4e017SAgata Olender     {
422c6f4e017SAgata Olender         return "smb://" + imageUri;
423c6f4e017SAgata Olender     }
424c6f4e017SAgata Olender 
425c6f4e017SAgata Olender     if (transferProtocol == TransferProtocol::https)
426c6f4e017SAgata Olender     {
427c6f4e017SAgata Olender         return "https://" + imageUri;
428c6f4e017SAgata Olender     }
429c6f4e017SAgata Olender 
430c6f4e017SAgata Olender     return imageUri;
431c6f4e017SAgata Olender }
432c6f4e017SAgata Olender 
4331f2a40ceSPrzemyslaw Czarnowski struct InsertMediaActionParams
4341f2a40ceSPrzemyslaw Czarnowski {
435120fa86aSPrzemyslaw Czarnowski     std::optional<std::string> imageUrl;
4361f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> userName;
4371f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> password;
4381f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> transferMethod;
4391f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> transferProtocolType;
4401f2a40ceSPrzemyslaw Czarnowski     std::optional<bool> writeProtected = true;
4411f2a40ceSPrzemyslaw Czarnowski     std::optional<bool> inserted;
4421f2a40ceSPrzemyslaw Czarnowski };
4431f2a40ceSPrzemyslaw Czarnowski 
4441214b7e7SGunnar Mills template <typename T>
4451214b7e7SGunnar Mills static void secureCleanup(T& value)
446988fb7b2SAdrian Ambrożewicz {
4474ecc618fSEd Tanous     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
448988fb7b2SAdrian Ambrożewicz     auto raw = const_cast<typename T::value_type*>(value.data());
449988fb7b2SAdrian Ambrożewicz     explicit_bzero(raw, value.size() * sizeof(*raw));
450988fb7b2SAdrian Ambrożewicz }
451988fb7b2SAdrian Ambrożewicz 
452988fb7b2SAdrian Ambrożewicz class Credentials
453988fb7b2SAdrian Ambrożewicz {
454988fb7b2SAdrian Ambrożewicz   public:
455988fb7b2SAdrian Ambrożewicz     Credentials(std::string&& user, std::string&& password) :
456988fb7b2SAdrian Ambrożewicz         userBuf(std::move(user)), passBuf(std::move(password))
4571214b7e7SGunnar Mills     {}
458988fb7b2SAdrian Ambrożewicz 
459988fb7b2SAdrian Ambrożewicz     ~Credentials()
460988fb7b2SAdrian Ambrożewicz     {
461988fb7b2SAdrian Ambrożewicz         secureCleanup(userBuf);
462988fb7b2SAdrian Ambrożewicz         secureCleanup(passBuf);
463988fb7b2SAdrian Ambrożewicz     }
464988fb7b2SAdrian Ambrożewicz 
465988fb7b2SAdrian Ambrożewicz     const std::string& user()
466988fb7b2SAdrian Ambrożewicz     {
467988fb7b2SAdrian Ambrożewicz         return userBuf;
468988fb7b2SAdrian Ambrożewicz     }
469988fb7b2SAdrian Ambrożewicz 
470988fb7b2SAdrian Ambrożewicz     const std::string& password()
471988fb7b2SAdrian Ambrożewicz     {
472988fb7b2SAdrian Ambrożewicz         return passBuf;
473988fb7b2SAdrian Ambrożewicz     }
474988fb7b2SAdrian Ambrożewicz 
475988fb7b2SAdrian Ambrożewicz     Credentials() = delete;
476988fb7b2SAdrian Ambrożewicz     Credentials(const Credentials&) = delete;
477988fb7b2SAdrian Ambrożewicz     Credentials& operator=(const Credentials&) = delete;
478ecd6a3a2SEd Tanous     Credentials(Credentials&&) = delete;
479ecd6a3a2SEd Tanous     Credentials& operator=(Credentials&&) = delete;
480988fb7b2SAdrian Ambrożewicz 
48122db1728SEd Tanous   private:
482988fb7b2SAdrian Ambrożewicz     std::string userBuf;
483988fb7b2SAdrian Ambrożewicz     std::string passBuf;
484988fb7b2SAdrian Ambrożewicz };
485988fb7b2SAdrian Ambrożewicz 
486988fb7b2SAdrian Ambrożewicz class CredentialsProvider
487988fb7b2SAdrian Ambrożewicz {
488988fb7b2SAdrian Ambrożewicz   public:
4891214b7e7SGunnar Mills     template <typename T>
4901214b7e7SGunnar Mills     struct Deleter
491988fb7b2SAdrian Ambrożewicz     {
492988fb7b2SAdrian Ambrożewicz         void operator()(T* buff) const
493988fb7b2SAdrian Ambrożewicz         {
494988fb7b2SAdrian Ambrożewicz             if (buff)
495988fb7b2SAdrian Ambrożewicz             {
496988fb7b2SAdrian Ambrożewicz                 secureCleanup(*buff);
497988fb7b2SAdrian Ambrożewicz                 delete buff;
498988fb7b2SAdrian Ambrożewicz             }
499988fb7b2SAdrian Ambrożewicz         }
500988fb7b2SAdrian Ambrożewicz     };
501988fb7b2SAdrian Ambrożewicz 
502988fb7b2SAdrian Ambrożewicz     using Buffer = std::vector<char>;
503988fb7b2SAdrian Ambrożewicz     using SecureBuffer = std::unique_ptr<Buffer, Deleter<Buffer>>;
504988fb7b2SAdrian Ambrożewicz     // Using explicit definition instead of std::function to avoid implicit
505988fb7b2SAdrian Ambrożewicz     // conversions eg. stack copy instead of reference
506988fb7b2SAdrian Ambrożewicz     using FormatterFunc = void(const std::string& username,
507988fb7b2SAdrian Ambrożewicz                                const std::string& password, Buffer& dest);
508988fb7b2SAdrian Ambrożewicz 
509988fb7b2SAdrian Ambrożewicz     CredentialsProvider(std::string&& user, std::string&& password) :
510988fb7b2SAdrian Ambrożewicz         credentials(std::move(user), std::move(password))
5111214b7e7SGunnar Mills     {}
512988fb7b2SAdrian Ambrożewicz 
513988fb7b2SAdrian Ambrożewicz     const std::string& user()
514988fb7b2SAdrian Ambrożewicz     {
515988fb7b2SAdrian Ambrożewicz         return credentials.user();
516988fb7b2SAdrian Ambrożewicz     }
517988fb7b2SAdrian Ambrożewicz 
518988fb7b2SAdrian Ambrożewicz     const std::string& password()
519988fb7b2SAdrian Ambrożewicz     {
520988fb7b2SAdrian Ambrożewicz         return credentials.password();
521988fb7b2SAdrian Ambrożewicz     }
522988fb7b2SAdrian Ambrożewicz 
5231917ee95SEd Tanous     SecureBuffer pack(FormatterFunc* formatter)
524988fb7b2SAdrian Ambrożewicz     {
525988fb7b2SAdrian Ambrożewicz         SecureBuffer packed{new Buffer{}};
526e662eae8SEd Tanous         if (formatter != nullptr)
527988fb7b2SAdrian Ambrożewicz         {
528988fb7b2SAdrian Ambrożewicz             formatter(credentials.user(), credentials.password(), *packed);
529988fb7b2SAdrian Ambrożewicz         }
530988fb7b2SAdrian Ambrożewicz 
531988fb7b2SAdrian Ambrożewicz         return packed;
532988fb7b2SAdrian Ambrożewicz     }
533988fb7b2SAdrian Ambrożewicz 
534988fb7b2SAdrian Ambrożewicz   private:
535988fb7b2SAdrian Ambrożewicz     Credentials credentials;
536988fb7b2SAdrian Ambrożewicz };
537988fb7b2SAdrian Ambrożewicz 
538988fb7b2SAdrian Ambrożewicz // Wrapper for boost::async_pipe ensuring proper pipe cleanup
5390a48306bSEd Tanous class SecurePipe
540988fb7b2SAdrian Ambrożewicz {
541988fb7b2SAdrian Ambrożewicz   public:
542988fb7b2SAdrian Ambrożewicz     using unix_fd = sdbusplus::message::unix_fd;
543988fb7b2SAdrian Ambrożewicz 
5440a48306bSEd Tanous     SecurePipe(boost::asio::io_context& io,
5450a48306bSEd Tanous                CredentialsProvider::SecureBuffer&& bufferIn) :
5460a48306bSEd Tanous         impl(io),
5470a48306bSEd Tanous         buffer{std::move(bufferIn)}
5481214b7e7SGunnar Mills     {}
549988fb7b2SAdrian Ambrożewicz 
5500a48306bSEd Tanous     ~SecurePipe()
551988fb7b2SAdrian Ambrożewicz     {
552988fb7b2SAdrian Ambrożewicz         // Named pipe needs to be explicitly removed
553988fb7b2SAdrian Ambrożewicz         impl.close();
554988fb7b2SAdrian Ambrożewicz     }
555988fb7b2SAdrian Ambrożewicz 
5560a48306bSEd Tanous     SecurePipe(const SecurePipe&) = delete;
5570a48306bSEd Tanous     SecurePipe(SecurePipe&&) = delete;
5580a48306bSEd Tanous     SecurePipe& operator=(const SecurePipe&) = delete;
5590a48306bSEd Tanous     SecurePipe& operator=(SecurePipe&&) = delete;
560ecd6a3a2SEd Tanous 
5610a48306bSEd Tanous     unix_fd fd() const
562988fb7b2SAdrian Ambrożewicz     {
563988fb7b2SAdrian Ambrożewicz         return unix_fd{impl.native_source()};
564988fb7b2SAdrian Ambrożewicz     }
565988fb7b2SAdrian Ambrożewicz 
566988fb7b2SAdrian Ambrożewicz     template <typename WriteHandler>
56781ce609eSEd Tanous     void asyncWrite(WriteHandler&& handler)
568988fb7b2SAdrian Ambrożewicz     {
5690a48306bSEd Tanous         impl.async_write_some(boost::asio::buffer(*buffer),
5700a48306bSEd Tanous                               std::forward<WriteHandler>(handler));
571988fb7b2SAdrian Ambrożewicz     }
572988fb7b2SAdrian Ambrożewicz 
573988fb7b2SAdrian Ambrożewicz     const std::string name;
574988fb7b2SAdrian Ambrożewicz     boost::process::async_pipe impl;
5750a48306bSEd Tanous     CredentialsProvider::SecureBuffer buffer;
576988fb7b2SAdrian Ambrożewicz };
577988fb7b2SAdrian Ambrożewicz 
578e13c2760SPrzemyslaw Czarnowski /**
579e13c2760SPrzemyslaw Czarnowski  * @brief Function transceives data with dbus directly.
580e13c2760SPrzemyslaw Czarnowski  *
581e13c2760SPrzemyslaw Czarnowski  * All BMC state properties will be retrieved before sending reset request.
582e13c2760SPrzemyslaw Czarnowski  */
58322db1728SEd Tanous inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
584e13c2760SPrzemyslaw Czarnowski                             const std::string& service, const std::string& name,
585988fb7b2SAdrian Ambrożewicz                             const std::string& imageUrl, const bool rw,
586988fb7b2SAdrian Ambrożewicz                             std::string&& userName, std::string&& password)
587e13c2760SPrzemyslaw Czarnowski {
588988fb7b2SAdrian Ambrożewicz     constexpr const size_t secretLimit = 1024;
589988fb7b2SAdrian Ambrożewicz 
590988fb7b2SAdrian Ambrożewicz     std::shared_ptr<SecurePipe> secretPipe;
591168e20c1SEd Tanous     dbus::utility::DbusVariantType unixFd = -1;
592988fb7b2SAdrian Ambrożewicz 
593988fb7b2SAdrian Ambrożewicz     if (!userName.empty() || !password.empty())
594988fb7b2SAdrian Ambrożewicz     {
595988fb7b2SAdrian Ambrożewicz         // Encapsulate in safe buffer
596988fb7b2SAdrian Ambrożewicz         CredentialsProvider credentials(std::move(userName),
597988fb7b2SAdrian Ambrożewicz                                         std::move(password));
598988fb7b2SAdrian Ambrożewicz 
599988fb7b2SAdrian Ambrożewicz         // Payload must contain data + NULL delimiters
600988fb7b2SAdrian Ambrożewicz         if (credentials.user().size() + credentials.password().size() + 2 >
601988fb7b2SAdrian Ambrożewicz             secretLimit)
602988fb7b2SAdrian Ambrożewicz         {
603*62598e31SEd Tanous             BMCWEB_LOG_ERROR("Credentials too long to handle");
604988fb7b2SAdrian Ambrożewicz             messages::unrecognizedRequestBody(asyncResp->res);
605988fb7b2SAdrian Ambrożewicz             return;
606988fb7b2SAdrian Ambrożewicz         }
607988fb7b2SAdrian Ambrożewicz 
608988fb7b2SAdrian Ambrożewicz         // Pack secret
60922db1728SEd Tanous         auto secret = credentials.pack(
61022db1728SEd Tanous             [](const auto& user, const auto& pass, auto& buff) {
611988fb7b2SAdrian Ambrożewicz             std::copy(user.begin(), user.end(), std::back_inserter(buff));
612988fb7b2SAdrian Ambrożewicz             buff.push_back('\0');
613988fb7b2SAdrian Ambrożewicz             std::copy(pass.begin(), pass.end(), std::back_inserter(buff));
614988fb7b2SAdrian Ambrożewicz             buff.push_back('\0');
615988fb7b2SAdrian Ambrożewicz         });
616988fb7b2SAdrian Ambrożewicz 
617988fb7b2SAdrian Ambrożewicz         // Open pipe
618988fb7b2SAdrian Ambrożewicz         secretPipe = std::make_shared<SecurePipe>(
61922db1728SEd Tanous             crow::connections::systemBus->get_io_context(), std::move(secret));
620988fb7b2SAdrian Ambrożewicz         unixFd = secretPipe->fd();
621988fb7b2SAdrian Ambrożewicz 
622988fb7b2SAdrian Ambrożewicz         // Pass secret over pipe
62381ce609eSEd Tanous         secretPipe->asyncWrite(
624f5b16f03SVikram Bodireddy             [asyncResp](const boost::system::error_code& ec, std::size_t) {
625988fb7b2SAdrian Ambrożewicz             if (ec)
626988fb7b2SAdrian Ambrożewicz             {
627*62598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to pass secret: {}", ec);
628988fb7b2SAdrian Ambrożewicz                 messages::internalError(asyncResp->res);
629988fb7b2SAdrian Ambrożewicz             }
630988fb7b2SAdrian Ambrożewicz         });
631988fb7b2SAdrian Ambrożewicz     }
632988fb7b2SAdrian Ambrożewicz 
633e13c2760SPrzemyslaw Czarnowski     crow::connections::systemBus->async_method_call(
6345e7e2dc5SEd Tanous         [asyncResp, secretPipe](const boost::system::error_code& ec,
635988fb7b2SAdrian Ambrożewicz                                 bool success) {
636e13c2760SPrzemyslaw Czarnowski         if (ec)
637e13c2760SPrzemyslaw Czarnowski         {
638*62598e31SEd Tanous             BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
639e13c2760SPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
640d6da5bebSAdrian Ambrożewicz         }
641d6da5bebSAdrian Ambrożewicz         else if (!success)
642d6da5bebSAdrian Ambrożewicz         {
643*62598e31SEd Tanous             BMCWEB_LOG_ERROR("Service responded with error");
644d6da5bebSAdrian Ambrożewicz             messages::generalError(asyncResp->res);
645e13c2760SPrzemyslaw Czarnowski         }
646e13c2760SPrzemyslaw Czarnowski         },
647e13c2760SPrzemyslaw Czarnowski         service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
648988fb7b2SAdrian Ambrożewicz         "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", imageUrl, rw,
649988fb7b2SAdrian Ambrożewicz         unixFd);
650e13c2760SPrzemyslaw Czarnowski }
651e13c2760SPrzemyslaw Czarnowski 
652e13c2760SPrzemyslaw Czarnowski /**
653120fa86aSPrzemyslaw Czarnowski  * @brief Function validate parameters of insert media request.
654120fa86aSPrzemyslaw Czarnowski  *
655120fa86aSPrzemyslaw Czarnowski  */
656120fa86aSPrzemyslaw Czarnowski inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
657120fa86aSPrzemyslaw Czarnowski                            const std::string& service,
658120fa86aSPrzemyslaw Czarnowski                            const std::string& resName,
659120fa86aSPrzemyslaw Czarnowski                            InsertMediaActionParams& actionParams)
660120fa86aSPrzemyslaw Czarnowski {
661*62598e31SEd Tanous     BMCWEB_LOG_DEBUG("Validation started");
662120fa86aSPrzemyslaw Czarnowski     // required param imageUrl must not be empty
663120fa86aSPrzemyslaw Czarnowski     if (!actionParams.imageUrl)
664120fa86aSPrzemyslaw Czarnowski     {
665*62598e31SEd Tanous         BMCWEB_LOG_ERROR("Request action parameter Image is empty.");
666120fa86aSPrzemyslaw Czarnowski 
667120fa86aSPrzemyslaw Czarnowski         messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image");
668120fa86aSPrzemyslaw Czarnowski 
669120fa86aSPrzemyslaw Czarnowski         return;
670120fa86aSPrzemyslaw Czarnowski     }
671120fa86aSPrzemyslaw Czarnowski 
672120fa86aSPrzemyslaw Czarnowski     // optional param inserted must be true
673120fa86aSPrzemyslaw Czarnowski     if ((actionParams.inserted != std::nullopt) && !*actionParams.inserted)
674120fa86aSPrzemyslaw Czarnowski     {
675*62598e31SEd Tanous         BMCWEB_LOG_ERROR(
676*62598e31SEd Tanous             "Request action optional parameter Inserted must be true.");
677120fa86aSPrzemyslaw Czarnowski 
678120fa86aSPrzemyslaw Czarnowski         messages::actionParameterNotSupported(asyncResp->res, "Inserted",
679120fa86aSPrzemyslaw Czarnowski                                               "InsertMedia");
680120fa86aSPrzemyslaw Czarnowski 
681120fa86aSPrzemyslaw Czarnowski         return;
682120fa86aSPrzemyslaw Czarnowski     }
683120fa86aSPrzemyslaw Czarnowski 
684120fa86aSPrzemyslaw Czarnowski     // optional param transferMethod must be stream
685120fa86aSPrzemyslaw Czarnowski     if ((actionParams.transferMethod != std::nullopt) &&
686120fa86aSPrzemyslaw Czarnowski         (*actionParams.transferMethod != "Stream"))
687120fa86aSPrzemyslaw Czarnowski     {
688*62598e31SEd Tanous         BMCWEB_LOG_ERROR("Request action optional parameter "
689*62598e31SEd Tanous                          "TransferMethod must be Stream.");
690120fa86aSPrzemyslaw Czarnowski 
691120fa86aSPrzemyslaw Czarnowski         messages::actionParameterNotSupported(asyncResp->res, "TransferMethod",
692120fa86aSPrzemyslaw Czarnowski                                               "InsertMedia");
693120fa86aSPrzemyslaw Czarnowski 
694120fa86aSPrzemyslaw Czarnowski         return;
695120fa86aSPrzemyslaw Czarnowski     }
696120fa86aSPrzemyslaw Czarnowski     boost::urls::result<boost::urls::url_view> url =
697120fa86aSPrzemyslaw Czarnowski         boost::urls::parse_uri(*actionParams.imageUrl);
698120fa86aSPrzemyslaw Czarnowski     if (!url)
699120fa86aSPrzemyslaw Czarnowski     {
700120fa86aSPrzemyslaw Czarnowski         messages::actionParameterValueFormatError(
701120fa86aSPrzemyslaw Czarnowski             asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia");
702120fa86aSPrzemyslaw Czarnowski         return;
703120fa86aSPrzemyslaw Czarnowski     }
704120fa86aSPrzemyslaw Czarnowski     std::optional<TransferProtocol> uriTransferProtocolType =
705120fa86aSPrzemyslaw Czarnowski         getTransferProtocolFromUri(*url);
706120fa86aSPrzemyslaw Czarnowski 
707120fa86aSPrzemyslaw Czarnowski     std::optional<TransferProtocol> paramTransferProtocolType =
708120fa86aSPrzemyslaw Czarnowski         getTransferProtocolFromParam(actionParams.transferProtocolType);
709120fa86aSPrzemyslaw Czarnowski 
710120fa86aSPrzemyslaw Czarnowski     // ImageUrl does not contain valid protocol type
711120fa86aSPrzemyslaw Czarnowski     if (*uriTransferProtocolType == TransferProtocol::invalid)
712120fa86aSPrzemyslaw Czarnowski     {
713*62598e31SEd Tanous         BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
714120fa86aSPrzemyslaw Czarnowski                          "contain specified protocol type from list: "
715*62598e31SEd Tanous                          "(smb, https).");
716120fa86aSPrzemyslaw Czarnowski 
717120fa86aSPrzemyslaw Czarnowski         messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
718120fa86aSPrzemyslaw Czarnowski 
719120fa86aSPrzemyslaw Czarnowski         return;
720120fa86aSPrzemyslaw Czarnowski     }
721120fa86aSPrzemyslaw Czarnowski 
722120fa86aSPrzemyslaw Czarnowski     // transferProtocolType should contain value from list
723120fa86aSPrzemyslaw Czarnowski     if (*paramTransferProtocolType == TransferProtocol::invalid)
724120fa86aSPrzemyslaw Czarnowski     {
725*62598e31SEd Tanous         BMCWEB_LOG_ERROR("Request action parameter TransferProtocolType "
726120fa86aSPrzemyslaw Czarnowski                          "must be provided with value from list: "
727*62598e31SEd Tanous                          "(CIFS, HTTPS).");
728120fa86aSPrzemyslaw Czarnowski 
729120fa86aSPrzemyslaw Czarnowski         messages::propertyValueNotInList(asyncResp->res,
730120fa86aSPrzemyslaw Czarnowski                                          *actionParams.transferProtocolType,
731120fa86aSPrzemyslaw Czarnowski                                          "TransferProtocolType");
732120fa86aSPrzemyslaw Czarnowski         return;
733120fa86aSPrzemyslaw Czarnowski     }
734120fa86aSPrzemyslaw Czarnowski 
735120fa86aSPrzemyslaw Czarnowski     // valid transfer protocol not provided either with URI nor param
736120fa86aSPrzemyslaw Czarnowski     if ((uriTransferProtocolType == std::nullopt) &&
737120fa86aSPrzemyslaw Czarnowski         (paramTransferProtocolType == std::nullopt))
738120fa86aSPrzemyslaw Czarnowski     {
739*62598e31SEd Tanous         BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
740120fa86aSPrzemyslaw Czarnowski                          "contain specified protocol type or param "
741*62598e31SEd Tanous                          "TransferProtocolType must be provided.");
742120fa86aSPrzemyslaw Czarnowski 
743120fa86aSPrzemyslaw Czarnowski         messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
744120fa86aSPrzemyslaw Czarnowski 
745120fa86aSPrzemyslaw Czarnowski         return;
746120fa86aSPrzemyslaw Czarnowski     }
747120fa86aSPrzemyslaw Czarnowski 
748120fa86aSPrzemyslaw Czarnowski     // valid transfer protocol provided both with URI and param
749120fa86aSPrzemyslaw Czarnowski     if ((paramTransferProtocolType != std::nullopt) &&
750120fa86aSPrzemyslaw Czarnowski         (uriTransferProtocolType != std::nullopt))
751120fa86aSPrzemyslaw Czarnowski     {
752120fa86aSPrzemyslaw Czarnowski         // check if protocol is the same for URI and param
753120fa86aSPrzemyslaw Czarnowski         if (*paramTransferProtocolType != *uriTransferProtocolType)
754120fa86aSPrzemyslaw Czarnowski         {
755*62598e31SEd Tanous             BMCWEB_LOG_ERROR("Request action parameter "
756120fa86aSPrzemyslaw Czarnowski                              "TransferProtocolType must  contain the "
757120fa86aSPrzemyslaw Czarnowski                              "same protocol type as protocol type "
758*62598e31SEd Tanous                              "provided with param imageUrl.");
759120fa86aSPrzemyslaw Czarnowski 
760120fa86aSPrzemyslaw Czarnowski             messages::actionParameterValueTypeError(
761120fa86aSPrzemyslaw Czarnowski                 asyncResp->res, *actionParams.transferProtocolType,
762120fa86aSPrzemyslaw Czarnowski                 "TransferProtocolType", "InsertMedia");
763120fa86aSPrzemyslaw Czarnowski 
764120fa86aSPrzemyslaw Czarnowski             return;
765120fa86aSPrzemyslaw Czarnowski         }
766120fa86aSPrzemyslaw Czarnowski     }
767120fa86aSPrzemyslaw Czarnowski 
768120fa86aSPrzemyslaw Czarnowski     // validation passed, add protocol to URI if needed
769120fa86aSPrzemyslaw Czarnowski     if (uriTransferProtocolType == std::nullopt)
770120fa86aSPrzemyslaw Czarnowski     {
771120fa86aSPrzemyslaw Czarnowski         actionParams.imageUrl = getUriWithTransferProtocol(
772120fa86aSPrzemyslaw Czarnowski             *actionParams.imageUrl, *paramTransferProtocolType);
773120fa86aSPrzemyslaw Czarnowski     }
774120fa86aSPrzemyslaw Czarnowski 
775452bd8d8SJayaprakash Mutyala     if (!actionParams.userName)
776452bd8d8SJayaprakash Mutyala     {
777452bd8d8SJayaprakash Mutyala         actionParams.userName = "";
778452bd8d8SJayaprakash Mutyala     }
779452bd8d8SJayaprakash Mutyala 
780452bd8d8SJayaprakash Mutyala     if (!actionParams.password)
781452bd8d8SJayaprakash Mutyala     {
782452bd8d8SJayaprakash Mutyala         actionParams.password = "";
783452bd8d8SJayaprakash Mutyala     }
784452bd8d8SJayaprakash Mutyala 
785120fa86aSPrzemyslaw Czarnowski     doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl,
786120fa86aSPrzemyslaw Czarnowski                     !(*actionParams.writeProtected),
787120fa86aSPrzemyslaw Czarnowski                     std::move(*actionParams.userName),
788120fa86aSPrzemyslaw Czarnowski                     std::move(*actionParams.password));
789120fa86aSPrzemyslaw Czarnowski }
790120fa86aSPrzemyslaw Czarnowski 
791120fa86aSPrzemyslaw Czarnowski /**
792e13c2760SPrzemyslaw Czarnowski  * @brief Function transceives data with dbus directly.
793e13c2760SPrzemyslaw Czarnowski  *
794e13c2760SPrzemyslaw Czarnowski  * All BMC state properties will be retrieved before sending reset request.
795e13c2760SPrzemyslaw Czarnowski  */
79624e740a7SEd Tanous inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
797e13c2760SPrzemyslaw Czarnowski                           const std::string& service, const std::string& name,
798e13c2760SPrzemyslaw Czarnowski                           bool legacy)
799e13c2760SPrzemyslaw Czarnowski {
800e13c2760SPrzemyslaw Czarnowski     // Legacy mount requires parameter with image
801e13c2760SPrzemyslaw Czarnowski     if (legacy)
802e13c2760SPrzemyslaw Czarnowski     {
803e13c2760SPrzemyslaw Czarnowski         crow::connections::systemBus->async_method_call(
8045e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
805e13c2760SPrzemyslaw Czarnowski             if (ec)
806e13c2760SPrzemyslaw Czarnowski             {
807*62598e31SEd Tanous                 BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
808e13c2760SPrzemyslaw Czarnowski 
809e13c2760SPrzemyslaw Czarnowski                 messages::internalError(asyncResp->res);
810e13c2760SPrzemyslaw Czarnowski                 return;
811e13c2760SPrzemyslaw Czarnowski             }
812e13c2760SPrzemyslaw Czarnowski             },
813e13c2760SPrzemyslaw Czarnowski             service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
814e13c2760SPrzemyslaw Czarnowski             "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount");
815e13c2760SPrzemyslaw Czarnowski     }
816e13c2760SPrzemyslaw Czarnowski     else // proxy
817e13c2760SPrzemyslaw Czarnowski     {
818e13c2760SPrzemyslaw Czarnowski         crow::connections::systemBus->async_method_call(
8195e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
820e13c2760SPrzemyslaw Czarnowski             if (ec)
821e13c2760SPrzemyslaw Czarnowski             {
822*62598e31SEd Tanous                 BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
823e13c2760SPrzemyslaw Czarnowski 
824e13c2760SPrzemyslaw Czarnowski                 messages::internalError(asyncResp->res);
825e13c2760SPrzemyslaw Czarnowski                 return;
826e13c2760SPrzemyslaw Czarnowski             }
827e13c2760SPrzemyslaw Czarnowski             },
828e13c2760SPrzemyslaw Czarnowski             service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name,
829e13c2760SPrzemyslaw Czarnowski             "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount");
830e13c2760SPrzemyslaw Czarnowski     }
831e13c2760SPrzemyslaw Czarnowski }
832e13c2760SPrzemyslaw Czarnowski 
83396825bebSEd Tanous inline void handleManagersVirtualMediaActionInsertPost(
83496825bebSEd Tanous     crow::App& app, const crow::Request& req,
83522db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
83696825bebSEd Tanous     const std::string& name, const std::string& resName)
83796825bebSEd Tanous {
8383ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
83945ca1b86SEd Tanous     {
84045ca1b86SEd Tanous         return;
84145ca1b86SEd Tanous     }
84279fdf63eSPrzemyslaw Czarnowski 
84379fdf63eSPrzemyslaw Czarnowski     constexpr std::string_view action = "VirtualMedia.InsertMedia";
84422db1728SEd Tanous     if (name != "bmc")
845107077deSPrzemyslaw Czarnowski     {
84679fdf63eSPrzemyslaw Czarnowski         messages::resourceNotFound(asyncResp->res, action, resName);
847107077deSPrzemyslaw Czarnowski 
848107077deSPrzemyslaw Czarnowski         return;
849107077deSPrzemyslaw Czarnowski     }
85079fdf63eSPrzemyslaw Czarnowski     InsertMediaActionParams actionParams;
85198be3e39SEd Tanous 
852120fa86aSPrzemyslaw Czarnowski     // Read obligatory parameters (url of image)
85315ed6780SWilly Tu     if (!json_util::readJsonAction(
85479fdf63eSPrzemyslaw Czarnowski             req, asyncResp->res, "Image", actionParams.imageUrl,
85579fdf63eSPrzemyslaw Czarnowski             "WriteProtected", actionParams.writeProtected, "UserName",
85679fdf63eSPrzemyslaw Czarnowski             actionParams.userName, "Password", actionParams.password,
85779fdf63eSPrzemyslaw Czarnowski             "Inserted", actionParams.inserted, "TransferMethod",
85879fdf63eSPrzemyslaw Czarnowski             actionParams.transferMethod, "TransferProtocolType",
85979fdf63eSPrzemyslaw Czarnowski             actionParams.transferProtocolType))
86098be3e39SEd Tanous     {
86198be3e39SEd Tanous         return;
86298be3e39SEd Tanous     }
863107077deSPrzemyslaw Czarnowski 
8642b73119cSGeorge Liu     dbus::utility::getDbusObject(
8652b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
86679fdf63eSPrzemyslaw Czarnowski         [asyncResp, action, actionParams,
8672b73119cSGeorge Liu          resName](const boost::system::error_code& ec,
868002d39b4SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) mutable {
86922db1728SEd Tanous         if (ec)
87022db1728SEd Tanous         {
871*62598e31SEd Tanous             BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
87279fdf63eSPrzemyslaw Czarnowski             messages::resourceNotFound(asyncResp->res, action, resName);
873107077deSPrzemyslaw Czarnowski 
87422db1728SEd Tanous             return;
87522db1728SEd Tanous         }
87679fdf63eSPrzemyslaw Czarnowski 
87722db1728SEd Tanous         std::string service = getObjectType.begin()->first;
878*62598e31SEd Tanous         BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
87922db1728SEd Tanous 
8805eb468daSGeorge Liu         sdbusplus::message::object_path path(
8815eb468daSGeorge Liu             "/xyz/openbmc_project/VirtualMedia");
8825eb468daSGeorge Liu         dbus::utility::getManagedObjects(
8835eb468daSGeorge Liu             service, path,
8845eb468daSGeorge Liu             [service, resName, action, actionParams, asyncResp](
8855eb468daSGeorge Liu                 const boost::system::error_code& ec2,
8865eb468daSGeorge Liu                 const dbus::utility::ManagedObjectType& subtree) mutable {
8878a592810SEd Tanous             if (ec2)
88822db1728SEd Tanous             {
88979fdf63eSPrzemyslaw Czarnowski                 // Not possible in proxy mode
890*62598e31SEd Tanous                 BMCWEB_LOG_DEBUG("InsertMedia not "
891*62598e31SEd Tanous                                  "allowed in proxy mode");
89279fdf63eSPrzemyslaw Czarnowski                 messages::resourceNotFound(asyncResp->res, action, resName);
89322db1728SEd Tanous 
89422db1728SEd Tanous                 return;
89522db1728SEd Tanous             }
89622db1728SEd Tanous             for (const auto& object : subtree)
89722db1728SEd Tanous             {
898365a73f4SEd Tanous                 VmMode mode = parseObjectPathAndGetMode(object.first, resName);
8995880f0c5SBoleslaw Ogonczyk Makowski                 if (mode == VmMode::Legacy)
90022db1728SEd Tanous                 {
90179fdf63eSPrzemyslaw Czarnowski                     validateParams(asyncResp, service, resName, actionParams);
90222db1728SEd Tanous 
90322db1728SEd Tanous                     return;
90422db1728SEd Tanous                 }
90522db1728SEd Tanous             }
906*62598e31SEd Tanous             BMCWEB_LOG_DEBUG("Parent item not found");
90796825bebSEd Tanous             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
9085eb468daSGeorge Liu             });
9092b73119cSGeorge Liu         });
91096825bebSEd Tanous }
91122db1728SEd Tanous 
91296825bebSEd Tanous inline void handleManagersVirtualMediaActionEject(
91396825bebSEd Tanous     crow::App& app, const crow::Request& req,
91422db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
91596825bebSEd Tanous     const std::string& managerName, const std::string& resName)
91696825bebSEd Tanous {
9173ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
91845ca1b86SEd Tanous     {
91945ca1b86SEd Tanous         return;
92045ca1b86SEd Tanous     }
92179fdf63eSPrzemyslaw Czarnowski 
92279fdf63eSPrzemyslaw Czarnowski     constexpr std::string_view action = "VirtualMedia.EjectMedia";
92396825bebSEd Tanous     if (managerName != "bmc")
924107077deSPrzemyslaw Czarnowski     {
92579fdf63eSPrzemyslaw Czarnowski         messages::resourceNotFound(asyncResp->res, action, resName);
92622db1728SEd Tanous 
92722db1728SEd Tanous         return;
92822db1728SEd Tanous     }
92922db1728SEd Tanous 
9302b73119cSGeorge Liu     dbus::utility::getDbusObject(
9312b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
93279fdf63eSPrzemyslaw Czarnowski         [asyncResp, action,
9332b73119cSGeorge Liu          resName](const boost::system::error_code& ec2,
934b9d36b47SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) {
9358a592810SEd Tanous         if (ec2)
93622db1728SEd Tanous         {
937*62598e31SEd Tanous             BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec2);
93822db1728SEd Tanous             messages::internalError(asyncResp->res);
93922db1728SEd Tanous 
94022db1728SEd Tanous             return;
94122db1728SEd Tanous         }
94222db1728SEd Tanous         std::string service = getObjectType.begin()->first;
943*62598e31SEd Tanous         BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
94422db1728SEd Tanous 
9455eb468daSGeorge Liu         sdbusplus::message::object_path path(
9465eb468daSGeorge Liu             "/xyz/openbmc_project/VirtualMedia");
9475eb468daSGeorge Liu         dbus::utility::getManagedObjects(
9485eb468daSGeorge Liu             service, path,
94979fdf63eSPrzemyslaw Czarnowski             [resName, service, action,
95079fdf63eSPrzemyslaw Czarnowski              asyncResp](const boost::system::error_code& ec,
95102cad96eSEd Tanous                         const dbus::utility::ManagedObjectType& subtree) {
95222db1728SEd Tanous             if (ec)
95322db1728SEd Tanous             {
954*62598e31SEd Tanous                 BMCWEB_LOG_ERROR("ObjectMapper : No Service found");
95579fdf63eSPrzemyslaw Czarnowski                 messages::resourceNotFound(asyncResp->res, action, resName);
95622db1728SEd Tanous                 return;
95722db1728SEd Tanous             }
95822db1728SEd Tanous 
95922db1728SEd Tanous             for (const auto& object : subtree)
96022db1728SEd Tanous             {
961365a73f4SEd Tanous                 VmMode mode = parseObjectPathAndGetMode(object.first, resName);
962365a73f4SEd Tanous                 if (mode != VmMode::Invalid)
96322db1728SEd Tanous                 {
964365a73f4SEd Tanous                     doEjectAction(asyncResp, service, resName,
965365a73f4SEd Tanous                                   mode == VmMode::Legacy);
9665880f0c5SBoleslaw Ogonczyk Makowski                     return;
96722db1728SEd Tanous                 }
96822db1728SEd Tanous             }
969*62598e31SEd Tanous             BMCWEB_LOG_DEBUG("Parent item not found");
97096825bebSEd Tanous             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
9715eb468daSGeorge Liu             });
9722b73119cSGeorge Liu         });
97396825bebSEd Tanous }
97496825bebSEd Tanous 
97596825bebSEd Tanous inline void handleManagersVirtualMediaCollectionGet(
97696825bebSEd Tanous     crow::App& app, const crow::Request& req,
97722db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
97896825bebSEd Tanous     const std::string& name)
97996825bebSEd Tanous {
9803ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
98145ca1b86SEd Tanous     {
98245ca1b86SEd Tanous         return;
98345ca1b86SEd Tanous     }
98422db1728SEd Tanous     if (name != "bmc")
98522db1728SEd Tanous     {
986002d39b4SEd Tanous         messages::resourceNotFound(asyncResp->res, "VirtualMedia", name);
987107077deSPrzemyslaw Czarnowski 
988107077deSPrzemyslaw Czarnowski         return;
989107077deSPrzemyslaw Czarnowski     }
990107077deSPrzemyslaw Czarnowski 
9918d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
992107077deSPrzemyslaw Czarnowski         "#VirtualMediaCollection.VirtualMediaCollection";
9938d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Virtual Media Services";
994ef4c65b7SEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
995ef4c65b7SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", name);
996107077deSPrzemyslaw Czarnowski 
9972b73119cSGeorge Liu     dbus::utility::getDbusObject(
9982b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
9992b73119cSGeorge Liu         [asyncResp, name](const boost::system::error_code& ec,
1000b9d36b47SEd Tanous                           const dbus::utility::MapperGetObject& getObjectType) {
1001107077deSPrzemyslaw Czarnowski         if (ec)
1002107077deSPrzemyslaw Czarnowski         {
1003*62598e31SEd Tanous             BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
1004107077deSPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
1005107077deSPrzemyslaw Czarnowski 
1006107077deSPrzemyslaw Czarnowski             return;
1007107077deSPrzemyslaw Czarnowski         }
1008107077deSPrzemyslaw Czarnowski         std::string service = getObjectType.begin()->first;
1009*62598e31SEd Tanous         BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
1010107077deSPrzemyslaw Czarnowski 
1011107077deSPrzemyslaw Czarnowski         getVmResourceList(asyncResp, service, name);
10122b73119cSGeorge Liu         });
101396825bebSEd Tanous }
1014107077deSPrzemyslaw Czarnowski 
101596825bebSEd Tanous inline void
101696825bebSEd Tanous     handleVirtualMediaGet(crow::App& app, const crow::Request& req,
101722db1728SEd Tanous                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
101896825bebSEd Tanous                           const std::string& name, const std::string& resName)
101996825bebSEd Tanous {
10203ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
102145ca1b86SEd Tanous     {
102245ca1b86SEd Tanous         return;
102345ca1b86SEd Tanous     }
1024107077deSPrzemyslaw Czarnowski     if (name != "bmc")
1025107077deSPrzemyslaw Czarnowski     {
1026002d39b4SEd Tanous         messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
1027107077deSPrzemyslaw Czarnowski 
1028107077deSPrzemyslaw Czarnowski         return;
1029107077deSPrzemyslaw Czarnowski     }
1030107077deSPrzemyslaw Czarnowski 
10312b73119cSGeorge Liu     dbus::utility::getDbusObject(
10322b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
1033002d39b4SEd Tanous         [asyncResp, name,
10342b73119cSGeorge Liu          resName](const boost::system::error_code& ec,
1035b9d36b47SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) {
1036107077deSPrzemyslaw Czarnowski         if (ec)
1037107077deSPrzemyslaw Czarnowski         {
1038*62598e31SEd Tanous             BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
1039107077deSPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
1040107077deSPrzemyslaw Czarnowski 
1041107077deSPrzemyslaw Czarnowski             return;
1042107077deSPrzemyslaw Czarnowski         }
1043107077deSPrzemyslaw Czarnowski         std::string service = getObjectType.begin()->first;
1044*62598e31SEd Tanous         BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
1045107077deSPrzemyslaw Czarnowski 
1046107077deSPrzemyslaw Czarnowski         getVmData(asyncResp, service, name, resName);
10472b73119cSGeorge Liu         });
104896825bebSEd Tanous }
104996825bebSEd Tanous 
105096825bebSEd Tanous inline void requestNBDVirtualMediaRoutes(App& app)
105196825bebSEd Tanous {
105296825bebSEd Tanous     BMCWEB_ROUTE(
105396825bebSEd Tanous         app,
105496825bebSEd Tanous         "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia")
105596825bebSEd Tanous         .privileges(redfish::privileges::postVirtualMedia)
105696825bebSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
105796825bebSEd Tanous             handleManagersVirtualMediaActionInsertPost, std::ref(app)));
105896825bebSEd Tanous 
105996825bebSEd Tanous     BMCWEB_ROUTE(
106096825bebSEd Tanous         app,
106196825bebSEd Tanous         "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
106296825bebSEd Tanous         .privileges(redfish::privileges::postVirtualMedia)
106396825bebSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
106496825bebSEd Tanous             handleManagersVirtualMediaActionEject, std::ref(app)));
106596825bebSEd Tanous 
106696825bebSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/")
106796825bebSEd Tanous         .privileges(redfish::privileges::getVirtualMediaCollection)
106896825bebSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
106996825bebSEd Tanous             handleManagersVirtualMediaCollectionGet, std::ref(app)));
107096825bebSEd Tanous 
107196825bebSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/")
107296825bebSEd Tanous         .privileges(redfish::privileges::getVirtualMedia)
107396825bebSEd Tanous         .methods(boost::beast::http::verb::get)(
107496825bebSEd Tanous             std::bind_front(handleVirtualMediaGet, std::ref(app)));
1075107077deSPrzemyslaw Czarnowski }
1076107077deSPrzemyslaw Czarnowski 
1077107077deSPrzemyslaw Czarnowski } // namespace redfish
1078