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> 23168e20c1SEd Tanous #include <dbus_utility.hpp> 24ed398213SEd Tanous #include <registries/privilege_registry.hpp> 25*1e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 2620e6ea5dSraviteja-b #include <utils/json_utils.hpp> 27287ece64SGeorge Liu #include <utils/stl_utils.hpp> 281214b7e7SGunnar Mills 291214b7e7SGunnar Mills #include <optional> 30abf2add6SEd Tanous #include <variant> 311abe55efSEd Tanous namespace redfish 321abe55efSEd Tanous { 3370141561SBorawski.Lukasz 347e860f15SJohn Edward Broadbent void getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp); 357e860f15SJohn Edward Broadbent std::string getHostName(); 367e860f15SJohn Edward Broadbent 37b4bec66bSAbhishek Patel const static std::array<std::pair<std::string, std::string>, 3> protocolToDBus{ 38b0972a63SEd Tanous {{"SSH", "dropbear"}, {"HTTPS", "bmcweb"}, {"IPMI", "phosphor-ipmi-net"}}}; 393a8a0088SKowalski, Kamil 40d24bfc7aSJennifer Lee inline void 4181ce609eSEd Tanous extractNTPServersAndDomainNamesData(const GetManagedObjects& dbusData, 42d24bfc7aSJennifer Lee std::vector<std::string>& ntpData, 43d24bfc7aSJennifer Lee std::vector<std::string>& dnData) 4420e6ea5dSraviteja-b { 4581ce609eSEd Tanous for (const auto& obj : dbusData) 4620e6ea5dSraviteja-b { 4720e6ea5dSraviteja-b for (const auto& ifacePair : obj.second) 4820e6ea5dSraviteja-b { 490a052baaSGeorge Liu if (ifacePair.first != 5020e6ea5dSraviteja-b "xyz.openbmc_project.Network.EthernetInterface") 5120e6ea5dSraviteja-b { 520a052baaSGeorge Liu continue; 530a052baaSGeorge Liu } 540a052baaSGeorge Liu 5520e6ea5dSraviteja-b for (const auto& propertyPair : ifacePair.second) 5620e6ea5dSraviteja-b { 5720e6ea5dSraviteja-b if (propertyPair.first == "NTPServers") 5820e6ea5dSraviteja-b { 5920e6ea5dSraviteja-b const std::vector<std::string>* ntpServers = 608d78b7a9SPatrick Williams std::get_if<std::vector<std::string>>( 6120e6ea5dSraviteja-b &propertyPair.second); 6220e6ea5dSraviteja-b if (ntpServers != nullptr) 6320e6ea5dSraviteja-b { 64f23b7296SEd Tanous ntpData = *ntpServers; 6520e6ea5dSraviteja-b } 6620e6ea5dSraviteja-b } 67d24bfc7aSJennifer Lee else if (propertyPair.first == "DomainName") 68d24bfc7aSJennifer Lee { 69d24bfc7aSJennifer Lee const std::vector<std::string>* domainNames = 708d78b7a9SPatrick Williams std::get_if<std::vector<std::string>>( 71d24bfc7aSJennifer Lee &propertyPair.second); 72d24bfc7aSJennifer Lee if (domainNames != nullptr) 73d24bfc7aSJennifer Lee { 74f23b7296SEd Tanous dnData = *domainNames; 75d24bfc7aSJennifer Lee } 76d24bfc7aSJennifer Lee } 7720e6ea5dSraviteja-b } 7820e6ea5dSraviteja-b } 7920e6ea5dSraviteja-b } 8020e6ea5dSraviteja-b } 8120e6ea5dSraviteja-b 8220e6ea5dSraviteja-b template <typename CallbackFunc> 8320e6ea5dSraviteja-b void getEthernetIfaceData(CallbackFunc&& callback) 8420e6ea5dSraviteja-b { 8520e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 8620e6ea5dSraviteja-b [callback{std::move(callback)}]( 8781ce609eSEd Tanous const boost::system::error_code errorCode, 8881ce609eSEd Tanous const GetManagedObjects& dbusData) { 8920e6ea5dSraviteja-b std::vector<std::string> ntpServers; 90d24bfc7aSJennifer Lee std::vector<std::string> domainNames; 9120e6ea5dSraviteja-b 9281ce609eSEd Tanous if (errorCode) 9320e6ea5dSraviteja-b { 94d24bfc7aSJennifer Lee callback(false, ntpServers, domainNames); 9520e6ea5dSraviteja-b return; 9620e6ea5dSraviteja-b } 9720e6ea5dSraviteja-b 9881ce609eSEd Tanous extractNTPServersAndDomainNamesData(dbusData, ntpServers, 99d24bfc7aSJennifer Lee domainNames); 10020e6ea5dSraviteja-b 101d24bfc7aSJennifer Lee callback(true, ntpServers, domainNames); 10220e6ea5dSraviteja-b }, 10320e6ea5dSraviteja-b "xyz.openbmc_project.Network", "/xyz/openbmc_project/network", 10420e6ea5dSraviteja-b "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 105271584abSEd Tanous } 10620e6ea5dSraviteja-b 1074f48d5f6SEd Tanous inline void getNetworkData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 10872048780SAbhishek Patel const crow::Request& req) 1091abe55efSEd Tanous { 1100f74e643SEd Tanous asyncResp->res.jsonValue["@odata.type"] = 11161932318SXiaochao Ma "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol"; 1120f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1130f74e643SEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 1140f74e643SEd Tanous asyncResp->res.jsonValue["Id"] = "NetworkProtocol"; 1150f74e643SEd Tanous asyncResp->res.jsonValue["Name"] = "Manager Network Protocol"; 1160f74e643SEd Tanous asyncResp->res.jsonValue["Description"] = "Manager Network Service"; 1170f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 1180f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK"; 1190f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 1200f74e643SEd Tanous 12161932318SXiaochao Ma // HTTP is Mandatory attribute as per OCP Baseline Profile - v1.0.0, 122818ea7b8SJoshi-Mansi // but from security perspective it is not recommended to use. 123818ea7b8SJoshi-Mansi // Hence using protocolEnabled as false to make it OCP and security-wise 124818ea7b8SJoshi-Mansi // compliant 125818ea7b8SJoshi-Mansi asyncResp->res.jsonValue["HTTP"]["Port"] = 0; 126818ea7b8SJoshi-Mansi asyncResp->res.jsonValue["HTTP"]["ProtocolEnabled"] = false; 127818ea7b8SJoshi-Mansi 128d24bfc7aSJennifer Lee std::string hostName = getHostName(); 129d24bfc7aSJennifer Lee 130d24bfc7aSJennifer Lee asyncResp->res.jsonValue["HostName"] = hostName; 1313a8a0088SKowalski, Kamil 13220e6ea5dSraviteja-b getNTPProtocolEnabled(asyncResp); 13320e6ea5dSraviteja-b 1340a052baaSGeorge Liu getEthernetIfaceData([hostName, asyncResp]( 1350a052baaSGeorge Liu const bool& success, 136d24bfc7aSJennifer Lee const std::vector<std::string>& ntpServers, 137d24bfc7aSJennifer Lee const std::vector<std::string>& domainNames) { 13820e6ea5dSraviteja-b if (!success) 13920e6ea5dSraviteja-b { 1400a052baaSGeorge Liu messages::resourceNotFound(asyncResp->res, "ManagerNetworkProtocol", 1410a052baaSGeorge Liu "NetworkProtocol"); 14220e6ea5dSraviteja-b return; 14320e6ea5dSraviteja-b } 14420e6ea5dSraviteja-b asyncResp->res.jsonValue["NTP"]["NTPServers"] = ntpServers; 145d24bfc7aSJennifer Lee if (hostName.empty() == false) 146d24bfc7aSJennifer Lee { 147f23b7296SEd Tanous std::string fqdn = hostName; 148d24bfc7aSJennifer Lee if (domainNames.empty() == false) 149d24bfc7aSJennifer Lee { 150f23b7296SEd Tanous fqdn += "."; 151f23b7296SEd Tanous fqdn += domainNames[0]; 152d24bfc7aSJennifer Lee } 1532c70f800SEd Tanous asyncResp->res.jsonValue["FQDN"] = std::move(fqdn); 154d24bfc7aSJennifer Lee } 15520e6ea5dSraviteja-b }); 15620e6ea5dSraviteja-b 15772048780SAbhishek Patel Privileges effectiveUserPrivileges = 15872048780SAbhishek Patel redfish::getUserPrivileges(req.userRole); 15972048780SAbhishek Patel 16072048780SAbhishek Patel // /redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates is 16172048780SAbhishek Patel // something only ConfigureManager can access then only display when 16272048780SAbhishek Patel // the user has permissions ConfigureManager 16372048780SAbhishek Patel if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, 16472048780SAbhishek Patel effectiveUserPrivileges)) 16572048780SAbhishek Patel { 1665968caeeSMarri Devender Rao asyncResp->res.jsonValue["HTTPS"]["Certificates"] = { 167b4bec66bSAbhishek Patel {"@odata.id", 168b4bec66bSAbhishek Patel "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"}}; 16970141561SBorawski.Lukasz } 17070141561SBorawski.Lukasz 171b4bec66bSAbhishek Patel for (const auto& protocol : protocolToDBus) 172ec4974ddSAppaRao Puli { 173b4bec66bSAbhishek Patel const std::string& protocolName = protocol.first; 174b4bec66bSAbhishek Patel const std::string& serviceName = protocol.second; 175b4bec66bSAbhishek Patel getPortStatusAndPath( 176b4bec66bSAbhishek Patel serviceName, 177b4bec66bSAbhishek Patel [asyncResp, protocolName](const boost::system::error_code ec, 178b4bec66bSAbhishek Patel const std::string& socketPath, 179b4bec66bSAbhishek Patel bool isProtocolEnabled) { 1804d875bd8SEd Tanous // If the service is not installed, that is not an error 1814d875bd8SEd Tanous if (ec == boost::system::errc::no_such_process) 1824d875bd8SEd Tanous { 1834d875bd8SEd Tanous asyncResp->res.jsonValue[protocolName]["Port"] = 1844d875bd8SEd Tanous nlohmann::detail::value_t::null; 1854d875bd8SEd Tanous asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] = 1864d875bd8SEd Tanous false; 1874d875bd8SEd Tanous return; 1884d875bd8SEd Tanous } 1891abe55efSEd Tanous if (ec) 1901abe55efSEd Tanous { 191a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 192865fbb75SEd Tanous return; 1933a8a0088SKowalski, Kamil } 194b4bec66bSAbhishek Patel asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] = 195b4bec66bSAbhishek Patel isProtocolEnabled; 196b4bec66bSAbhishek Patel getPortNumber( 197b4bec66bSAbhishek Patel socketPath, 198b4bec66bSAbhishek Patel [asyncResp, protocolName]( 199b4bec66bSAbhishek Patel const boost::system::error_code ec, int portNumber) { 200b4bec66bSAbhishek Patel if (ec) 2011abe55efSEd Tanous { 202b4bec66bSAbhishek Patel messages::internalError(asyncResp->res); 203865fbb75SEd Tanous return; 20470141561SBorawski.Lukasz } 205b4bec66bSAbhishek Patel asyncResp->res.jsonValue[protocolName]["Port"] = 206b4bec66bSAbhishek Patel portNumber; 207b4bec66bSAbhishek Patel }); 208b4bec66bSAbhishek Patel }); 209865fbb75SEd Tanous } 210b4bec66bSAbhishek Patel } // namespace redfish 211501be32bSraviteja-b 2124f48d5f6SEd Tanous inline void handleNTPProtocolEnabled( 2137e860f15SJohn Edward Broadbent const bool& ntpEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21420e6ea5dSraviteja-b { 21520e6ea5dSraviteja-b std::string timeSyncMethod; 21620e6ea5dSraviteja-b if (ntpEnabled) 21720e6ea5dSraviteja-b { 2187e860f15SJohn Edward Broadbent timeSyncMethod = "xyz.openbmc_project.Time.Synchronization.Method.NTP"; 21920e6ea5dSraviteja-b } 22020e6ea5dSraviteja-b else 22120e6ea5dSraviteja-b { 22220e6ea5dSraviteja-b timeSyncMethod = 22320e6ea5dSraviteja-b "xyz.openbmc_project.Time.Synchronization.Method.Manual"; 22420e6ea5dSraviteja-b } 22520e6ea5dSraviteja-b 22620e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 22781ce609eSEd Tanous [asyncResp](const boost::system::error_code errorCode) { 22881ce609eSEd Tanous if (errorCode) 229cb13a392SEd Tanous { 230cb13a392SEd Tanous messages::internalError(asyncResp->res); 231cb13a392SEd Tanous } 232cb13a392SEd Tanous }, 2337e860f15SJohn Edward Broadbent "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method", 23420e6ea5dSraviteja-b "org.freedesktop.DBus.Properties", "Set", 23520e6ea5dSraviteja-b "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", 236168e20c1SEd Tanous dbus::utility::DbusVariantType{timeSyncMethod}); 23720e6ea5dSraviteja-b } 23820e6ea5dSraviteja-b 2394f48d5f6SEd Tanous inline void 240287ece64SGeorge Liu handleNTPServersPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 241287ece64SGeorge Liu std::vector<std::string>& ntpServers) 24220e6ea5dSraviteja-b { 243287ece64SGeorge Liu auto iter = stl_utils::firstDuplicate(ntpServers.begin(), ntpServers.end()); 244287ece64SGeorge Liu if (iter != ntpServers.end()) 245287ece64SGeorge Liu { 246287ece64SGeorge Liu std::string pointer = 247287ece64SGeorge Liu "NTPServers/" + 248287ece64SGeorge Liu std::to_string(std::distance(ntpServers.begin(), iter)); 249287ece64SGeorge Liu messages::propertyValueIncorrect(asyncResp->res, pointer, *iter); 250287ece64SGeorge Liu return; 251287ece64SGeorge Liu } 252287ece64SGeorge Liu 25320e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 2540a052baaSGeorge Liu [asyncResp, 2550a052baaSGeorge Liu ntpServers](boost::system::error_code ec, 2560a052baaSGeorge Liu const crow::openbmc_mapper::GetSubTreeType& subtree) { 2570a052baaSGeorge Liu if (ec) 2580a052baaSGeorge Liu { 2590a052baaSGeorge Liu BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " 2600a052baaSGeorge Liu << ec.message(); 2610a052baaSGeorge Liu messages::internalError(asyncResp->res); 2620a052baaSGeorge Liu return; 2630a052baaSGeorge Liu } 2640a052baaSGeorge Liu 2650a052baaSGeorge Liu for (const auto& [objectPath, serviceMap] : subtree) 2660a052baaSGeorge Liu { 2670a052baaSGeorge Liu for (const auto& [service, interfaces] : serviceMap) 2680a052baaSGeorge Liu { 2690a052baaSGeorge Liu for (const auto& interface : interfaces) 2700a052baaSGeorge Liu { 2710a052baaSGeorge Liu if (interface != 2720a052baaSGeorge Liu "xyz.openbmc_project.Network.EthernetInterface") 2730a052baaSGeorge Liu { 2740a052baaSGeorge Liu continue; 2750a052baaSGeorge Liu } 2760a052baaSGeorge Liu 2770a052baaSGeorge Liu crow::connections::systemBus->async_method_call( 278cf05f9dcSJohnathan Mantey [asyncResp](const boost::system::error_code ec) { 27920e6ea5dSraviteja-b if (ec) 28020e6ea5dSraviteja-b { 28120e6ea5dSraviteja-b messages::internalError(asyncResp->res); 28220e6ea5dSraviteja-b return; 28320e6ea5dSraviteja-b } 28420e6ea5dSraviteja-b }, 2850a052baaSGeorge Liu service, objectPath, 2860a052baaSGeorge Liu "org.freedesktop.DBus.Properties", "Set", interface, 2870a052baaSGeorge Liu "NTPServers", 288168e20c1SEd Tanous dbus::utility::DbusVariantType{ntpServers}); 28920e6ea5dSraviteja-b } 2900a052baaSGeorge Liu } 2910a052baaSGeorge Liu } 2920a052baaSGeorge Liu }, 2930a052baaSGeorge Liu "xyz.openbmc_project.ObjectMapper", 2940a052baaSGeorge Liu "/xyz/openbmc_project/object_mapper", 2950a052baaSGeorge Liu "xyz.openbmc_project.ObjectMapper", "GetSubTree", 2960a052baaSGeorge Liu "/xyz/openbmc_project", 0, 2970a052baaSGeorge Liu std::array<const char*, 1>{ 2980a052baaSGeorge Liu "xyz.openbmc_project.Network.EthernetInterface"}); 2990a052baaSGeorge Liu } 30020e6ea5dSraviteja-b 3014f48d5f6SEd Tanous inline void 3024f48d5f6SEd Tanous handleProtocolEnabled(const bool protocolEnabled, 303e5a99777SAlbert Zhang const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 304e5a99777SAlbert Zhang const std::string_view netBasePath) 30567a78d87STom Joseph { 30667a78d87STom Joseph crow::connections::systemBus->async_method_call( 307e5a99777SAlbert Zhang [protocolEnabled, asyncResp, 308e5a99777SAlbert Zhang netBasePath](const boost::system::error_code ec, 30967a78d87STom Joseph const crow::openbmc_mapper::GetSubTreeType& subtree) { 31067a78d87STom Joseph if (ec) 31167a78d87STom Joseph { 31267a78d87STom Joseph messages::internalError(asyncResp->res); 31367a78d87STom Joseph return; 31467a78d87STom Joseph } 31567a78d87STom Joseph 31667a78d87STom Joseph for (const auto& entry : subtree) 31767a78d87STom Joseph { 318e5a99777SAlbert Zhang if (boost::algorithm::starts_with(entry.first, netBasePath)) 31967a78d87STom Joseph { 32067a78d87STom Joseph crow::connections::systemBus->async_method_call( 32123a21a1cSEd Tanous [asyncResp](const boost::system::error_code ec2) { 32223a21a1cSEd Tanous if (ec2) 32367a78d87STom Joseph { 32467a78d87STom Joseph messages::internalError(asyncResp->res); 32567a78d87STom Joseph return; 32667a78d87STom Joseph } 32767a78d87STom Joseph }, 32867a78d87STom Joseph entry.second.begin()->first, entry.first, 32967a78d87STom Joseph "org.freedesktop.DBus.Properties", "Set", 33067a78d87STom Joseph "xyz.openbmc_project.Control.Service.Attributes", 331168e20c1SEd Tanous "Running", 332168e20c1SEd Tanous dbus::utility::DbusVariantType{protocolEnabled}); 33367a78d87STom Joseph 33467a78d87STom Joseph crow::connections::systemBus->async_method_call( 33523a21a1cSEd Tanous [asyncResp](const boost::system::error_code ec2) { 33623a21a1cSEd Tanous if (ec2) 33767a78d87STom Joseph { 33867a78d87STom Joseph messages::internalError(asyncResp->res); 33967a78d87STom Joseph return; 34067a78d87STom Joseph } 34167a78d87STom Joseph }, 34267a78d87STom Joseph entry.second.begin()->first, entry.first, 34367a78d87STom Joseph "org.freedesktop.DBus.Properties", "Set", 34467a78d87STom Joseph "xyz.openbmc_project.Control.Service.Attributes", 345168e20c1SEd Tanous "Enabled", 346168e20c1SEd Tanous dbus::utility::DbusVariantType{protocolEnabled}); 34767a78d87STom Joseph } 34867a78d87STom Joseph } 34967a78d87STom Joseph }, 35067a78d87STom Joseph "xyz.openbmc_project.ObjectMapper", 35167a78d87STom Joseph "/xyz/openbmc_project/object_mapper", 35267a78d87STom Joseph "xyz.openbmc_project.ObjectMapper", "GetSubTree", 35367a78d87STom Joseph "/xyz/openbmc_project/control/service", 0, 35467a78d87STom Joseph std::array<const char*, 1>{ 35567a78d87STom Joseph "xyz.openbmc_project.Control.Service.Attributes"}); 35667a78d87STom Joseph } 35767a78d87STom Joseph 3584f48d5f6SEd Tanous inline std::string getHostName() 359501be32bSraviteja-b { 3607e860f15SJohn Edward Broadbent std::string hostName; 3618d1b46d7Szhanghch05 3627e860f15SJohn Edward Broadbent std::array<char, HOST_NAME_MAX> hostNameCStr; 3637e860f15SJohn Edward Broadbent if (gethostname(hostNameCStr.data(), hostNameCStr.size()) == 0) 3647e860f15SJohn Edward Broadbent { 3657e860f15SJohn Edward Broadbent hostName = hostNameCStr.data(); 3667e860f15SJohn Edward Broadbent } 3677e860f15SJohn Edward Broadbent return hostName; 3687e860f15SJohn Edward Broadbent } 3697e860f15SJohn Edward Broadbent 3704f48d5f6SEd Tanous inline void 3714f48d5f6SEd Tanous getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3727e860f15SJohn Edward Broadbent { 373*1e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 374*1e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 375*1e1e598dSJonathan Doman "/xyz/openbmc_project/time/sync_method", 376*1e1e598dSJonathan Doman "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", 3777e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code errorCode, 378*1e1e598dSJonathan Doman const std::string& timeSyncMethod) { 3797e860f15SJohn Edward Broadbent if (errorCode) 3807e860f15SJohn Edward Broadbent { 3817e860f15SJohn Edward Broadbent return; 3827e860f15SJohn Edward Broadbent } 3837e860f15SJohn Edward Broadbent 384*1e1e598dSJonathan Doman if (timeSyncMethod == 385*1e1e598dSJonathan Doman "xyz.openbmc_project.Time.Synchronization.Method.NTP") 3867e860f15SJohn Edward Broadbent { 3877e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = true; 3887e860f15SJohn Edward Broadbent } 389*1e1e598dSJonathan Doman else if (timeSyncMethod == 390*1e1e598dSJonathan Doman "xyz.openbmc_project.Time.Synchronization." 391*1e1e598dSJonathan Doman "Method.Manual") 3927e860f15SJohn Edward Broadbent { 3937e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = false; 3947e860f15SJohn Edward Broadbent } 395*1e1e598dSJonathan Doman }); 3967e860f15SJohn Edward Broadbent } 3977e860f15SJohn Edward Broadbent 3987e860f15SJohn Edward Broadbent inline void requestRoutesNetworkProtocol(App& app) 3997e860f15SJohn Edward Broadbent { 4007e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/") 401ed398213SEd Tanous .privileges(redfish::privileges::patchManagerNetworkProtocol) 4020fda0f12SGeorge Liu .methods( 4030fda0f12SGeorge Liu boost::beast::http::verb:: 4040fda0f12SGeorge Liu patch)([](const crow::Request& req, 4057e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 406501be32bSraviteja-b std::optional<std::string> newHostName; 407cf05f9dcSJohnathan Mantey std::optional<nlohmann::json> ntp; 40867a78d87STom Joseph std::optional<nlohmann::json> ipmi; 409e5a99777SAlbert Zhang std::optional<nlohmann::json> ssh; 410501be32bSraviteja-b 4117e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "NTP", ntp, 412e5a99777SAlbert Zhang "HostName", newHostName, "IPMI", ipmi, 413e5a99777SAlbert Zhang "SSH", ssh)) 414501be32bSraviteja-b { 415501be32bSraviteja-b return; 416501be32bSraviteja-b } 417cf05f9dcSJohnathan Mantey 4188d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 419501be32bSraviteja-b if (newHostName) 420501be32bSraviteja-b { 4212db77d34SJohnathan Mantey messages::propertyNotWritable(asyncResp->res, "HostName"); 42244fad2aaSEd Tanous return; 423cf05f9dcSJohnathan Mantey } 424cf05f9dcSJohnathan Mantey 425cf05f9dcSJohnathan Mantey if (ntp) 426cf05f9dcSJohnathan Mantey { 427cf05f9dcSJohnathan Mantey std::optional<std::vector<std::string>> ntpServers; 428cf05f9dcSJohnathan Mantey std::optional<bool> ntpEnabled; 4298d1b46d7Szhanghch05 if (!json_util::readJson(*ntp, asyncResp->res, "NTPServers", 4307e860f15SJohn Edward Broadbent ntpServers, "ProtocolEnabled", 4317e860f15SJohn Edward Broadbent ntpEnabled)) 432cf05f9dcSJohnathan Mantey { 433501be32bSraviteja-b return; 434501be32bSraviteja-b } 435cf05f9dcSJohnathan Mantey 43620e6ea5dSraviteja-b if (ntpEnabled) 43720e6ea5dSraviteja-b { 43820e6ea5dSraviteja-b handleNTPProtocolEnabled(*ntpEnabled, asyncResp); 43920e6ea5dSraviteja-b } 440cf05f9dcSJohnathan Mantey 44120e6ea5dSraviteja-b if (ntpServers) 44220e6ea5dSraviteja-b { 443287ece64SGeorge Liu stl_utils::removeDuplicate(*ntpServers); 444287ece64SGeorge Liu handleNTPServersPatch(asyncResp, *ntpServers); 44520e6ea5dSraviteja-b } 446501be32bSraviteja-b } 44767a78d87STom Joseph 44867a78d87STom Joseph if (ipmi) 44967a78d87STom Joseph { 45067a78d87STom Joseph std::optional<bool> ipmiProtocolEnabled; 4517e860f15SJohn Edward Broadbent if (!json_util::readJson(*ipmi, asyncResp->res, 4527e860f15SJohn Edward Broadbent "ProtocolEnabled", 45367a78d87STom Joseph ipmiProtocolEnabled)) 45467a78d87STom Joseph { 45567a78d87STom Joseph return; 45667a78d87STom Joseph } 45767a78d87STom Joseph 45867a78d87STom Joseph if (ipmiProtocolEnabled) 45967a78d87STom Joseph { 460e5a99777SAlbert Zhang handleProtocolEnabled( 461e5a99777SAlbert Zhang *ipmiProtocolEnabled, asyncResp, 4620fda0f12SGeorge Liu "/xyz/openbmc_project/control/service/phosphor_2dipmi_2dnet_40"); 463e5a99777SAlbert Zhang } 464e5a99777SAlbert Zhang } 465e5a99777SAlbert Zhang 466e5a99777SAlbert Zhang if (ssh) 467e5a99777SAlbert Zhang { 468e5a99777SAlbert Zhang std::optional<bool> sshProtocolEnabled; 469e5a99777SAlbert Zhang if (!json_util::readJson(*ssh, asyncResp->res, 4700fda0f12SGeorge Liu "ProtocolEnabled", sshProtocolEnabled)) 471e5a99777SAlbert Zhang { 472e5a99777SAlbert Zhang return; 473e5a99777SAlbert Zhang } 474e5a99777SAlbert Zhang 475e5a99777SAlbert Zhang if (sshProtocolEnabled) 476e5a99777SAlbert Zhang { 477e5a99777SAlbert Zhang handleProtocolEnabled( 478e5a99777SAlbert Zhang *sshProtocolEnabled, asyncResp, 479e5a99777SAlbert Zhang "/xyz/openbmc_project/control/service/dropbear"); 48067a78d87STom Joseph } 48167a78d87STom Joseph } 4827e860f15SJohn Edward Broadbent }); 4837e860f15SJohn Edward Broadbent 4847e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/") 485ed398213SEd Tanous .privileges(redfish::privileges::getManagerNetworkProtocol) 4867e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 48772048780SAbhishek Patel [](const crow::Request& req, 4887e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 48972048780SAbhishek Patel getNetworkData(asyncResp, req); 4907e860f15SJohn Edward Broadbent }); 491cf05f9dcSJohnathan Mantey } 49270141561SBorawski.Lukasz 49370141561SBorawski.Lukasz } // namespace redfish 494