xref: /openbmc/bmcweb/features/redfish/lib/network_protocol.hpp (revision 287ece64bf9a8ee0c42f77cefce559054b488ae7)
170141561SBorawski.Lukasz /*
270141561SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation
370141561SBorawski.Lukasz //
470141561SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License");
570141561SBorawski.Lukasz // you may not use this file except in compliance with the License.
670141561SBorawski.Lukasz // You may obtain a copy of the License at
770141561SBorawski.Lukasz //
870141561SBorawski.Lukasz //      http://www.apache.org/licenses/LICENSE-2.0
970141561SBorawski.Lukasz //
1070141561SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software
1170141561SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS,
1270141561SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1370141561SBorawski.Lukasz // See the License for the specific language governing permissions and
1470141561SBorawski.Lukasz // limitations under the License.
1570141561SBorawski.Lukasz */
1670141561SBorawski.Lukasz #pragma once
1770141561SBorawski.Lukasz 
183a8a0088SKowalski, Kamil #include "error_messages.hpp"
1967a78d87STom Joseph #include "openbmc_dbus_rest.hpp"
20b4bec66bSAbhishek Patel #include "redfish_util.hpp"
2170141561SBorawski.Lukasz 
227e860f15SJohn Edward Broadbent #include <app.hpp>
23ed398213SEd Tanous #include <registries/privilege_registry.hpp>
2420e6ea5dSraviteja-b #include <utils/json_utils.hpp>
25*287ece64SGeorge Liu #include <utils/stl_utils.hpp>
261214b7e7SGunnar Mills 
271214b7e7SGunnar Mills #include <optional>
28abf2add6SEd Tanous #include <variant>
291abe55efSEd Tanous namespace redfish
301abe55efSEd Tanous {
3170141561SBorawski.Lukasz 
327e860f15SJohn Edward Broadbent void getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp);
337e860f15SJohn Edward Broadbent std::string getHostName();
347e860f15SJohn Edward Broadbent 
35b4bec66bSAbhishek Patel const static std::array<std::pair<std::string, std::string>, 3> protocolToDBus{
36b0972a63SEd Tanous     {{"SSH", "dropbear"}, {"HTTPS", "bmcweb"}, {"IPMI", "phosphor-ipmi-net"}}};
373a8a0088SKowalski, Kamil 
38d24bfc7aSJennifer Lee inline void
3981ce609eSEd Tanous     extractNTPServersAndDomainNamesData(const GetManagedObjects& dbusData,
40d24bfc7aSJennifer Lee                                         std::vector<std::string>& ntpData,
41d24bfc7aSJennifer Lee                                         std::vector<std::string>& dnData)
4220e6ea5dSraviteja-b {
4381ce609eSEd Tanous     for (const auto& obj : dbusData)
4420e6ea5dSraviteja-b     {
4520e6ea5dSraviteja-b         for (const auto& ifacePair : obj.second)
4620e6ea5dSraviteja-b         {
4720e6ea5dSraviteja-b             if (obj.first == "/xyz/openbmc_project/network/eth0")
4820e6ea5dSraviteja-b             {
4920e6ea5dSraviteja-b                 if (ifacePair.first ==
5020e6ea5dSraviteja-b                     "xyz.openbmc_project.Network.EthernetInterface")
5120e6ea5dSraviteja-b                 {
5220e6ea5dSraviteja-b                     for (const auto& propertyPair : ifacePair.second)
5320e6ea5dSraviteja-b                     {
5420e6ea5dSraviteja-b                         if (propertyPair.first == "NTPServers")
5520e6ea5dSraviteja-b                         {
5620e6ea5dSraviteja-b                             const std::vector<std::string>* ntpServers =
578d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
5820e6ea5dSraviteja-b                                     &propertyPair.second);
5920e6ea5dSraviteja-b                             if (ntpServers != nullptr)
6020e6ea5dSraviteja-b                             {
61f23b7296SEd Tanous                                 ntpData = *ntpServers;
6220e6ea5dSraviteja-b                             }
6320e6ea5dSraviteja-b                         }
64d24bfc7aSJennifer Lee                         else if (propertyPair.first == "DomainName")
65d24bfc7aSJennifer Lee                         {
66d24bfc7aSJennifer Lee                             const std::vector<std::string>* domainNames =
678d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
68d24bfc7aSJennifer Lee                                     &propertyPair.second);
69d24bfc7aSJennifer Lee                             if (domainNames != nullptr)
70d24bfc7aSJennifer Lee                             {
71f23b7296SEd Tanous                                 dnData = *domainNames;
72d24bfc7aSJennifer Lee                             }
73d24bfc7aSJennifer Lee                         }
7420e6ea5dSraviteja-b                     }
7520e6ea5dSraviteja-b                 }
7620e6ea5dSraviteja-b             }
7720e6ea5dSraviteja-b         }
7820e6ea5dSraviteja-b     }
7920e6ea5dSraviteja-b }
8020e6ea5dSraviteja-b 
8120e6ea5dSraviteja-b template <typename CallbackFunc>
8220e6ea5dSraviteja-b void getEthernetIfaceData(CallbackFunc&& callback)
8320e6ea5dSraviteja-b {
8420e6ea5dSraviteja-b     crow::connections::systemBus->async_method_call(
8520e6ea5dSraviteja-b         [callback{std::move(callback)}](
8681ce609eSEd Tanous             const boost::system::error_code errorCode,
8781ce609eSEd Tanous             const GetManagedObjects& dbusData) {
8820e6ea5dSraviteja-b             std::vector<std::string> ntpServers;
89d24bfc7aSJennifer Lee             std::vector<std::string> domainNames;
9020e6ea5dSraviteja-b 
9181ce609eSEd Tanous             if (errorCode)
9220e6ea5dSraviteja-b             {
93d24bfc7aSJennifer Lee                 callback(false, ntpServers, domainNames);
9420e6ea5dSraviteja-b                 return;
9520e6ea5dSraviteja-b             }
9620e6ea5dSraviteja-b 
9781ce609eSEd Tanous             extractNTPServersAndDomainNamesData(dbusData, ntpServers,
98d24bfc7aSJennifer Lee                                                 domainNames);
9920e6ea5dSraviteja-b 
100d24bfc7aSJennifer Lee             callback(true, ntpServers, domainNames);
10120e6ea5dSraviteja-b         },
10220e6ea5dSraviteja-b         "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
10320e6ea5dSraviteja-b         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
104271584abSEd Tanous }
10520e6ea5dSraviteja-b 
1064f48d5f6SEd Tanous inline void getNetworkData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
10772048780SAbhishek Patel                            const crow::Request& req)
1081abe55efSEd Tanous {
1090f74e643SEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
11061932318SXiaochao Ma         "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol";
1110f74e643SEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
1120f74e643SEd Tanous         "/redfish/v1/Managers/bmc/NetworkProtocol";
1130f74e643SEd Tanous     asyncResp->res.jsonValue["Id"] = "NetworkProtocol";
1140f74e643SEd Tanous     asyncResp->res.jsonValue["Name"] = "Manager Network Protocol";
1150f74e643SEd Tanous     asyncResp->res.jsonValue["Description"] = "Manager Network Service";
1160f74e643SEd Tanous     asyncResp->res.jsonValue["Status"]["Health"] = "OK";
1170f74e643SEd Tanous     asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK";
1180f74e643SEd Tanous     asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
1190f74e643SEd Tanous 
12061932318SXiaochao Ma     // HTTP is Mandatory attribute as per OCP Baseline Profile - v1.0.0,
121818ea7b8SJoshi-Mansi     // but from security perspective it is not recommended to use.
122818ea7b8SJoshi-Mansi     // Hence using protocolEnabled as false to make it OCP and security-wise
123818ea7b8SJoshi-Mansi     // compliant
124818ea7b8SJoshi-Mansi     asyncResp->res.jsonValue["HTTP"]["Port"] = 0;
125818ea7b8SJoshi-Mansi     asyncResp->res.jsonValue["HTTP"]["ProtocolEnabled"] = false;
126818ea7b8SJoshi-Mansi 
127d24bfc7aSJennifer Lee     std::string hostName = getHostName();
128d24bfc7aSJennifer Lee 
129d24bfc7aSJennifer Lee     asyncResp->res.jsonValue["HostName"] = hostName;
1303a8a0088SKowalski, Kamil 
13120e6ea5dSraviteja-b     getNTPProtocolEnabled(asyncResp);
13220e6ea5dSraviteja-b 
13320e6ea5dSraviteja-b     // TODO Get eth0 interface data, and call the below callback for JSON
13420e6ea5dSraviteja-b     // preparation
135271584abSEd Tanous     getEthernetIfaceData(
136271584abSEd Tanous         [hostName, asyncResp](const bool& success,
137d24bfc7aSJennifer Lee                               const std::vector<std::string>& ntpServers,
138d24bfc7aSJennifer Lee                               const std::vector<std::string>& domainNames) {
13920e6ea5dSraviteja-b             if (!success)
14020e6ea5dSraviteja-b             {
1417e860f15SJohn Edward Broadbent                 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
1427e860f15SJohn Edward Broadbent                                            "eth0");
14320e6ea5dSraviteja-b                 return;
14420e6ea5dSraviteja-b             }
14520e6ea5dSraviteja-b             asyncResp->res.jsonValue["NTP"]["NTPServers"] = ntpServers;
146d24bfc7aSJennifer Lee             if (hostName.empty() == false)
147d24bfc7aSJennifer Lee             {
148f23b7296SEd Tanous                 std::string fqdn = hostName;
149d24bfc7aSJennifer Lee                 if (domainNames.empty() == false)
150d24bfc7aSJennifer Lee                 {
151f23b7296SEd Tanous                     fqdn += ".";
152f23b7296SEd Tanous                     fqdn += domainNames[0];
153d24bfc7aSJennifer Lee                 }
1542c70f800SEd Tanous                 asyncResp->res.jsonValue["FQDN"] = std::move(fqdn);
155d24bfc7aSJennifer Lee             }
15620e6ea5dSraviteja-b         });
15720e6ea5dSraviteja-b 
15872048780SAbhishek Patel     Privileges effectiveUserPrivileges =
15972048780SAbhishek Patel         redfish::getUserPrivileges(req.userRole);
16072048780SAbhishek Patel 
16172048780SAbhishek Patel     // /redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates is
16272048780SAbhishek Patel     // something only ConfigureManager can access then only display when
16372048780SAbhishek Patel     // the user has permissions ConfigureManager
16472048780SAbhishek Patel     if (isOperationAllowedWithPrivileges({{"ConfigureManager"}},
16572048780SAbhishek Patel                                          effectiveUserPrivileges))
16672048780SAbhishek Patel     {
1675968caeeSMarri Devender Rao         asyncResp->res.jsonValue["HTTPS"]["Certificates"] = {
168b4bec66bSAbhishek Patel             {"@odata.id",
169b4bec66bSAbhishek Patel              "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"}};
17070141561SBorawski.Lukasz     }
17170141561SBorawski.Lukasz 
172b4bec66bSAbhishek Patel     for (const auto& protocol : protocolToDBus)
173ec4974ddSAppaRao Puli     {
174b4bec66bSAbhishek Patel         const std::string& protocolName = protocol.first;
175b4bec66bSAbhishek Patel         const std::string& serviceName = protocol.second;
176b4bec66bSAbhishek Patel         getPortStatusAndPath(
177b4bec66bSAbhishek Patel             serviceName,
178b4bec66bSAbhishek Patel             [asyncResp, protocolName](const boost::system::error_code ec,
179b4bec66bSAbhishek Patel                                       const std::string& socketPath,
180b4bec66bSAbhishek Patel                                       bool isProtocolEnabled) {
1814d875bd8SEd Tanous                 // If the service is not installed, that is not an error
1824d875bd8SEd Tanous                 if (ec == boost::system::errc::no_such_process)
1834d875bd8SEd Tanous                 {
1844d875bd8SEd Tanous                     asyncResp->res.jsonValue[protocolName]["Port"] =
1854d875bd8SEd Tanous                         nlohmann::detail::value_t::null;
1864d875bd8SEd Tanous                     asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] =
1874d875bd8SEd Tanous                         false;
1884d875bd8SEd Tanous                     return;
1894d875bd8SEd Tanous                 }
1901abe55efSEd Tanous                 if (ec)
1911abe55efSEd Tanous                 {
192a08b46ccSJason M. Bills                     messages::internalError(asyncResp->res);
193865fbb75SEd Tanous                     return;
1943a8a0088SKowalski, Kamil                 }
195b4bec66bSAbhishek Patel                 asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] =
196b4bec66bSAbhishek Patel                     isProtocolEnabled;
197b4bec66bSAbhishek Patel                 getPortNumber(
198b4bec66bSAbhishek Patel                     socketPath,
199b4bec66bSAbhishek Patel                     [asyncResp, protocolName](
200b4bec66bSAbhishek Patel                         const boost::system::error_code ec, int portNumber) {
201b4bec66bSAbhishek Patel                         if (ec)
2021abe55efSEd Tanous                         {
203b4bec66bSAbhishek Patel                             messages::internalError(asyncResp->res);
204865fbb75SEd Tanous                             return;
20570141561SBorawski.Lukasz                         }
206b4bec66bSAbhishek Patel                         asyncResp->res.jsonValue[protocolName]["Port"] =
207b4bec66bSAbhishek Patel                             portNumber;
208b4bec66bSAbhishek Patel                     });
209b4bec66bSAbhishek Patel             });
210865fbb75SEd Tanous     }
211b4bec66bSAbhishek Patel } // namespace redfish
212501be32bSraviteja-b 
2134f48d5f6SEd Tanous inline void handleNTPProtocolEnabled(
2147e860f15SJohn Edward Broadbent     const bool& ntpEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
21520e6ea5dSraviteja-b {
21620e6ea5dSraviteja-b     std::string timeSyncMethod;
21720e6ea5dSraviteja-b     if (ntpEnabled)
21820e6ea5dSraviteja-b     {
2197e860f15SJohn Edward Broadbent         timeSyncMethod = "xyz.openbmc_project.Time.Synchronization.Method.NTP";
22020e6ea5dSraviteja-b     }
22120e6ea5dSraviteja-b     else
22220e6ea5dSraviteja-b     {
22320e6ea5dSraviteja-b         timeSyncMethod =
22420e6ea5dSraviteja-b             "xyz.openbmc_project.Time.Synchronization.Method.Manual";
22520e6ea5dSraviteja-b     }
22620e6ea5dSraviteja-b 
22720e6ea5dSraviteja-b     crow::connections::systemBus->async_method_call(
22881ce609eSEd Tanous         [asyncResp](const boost::system::error_code errorCode) {
22981ce609eSEd Tanous             if (errorCode)
230cb13a392SEd Tanous             {
231cb13a392SEd Tanous                 messages::internalError(asyncResp->res);
232cb13a392SEd Tanous             }
233cb13a392SEd Tanous         },
2347e860f15SJohn Edward Broadbent         "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method",
23520e6ea5dSraviteja-b         "org.freedesktop.DBus.Properties", "Set",
23620e6ea5dSraviteja-b         "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod",
23720e6ea5dSraviteja-b         std::variant<std::string>{timeSyncMethod});
23820e6ea5dSraviteja-b }
23920e6ea5dSraviteja-b 
2404f48d5f6SEd Tanous inline void
241*287ece64SGeorge Liu     handleNTPServersPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
242*287ece64SGeorge Liu                           std::vector<std::string>& ntpServers)
24320e6ea5dSraviteja-b {
244*287ece64SGeorge Liu     auto iter = stl_utils::firstDuplicate(ntpServers.begin(), ntpServers.end());
245*287ece64SGeorge Liu     if (iter != ntpServers.end())
246*287ece64SGeorge Liu     {
247*287ece64SGeorge Liu         std::string pointer =
248*287ece64SGeorge Liu             "NTPServers/" +
249*287ece64SGeorge Liu             std::to_string(std::distance(ntpServers.begin(), iter));
250*287ece64SGeorge Liu         messages::propertyValueIncorrect(asyncResp->res, pointer, *iter);
251*287ece64SGeorge Liu         return;
252*287ece64SGeorge Liu     }
253*287ece64SGeorge Liu 
25420e6ea5dSraviteja-b     crow::connections::systemBus->async_method_call(
255cf05f9dcSJohnathan Mantey         [asyncResp](const boost::system::error_code ec) {
25620e6ea5dSraviteja-b             if (ec)
25720e6ea5dSraviteja-b             {
25820e6ea5dSraviteja-b                 messages::internalError(asyncResp->res);
25920e6ea5dSraviteja-b                 return;
26020e6ea5dSraviteja-b             }
26120e6ea5dSraviteja-b         },
26220e6ea5dSraviteja-b         "xyz.openbmc_project.Network", "/xyz/openbmc_project/network/eth0",
26320e6ea5dSraviteja-b         "org.freedesktop.DBus.Properties", "Set",
26420e6ea5dSraviteja-b         "xyz.openbmc_project.Network.EthernetInterface", "NTPServers",
26520e6ea5dSraviteja-b         std::variant<std::vector<std::string>>{ntpServers});
26620e6ea5dSraviteja-b }
26720e6ea5dSraviteja-b 
2684f48d5f6SEd Tanous inline void
2694f48d5f6SEd Tanous     handleProtocolEnabled(const bool protocolEnabled,
270e5a99777SAlbert Zhang                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
271e5a99777SAlbert Zhang                           const std::string_view netBasePath)
27267a78d87STom Joseph {
27367a78d87STom Joseph     crow::connections::systemBus->async_method_call(
274e5a99777SAlbert Zhang         [protocolEnabled, asyncResp,
275e5a99777SAlbert Zhang          netBasePath](const boost::system::error_code ec,
27667a78d87STom Joseph                       const crow::openbmc_mapper::GetSubTreeType& subtree) {
27767a78d87STom Joseph             if (ec)
27867a78d87STom Joseph             {
27967a78d87STom Joseph                 messages::internalError(asyncResp->res);
28067a78d87STom Joseph                 return;
28167a78d87STom Joseph             }
28267a78d87STom Joseph 
28367a78d87STom Joseph             for (const auto& entry : subtree)
28467a78d87STom Joseph             {
285e5a99777SAlbert Zhang                 if (boost::algorithm::starts_with(entry.first, netBasePath))
28667a78d87STom Joseph                 {
28767a78d87STom Joseph                     crow::connections::systemBus->async_method_call(
28823a21a1cSEd Tanous                         [asyncResp](const boost::system::error_code ec2) {
28923a21a1cSEd Tanous                             if (ec2)
29067a78d87STom Joseph                             {
29167a78d87STom Joseph                                 messages::internalError(asyncResp->res);
29267a78d87STom Joseph                                 return;
29367a78d87STom Joseph                             }
29467a78d87STom Joseph                         },
29567a78d87STom Joseph                         entry.second.begin()->first, entry.first,
29667a78d87STom Joseph                         "org.freedesktop.DBus.Properties", "Set",
29767a78d87STom Joseph                         "xyz.openbmc_project.Control.Service.Attributes",
298e5a99777SAlbert Zhang                         "Running", std::variant<bool>{protocolEnabled});
29967a78d87STom Joseph 
30067a78d87STom Joseph                     crow::connections::systemBus->async_method_call(
30123a21a1cSEd Tanous                         [asyncResp](const boost::system::error_code ec2) {
30223a21a1cSEd Tanous                             if (ec2)
30367a78d87STom Joseph                             {
30467a78d87STom Joseph                                 messages::internalError(asyncResp->res);
30567a78d87STom Joseph                                 return;
30667a78d87STom Joseph                             }
30767a78d87STom Joseph                         },
30867a78d87STom Joseph                         entry.second.begin()->first, entry.first,
30967a78d87STom Joseph                         "org.freedesktop.DBus.Properties", "Set",
31067a78d87STom Joseph                         "xyz.openbmc_project.Control.Service.Attributes",
311e5a99777SAlbert Zhang                         "Enabled", std::variant<bool>{protocolEnabled});
31267a78d87STom Joseph                 }
31367a78d87STom Joseph             }
31467a78d87STom Joseph         },
31567a78d87STom Joseph         "xyz.openbmc_project.ObjectMapper",
31667a78d87STom Joseph         "/xyz/openbmc_project/object_mapper",
31767a78d87STom Joseph         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
31867a78d87STom Joseph         "/xyz/openbmc_project/control/service", 0,
31967a78d87STom Joseph         std::array<const char*, 1>{
32067a78d87STom Joseph             "xyz.openbmc_project.Control.Service.Attributes"});
32167a78d87STom Joseph }
32267a78d87STom Joseph 
3234f48d5f6SEd Tanous inline std::string getHostName()
324501be32bSraviteja-b {
3257e860f15SJohn Edward Broadbent     std::string hostName;
3268d1b46d7Szhanghch05 
3277e860f15SJohn Edward Broadbent     std::array<char, HOST_NAME_MAX> hostNameCStr;
3287e860f15SJohn Edward Broadbent     if (gethostname(hostNameCStr.data(), hostNameCStr.size()) == 0)
3297e860f15SJohn Edward Broadbent     {
3307e860f15SJohn Edward Broadbent         hostName = hostNameCStr.data();
3317e860f15SJohn Edward Broadbent     }
3327e860f15SJohn Edward Broadbent     return hostName;
3337e860f15SJohn Edward Broadbent }
3347e860f15SJohn Edward Broadbent 
3354f48d5f6SEd Tanous inline void
3364f48d5f6SEd Tanous     getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3377e860f15SJohn Edward Broadbent {
3387e860f15SJohn Edward Broadbent     crow::connections::systemBus->async_method_call(
3397e860f15SJohn Edward Broadbent         [asyncResp](const boost::system::error_code errorCode,
3407e860f15SJohn Edward Broadbent                     const std::variant<std::string>& timeSyncMethod) {
3417e860f15SJohn Edward Broadbent             if (errorCode)
3427e860f15SJohn Edward Broadbent             {
3437e860f15SJohn Edward Broadbent                 return;
3447e860f15SJohn Edward Broadbent             }
3457e860f15SJohn Edward Broadbent 
3467e860f15SJohn Edward Broadbent             const std::string* s = std::get_if<std::string>(&timeSyncMethod);
3477e860f15SJohn Edward Broadbent 
3487e860f15SJohn Edward Broadbent             if (*s == "xyz.openbmc_project.Time.Synchronization.Method.NTP")
3497e860f15SJohn Edward Broadbent             {
3507e860f15SJohn Edward Broadbent                 asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = true;
3517e860f15SJohn Edward Broadbent             }
3527e860f15SJohn Edward Broadbent             else if (*s == "xyz.openbmc_project.Time.Synchronization."
3537e860f15SJohn Edward Broadbent                            "Method.Manual")
3547e860f15SJohn Edward Broadbent             {
3557e860f15SJohn Edward Broadbent                 asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = false;
3567e860f15SJohn Edward Broadbent             }
3577e860f15SJohn Edward Broadbent         },
3587e860f15SJohn Edward Broadbent         "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method",
3597e860f15SJohn Edward Broadbent         "org.freedesktop.DBus.Properties", "Get",
3607e860f15SJohn Edward Broadbent         "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod");
3617e860f15SJohn Edward Broadbent }
3627e860f15SJohn Edward Broadbent 
3637e860f15SJohn Edward Broadbent inline void requestRoutesNetworkProtocol(App& app)
3647e860f15SJohn Edward Broadbent {
3657e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/")
366ed398213SEd Tanous         .privileges(redfish::privileges::patchManagerNetworkProtocol)
3677e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
3687e860f15SJohn Edward Broadbent             [](const crow::Request& req,
3697e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
370501be32bSraviteja-b                 std::optional<std::string> newHostName;
371cf05f9dcSJohnathan Mantey                 std::optional<nlohmann::json> ntp;
37267a78d87STom Joseph                 std::optional<nlohmann::json> ipmi;
373e5a99777SAlbert Zhang                 std::optional<nlohmann::json> ssh;
374501be32bSraviteja-b 
3757e860f15SJohn Edward Broadbent                 if (!json_util::readJson(req, asyncResp->res, "NTP", ntp,
376e5a99777SAlbert Zhang                                          "HostName", newHostName, "IPMI", ipmi,
377e5a99777SAlbert Zhang                                          "SSH", ssh))
378501be32bSraviteja-b                 {
379501be32bSraviteja-b                     return;
380501be32bSraviteja-b                 }
381cf05f9dcSJohnathan Mantey 
3828d1b46d7Szhanghch05                 asyncResp->res.result(boost::beast::http::status::no_content);
383501be32bSraviteja-b                 if (newHostName)
384501be32bSraviteja-b                 {
3852db77d34SJohnathan Mantey                     messages::propertyNotWritable(asyncResp->res, "HostName");
38644fad2aaSEd Tanous                     return;
387cf05f9dcSJohnathan Mantey                 }
388cf05f9dcSJohnathan Mantey 
389cf05f9dcSJohnathan Mantey                 if (ntp)
390cf05f9dcSJohnathan Mantey                 {
391cf05f9dcSJohnathan Mantey                     std::optional<std::vector<std::string>> ntpServers;
392cf05f9dcSJohnathan Mantey                     std::optional<bool> ntpEnabled;
3938d1b46d7Szhanghch05                     if (!json_util::readJson(*ntp, asyncResp->res, "NTPServers",
3947e860f15SJohn Edward Broadbent                                              ntpServers, "ProtocolEnabled",
3957e860f15SJohn Edward Broadbent                                              ntpEnabled))
396cf05f9dcSJohnathan Mantey                     {
397501be32bSraviteja-b                         return;
398501be32bSraviteja-b                     }
399cf05f9dcSJohnathan Mantey 
40020e6ea5dSraviteja-b                     if (ntpEnabled)
40120e6ea5dSraviteja-b                     {
40220e6ea5dSraviteja-b                         handleNTPProtocolEnabled(*ntpEnabled, asyncResp);
40320e6ea5dSraviteja-b                     }
404cf05f9dcSJohnathan Mantey 
40520e6ea5dSraviteja-b                     if (ntpServers)
40620e6ea5dSraviteja-b                     {
407*287ece64SGeorge Liu                         stl_utils::removeDuplicate(*ntpServers);
408*287ece64SGeorge Liu                         handleNTPServersPatch(asyncResp, *ntpServers);
40920e6ea5dSraviteja-b                     }
410501be32bSraviteja-b                 }
41167a78d87STom Joseph 
41267a78d87STom Joseph                 if (ipmi)
41367a78d87STom Joseph                 {
41467a78d87STom Joseph                     std::optional<bool> ipmiProtocolEnabled;
4157e860f15SJohn Edward Broadbent                     if (!json_util::readJson(*ipmi, asyncResp->res,
4167e860f15SJohn Edward Broadbent                                              "ProtocolEnabled",
41767a78d87STom Joseph                                              ipmiProtocolEnabled))
41867a78d87STom Joseph                     {
41967a78d87STom Joseph                         return;
42067a78d87STom Joseph                     }
42167a78d87STom Joseph 
42267a78d87STom Joseph                     if (ipmiProtocolEnabled)
42367a78d87STom Joseph                     {
424e5a99777SAlbert Zhang                         handleProtocolEnabled(
425e5a99777SAlbert Zhang                             *ipmiProtocolEnabled, asyncResp,
426e5a99777SAlbert Zhang                             "/xyz/openbmc_project/control/service/"
427e5a99777SAlbert Zhang                             "phosphor_2dipmi_2dnet_40");
428e5a99777SAlbert Zhang                     }
429e5a99777SAlbert Zhang                 }
430e5a99777SAlbert Zhang 
431e5a99777SAlbert Zhang                 if (ssh)
432e5a99777SAlbert Zhang                 {
433e5a99777SAlbert Zhang                     std::optional<bool> sshProtocolEnabled;
434e5a99777SAlbert Zhang                     if (!json_util::readJson(*ssh, asyncResp->res,
435e5a99777SAlbert Zhang                                              "ProtocolEnabled",
436e5a99777SAlbert Zhang                                              sshProtocolEnabled))
437e5a99777SAlbert Zhang                     {
438e5a99777SAlbert Zhang                         return;
439e5a99777SAlbert Zhang                     }
440e5a99777SAlbert Zhang 
441e5a99777SAlbert Zhang                     if (sshProtocolEnabled)
442e5a99777SAlbert Zhang                     {
443e5a99777SAlbert Zhang                         handleProtocolEnabled(
444e5a99777SAlbert Zhang                             *sshProtocolEnabled, asyncResp,
445e5a99777SAlbert Zhang                             "/xyz/openbmc_project/control/service/dropbear");
44667a78d87STom Joseph                     }
44767a78d87STom Joseph                 }
4487e860f15SJohn Edward Broadbent             });
4497e860f15SJohn Edward Broadbent 
4507e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/")
451ed398213SEd Tanous         .privileges(redfish::privileges::getManagerNetworkProtocol)
4527e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
45372048780SAbhishek Patel             [](const crow::Request& req,
4547e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
45572048780SAbhishek Patel                 getNetworkData(asyncResp, req);
4567e860f15SJohn Edward Broadbent             });
457cf05f9dcSJohnathan Mantey }
45870141561SBorawski.Lukasz 
45970141561SBorawski.Lukasz } // namespace redfish
460