blob: b95fcabc7699b832529cf73b6dd3c41bb7de82b3 [file] [log] [blame]
Alexander Hansencc372352025-01-14 14:15:39 +01001#include "software_manager.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4#include <sdbusplus/asio/object_server.hpp>
5#include <sdbusplus/async.hpp>
6#include <sdbusplus/async/context.hpp>
7#include <sdbusplus/bus.hpp>
8#include <xyz/openbmc_project/Association/Definitions/server.hpp>
9#include <xyz/openbmc_project/ObjectMapper/client.hpp>
10#include <xyz/openbmc_project/State/Host/client.hpp>
11
12#include <cstdint>
13
14PHOSPHOR_LOG2_USING;
15
16using namespace phosphor::software::manager;
17
18SoftwareManager::SoftwareManager(sdbusplus::async::context& ctx,
19 const std::string& serviceNameSuffix) :
20 ctx(ctx), serviceNameSuffix(serviceNameSuffix), manager(ctx, "/")
21{
22 debug("initialized SoftwareManager");
23}
24
25std::string SoftwareManager::setupBusName()
26{
27 const std::string serviceNameFull =
28 "xyz.openbmc_project.Software." + serviceNameSuffix;
29
30 debug("requesting dbus name {BUSNAME}", "BUSNAME", serviceNameFull);
31
32 ctx.get_bus().request_name(serviceNameFull.c_str());
33
34 return serviceNameFull;
35}
36
37// NOLINTBEGIN(readability-static-accessed-through-instance)
38sdbusplus::async::task<> SoftwareManager::initDevices(
39 const std::vector<std::string>& configurationInterfaces)
40// NOLINTEND(readability-static-accessed-through-instance)
41{
42 auto client = sdbusplus::client::xyz::openbmc_project::ObjectMapper<>(ctx)
43 .service("xyz.openbmc_project.ObjectMapper")
44 .path("/xyz/openbmc_project/object_mapper");
45
Alexander Hansen0a457ff2025-02-25 16:13:47 +010046 auto res = co_await client.get_sub_tree("/xyz/openbmc_project/inventory", 0,
47 configurationInterfaces);
Alexander Hansencc372352025-01-14 14:15:39 +010048
49 for (auto& iface : configurationInterfaces)
50 {
51 debug("[config] looking for dbus interface {INTF}", "INTF", iface);
52 }
53
54 for (auto& [path, v] : res)
55 {
56 for (auto& [service, interfaceNames] : v)
57 {
58 std::string interfaceFound;
59
60 for (std::string& interfaceName : interfaceNames)
61 {
62 for (auto& iface : configurationInterfaces)
63 {
64 if (interfaceName == iface)
65 {
66 interfaceFound = interfaceName;
67 }
68 }
69 }
70
71 if (interfaceFound.empty())
72 {
73 continue;
74 }
75
76 debug(
77 "[config] found configuration interface at {SERVICE}, {OBJPATH}",
78 "SERVICE", service, "OBJPATH", path);
79
80 auto client =
81 sdbusplus::async::proxy().service(service).path(path).interface(
82 "org.freedesktop.DBus.Properties");
83
84 uint64_t vendorIANA = 0;
85 std::string compatible{};
86 std::string emConfigType{};
87 std::string emConfigName{};
88
Alexander Hansen4983b132025-02-26 16:55:14 +010089 const std::string ifaceFwInfoDef = interfaceFound + ".FirmwareInfo";
90
Alexander Hansencc372352025-01-14 14:15:39 +010091 try
92 {
93 {
94 auto propVendorIANA =
95 co_await client.call<std::variant<uint64_t>>(
Alexander Hansen4983b132025-02-26 16:55:14 +010096 ctx, "Get", ifaceFwInfoDef, "VendorIANA");
Alexander Hansencc372352025-01-14 14:15:39 +010097
98 vendorIANA = std::get<uint64_t>(propVendorIANA);
99 }
100 {
101 auto propCompatible =
102 co_await client.call<std::variant<std::string>>(
Alexander Hansen4983b132025-02-26 16:55:14 +0100103 ctx, "Get", ifaceFwInfoDef, "CompatibleHardware");
Alexander Hansencc372352025-01-14 14:15:39 +0100104
105 compatible = std::get<std::string>(propCompatible);
106 }
107 {
108 auto propEMConfigType =
109 co_await client.call<std::variant<std::string>>(
110 ctx, "Get", interfaceFound, "Type");
111
112 emConfigType = std::get<std::string>(propEMConfigType);
113 }
114 {
115 auto propEMConfigName =
116 co_await client.call<std::variant<std::string>>(
117 ctx, "Get", interfaceFound, "Name");
118
119 emConfigName = std::get<std::string>(propEMConfigName);
120 }
121 }
122 catch (std::exception& e)
123 {
124 error(e.what());
125 continue;
126 }
127
128 SoftwareConfig config(path, vendorIANA, compatible, emConfigType,
129 emConfigName);
130
131 co_await initDevice(service, path, config);
132 }
133 }
134
135 debug("[config] done with initial configuration");
136
137 setupBusName();
138}