xref: /openbmc/bmcweb/features/redfish/lib/virtual_media.hpp (revision 79fdf63e2c4148593bb7aec4a3f471ade4c5cba0)
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"
20*79fdf63eSPrzemyslaw 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>
289e319cf0SAnna Platash #include <boost/url/url_view.hpp>
29107077deSPrzemyslaw Czarnowski 
302b73119cSGeorge Liu #include <array>
312b73119cSGeorge Liu #include <string_view>
322b73119cSGeorge Liu 
33107077deSPrzemyslaw Czarnowski namespace redfish
34107077deSPrzemyslaw Czarnowski {
35365a73f4SEd Tanous 
36365a73f4SEd Tanous enum class VmMode
37365a73f4SEd Tanous {
38365a73f4SEd Tanous     Invalid,
39365a73f4SEd Tanous     Legacy,
40365a73f4SEd Tanous     Proxy
41365a73f4SEd Tanous };
42365a73f4SEd Tanous 
43365a73f4SEd Tanous inline VmMode
44365a73f4SEd Tanous     parseObjectPathAndGetMode(const sdbusplus::message::object_path& itemPath,
45365a73f4SEd Tanous                               const std::string& resName)
46365a73f4SEd Tanous {
47365a73f4SEd Tanous     std::string thisPath = itemPath.filename();
48365a73f4SEd Tanous     BMCWEB_LOG_DEBUG << "Filename: " << itemPath.str
49365a73f4SEd Tanous                      << ", ThisPath: " << 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 
85*79fdf63eSPrzemyslaw Czarnowski using CheckItemHandler =
86*79fdf63eSPrzemyslaw Czarnowski     std::function<void(const std::string& service, const std::string& resName,
87*79fdf63eSPrzemyslaw Czarnowski                        const std::shared_ptr<bmcweb::AsyncResp>&,
88*79fdf63eSPrzemyslaw Czarnowski                        std::pair<sdbusplus::message::object_path,
89*79fdf63eSPrzemyslaw Czarnowski                                  dbus::utility::DBusInteracesMap>&)>;
90*79fdf63eSPrzemyslaw Czarnowski 
91*79fdf63eSPrzemyslaw Czarnowski inline void findAndParseObject(const std::string& service,
92*79fdf63eSPrzemyslaw Czarnowski                                const std::string& resName,
93*79fdf63eSPrzemyslaw Czarnowski                                const std::shared_ptr<bmcweb::AsyncResp>& aResp,
94*79fdf63eSPrzemyslaw Czarnowski                                CheckItemHandler&& handler)
95*79fdf63eSPrzemyslaw Czarnowski {
96*79fdf63eSPrzemyslaw Czarnowski     crow::connections::systemBus->async_method_call(
97*79fdf63eSPrzemyslaw Czarnowski         [service, resName, aResp,
98*79fdf63eSPrzemyslaw Czarnowski          handler](const boost::system::error_code ec,
99*79fdf63eSPrzemyslaw Czarnowski                   dbus::utility::ManagedObjectType& subtree) {
100*79fdf63eSPrzemyslaw Czarnowski         if (ec)
101*79fdf63eSPrzemyslaw Czarnowski         {
102*79fdf63eSPrzemyslaw Czarnowski             BMCWEB_LOG_DEBUG << "DBUS response error";
103*79fdf63eSPrzemyslaw Czarnowski 
104*79fdf63eSPrzemyslaw Czarnowski             return;
105*79fdf63eSPrzemyslaw Czarnowski         }
106*79fdf63eSPrzemyslaw Czarnowski 
107*79fdf63eSPrzemyslaw Czarnowski         for (auto& item : subtree)
108*79fdf63eSPrzemyslaw Czarnowski         {
109*79fdf63eSPrzemyslaw Czarnowski             VmMode mode = parseObjectPathAndGetMode(item.first, resName);
110*79fdf63eSPrzemyslaw Czarnowski             if (mode != VmMode::Invalid)
111*79fdf63eSPrzemyslaw Czarnowski             {
112*79fdf63eSPrzemyslaw Czarnowski                 handler(service, resName, aResp, item);
113*79fdf63eSPrzemyslaw Czarnowski                 return;
114*79fdf63eSPrzemyslaw Czarnowski             }
115*79fdf63eSPrzemyslaw Czarnowski         }
116*79fdf63eSPrzemyslaw Czarnowski 
117*79fdf63eSPrzemyslaw Czarnowski         BMCWEB_LOG_DEBUG << "Parent item not found";
118*79fdf63eSPrzemyslaw Czarnowski         aResp->res.result(boost::beast::http::status::not_found);
119*79fdf63eSPrzemyslaw Czarnowski         },
120*79fdf63eSPrzemyslaw Czarnowski         service, "/xyz/openbmc_project/VirtualMedia",
121*79fdf63eSPrzemyslaw Czarnowski         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
122*79fdf63eSPrzemyslaw Czarnowski }
123*79fdf63eSPrzemyslaw 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,
1538d1b46d7Szhanghch05                            const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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
172711ac7a9SEd Tanous                         aResp->res
173711ac7a9SEd Tanous                             .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] =
174d04ba325SPrzemyslaw Czarnowski                             *endpointIdValue;
175107077deSPrzemyslaw Czarnowski                         aResp->res.jsonValue["TransferProtocolType"] = "OEM";
176107077deSPrzemyslaw Czarnowski                     }
177107077deSPrzemyslaw Czarnowski                 }
178711ac7a9SEd Tanous                 if (property == "ImageURL")
179107077deSPrzemyslaw Czarnowski                 {
180107077deSPrzemyslaw Czarnowski                     const std::string* imageUrlValue =
181711ac7a9SEd Tanous                         std::get_if<std::string>(&value);
18226f6976fSEd Tanous                     if (imageUrlValue != nullptr && !imageUrlValue->empty())
183107077deSPrzemyslaw Czarnowski                     {
184da4784d8SPrzemyslaw Czarnowski                         std::filesystem::path filePath = *imageUrlValue;
185da4784d8SPrzemyslaw Czarnowski                         if (!filePath.has_filename())
186da4784d8SPrzemyslaw Czarnowski                         {
1879e319cf0SAnna Platash                             // this will handle https share, which not
1889e319cf0SAnna Platash                             // necessarily has to have filename given.
189da4784d8SPrzemyslaw Czarnowski                             aResp->res.jsonValue["ImageName"] = "";
190da4784d8SPrzemyslaw Czarnowski                         }
191da4784d8SPrzemyslaw Czarnowski                         else
192da4784d8SPrzemyslaw Czarnowski                         {
1939e319cf0SAnna Platash                             aResp->res.jsonValue["ImageName"] =
1949e319cf0SAnna Platash                                 filePath.filename();
195da4784d8SPrzemyslaw Czarnowski                         }
196da4784d8SPrzemyslaw Czarnowski 
197da4784d8SPrzemyslaw Czarnowski                         aResp->res.jsonValue["Image"] = *imageUrlValue;
1989e319cf0SAnna Platash                         aResp->res.jsonValue["TransferProtocolType"] =
1999e319cf0SAnna Platash                             getTransferProtocolTypeFromUri(*imageUrlValue);
2009e319cf0SAnna Platash 
201739b87efSEd Tanous                         aResp->res.jsonValue["ConnectedVia"] =
202739b87efSEd Tanous                             virtual_media::ConnectedVia::URI;
203107077deSPrzemyslaw Czarnowski                     }
204107077deSPrzemyslaw Czarnowski                 }
205711ac7a9SEd Tanous                 if (property == "WriteProtected")
2069e319cf0SAnna Platash                 {
207711ac7a9SEd Tanous                     const bool* writeProtectedValue = std::get_if<bool>(&value);
208e662eae8SEd Tanous                     if (writeProtectedValue != nullptr)
2099e319cf0SAnna Platash                     {
2109e319cf0SAnna Platash                         aResp->res.jsonValue["WriteProtected"] =
2119e319cf0SAnna Platash                             *writeProtectedValue;
2129e319cf0SAnna Platash                     }
2139e319cf0SAnna Platash                 }
2149e319cf0SAnna Platash             }
215107077deSPrzemyslaw Czarnowski         }
216711ac7a9SEd Tanous         if (interface == "xyz.openbmc_project.VirtualMedia.Process")
217711ac7a9SEd Tanous         {
218711ac7a9SEd Tanous             for (const auto& [property, value] : values)
219711ac7a9SEd Tanous             {
220711ac7a9SEd Tanous                 if (property == "Active")
221711ac7a9SEd Tanous                 {
222711ac7a9SEd Tanous                     const bool* activeValue = std::get_if<bool>(&value);
223e662eae8SEd Tanous                     if (activeValue == nullptr)
224711ac7a9SEd Tanous                     {
225711ac7a9SEd Tanous                         BMCWEB_LOG_DEBUG << "Value Active not found";
226711ac7a9SEd Tanous                         return;
227711ac7a9SEd Tanous                     }
228711ac7a9SEd Tanous                     aResp->res.jsonValue["Inserted"] = *activeValue;
229711ac7a9SEd Tanous 
230e05aec50SEd Tanous                     if (*activeValue)
231711ac7a9SEd Tanous                     {
232739b87efSEd Tanous                         aResp->res.jsonValue["ConnectedVia"] =
233739b87efSEd Tanous                             virtual_media::ConnectedVia::Applet;
234711ac7a9SEd Tanous                     }
235711ac7a9SEd Tanous                 }
236711ac7a9SEd Tanous             }
237711ac7a9SEd Tanous         }
238107077deSPrzemyslaw Czarnowski     }
239107077deSPrzemyslaw Czarnowski }
240107077deSPrzemyslaw Czarnowski 
241107077deSPrzemyslaw Czarnowski /**
242107077deSPrzemyslaw Czarnowski  * @brief Fill template for Virtual Media Item.
243107077deSPrzemyslaw Czarnowski  */
24422db1728SEd Tanous inline nlohmann::json vmItemTemplate(const std::string& name,
245107077deSPrzemyslaw Czarnowski                                      const std::string& resName)
246107077deSPrzemyslaw Czarnowski {
247107077deSPrzemyslaw Czarnowski     nlohmann::json item;
248fdb20347SEd Tanous     item["@odata.id"] = crow::utility::urlFromPieces(
249fdb20347SEd Tanous         "redfish", "v1", "Managers", name, "VirtualMedia", resName);
25022db1728SEd Tanous 
251d04ba325SPrzemyslaw Czarnowski     item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia";
252107077deSPrzemyslaw Czarnowski     item["Name"] = "Virtual Removable Media";
253107077deSPrzemyslaw Czarnowski     item["Id"] = resName;
254107077deSPrzemyslaw Czarnowski     item["WriteProtected"] = true;
255739b87efSEd Tanous     item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected;
256613dabeaSEd Tanous     item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"});
257107077deSPrzemyslaw Czarnowski     item["TransferMethod"] = "Stream";
258d04ba325SPrzemyslaw Czarnowski     item["Oem"]["OpenBMC"]["@odata.type"] =
259d04ba325SPrzemyslaw Czarnowski         "#OemVirtualMedia.v1_0_0.VirtualMedia";
260107077deSPrzemyslaw Czarnowski 
261107077deSPrzemyslaw Czarnowski     return item;
262107077deSPrzemyslaw Czarnowski }
263107077deSPrzemyslaw Czarnowski 
264107077deSPrzemyslaw Czarnowski /**
265107077deSPrzemyslaw Czarnowski  *  @brief Fills collection data
266107077deSPrzemyslaw Czarnowski  */
26722db1728SEd Tanous inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> aResp,
268107077deSPrzemyslaw Czarnowski                               const std::string& service,
269107077deSPrzemyslaw Czarnowski                               const std::string& name)
270107077deSPrzemyslaw Czarnowski {
271107077deSPrzemyslaw Czarnowski     BMCWEB_LOG_DEBUG << "Get available Virtual Media resources.";
272107077deSPrzemyslaw Czarnowski     crow::connections::systemBus->async_method_call(
27302cad96eSEd Tanous         [name, aResp{std::move(aResp)}](
2745e7e2dc5SEd Tanous             const boost::system::error_code& ec,
27502cad96eSEd Tanous             const dbus::utility::ManagedObjectType& subtree) {
276107077deSPrzemyslaw Czarnowski         if (ec)
277107077deSPrzemyslaw Czarnowski         {
278107077deSPrzemyslaw Czarnowski             BMCWEB_LOG_DEBUG << "DBUS response error";
279107077deSPrzemyslaw Czarnowski             return;
280107077deSPrzemyslaw Czarnowski         }
281107077deSPrzemyslaw Czarnowski         nlohmann::json& members = aResp->res.jsonValue["Members"];
282107077deSPrzemyslaw Czarnowski         members = nlohmann::json::array();
283107077deSPrzemyslaw Czarnowski 
284107077deSPrzemyslaw Czarnowski         for (const auto& object : subtree)
285107077deSPrzemyslaw Czarnowski         {
286107077deSPrzemyslaw Czarnowski             nlohmann::json item;
2872dfd18efSEd Tanous             std::string path = object.first.filename();
2882dfd18efSEd Tanous             if (path.empty())
289107077deSPrzemyslaw Czarnowski             {
290107077deSPrzemyslaw Czarnowski                 continue;
291107077deSPrzemyslaw Czarnowski             }
292107077deSPrzemyslaw Czarnowski 
293fdb20347SEd Tanous             item["@odata.id"] = crow::utility::urlFromPieces(
294fdb20347SEd Tanous                 "redfish", "v1", "Managers", name, "VirtualMedia", path);
295107077deSPrzemyslaw Czarnowski             members.emplace_back(std::move(item));
296107077deSPrzemyslaw Czarnowski         }
297107077deSPrzemyslaw Czarnowski         aResp->res.jsonValue["Members@odata.count"] = members.size();
298107077deSPrzemyslaw Czarnowski         },
299107077deSPrzemyslaw Czarnowski         service, "/xyz/openbmc_project/VirtualMedia",
300107077deSPrzemyslaw Czarnowski         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
301107077deSPrzemyslaw Czarnowski }
302107077deSPrzemyslaw Czarnowski 
303*79fdf63eSPrzemyslaw Czarnowski inline void afterGetVmData(const std::string& name,
304*79fdf63eSPrzemyslaw Czarnowski                            const std::string& /*service*/,
305*79fdf63eSPrzemyslaw Czarnowski                            const std::string& resName,
306*79fdf63eSPrzemyslaw Czarnowski                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
307*79fdf63eSPrzemyslaw Czarnowski                            std::pair<sdbusplus::message::object_path,
308*79fdf63eSPrzemyslaw Czarnowski                                      dbus::utility::DBusInteracesMap>& item)
309*79fdf63eSPrzemyslaw Czarnowski {
310*79fdf63eSPrzemyslaw Czarnowski     VmMode mode = parseObjectPathAndGetMode(item.first, resName);
311*79fdf63eSPrzemyslaw Czarnowski     if (mode == VmMode::Invalid)
312*79fdf63eSPrzemyslaw Czarnowski     {
313*79fdf63eSPrzemyslaw Czarnowski         return;
314*79fdf63eSPrzemyslaw Czarnowski     }
315*79fdf63eSPrzemyslaw Czarnowski 
316*79fdf63eSPrzemyslaw Czarnowski     asyncResp->res.jsonValue = vmItemTemplate(name, resName);
317*79fdf63eSPrzemyslaw Czarnowski 
318*79fdf63eSPrzemyslaw Czarnowski     // Check if dbus path is Legacy type
319*79fdf63eSPrzemyslaw Czarnowski     if (mode == VmMode::Legacy)
320*79fdf63eSPrzemyslaw Czarnowski     {
321*79fdf63eSPrzemyslaw Czarnowski         asyncResp->res
322*79fdf63eSPrzemyslaw Czarnowski             .jsonValue["Actions"]["#VirtualMedia.InsertMedia"]["target"] =
323*79fdf63eSPrzemyslaw Czarnowski             crow::utility::urlFromPieces("redfish", "v1", "Managers", name,
324*79fdf63eSPrzemyslaw Czarnowski                                          "VirtualMedia", resName, "Actions",
325*79fdf63eSPrzemyslaw Czarnowski                                          "VirtualMedia.InsertMedia");
326*79fdf63eSPrzemyslaw Czarnowski     }
327*79fdf63eSPrzemyslaw Czarnowski 
328*79fdf63eSPrzemyslaw Czarnowski     vmParseInterfaceObject(item.second, asyncResp);
329*79fdf63eSPrzemyslaw Czarnowski 
330*79fdf63eSPrzemyslaw Czarnowski     asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"]["target"] =
331*79fdf63eSPrzemyslaw Czarnowski         crow::utility::urlFromPieces("redfish", "v1", "Managers", name,
332*79fdf63eSPrzemyslaw Czarnowski                                      "VirtualMedia", resName, "Actions",
333*79fdf63eSPrzemyslaw Czarnowski                                      "VirtualMedia.EjectMedia");
334*79fdf63eSPrzemyslaw Czarnowski }
335*79fdf63eSPrzemyslaw Czarnowski 
336107077deSPrzemyslaw Czarnowski /**
337107077deSPrzemyslaw Czarnowski  *  @brief Fills data for specific resource
338107077deSPrzemyslaw Czarnowski  */
33922db1728SEd Tanous inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
340107077deSPrzemyslaw Czarnowski                       const std::string& service, const std::string& name,
341107077deSPrzemyslaw Czarnowski                       const std::string& resName)
342107077deSPrzemyslaw Czarnowski {
343107077deSPrzemyslaw Czarnowski     BMCWEB_LOG_DEBUG << "Get Virtual Media resource data.";
344107077deSPrzemyslaw Czarnowski 
345*79fdf63eSPrzemyslaw Czarnowski     findAndParseObject(service, resName, aResp,
346*79fdf63eSPrzemyslaw Czarnowski                        std::bind_front(&afterGetVmData, name));
347107077deSPrzemyslaw Czarnowski }
348107077deSPrzemyslaw Czarnowski 
349e13c2760SPrzemyslaw Czarnowski /**
350c6f4e017SAgata Olender  * @brief Transfer protocols supported for InsertMedia action.
351c6f4e017SAgata Olender  *
352c6f4e017SAgata Olender  */
353c6f4e017SAgata Olender enum class TransferProtocol
354c6f4e017SAgata Olender {
355c6f4e017SAgata Olender     https,
356c6f4e017SAgata Olender     smb,
357c6f4e017SAgata Olender     invalid
358c6f4e017SAgata Olender };
359c6f4e017SAgata Olender 
360c6f4e017SAgata Olender /**
361c6f4e017SAgata Olender  * @brief Function extracts transfer protocol type from URI.
362c6f4e017SAgata Olender  *
363c6f4e017SAgata Olender  */
36467df073bSEd Tanous inline std::optional<TransferProtocol>
365ace85d60SEd Tanous     getTransferProtocolFromUri(const boost::urls::url_view& imageUri)
36667df073bSEd Tanous {
367079360aeSEd Tanous     std::string_view scheme = imageUri.scheme();
36867df073bSEd Tanous     if (scheme == "smb")
36967df073bSEd Tanous     {
37067df073bSEd Tanous         return TransferProtocol::smb;
37167df073bSEd Tanous     }
37267df073bSEd Tanous     if (scheme == "https")
37367df073bSEd Tanous     {
37467df073bSEd Tanous         return TransferProtocol::https;
37567df073bSEd Tanous     }
37667df073bSEd Tanous     if (!scheme.empty())
37767df073bSEd Tanous     {
37867df073bSEd Tanous         return TransferProtocol::invalid;
37967df073bSEd Tanous     }
38067df073bSEd Tanous 
38167df073bSEd Tanous     return {};
38267df073bSEd Tanous }
383c6f4e017SAgata Olender 
384c6f4e017SAgata Olender /**
385c6f4e017SAgata Olender  * @brief Function convert transfer protocol from string param.
386c6f4e017SAgata Olender  *
387c6f4e017SAgata Olender  */
38822db1728SEd Tanous inline std::optional<TransferProtocol> getTransferProtocolFromParam(
389c6f4e017SAgata Olender     const std::optional<std::string>& transferProtocolType)
390c6f4e017SAgata Olender {
391c6f4e017SAgata Olender     if (transferProtocolType == std::nullopt)
392c6f4e017SAgata Olender     {
393c6f4e017SAgata Olender         return {};
394c6f4e017SAgata Olender     }
395c6f4e017SAgata Olender 
396c6f4e017SAgata Olender     if (*transferProtocolType == "CIFS")
397c6f4e017SAgata Olender     {
398c6f4e017SAgata Olender         return TransferProtocol::smb;
399c6f4e017SAgata Olender     }
400c6f4e017SAgata Olender 
401c6f4e017SAgata Olender     if (*transferProtocolType == "HTTPS")
402c6f4e017SAgata Olender     {
403c6f4e017SAgata Olender         return TransferProtocol::https;
404c6f4e017SAgata Olender     }
405c6f4e017SAgata Olender 
406c6f4e017SAgata Olender     return TransferProtocol::invalid;
407c6f4e017SAgata Olender }
408c6f4e017SAgata Olender 
409c6f4e017SAgata Olender /**
410c6f4e017SAgata Olender  * @brief Function extends URI with transfer protocol type.
411c6f4e017SAgata Olender  *
412c6f4e017SAgata Olender  */
41322db1728SEd Tanous inline std::string
414c6f4e017SAgata Olender     getUriWithTransferProtocol(const std::string& imageUri,
415c6f4e017SAgata Olender                                const TransferProtocol& transferProtocol)
416c6f4e017SAgata Olender {
417c6f4e017SAgata Olender     if (transferProtocol == TransferProtocol::smb)
418c6f4e017SAgata Olender     {
419c6f4e017SAgata Olender         return "smb://" + imageUri;
420c6f4e017SAgata Olender     }
421c6f4e017SAgata Olender 
422c6f4e017SAgata Olender     if (transferProtocol == TransferProtocol::https)
423c6f4e017SAgata Olender     {
424c6f4e017SAgata Olender         return "https://" + imageUri;
425c6f4e017SAgata Olender     }
426c6f4e017SAgata Olender 
427c6f4e017SAgata Olender     return imageUri;
428c6f4e017SAgata Olender }
429c6f4e017SAgata Olender 
4301f2a40ceSPrzemyslaw Czarnowski struct InsertMediaActionParams
4311f2a40ceSPrzemyslaw Czarnowski {
432120fa86aSPrzemyslaw Czarnowski     std::optional<std::string> imageUrl;
4331f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> userName;
4341f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> password;
4351f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> transferMethod;
4361f2a40ceSPrzemyslaw Czarnowski     std::optional<std::string> transferProtocolType;
4371f2a40ceSPrzemyslaw Czarnowski     std::optional<bool> writeProtected = true;
4381f2a40ceSPrzemyslaw Czarnowski     std::optional<bool> inserted;
4391f2a40ceSPrzemyslaw Czarnowski };
4401f2a40ceSPrzemyslaw Czarnowski 
4411214b7e7SGunnar Mills template <typename T>
4421214b7e7SGunnar Mills static void secureCleanup(T& value)
443988fb7b2SAdrian Ambrożewicz {
4444ecc618fSEd Tanous     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
445988fb7b2SAdrian Ambrożewicz     auto raw = const_cast<typename T::value_type*>(value.data());
446988fb7b2SAdrian Ambrożewicz     explicit_bzero(raw, value.size() * sizeof(*raw));
447988fb7b2SAdrian Ambrożewicz }
448988fb7b2SAdrian Ambrożewicz 
449988fb7b2SAdrian Ambrożewicz class Credentials
450988fb7b2SAdrian Ambrożewicz {
451988fb7b2SAdrian Ambrożewicz   public:
452988fb7b2SAdrian Ambrożewicz     Credentials(std::string&& user, std::string&& password) :
453988fb7b2SAdrian Ambrożewicz         userBuf(std::move(user)), passBuf(std::move(password))
4541214b7e7SGunnar Mills     {}
455988fb7b2SAdrian Ambrożewicz 
456988fb7b2SAdrian Ambrożewicz     ~Credentials()
457988fb7b2SAdrian Ambrożewicz     {
458988fb7b2SAdrian Ambrożewicz         secureCleanup(userBuf);
459988fb7b2SAdrian Ambrożewicz         secureCleanup(passBuf);
460988fb7b2SAdrian Ambrożewicz     }
461988fb7b2SAdrian Ambrożewicz 
462988fb7b2SAdrian Ambrożewicz     const std::string& user()
463988fb7b2SAdrian Ambrożewicz     {
464988fb7b2SAdrian Ambrożewicz         return userBuf;
465988fb7b2SAdrian Ambrożewicz     }
466988fb7b2SAdrian Ambrożewicz 
467988fb7b2SAdrian Ambrożewicz     const std::string& password()
468988fb7b2SAdrian Ambrożewicz     {
469988fb7b2SAdrian Ambrożewicz         return passBuf;
470988fb7b2SAdrian Ambrożewicz     }
471988fb7b2SAdrian Ambrożewicz 
472988fb7b2SAdrian Ambrożewicz     Credentials() = delete;
473988fb7b2SAdrian Ambrożewicz     Credentials(const Credentials&) = delete;
474988fb7b2SAdrian Ambrożewicz     Credentials& operator=(const Credentials&) = delete;
475ecd6a3a2SEd Tanous     Credentials(Credentials&&) = delete;
476ecd6a3a2SEd Tanous     Credentials& operator=(Credentials&&) = delete;
477988fb7b2SAdrian Ambrożewicz 
47822db1728SEd Tanous   private:
479988fb7b2SAdrian Ambrożewicz     std::string userBuf;
480988fb7b2SAdrian Ambrożewicz     std::string passBuf;
481988fb7b2SAdrian Ambrożewicz };
482988fb7b2SAdrian Ambrożewicz 
483988fb7b2SAdrian Ambrożewicz class CredentialsProvider
484988fb7b2SAdrian Ambrożewicz {
485988fb7b2SAdrian Ambrożewicz   public:
4861214b7e7SGunnar Mills     template <typename T>
4871214b7e7SGunnar Mills     struct Deleter
488988fb7b2SAdrian Ambrożewicz     {
489988fb7b2SAdrian Ambrożewicz         void operator()(T* buff) const
490988fb7b2SAdrian Ambrożewicz         {
491988fb7b2SAdrian Ambrożewicz             if (buff)
492988fb7b2SAdrian Ambrożewicz             {
493988fb7b2SAdrian Ambrożewicz                 secureCleanup(*buff);
494988fb7b2SAdrian Ambrożewicz                 delete buff;
495988fb7b2SAdrian Ambrożewicz             }
496988fb7b2SAdrian Ambrożewicz         }
497988fb7b2SAdrian Ambrożewicz     };
498988fb7b2SAdrian Ambrożewicz 
499988fb7b2SAdrian Ambrożewicz     using Buffer = std::vector<char>;
500988fb7b2SAdrian Ambrożewicz     using SecureBuffer = std::unique_ptr<Buffer, Deleter<Buffer>>;
501988fb7b2SAdrian Ambrożewicz     // Using explicit definition instead of std::function to avoid implicit
502988fb7b2SAdrian Ambrożewicz     // conversions eg. stack copy instead of reference
503988fb7b2SAdrian Ambrożewicz     using FormatterFunc = void(const std::string& username,
504988fb7b2SAdrian Ambrożewicz                                const std::string& password, Buffer& dest);
505988fb7b2SAdrian Ambrożewicz 
506988fb7b2SAdrian Ambrożewicz     CredentialsProvider(std::string&& user, std::string&& password) :
507988fb7b2SAdrian Ambrożewicz         credentials(std::move(user), std::move(password))
5081214b7e7SGunnar Mills     {}
509988fb7b2SAdrian Ambrożewicz 
510988fb7b2SAdrian Ambrożewicz     const std::string& user()
511988fb7b2SAdrian Ambrożewicz     {
512988fb7b2SAdrian Ambrożewicz         return credentials.user();
513988fb7b2SAdrian Ambrożewicz     }
514988fb7b2SAdrian Ambrożewicz 
515988fb7b2SAdrian Ambrożewicz     const std::string& password()
516988fb7b2SAdrian Ambrożewicz     {
517988fb7b2SAdrian Ambrożewicz         return credentials.password();
518988fb7b2SAdrian Ambrożewicz     }
519988fb7b2SAdrian Ambrożewicz 
5201917ee95SEd Tanous     SecureBuffer pack(FormatterFunc* formatter)
521988fb7b2SAdrian Ambrożewicz     {
522988fb7b2SAdrian Ambrożewicz         SecureBuffer packed{new Buffer{}};
523e662eae8SEd Tanous         if (formatter != nullptr)
524988fb7b2SAdrian Ambrożewicz         {
525988fb7b2SAdrian Ambrożewicz             formatter(credentials.user(), credentials.password(), *packed);
526988fb7b2SAdrian Ambrożewicz         }
527988fb7b2SAdrian Ambrożewicz 
528988fb7b2SAdrian Ambrożewicz         return packed;
529988fb7b2SAdrian Ambrożewicz     }
530988fb7b2SAdrian Ambrożewicz 
531988fb7b2SAdrian Ambrożewicz   private:
532988fb7b2SAdrian Ambrożewicz     Credentials credentials;
533988fb7b2SAdrian Ambrożewicz };
534988fb7b2SAdrian Ambrożewicz 
535988fb7b2SAdrian Ambrożewicz // Wrapper for boost::async_pipe ensuring proper pipe cleanup
5360a48306bSEd Tanous class SecurePipe
537988fb7b2SAdrian Ambrożewicz {
538988fb7b2SAdrian Ambrożewicz   public:
539988fb7b2SAdrian Ambrożewicz     using unix_fd = sdbusplus::message::unix_fd;
540988fb7b2SAdrian Ambrożewicz 
5410a48306bSEd Tanous     SecurePipe(boost::asio::io_context& io,
5420a48306bSEd Tanous                CredentialsProvider::SecureBuffer&& bufferIn) :
5430a48306bSEd Tanous         impl(io),
5440a48306bSEd Tanous         buffer{std::move(bufferIn)}
5451214b7e7SGunnar Mills     {}
546988fb7b2SAdrian Ambrożewicz 
5470a48306bSEd Tanous     ~SecurePipe()
548988fb7b2SAdrian Ambrożewicz     {
549988fb7b2SAdrian Ambrożewicz         // Named pipe needs to be explicitly removed
550988fb7b2SAdrian Ambrożewicz         impl.close();
551988fb7b2SAdrian Ambrożewicz     }
552988fb7b2SAdrian Ambrożewicz 
5530a48306bSEd Tanous     SecurePipe(const SecurePipe&) = delete;
5540a48306bSEd Tanous     SecurePipe(SecurePipe&&) = delete;
5550a48306bSEd Tanous     SecurePipe& operator=(const SecurePipe&) = delete;
5560a48306bSEd Tanous     SecurePipe& operator=(SecurePipe&&) = delete;
557ecd6a3a2SEd Tanous 
5580a48306bSEd Tanous     unix_fd fd() const
559988fb7b2SAdrian Ambrożewicz     {
560988fb7b2SAdrian Ambrożewicz         return unix_fd{impl.native_source()};
561988fb7b2SAdrian Ambrożewicz     }
562988fb7b2SAdrian Ambrożewicz 
563988fb7b2SAdrian Ambrożewicz     template <typename WriteHandler>
56481ce609eSEd Tanous     void asyncWrite(WriteHandler&& handler)
565988fb7b2SAdrian Ambrożewicz     {
5660a48306bSEd Tanous         impl.async_write_some(boost::asio::buffer(*buffer),
5670a48306bSEd Tanous                               std::forward<WriteHandler>(handler));
568988fb7b2SAdrian Ambrożewicz     }
569988fb7b2SAdrian Ambrożewicz 
570988fb7b2SAdrian Ambrożewicz     const std::string name;
571988fb7b2SAdrian Ambrożewicz     boost::process::async_pipe impl;
5720a48306bSEd Tanous     CredentialsProvider::SecureBuffer buffer;
573988fb7b2SAdrian Ambrożewicz };
574988fb7b2SAdrian Ambrożewicz 
575e13c2760SPrzemyslaw Czarnowski /**
576e13c2760SPrzemyslaw Czarnowski  * @brief Function transceives data with dbus directly.
577e13c2760SPrzemyslaw Czarnowski  *
578e13c2760SPrzemyslaw Czarnowski  * All BMC state properties will be retrieved before sending reset request.
579e13c2760SPrzemyslaw Czarnowski  */
58022db1728SEd Tanous inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
581e13c2760SPrzemyslaw Czarnowski                             const std::string& service, const std::string& name,
582988fb7b2SAdrian Ambrożewicz                             const std::string& imageUrl, const bool rw,
583988fb7b2SAdrian Ambrożewicz                             std::string&& userName, std::string&& password)
584e13c2760SPrzemyslaw Czarnowski {
585988fb7b2SAdrian Ambrożewicz     constexpr const size_t secretLimit = 1024;
586988fb7b2SAdrian Ambrożewicz 
587988fb7b2SAdrian Ambrożewicz     std::shared_ptr<SecurePipe> secretPipe;
588168e20c1SEd Tanous     dbus::utility::DbusVariantType unixFd = -1;
589988fb7b2SAdrian Ambrożewicz 
590988fb7b2SAdrian Ambrożewicz     if (!userName.empty() || !password.empty())
591988fb7b2SAdrian Ambrożewicz     {
592988fb7b2SAdrian Ambrożewicz         // Encapsulate in safe buffer
593988fb7b2SAdrian Ambrożewicz         CredentialsProvider credentials(std::move(userName),
594988fb7b2SAdrian Ambrożewicz                                         std::move(password));
595988fb7b2SAdrian Ambrożewicz 
596988fb7b2SAdrian Ambrożewicz         // Payload must contain data + NULL delimiters
597988fb7b2SAdrian Ambrożewicz         if (credentials.user().size() + credentials.password().size() + 2 >
598988fb7b2SAdrian Ambrożewicz             secretLimit)
599988fb7b2SAdrian Ambrożewicz         {
600988fb7b2SAdrian Ambrożewicz             BMCWEB_LOG_ERROR << "Credentials too long to handle";
601988fb7b2SAdrian Ambrożewicz             messages::unrecognizedRequestBody(asyncResp->res);
602988fb7b2SAdrian Ambrożewicz             return;
603988fb7b2SAdrian Ambrożewicz         }
604988fb7b2SAdrian Ambrożewicz 
605988fb7b2SAdrian Ambrożewicz         // Pack secret
60622db1728SEd Tanous         auto secret = credentials.pack(
60722db1728SEd Tanous             [](const auto& user, const auto& pass, auto& buff) {
608988fb7b2SAdrian Ambrożewicz             std::copy(user.begin(), user.end(), std::back_inserter(buff));
609988fb7b2SAdrian Ambrożewicz             buff.push_back('\0');
610988fb7b2SAdrian Ambrożewicz             std::copy(pass.begin(), pass.end(), std::back_inserter(buff));
611988fb7b2SAdrian Ambrożewicz             buff.push_back('\0');
612988fb7b2SAdrian Ambrożewicz         });
613988fb7b2SAdrian Ambrożewicz 
614988fb7b2SAdrian Ambrożewicz         // Open pipe
615988fb7b2SAdrian Ambrożewicz         secretPipe = std::make_shared<SecurePipe>(
61622db1728SEd Tanous             crow::connections::systemBus->get_io_context(), std::move(secret));
617988fb7b2SAdrian Ambrożewicz         unixFd = secretPipe->fd();
618988fb7b2SAdrian Ambrożewicz 
619988fb7b2SAdrian Ambrożewicz         // Pass secret over pipe
62081ce609eSEd Tanous         secretPipe->asyncWrite(
621f5b16f03SVikram Bodireddy             [asyncResp](const boost::system::error_code& ec, std::size_t) {
622988fb7b2SAdrian Ambrożewicz             if (ec)
623988fb7b2SAdrian Ambrożewicz             {
624988fb7b2SAdrian Ambrożewicz                 BMCWEB_LOG_ERROR << "Failed to pass secret: " << ec;
625988fb7b2SAdrian Ambrożewicz                 messages::internalError(asyncResp->res);
626988fb7b2SAdrian Ambrożewicz             }
627988fb7b2SAdrian Ambrożewicz         });
628988fb7b2SAdrian Ambrożewicz     }
629988fb7b2SAdrian Ambrożewicz 
630e13c2760SPrzemyslaw Czarnowski     crow::connections::systemBus->async_method_call(
6315e7e2dc5SEd Tanous         [asyncResp, secretPipe](const boost::system::error_code& ec,
632988fb7b2SAdrian Ambrożewicz                                 bool success) {
633e13c2760SPrzemyslaw Czarnowski         if (ec)
634e13c2760SPrzemyslaw Czarnowski         {
635e13c2760SPrzemyslaw Czarnowski             BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
636e13c2760SPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
637d6da5bebSAdrian Ambrożewicz         }
638d6da5bebSAdrian Ambrożewicz         else if (!success)
639d6da5bebSAdrian Ambrożewicz         {
640d6da5bebSAdrian Ambrożewicz             BMCWEB_LOG_ERROR << "Service responded with error";
641d6da5bebSAdrian Ambrożewicz             messages::generalError(asyncResp->res);
642e13c2760SPrzemyslaw Czarnowski         }
643e13c2760SPrzemyslaw Czarnowski         },
644e13c2760SPrzemyslaw Czarnowski         service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
645988fb7b2SAdrian Ambrożewicz         "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", imageUrl, rw,
646988fb7b2SAdrian Ambrożewicz         unixFd);
647e13c2760SPrzemyslaw Czarnowski }
648e13c2760SPrzemyslaw Czarnowski 
649e13c2760SPrzemyslaw Czarnowski /**
650120fa86aSPrzemyslaw Czarnowski  * @brief Function validate parameters of insert media request.
651120fa86aSPrzemyslaw Czarnowski  *
652120fa86aSPrzemyslaw Czarnowski  */
653120fa86aSPrzemyslaw Czarnowski inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
654120fa86aSPrzemyslaw Czarnowski                            const std::string& service,
655120fa86aSPrzemyslaw Czarnowski                            const std::string& resName,
656120fa86aSPrzemyslaw Czarnowski                            InsertMediaActionParams& actionParams)
657120fa86aSPrzemyslaw Czarnowski {
658120fa86aSPrzemyslaw Czarnowski     BMCWEB_LOG_DEBUG << "Validation started";
659120fa86aSPrzemyslaw Czarnowski     // required param imageUrl must not be empty
660120fa86aSPrzemyslaw Czarnowski     if (!actionParams.imageUrl)
661120fa86aSPrzemyslaw Czarnowski     {
662120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR << "Request action parameter Image is empty.";
663120fa86aSPrzemyslaw Czarnowski 
664120fa86aSPrzemyslaw Czarnowski         messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image");
665120fa86aSPrzemyslaw Czarnowski 
666120fa86aSPrzemyslaw Czarnowski         return;
667120fa86aSPrzemyslaw Czarnowski     }
668120fa86aSPrzemyslaw Czarnowski 
669120fa86aSPrzemyslaw Czarnowski     // optional param inserted must be true
670120fa86aSPrzemyslaw Czarnowski     if ((actionParams.inserted != std::nullopt) && !*actionParams.inserted)
671120fa86aSPrzemyslaw Czarnowski     {
672120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR
673120fa86aSPrzemyslaw Czarnowski             << "Request action optional parameter Inserted must be true.";
674120fa86aSPrzemyslaw Czarnowski 
675120fa86aSPrzemyslaw Czarnowski         messages::actionParameterNotSupported(asyncResp->res, "Inserted",
676120fa86aSPrzemyslaw Czarnowski                                               "InsertMedia");
677120fa86aSPrzemyslaw Czarnowski 
678120fa86aSPrzemyslaw Czarnowski         return;
679120fa86aSPrzemyslaw Czarnowski     }
680120fa86aSPrzemyslaw Czarnowski 
681120fa86aSPrzemyslaw Czarnowski     // optional param transferMethod must be stream
682120fa86aSPrzemyslaw Czarnowski     if ((actionParams.transferMethod != std::nullopt) &&
683120fa86aSPrzemyslaw Czarnowski         (*actionParams.transferMethod != "Stream"))
684120fa86aSPrzemyslaw Czarnowski     {
685120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR << "Request action optional parameter "
686120fa86aSPrzemyslaw Czarnowski                             "TransferMethod must be Stream.";
687120fa86aSPrzemyslaw Czarnowski 
688120fa86aSPrzemyslaw Czarnowski         messages::actionParameterNotSupported(asyncResp->res, "TransferMethod",
689120fa86aSPrzemyslaw Czarnowski                                               "InsertMedia");
690120fa86aSPrzemyslaw Czarnowski 
691120fa86aSPrzemyslaw Czarnowski         return;
692120fa86aSPrzemyslaw Czarnowski     }
693120fa86aSPrzemyslaw Czarnowski     boost::urls::result<boost::urls::url_view> url =
694120fa86aSPrzemyslaw Czarnowski         boost::urls::parse_uri(*actionParams.imageUrl);
695120fa86aSPrzemyslaw Czarnowski     if (!url)
696120fa86aSPrzemyslaw Czarnowski     {
697120fa86aSPrzemyslaw Czarnowski         messages::actionParameterValueFormatError(
698120fa86aSPrzemyslaw Czarnowski             asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia");
699120fa86aSPrzemyslaw Czarnowski         return;
700120fa86aSPrzemyslaw Czarnowski     }
701120fa86aSPrzemyslaw Czarnowski     std::optional<TransferProtocol> uriTransferProtocolType =
702120fa86aSPrzemyslaw Czarnowski         getTransferProtocolFromUri(*url);
703120fa86aSPrzemyslaw Czarnowski 
704120fa86aSPrzemyslaw Czarnowski     std::optional<TransferProtocol> paramTransferProtocolType =
705120fa86aSPrzemyslaw Czarnowski         getTransferProtocolFromParam(actionParams.transferProtocolType);
706120fa86aSPrzemyslaw Czarnowski 
707120fa86aSPrzemyslaw Czarnowski     // ImageUrl does not contain valid protocol type
708120fa86aSPrzemyslaw Czarnowski     if (*uriTransferProtocolType == TransferProtocol::invalid)
709120fa86aSPrzemyslaw Czarnowski     {
710120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
711120fa86aSPrzemyslaw Czarnowski                             "contain specified protocol type from list: "
712120fa86aSPrzemyslaw Czarnowski                             "(smb, https).";
713120fa86aSPrzemyslaw Czarnowski 
714120fa86aSPrzemyslaw Czarnowski         messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
715120fa86aSPrzemyslaw Czarnowski 
716120fa86aSPrzemyslaw Czarnowski         return;
717120fa86aSPrzemyslaw Czarnowski     }
718120fa86aSPrzemyslaw Czarnowski 
719120fa86aSPrzemyslaw Czarnowski     // transferProtocolType should contain value from list
720120fa86aSPrzemyslaw Czarnowski     if (*paramTransferProtocolType == TransferProtocol::invalid)
721120fa86aSPrzemyslaw Czarnowski     {
722120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR << "Request action parameter TransferProtocolType "
723120fa86aSPrzemyslaw Czarnowski                             "must be provided with value from list: "
724120fa86aSPrzemyslaw Czarnowski                             "(CIFS, HTTPS).";
725120fa86aSPrzemyslaw Czarnowski 
726120fa86aSPrzemyslaw Czarnowski         messages::propertyValueNotInList(asyncResp->res,
727120fa86aSPrzemyslaw Czarnowski                                          *actionParams.transferProtocolType,
728120fa86aSPrzemyslaw Czarnowski                                          "TransferProtocolType");
729120fa86aSPrzemyslaw Czarnowski         return;
730120fa86aSPrzemyslaw Czarnowski     }
731120fa86aSPrzemyslaw Czarnowski 
732120fa86aSPrzemyslaw Czarnowski     // valid transfer protocol not provided either with URI nor param
733120fa86aSPrzemyslaw Czarnowski     if ((uriTransferProtocolType == std::nullopt) &&
734120fa86aSPrzemyslaw Czarnowski         (paramTransferProtocolType == std::nullopt))
735120fa86aSPrzemyslaw Czarnowski     {
736120fa86aSPrzemyslaw Czarnowski         BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
737120fa86aSPrzemyslaw Czarnowski                             "contain specified protocol type or param "
738120fa86aSPrzemyslaw Czarnowski                             "TransferProtocolType must be provided.";
739120fa86aSPrzemyslaw Czarnowski 
740120fa86aSPrzemyslaw Czarnowski         messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
741120fa86aSPrzemyslaw Czarnowski 
742120fa86aSPrzemyslaw Czarnowski         return;
743120fa86aSPrzemyslaw Czarnowski     }
744120fa86aSPrzemyslaw Czarnowski 
745120fa86aSPrzemyslaw Czarnowski     // valid transfer protocol provided both with URI and param
746120fa86aSPrzemyslaw Czarnowski     if ((paramTransferProtocolType != std::nullopt) &&
747120fa86aSPrzemyslaw Czarnowski         (uriTransferProtocolType != std::nullopt))
748120fa86aSPrzemyslaw Czarnowski     {
749120fa86aSPrzemyslaw Czarnowski         // check if protocol is the same for URI and param
750120fa86aSPrzemyslaw Czarnowski         if (*paramTransferProtocolType != *uriTransferProtocolType)
751120fa86aSPrzemyslaw Czarnowski         {
752120fa86aSPrzemyslaw Czarnowski             BMCWEB_LOG_ERROR << "Request action parameter "
753120fa86aSPrzemyslaw Czarnowski                                 "TransferProtocolType must  contain the "
754120fa86aSPrzemyslaw Czarnowski                                 "same protocol type as protocol type "
755120fa86aSPrzemyslaw Czarnowski                                 "provided with param imageUrl.";
756120fa86aSPrzemyslaw Czarnowski 
757120fa86aSPrzemyslaw Czarnowski             messages::actionParameterValueTypeError(
758120fa86aSPrzemyslaw Czarnowski                 asyncResp->res, *actionParams.transferProtocolType,
759120fa86aSPrzemyslaw Czarnowski                 "TransferProtocolType", "InsertMedia");
760120fa86aSPrzemyslaw Czarnowski 
761120fa86aSPrzemyslaw Czarnowski             return;
762120fa86aSPrzemyslaw Czarnowski         }
763120fa86aSPrzemyslaw Czarnowski     }
764120fa86aSPrzemyslaw Czarnowski 
765120fa86aSPrzemyslaw Czarnowski     // validation passed, add protocol to URI if needed
766120fa86aSPrzemyslaw Czarnowski     if (uriTransferProtocolType == std::nullopt)
767120fa86aSPrzemyslaw Czarnowski     {
768120fa86aSPrzemyslaw Czarnowski         actionParams.imageUrl = getUriWithTransferProtocol(
769120fa86aSPrzemyslaw Czarnowski             *actionParams.imageUrl, *paramTransferProtocolType);
770120fa86aSPrzemyslaw Czarnowski     }
771120fa86aSPrzemyslaw Czarnowski 
772120fa86aSPrzemyslaw Czarnowski     doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl,
773120fa86aSPrzemyslaw Czarnowski                     !(*actionParams.writeProtected),
774120fa86aSPrzemyslaw Czarnowski                     std::move(*actionParams.userName),
775120fa86aSPrzemyslaw Czarnowski                     std::move(*actionParams.password));
776120fa86aSPrzemyslaw Czarnowski }
777120fa86aSPrzemyslaw Czarnowski 
778120fa86aSPrzemyslaw Czarnowski /**
779e13c2760SPrzemyslaw Czarnowski  * @brief Function transceives data with dbus directly.
780e13c2760SPrzemyslaw Czarnowski  *
781e13c2760SPrzemyslaw Czarnowski  * All BMC state properties will be retrieved before sending reset request.
782e13c2760SPrzemyslaw Czarnowski  */
78324e740a7SEd Tanous inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
784e13c2760SPrzemyslaw Czarnowski                           const std::string& service, const std::string& name,
785e13c2760SPrzemyslaw Czarnowski                           bool legacy)
786e13c2760SPrzemyslaw Czarnowski {
787e13c2760SPrzemyslaw Czarnowski 
788e13c2760SPrzemyslaw Czarnowski     // Legacy mount requires parameter with image
789e13c2760SPrzemyslaw Czarnowski     if (legacy)
790e13c2760SPrzemyslaw Czarnowski     {
791e13c2760SPrzemyslaw Czarnowski         crow::connections::systemBus->async_method_call(
7925e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
793e13c2760SPrzemyslaw Czarnowski             if (ec)
794e13c2760SPrzemyslaw Czarnowski             {
795e13c2760SPrzemyslaw Czarnowski                 BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
796e13c2760SPrzemyslaw Czarnowski 
797e13c2760SPrzemyslaw Czarnowski                 messages::internalError(asyncResp->res);
798e13c2760SPrzemyslaw Czarnowski                 return;
799e13c2760SPrzemyslaw Czarnowski             }
800e13c2760SPrzemyslaw Czarnowski             },
801e13c2760SPrzemyslaw Czarnowski             service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
802e13c2760SPrzemyslaw Czarnowski             "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount");
803e13c2760SPrzemyslaw Czarnowski     }
804e13c2760SPrzemyslaw Czarnowski     else // proxy
805e13c2760SPrzemyslaw Czarnowski     {
806e13c2760SPrzemyslaw Czarnowski         crow::connections::systemBus->async_method_call(
8075e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec) {
808e13c2760SPrzemyslaw Czarnowski             if (ec)
809e13c2760SPrzemyslaw Czarnowski             {
810e13c2760SPrzemyslaw Czarnowski                 BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
811e13c2760SPrzemyslaw Czarnowski 
812e13c2760SPrzemyslaw Czarnowski                 messages::internalError(asyncResp->res);
813e13c2760SPrzemyslaw Czarnowski                 return;
814e13c2760SPrzemyslaw Czarnowski             }
815e13c2760SPrzemyslaw Czarnowski             },
816e13c2760SPrzemyslaw Czarnowski             service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name,
817e13c2760SPrzemyslaw Czarnowski             "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount");
818e13c2760SPrzemyslaw Czarnowski     }
819e13c2760SPrzemyslaw Czarnowski }
820e13c2760SPrzemyslaw Czarnowski 
82196825bebSEd Tanous inline void handleManagersVirtualMediaActionInsertPost(
82296825bebSEd Tanous     crow::App& app, const crow::Request& req,
82322db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
82496825bebSEd Tanous     const std::string& name, const std::string& resName)
82596825bebSEd Tanous {
8263ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
82745ca1b86SEd Tanous     {
82845ca1b86SEd Tanous         return;
82945ca1b86SEd Tanous     }
830*79fdf63eSPrzemyslaw Czarnowski 
831*79fdf63eSPrzemyslaw Czarnowski     constexpr std::string_view action = "VirtualMedia.InsertMedia";
83222db1728SEd Tanous     if (name != "bmc")
833107077deSPrzemyslaw Czarnowski     {
834*79fdf63eSPrzemyslaw Czarnowski         messages::resourceNotFound(asyncResp->res, action, resName);
835107077deSPrzemyslaw Czarnowski 
836107077deSPrzemyslaw Czarnowski         return;
837107077deSPrzemyslaw Czarnowski     }
838*79fdf63eSPrzemyslaw Czarnowski     InsertMediaActionParams actionParams;
83998be3e39SEd Tanous 
840120fa86aSPrzemyslaw Czarnowski     // Read obligatory parameters (url of image)
84115ed6780SWilly Tu     if (!json_util::readJsonAction(
842*79fdf63eSPrzemyslaw Czarnowski             req, asyncResp->res, "Image", actionParams.imageUrl,
843*79fdf63eSPrzemyslaw Czarnowski             "WriteProtected", actionParams.writeProtected, "UserName",
844*79fdf63eSPrzemyslaw Czarnowski             actionParams.userName, "Password", actionParams.password,
845*79fdf63eSPrzemyslaw Czarnowski             "Inserted", actionParams.inserted, "TransferMethod",
846*79fdf63eSPrzemyslaw Czarnowski             actionParams.transferMethod, "TransferProtocolType",
847*79fdf63eSPrzemyslaw Czarnowski             actionParams.transferProtocolType))
84898be3e39SEd Tanous     {
84998be3e39SEd Tanous         return;
85098be3e39SEd Tanous     }
851107077deSPrzemyslaw Czarnowski 
8522b73119cSGeorge Liu     dbus::utility::getDbusObject(
8532b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
854*79fdf63eSPrzemyslaw Czarnowski         [asyncResp, action, actionParams,
8552b73119cSGeorge Liu          resName](const boost::system::error_code& ec,
856002d39b4SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) mutable {
85722db1728SEd Tanous         if (ec)
85822db1728SEd Tanous         {
85996825bebSEd Tanous             BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
860*79fdf63eSPrzemyslaw Czarnowski             messages::resourceNotFound(asyncResp->res, action, resName);
861107077deSPrzemyslaw Czarnowski 
86222db1728SEd Tanous             return;
86322db1728SEd Tanous         }
864*79fdf63eSPrzemyslaw Czarnowski 
86522db1728SEd Tanous         std::string service = getObjectType.begin()->first;
86622db1728SEd Tanous         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
86722db1728SEd Tanous 
86822db1728SEd Tanous         crow::connections::systemBus->async_method_call(
869*79fdf63eSPrzemyslaw Czarnowski             [service, resName, action, actionParams,
8705e7e2dc5SEd Tanous              asyncResp](const boost::system::error_code& ec2,
871002d39b4SEd Tanous                         dbus::utility::ManagedObjectType& subtree) mutable {
8728a592810SEd Tanous             if (ec2)
87322db1728SEd Tanous             {
874*79fdf63eSPrzemyslaw Czarnowski                 // Not possible in proxy mode
875*79fdf63eSPrzemyslaw Czarnowski                 BMCWEB_LOG_DEBUG << "InsertMedia not "
876*79fdf63eSPrzemyslaw Czarnowski                                     "allowed in proxy mode";
877*79fdf63eSPrzemyslaw Czarnowski                 messages::resourceNotFound(asyncResp->res, action, resName);
87822db1728SEd Tanous 
87922db1728SEd Tanous                 return;
88022db1728SEd Tanous             }
88122db1728SEd Tanous             for (const auto& object : subtree)
88222db1728SEd Tanous             {
883365a73f4SEd Tanous                 VmMode mode = parseObjectPathAndGetMode(object.first, resName);
884365a73f4SEd Tanous                 if (mode == VmMode::Proxy)
88522db1728SEd Tanous                 {
886*79fdf63eSPrzemyslaw Czarnowski                     validateParams(asyncResp, service, resName, actionParams);
88722db1728SEd Tanous 
88822db1728SEd Tanous                     return;
88922db1728SEd Tanous                 }
89022db1728SEd Tanous             }
89122db1728SEd Tanous             BMCWEB_LOG_DEBUG << "Parent item not found";
89296825bebSEd Tanous             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
89322db1728SEd Tanous             },
89422db1728SEd Tanous             service, "/xyz/openbmc_project/VirtualMedia",
895002d39b4SEd Tanous             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
8962b73119cSGeorge Liu         });
89796825bebSEd Tanous }
89822db1728SEd Tanous 
89996825bebSEd Tanous inline void handleManagersVirtualMediaActionEject(
90096825bebSEd Tanous     crow::App& app, const crow::Request& req,
90122db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
90296825bebSEd Tanous     const std::string& managerName, const std::string& resName)
90396825bebSEd Tanous {
9043ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
90545ca1b86SEd Tanous     {
90645ca1b86SEd Tanous         return;
90745ca1b86SEd Tanous     }
908*79fdf63eSPrzemyslaw Czarnowski 
909*79fdf63eSPrzemyslaw Czarnowski     constexpr std::string_view action = "VirtualMedia.EjectMedia";
91096825bebSEd Tanous     if (managerName != "bmc")
911107077deSPrzemyslaw Czarnowski     {
912*79fdf63eSPrzemyslaw Czarnowski         messages::resourceNotFound(asyncResp->res, action, resName);
91322db1728SEd Tanous 
91422db1728SEd Tanous         return;
91522db1728SEd Tanous     }
91622db1728SEd Tanous 
9172b73119cSGeorge Liu     dbus::utility::getDbusObject(
9182b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
919*79fdf63eSPrzemyslaw Czarnowski         [asyncResp, action,
9202b73119cSGeorge Liu          resName](const boost::system::error_code& ec2,
921b9d36b47SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) {
9228a592810SEd Tanous         if (ec2)
92322db1728SEd Tanous         {
9248a592810SEd Tanous             BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec2;
92522db1728SEd Tanous             messages::internalError(asyncResp->res);
92622db1728SEd Tanous 
92722db1728SEd Tanous             return;
92822db1728SEd Tanous         }
92922db1728SEd Tanous         std::string service = getObjectType.begin()->first;
93022db1728SEd Tanous         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
93122db1728SEd Tanous 
93222db1728SEd Tanous         crow::connections::systemBus->async_method_call(
933*79fdf63eSPrzemyslaw Czarnowski             [resName, service, action,
934*79fdf63eSPrzemyslaw Czarnowski              asyncResp](const boost::system::error_code& ec,
93502cad96eSEd Tanous                         const dbus::utility::ManagedObjectType& subtree) {
93622db1728SEd Tanous             if (ec)
93722db1728SEd Tanous             {
938*79fdf63eSPrzemyslaw Czarnowski                 BMCWEB_LOG_ERROR << "ObjectMapper : No Service found";
939*79fdf63eSPrzemyslaw Czarnowski                 messages::resourceNotFound(asyncResp->res, action, resName);
94022db1728SEd Tanous                 return;
94122db1728SEd Tanous             }
94222db1728SEd Tanous 
94322db1728SEd Tanous             for (const auto& object : subtree)
94422db1728SEd Tanous             {
94522db1728SEd Tanous 
946365a73f4SEd Tanous                 VmMode mode = parseObjectPathAndGetMode(object.first, resName);
947365a73f4SEd Tanous                 if (mode != VmMode::Invalid)
94822db1728SEd Tanous                 {
949365a73f4SEd Tanous                     doEjectAction(asyncResp, service, resName,
950365a73f4SEd Tanous                                   mode == VmMode::Legacy);
95122db1728SEd Tanous                 }
95222db1728SEd Tanous             }
95322db1728SEd Tanous             BMCWEB_LOG_DEBUG << "Parent item not found";
95496825bebSEd Tanous             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
95522db1728SEd Tanous             },
95622db1728SEd Tanous             service, "/xyz/openbmc_project/VirtualMedia",
957002d39b4SEd Tanous             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
9582b73119cSGeorge Liu         });
95996825bebSEd Tanous }
96096825bebSEd Tanous 
96196825bebSEd Tanous inline void handleManagersVirtualMediaCollectionGet(
96296825bebSEd Tanous     crow::App& app, const crow::Request& req,
96322db1728SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
96496825bebSEd Tanous     const std::string& name)
96596825bebSEd Tanous {
9663ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
96745ca1b86SEd Tanous     {
96845ca1b86SEd Tanous         return;
96945ca1b86SEd Tanous     }
97022db1728SEd Tanous     if (name != "bmc")
97122db1728SEd Tanous     {
972002d39b4SEd Tanous         messages::resourceNotFound(asyncResp->res, "VirtualMedia", name);
973107077deSPrzemyslaw Czarnowski 
974107077deSPrzemyslaw Czarnowski         return;
975107077deSPrzemyslaw Czarnowski     }
976107077deSPrzemyslaw Czarnowski 
9778d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
978107077deSPrzemyslaw Czarnowski         "#VirtualMediaCollection.VirtualMediaCollection";
9798d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Virtual Media Services";
980fdb20347SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
981fdb20347SEd Tanous         "redfish", "v1", "Managers", name, "VirtualMedia");
982107077deSPrzemyslaw Czarnowski 
9832b73119cSGeorge Liu     dbus::utility::getDbusObject(
9842b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
9852b73119cSGeorge Liu         [asyncResp, name](const boost::system::error_code& ec,
986b9d36b47SEd Tanous                           const dbus::utility::MapperGetObject& getObjectType) {
987107077deSPrzemyslaw Czarnowski         if (ec)
988107077deSPrzemyslaw Czarnowski         {
98996825bebSEd Tanous             BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
990107077deSPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
991107077deSPrzemyslaw Czarnowski 
992107077deSPrzemyslaw Czarnowski             return;
993107077deSPrzemyslaw Czarnowski         }
994107077deSPrzemyslaw Czarnowski         std::string service = getObjectType.begin()->first;
995107077deSPrzemyslaw Czarnowski         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
996107077deSPrzemyslaw Czarnowski 
997107077deSPrzemyslaw Czarnowski         getVmResourceList(asyncResp, service, name);
9982b73119cSGeorge Liu         });
99996825bebSEd Tanous }
1000107077deSPrzemyslaw Czarnowski 
100196825bebSEd Tanous inline void
100296825bebSEd Tanous     handleVirtualMediaGet(crow::App& app, const crow::Request& req,
100322db1728SEd Tanous                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
100496825bebSEd Tanous                           const std::string& name, const std::string& resName)
100596825bebSEd Tanous {
10063ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
100745ca1b86SEd Tanous     {
100845ca1b86SEd Tanous         return;
100945ca1b86SEd Tanous     }
1010107077deSPrzemyslaw Czarnowski     if (name != "bmc")
1011107077deSPrzemyslaw Czarnowski     {
1012002d39b4SEd Tanous         messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
1013107077deSPrzemyslaw Czarnowski 
1014107077deSPrzemyslaw Czarnowski         return;
1015107077deSPrzemyslaw Czarnowski     }
1016107077deSPrzemyslaw Czarnowski 
10172b73119cSGeorge Liu     dbus::utility::getDbusObject(
10182b73119cSGeorge Liu         "/xyz/openbmc_project/VirtualMedia", {},
1019002d39b4SEd Tanous         [asyncResp, name,
10202b73119cSGeorge Liu          resName](const boost::system::error_code& ec,
1021b9d36b47SEd Tanous                   const dbus::utility::MapperGetObject& getObjectType) {
1022107077deSPrzemyslaw Czarnowski         if (ec)
1023107077deSPrzemyslaw Czarnowski         {
102496825bebSEd Tanous             BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
1025107077deSPrzemyslaw Czarnowski             messages::internalError(asyncResp->res);
1026107077deSPrzemyslaw Czarnowski 
1027107077deSPrzemyslaw Czarnowski             return;
1028107077deSPrzemyslaw Czarnowski         }
1029107077deSPrzemyslaw Czarnowski         std::string service = getObjectType.begin()->first;
1030107077deSPrzemyslaw Czarnowski         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
1031107077deSPrzemyslaw Czarnowski 
1032107077deSPrzemyslaw Czarnowski         getVmData(asyncResp, service, name, resName);
10332b73119cSGeorge Liu         });
103496825bebSEd Tanous }
103596825bebSEd Tanous 
103696825bebSEd Tanous inline void requestNBDVirtualMediaRoutes(App& app)
103796825bebSEd Tanous {
103896825bebSEd Tanous     BMCWEB_ROUTE(
103996825bebSEd Tanous         app,
104096825bebSEd Tanous         "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia")
104196825bebSEd Tanous         .privileges(redfish::privileges::postVirtualMedia)
104296825bebSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
104396825bebSEd Tanous             handleManagersVirtualMediaActionInsertPost, std::ref(app)));
104496825bebSEd Tanous 
104596825bebSEd Tanous     BMCWEB_ROUTE(
104696825bebSEd Tanous         app,
104796825bebSEd Tanous         "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
104896825bebSEd Tanous         .privileges(redfish::privileges::postVirtualMedia)
104996825bebSEd Tanous         .methods(boost::beast::http::verb::post)(std::bind_front(
105096825bebSEd Tanous             handleManagersVirtualMediaActionEject, std::ref(app)));
105196825bebSEd Tanous 
105296825bebSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/")
105396825bebSEd Tanous         .privileges(redfish::privileges::getVirtualMediaCollection)
105496825bebSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
105596825bebSEd Tanous             handleManagersVirtualMediaCollectionGet, std::ref(app)));
105696825bebSEd Tanous 
105796825bebSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/")
105896825bebSEd Tanous         .privileges(redfish::privileges::getVirtualMedia)
105996825bebSEd Tanous         .methods(boost::beast::http::verb::get)(
106096825bebSEd Tanous             std::bind_front(handleVirtualMediaGet, std::ref(app)));
1061107077deSPrzemyslaw Czarnowski }
1062107077deSPrzemyslaw Czarnowski 
1063107077deSPrzemyslaw Czarnowski } // namespace redfish
1064