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> 2445ca1b86SEd Tanous #include <query.hpp> 25ed398213SEd Tanous #include <registries/privilege_registry.hpp> 261e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 2720e6ea5dSraviteja-b #include <utils/json_utils.hpp> 28287ece64SGeorge Liu #include <utils/stl_utils.hpp> 291214b7e7SGunnar Mills 301214b7e7SGunnar Mills #include <optional> 31abf2add6SEd Tanous #include <variant> 325f4c798dSJiaqing Zhao 331abe55efSEd Tanous namespace redfish 341abe55efSEd Tanous { 3570141561SBorawski.Lukasz 367e860f15SJohn Edward Broadbent void getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp); 377e860f15SJohn Edward Broadbent std::string getHostName(); 387e860f15SJohn Edward Broadbent 39*69320d54SJiaqing Zhao static constexpr const char* sshServiceName = "dropbear"; 40*69320d54SJiaqing Zhao static constexpr const char* httpsServiceName = "bmcweb"; 41*69320d54SJiaqing Zhao static constexpr const char* ipmiServiceName = "phosphor-ipmi-net"; 42*69320d54SJiaqing Zhao static constexpr std::array<std::pair<const char*, const char*>, 3> 43*69320d54SJiaqing Zhao protocolToService = {{{"SSH", sshServiceName}, 44*69320d54SJiaqing Zhao {"HTTPS", httpsServiceName}, 45*69320d54SJiaqing Zhao {"IPMI", ipmiServiceName}}}; 463a8a0088SKowalski, Kamil 47711ac7a9SEd Tanous inline void extractNTPServersAndDomainNamesData( 48711ac7a9SEd Tanous const dbus::utility::ManagedObjectType& dbusData, 49711ac7a9SEd Tanous std::vector<std::string>& ntpData, std::vector<std::string>& dnData) 5020e6ea5dSraviteja-b { 5181ce609eSEd Tanous for (const auto& obj : dbusData) 5220e6ea5dSraviteja-b { 5320e6ea5dSraviteja-b for (const auto& ifacePair : obj.second) 5420e6ea5dSraviteja-b { 550a052baaSGeorge Liu if (ifacePair.first != 5620e6ea5dSraviteja-b "xyz.openbmc_project.Network.EthernetInterface") 5720e6ea5dSraviteja-b { 580a052baaSGeorge Liu continue; 590a052baaSGeorge Liu } 600a052baaSGeorge Liu 6120e6ea5dSraviteja-b for (const auto& propertyPair : ifacePair.second) 6220e6ea5dSraviteja-b { 6320e6ea5dSraviteja-b if (propertyPair.first == "NTPServers") 6420e6ea5dSraviteja-b { 6520e6ea5dSraviteja-b const std::vector<std::string>* ntpServers = 668d78b7a9SPatrick Williams std::get_if<std::vector<std::string>>( 6720e6ea5dSraviteja-b &propertyPair.second); 6820e6ea5dSraviteja-b if (ntpServers != nullptr) 6920e6ea5dSraviteja-b { 70f23b7296SEd Tanous ntpData = *ntpServers; 7120e6ea5dSraviteja-b } 7220e6ea5dSraviteja-b } 73d24bfc7aSJennifer Lee else if (propertyPair.first == "DomainName") 74d24bfc7aSJennifer Lee { 75d24bfc7aSJennifer Lee const std::vector<std::string>* domainNames = 768d78b7a9SPatrick Williams std::get_if<std::vector<std::string>>( 77d24bfc7aSJennifer Lee &propertyPair.second); 78d24bfc7aSJennifer Lee if (domainNames != nullptr) 79d24bfc7aSJennifer Lee { 80f23b7296SEd Tanous dnData = *domainNames; 81d24bfc7aSJennifer Lee } 82d24bfc7aSJennifer Lee } 8320e6ea5dSraviteja-b } 8420e6ea5dSraviteja-b } 8520e6ea5dSraviteja-b } 8620e6ea5dSraviteja-b } 8720e6ea5dSraviteja-b 8820e6ea5dSraviteja-b template <typename CallbackFunc> 8920e6ea5dSraviteja-b void getEthernetIfaceData(CallbackFunc&& callback) 9020e6ea5dSraviteja-b { 9120e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 92f94c4ecfSEd Tanous [callback{std::forward<CallbackFunc>(callback)}]( 9381ce609eSEd Tanous const boost::system::error_code errorCode, 94711ac7a9SEd Tanous const dbus::utility::ManagedObjectType& dbusData) { 9520e6ea5dSraviteja-b std::vector<std::string> ntpServers; 96d24bfc7aSJennifer Lee std::vector<std::string> domainNames; 9720e6ea5dSraviteja-b 9881ce609eSEd Tanous if (errorCode) 9920e6ea5dSraviteja-b { 100d24bfc7aSJennifer Lee callback(false, ntpServers, domainNames); 10120e6ea5dSraviteja-b return; 10220e6ea5dSraviteja-b } 10320e6ea5dSraviteja-b 104002d39b4SEd Tanous extractNTPServersAndDomainNamesData(dbusData, ntpServers, domainNames); 10520e6ea5dSraviteja-b 106d24bfc7aSJennifer Lee callback(true, ntpServers, domainNames); 10720e6ea5dSraviteja-b }, 10820e6ea5dSraviteja-b "xyz.openbmc_project.Network", "/xyz/openbmc_project/network", 10920e6ea5dSraviteja-b "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 110271584abSEd Tanous } 11120e6ea5dSraviteja-b 1124f48d5f6SEd Tanous inline void getNetworkData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 11372048780SAbhishek Patel const crow::Request& req) 1141abe55efSEd Tanous { 1150f74e643SEd Tanous asyncResp->res.jsonValue["@odata.type"] = 11661932318SXiaochao Ma "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol"; 1170f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1180f74e643SEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 1190f74e643SEd Tanous asyncResp->res.jsonValue["Id"] = "NetworkProtocol"; 1200f74e643SEd Tanous asyncResp->res.jsonValue["Name"] = "Manager Network Protocol"; 1210f74e643SEd Tanous asyncResp->res.jsonValue["Description"] = "Manager Network Service"; 1220f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 1230f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["HealthRollup"] = "OK"; 1240f74e643SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 1250f74e643SEd Tanous 12661932318SXiaochao Ma // HTTP is Mandatory attribute as per OCP Baseline Profile - v1.0.0, 127818ea7b8SJoshi-Mansi // but from security perspective it is not recommended to use. 128818ea7b8SJoshi-Mansi // Hence using protocolEnabled as false to make it OCP and security-wise 129818ea7b8SJoshi-Mansi // compliant 130818ea7b8SJoshi-Mansi asyncResp->res.jsonValue["HTTP"]["Port"] = 0; 131818ea7b8SJoshi-Mansi asyncResp->res.jsonValue["HTTP"]["ProtocolEnabled"] = false; 132818ea7b8SJoshi-Mansi 133d24bfc7aSJennifer Lee std::string hostName = getHostName(); 134d24bfc7aSJennifer Lee 135d24bfc7aSJennifer Lee asyncResp->res.jsonValue["HostName"] = hostName; 1363a8a0088SKowalski, Kamil 13720e6ea5dSraviteja-b getNTPProtocolEnabled(asyncResp); 13820e6ea5dSraviteja-b 139002d39b4SEd Tanous getEthernetIfaceData( 140002d39b4SEd Tanous [hostName, asyncResp](const bool& success, 141927c17cdSRadivoje Jovanovic std::vector<std::string>& ntpServers, 142d24bfc7aSJennifer Lee const std::vector<std::string>& domainNames) { 14320e6ea5dSraviteja-b if (!success) 14420e6ea5dSraviteja-b { 1450a052baaSGeorge Liu messages::resourceNotFound(asyncResp->res, "ManagerNetworkProtocol", 1460a052baaSGeorge Liu "NetworkProtocol"); 14720e6ea5dSraviteja-b return; 14820e6ea5dSraviteja-b } 149927c17cdSRadivoje Jovanovic stl_utils::removeDuplicate(ntpServers); 15020e6ea5dSraviteja-b asyncResp->res.jsonValue["NTP"]["NTPServers"] = ntpServers; 15126f6976fSEd Tanous if (!hostName.empty()) 152d24bfc7aSJennifer Lee { 153f23b7296SEd Tanous std::string fqdn = hostName; 15426f6976fSEd Tanous if (!domainNames.empty()) 155d24bfc7aSJennifer Lee { 156f23b7296SEd Tanous fqdn += "."; 157f23b7296SEd Tanous fqdn += domainNames[0]; 158d24bfc7aSJennifer Lee } 1592c70f800SEd Tanous asyncResp->res.jsonValue["FQDN"] = std::move(fqdn); 160d24bfc7aSJennifer Lee } 16120e6ea5dSraviteja-b }); 16220e6ea5dSraviteja-b 16372048780SAbhishek Patel Privileges effectiveUserPrivileges = 16472048780SAbhishek Patel redfish::getUserPrivileges(req.userRole); 16572048780SAbhishek Patel 16672048780SAbhishek Patel // /redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates is 16772048780SAbhishek Patel // something only ConfigureManager can access then only display when 16872048780SAbhishek Patel // the user has permissions ConfigureManager 16972048780SAbhishek Patel if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, 17072048780SAbhishek Patel effectiveUserPrivileges)) 17172048780SAbhishek Patel { 1721476687dSEd Tanous asyncResp->res.jsonValue["HTTPS"]["Certificates"]["@odata.id"] = 1731476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"; 17470141561SBorawski.Lukasz } 17570141561SBorawski.Lukasz 176*69320d54SJiaqing Zhao for (const auto& protocol : protocolToService) 177ec4974ddSAppaRao Puli { 178b4bec66bSAbhishek Patel const std::string& protocolName = protocol.first; 179b4bec66bSAbhishek Patel const std::string& serviceName = protocol.second; 180b4bec66bSAbhishek Patel getPortStatusAndPath( 181b4bec66bSAbhishek Patel serviceName, 182b4bec66bSAbhishek Patel [asyncResp, protocolName](const boost::system::error_code ec, 183b4bec66bSAbhishek Patel const std::string& socketPath, 184b4bec66bSAbhishek Patel bool isProtocolEnabled) { 1854d875bd8SEd Tanous // If the service is not installed, that is not an error 1864d875bd8SEd Tanous if (ec == boost::system::errc::no_such_process) 1874d875bd8SEd Tanous { 1884d875bd8SEd Tanous asyncResp->res.jsonValue[protocolName]["Port"] = 1894d875bd8SEd Tanous nlohmann::detail::value_t::null; 1904d875bd8SEd Tanous asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] = 1914d875bd8SEd Tanous false; 1924d875bd8SEd Tanous return; 1934d875bd8SEd Tanous } 1941abe55efSEd Tanous if (ec) 1951abe55efSEd Tanous { 196a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 197865fbb75SEd Tanous return; 1983a8a0088SKowalski, Kamil } 199b4bec66bSAbhishek Patel asyncResp->res.jsonValue[protocolName]["ProtocolEnabled"] = 200b4bec66bSAbhishek Patel isProtocolEnabled; 201002d39b4SEd Tanous getPortNumber(socketPath, [asyncResp, protocolName]( 2028a592810SEd Tanous const boost::system::error_code ec2, 203002d39b4SEd Tanous int portNumber) { 2048a592810SEd Tanous if (ec2) 2051abe55efSEd Tanous { 206b4bec66bSAbhishek Patel messages::internalError(asyncResp->res); 207865fbb75SEd Tanous return; 20870141561SBorawski.Lukasz } 209002d39b4SEd Tanous asyncResp->res.jsonValue[protocolName]["Port"] = portNumber; 210b4bec66bSAbhishek Patel }); 211b4bec66bSAbhishek Patel }); 212865fbb75SEd Tanous } 213b4bec66bSAbhishek Patel } // namespace redfish 214501be32bSraviteja-b 2154f48d5f6SEd Tanous inline void handleNTPProtocolEnabled( 2167e860f15SJohn Edward Broadbent const bool& ntpEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21720e6ea5dSraviteja-b { 21820e6ea5dSraviteja-b std::string timeSyncMethod; 21920e6ea5dSraviteja-b if (ntpEnabled) 22020e6ea5dSraviteja-b { 2217e860f15SJohn Edward Broadbent timeSyncMethod = "xyz.openbmc_project.Time.Synchronization.Method.NTP"; 22220e6ea5dSraviteja-b } 22320e6ea5dSraviteja-b else 22420e6ea5dSraviteja-b { 22520e6ea5dSraviteja-b timeSyncMethod = 22620e6ea5dSraviteja-b "xyz.openbmc_project.Time.Synchronization.Method.Manual"; 22720e6ea5dSraviteja-b } 22820e6ea5dSraviteja-b 22920e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 23081ce609eSEd Tanous [asyncResp](const boost::system::error_code errorCode) { 23181ce609eSEd Tanous if (errorCode) 232cb13a392SEd Tanous { 233cb13a392SEd Tanous messages::internalError(asyncResp->res); 234cb13a392SEd Tanous } 235cb13a392SEd Tanous }, 2367e860f15SJohn Edward Broadbent "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method", 23720e6ea5dSraviteja-b "org.freedesktop.DBus.Properties", "Set", 23820e6ea5dSraviteja-b "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", 239168e20c1SEd Tanous dbus::utility::DbusVariantType{timeSyncMethod}); 24020e6ea5dSraviteja-b } 24120e6ea5dSraviteja-b 2424f48d5f6SEd Tanous inline void 243287ece64SGeorge Liu handleNTPServersPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 244287ece64SGeorge Liu std::vector<std::string>& ntpServers) 24520e6ea5dSraviteja-b { 246287ece64SGeorge Liu auto iter = stl_utils::firstDuplicate(ntpServers.begin(), ntpServers.end()); 247287ece64SGeorge Liu if (iter != ntpServers.end()) 248287ece64SGeorge Liu { 249287ece64SGeorge Liu std::string pointer = 250287ece64SGeorge Liu "NTPServers/" + 251287ece64SGeorge Liu std::to_string(std::distance(ntpServers.begin(), iter)); 252287ece64SGeorge Liu messages::propertyValueIncorrect(asyncResp->res, pointer, *iter); 253287ece64SGeorge Liu return; 254287ece64SGeorge Liu } 255287ece64SGeorge Liu 25620e6ea5dSraviteja-b crow::connections::systemBus->async_method_call( 2570a052baaSGeorge Liu [asyncResp, 2580a052baaSGeorge Liu ntpServers](boost::system::error_code ec, 259b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 2600a052baaSGeorge Liu if (ec) 2610a052baaSGeorge Liu { 262002d39b4SEd Tanous BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " << ec.message(); 2630a052baaSGeorge Liu messages::internalError(asyncResp->res); 2640a052baaSGeorge Liu return; 2650a052baaSGeorge Liu } 2660a052baaSGeorge Liu 2670a052baaSGeorge Liu for (const auto& [objectPath, serviceMap] : subtree) 2680a052baaSGeorge Liu { 2690a052baaSGeorge Liu for (const auto& [service, interfaces] : serviceMap) 2700a052baaSGeorge Liu { 2710a052baaSGeorge Liu for (const auto& interface : interfaces) 2720a052baaSGeorge Liu { 2730a052baaSGeorge Liu if (interface != 2740a052baaSGeorge Liu "xyz.openbmc_project.Network.EthernetInterface") 2750a052baaSGeorge Liu { 2760a052baaSGeorge Liu continue; 2770a052baaSGeorge Liu } 2780a052baaSGeorge Liu 2790a052baaSGeorge Liu crow::connections::systemBus->async_method_call( 2808a592810SEd Tanous [asyncResp](const boost::system::error_code ec2) { 2818a592810SEd Tanous if (ec2) 28220e6ea5dSraviteja-b { 28320e6ea5dSraviteja-b messages::internalError(asyncResp->res); 28420e6ea5dSraviteja-b return; 28520e6ea5dSraviteja-b } 28620e6ea5dSraviteja-b }, 287002d39b4SEd Tanous service, objectPath, "org.freedesktop.DBus.Properties", 288002d39b4SEd Tanous "Set", interface, "NTPServers", 289168e20c1SEd Tanous dbus::utility::DbusVariantType{ntpServers}); 29020e6ea5dSraviteja-b } 2910a052baaSGeorge Liu } 2920a052baaSGeorge Liu } 2930a052baaSGeorge Liu }, 2940a052baaSGeorge Liu "xyz.openbmc_project.ObjectMapper", 2950a052baaSGeorge Liu "/xyz/openbmc_project/object_mapper", 2960a052baaSGeorge Liu "xyz.openbmc_project.ObjectMapper", "GetSubTree", 2970a052baaSGeorge Liu "/xyz/openbmc_project", 0, 2980a052baaSGeorge Liu std::array<const char*, 1>{ 2990a052baaSGeorge Liu "xyz.openbmc_project.Network.EthernetInterface"}); 3000a052baaSGeorge Liu } 30120e6ea5dSraviteja-b 3024f48d5f6SEd Tanous inline void 3034f48d5f6SEd Tanous handleProtocolEnabled(const bool protocolEnabled, 304e5a99777SAlbert Zhang const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 305*69320d54SJiaqing Zhao const std::string& netBasePath) 30667a78d87STom Joseph { 30767a78d87STom Joseph crow::connections::systemBus->async_method_call( 308e5a99777SAlbert Zhang [protocolEnabled, asyncResp, 309e5a99777SAlbert Zhang netBasePath](const boost::system::error_code ec, 310b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 31167a78d87STom Joseph if (ec) 31267a78d87STom Joseph { 31367a78d87STom Joseph messages::internalError(asyncResp->res); 31467a78d87STom Joseph return; 31567a78d87STom Joseph } 31667a78d87STom Joseph 31767a78d87STom Joseph for (const auto& entry : subtree) 31867a78d87STom Joseph { 319e5a99777SAlbert Zhang if (boost::algorithm::starts_with(entry.first, netBasePath)) 32067a78d87STom Joseph { 32167a78d87STom Joseph crow::connections::systemBus->async_method_call( 32223a21a1cSEd Tanous [asyncResp](const boost::system::error_code ec2) { 32323a21a1cSEd Tanous if (ec2) 32467a78d87STom Joseph { 32567a78d87STom Joseph messages::internalError(asyncResp->res); 32667a78d87STom Joseph return; 32767a78d87STom Joseph } 32867a78d87STom Joseph }, 32967a78d87STom Joseph entry.second.begin()->first, entry.first, 33067a78d87STom Joseph "org.freedesktop.DBus.Properties", "Set", 331002d39b4SEd Tanous "xyz.openbmc_project.Control.Service.Attributes", "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", 344002d39b4SEd Tanous "xyz.openbmc_project.Control.Service.Attributes", "Enabled", 345168e20c1SEd Tanous dbus::utility::DbusVariantType{protocolEnabled}); 34667a78d87STom Joseph } 34767a78d87STom Joseph } 34867a78d87STom Joseph }, 34967a78d87STom Joseph "xyz.openbmc_project.ObjectMapper", 35067a78d87STom Joseph "/xyz/openbmc_project/object_mapper", 35167a78d87STom Joseph "xyz.openbmc_project.ObjectMapper", "GetSubTree", 35267a78d87STom Joseph "/xyz/openbmc_project/control/service", 0, 35367a78d87STom Joseph std::array<const char*, 1>{ 35467a78d87STom Joseph "xyz.openbmc_project.Control.Service.Attributes"}); 35567a78d87STom Joseph } 35667a78d87STom Joseph 3574f48d5f6SEd Tanous inline std::string getHostName() 358501be32bSraviteja-b { 3597e860f15SJohn Edward Broadbent std::string hostName; 3608d1b46d7Szhanghch05 361d3a9e084SEd Tanous std::array<char, HOST_NAME_MAX> hostNameCStr{}; 3627e860f15SJohn Edward Broadbent if (gethostname(hostNameCStr.data(), hostNameCStr.size()) == 0) 3637e860f15SJohn Edward Broadbent { 3647e860f15SJohn Edward Broadbent hostName = hostNameCStr.data(); 3657e860f15SJohn Edward Broadbent } 3667e860f15SJohn Edward Broadbent return hostName; 3677e860f15SJohn Edward Broadbent } 3687e860f15SJohn Edward Broadbent 3694f48d5f6SEd Tanous inline void 3704f48d5f6SEd Tanous getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3717e860f15SJohn Edward Broadbent { 3721e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 3731e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.Settings", 3741e1e598dSJonathan Doman "/xyz/openbmc_project/time/sync_method", 3751e1e598dSJonathan Doman "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", 3767e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code errorCode, 3771e1e598dSJonathan Doman const std::string& timeSyncMethod) { 3787e860f15SJohn Edward Broadbent if (errorCode) 3797e860f15SJohn Edward Broadbent { 3807e860f15SJohn Edward Broadbent return; 3817e860f15SJohn Edward Broadbent } 3827e860f15SJohn Edward Broadbent 3831e1e598dSJonathan Doman if (timeSyncMethod == 3841e1e598dSJonathan Doman "xyz.openbmc_project.Time.Synchronization.Method.NTP") 3857e860f15SJohn Edward Broadbent { 3867e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = true; 3877e860f15SJohn Edward Broadbent } 388002d39b4SEd Tanous else if (timeSyncMethod == "xyz.openbmc_project.Time.Synchronization." 3891e1e598dSJonathan Doman "Method.Manual") 3907e860f15SJohn Edward Broadbent { 3917e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = false; 3927e860f15SJohn Edward Broadbent } 3931e1e598dSJonathan Doman }); 3947e860f15SJohn Edward Broadbent } 3957e860f15SJohn Edward Broadbent 396*69320d54SJiaqing Zhao inline std::string encodeServiceObjectPath(const std::string& serviceName) 397*69320d54SJiaqing Zhao { 398*69320d54SJiaqing Zhao sdbusplus::message::object_path objPath( 399*69320d54SJiaqing Zhao "/xyz/openbmc_project/control/service"); 400*69320d54SJiaqing Zhao objPath /= serviceName; 401*69320d54SJiaqing Zhao return objPath.str; 402*69320d54SJiaqing Zhao } 403*69320d54SJiaqing Zhao 4047e860f15SJohn Edward Broadbent inline void requestRoutesNetworkProtocol(App& app) 4057e860f15SJohn Edward Broadbent { 4067e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/") 407ed398213SEd Tanous .privileges(redfish::privileges::patchManagerNetworkProtocol) 408002d39b4SEd Tanous .methods(boost::beast::http::verb::patch)( 409002d39b4SEd Tanous [&app](const crow::Request& req, 410002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 4113ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 41245ca1b86SEd Tanous { 41345ca1b86SEd Tanous return; 41445ca1b86SEd Tanous } 415501be32bSraviteja-b std::optional<std::string> newHostName; 4165f4c798dSJiaqing Zhao std::optional<std::vector<std::string>> ntpServers; 4175f4c798dSJiaqing Zhao std::optional<bool> ntpEnabled; 4185f4c798dSJiaqing Zhao std::optional<bool> ipmiEnabled; 4195f4c798dSJiaqing Zhao std::optional<bool> sshEnabled; 420501be32bSraviteja-b 4215f4c798dSJiaqing Zhao // clang-format off 4225f4c798dSJiaqing Zhao if (!json_util::readJsonPatch( 4235f4c798dSJiaqing Zhao req, asyncResp->res, 4245f4c798dSJiaqing Zhao "HostName", newHostName, 4255f4c798dSJiaqing Zhao "NTP/NTPServers", ntpServers, 4265f4c798dSJiaqing Zhao "NTP/ProtocolEnabled", ntpEnabled, 4275f4c798dSJiaqing Zhao "IPMI/ProtocolEnabled", ipmiEnabled, 4285f4c798dSJiaqing Zhao "SSH/ProtocolEnabled", sshEnabled)) 429501be32bSraviteja-b { 430501be32bSraviteja-b return; 431501be32bSraviteja-b } 4325f4c798dSJiaqing Zhao // clang-format on 433cf05f9dcSJohnathan Mantey 4348d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 435501be32bSraviteja-b if (newHostName) 436501be32bSraviteja-b { 4372db77d34SJohnathan Mantey messages::propertyNotWritable(asyncResp->res, "HostName"); 43844fad2aaSEd Tanous return; 439cf05f9dcSJohnathan Mantey } 440cf05f9dcSJohnathan Mantey 44120e6ea5dSraviteja-b if (ntpEnabled) 44220e6ea5dSraviteja-b { 44320e6ea5dSraviteja-b handleNTPProtocolEnabled(*ntpEnabled, asyncResp); 44420e6ea5dSraviteja-b } 44520e6ea5dSraviteja-b if (ntpServers) 44620e6ea5dSraviteja-b { 447287ece64SGeorge Liu stl_utils::removeDuplicate(*ntpServers); 448287ece64SGeorge Liu handleNTPServersPatch(asyncResp, *ntpServers); 44920e6ea5dSraviteja-b } 45067a78d87STom Joseph 4515f4c798dSJiaqing Zhao if (ipmiEnabled) 45267a78d87STom Joseph { 453e5a99777SAlbert Zhang handleProtocolEnabled( 4545f4c798dSJiaqing Zhao *ipmiEnabled, asyncResp, 455*69320d54SJiaqing Zhao encodeServiceObjectPath(std::string(ipmiServiceName) + '@')); 456e5a99777SAlbert Zhang } 457e5a99777SAlbert Zhang 4585f4c798dSJiaqing Zhao if (sshEnabled) 459e5a99777SAlbert Zhang { 460*69320d54SJiaqing Zhao handleProtocolEnabled(*sshEnabled, asyncResp, 461*69320d54SJiaqing Zhao encodeServiceObjectPath(sshServiceName)); 46267a78d87STom Joseph } 4637e860f15SJohn Edward Broadbent }); 4647e860f15SJohn Edward Broadbent 4657e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/") 466ed398213SEd Tanous .privileges(redfish::privileges::getManagerNetworkProtocol) 4677e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 46845ca1b86SEd Tanous [&app](const crow::Request& req, 4697e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 4703ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 47145ca1b86SEd Tanous { 47245ca1b86SEd Tanous return; 47345ca1b86SEd Tanous } 47472048780SAbhishek Patel getNetworkData(asyncResp, req); 4757e860f15SJohn Edward Broadbent }); 476cf05f9dcSJohnathan Mantey } 47770141561SBorawski.Lukasz 47870141561SBorawski.Lukasz } // namespace redfish 479