xref: /openbmc/google-ipmi-sys/handler.cpp (revision 8cfa4c44)
1f085d91dSPatrick Venture /*
2f085d91dSPatrick Venture  * Copyright 2019 Google Inc.
3f085d91dSPatrick Venture  *
4f085d91dSPatrick Venture  * Licensed under the Apache License, Version 2.0 (the "License");
5f085d91dSPatrick Venture  * you may not use this file except in compliance with the License.
6f085d91dSPatrick Venture  * You may obtain a copy of the License at
7f085d91dSPatrick Venture  *
8f085d91dSPatrick Venture  *     http://www.apache.org/licenses/LICENSE-2.0
9f085d91dSPatrick Venture  *
10f085d91dSPatrick Venture  * Unless required by applicable law or agreed to in writing, software
11f085d91dSPatrick Venture  * distributed under the License is distributed on an "AS IS" BASIS,
12f085d91dSPatrick Venture  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f085d91dSPatrick Venture  * See the License for the specific language governing permissions and
14f085d91dSPatrick Venture  * limitations under the License.
15f085d91dSPatrick Venture  */
16f085d91dSPatrick Venture 
17f085d91dSPatrick Venture #include "handler.hpp"
18f085d91dSPatrick Venture 
19d2037c6aSPatrick Venture #include "errors.hpp"
20c87de558SPatrick Venture #include "handler_impl.hpp"
21ab650004SPatrick Venture #include "util.hpp"
22d2037c6aSPatrick Venture 
233b1b427cSWilly Tu #include <fcntl.h>
24d2037c6aSPatrick Venture #include <ipmid/api.h>
253b1b427cSWilly Tu #include <mtd/mtd-abi.h>
263b1b427cSWilly Tu #include <mtd/mtd-user.h>
273b1b427cSWilly Tu #include <sys/ioctl.h>
283b1b427cSWilly Tu #include <unistd.h>
29d2037c6aSPatrick Venture 
30bb90d4fdSPatrick Venture #include <cinttypes>
31d2037c6aSPatrick Venture #include <cstdio>
32d2037c6aSPatrick Venture #include <filesystem>
33d2037c6aSPatrick Venture #include <fstream>
3407f85150SPatrick Venture #include <map>
3507f85150SPatrick Venture #include <nlohmann/json.hpp>
3607f85150SPatrick Venture #include <phosphor-logging/elog-errors.hpp>
37aa374120SPatrick Venture #include <phosphor-logging/log.hpp>
38aa374120SPatrick Venture #include <sdbusplus/bus.hpp>
39d2037c6aSPatrick Venture #include <sstream>
40d2037c6aSPatrick Venture #include <string>
4129f35bceSWilliam A. Kennington III #include <string_view>
42d2037c6aSPatrick Venture #include <tuple>
4307f85150SPatrick Venture #include <xyz/openbmc_project/Common/error.hpp>
44d2037c6aSPatrick Venture 
45f085d91dSPatrick Venture // The phosphor-host-ipmi daemon requires a configuration that maps
46f085d91dSPatrick Venture // the if_name to the IPMI LAN channel.  However, that doesn't strictly
47f085d91dSPatrick Venture // define which is meant to be used for NCSI.
48f085d91dSPatrick Venture #ifndef NCSI_IPMI_CHANNEL
49f085d91dSPatrick Venture #define NCSI_IPMI_CHANNEL 1
50f085d91dSPatrick Venture #endif
51f085d91dSPatrick Venture 
52f085d91dSPatrick Venture #ifndef NCSI_IF_NAME
53f085d91dSPatrick Venture #define NCSI_IF_NAME eth0
54f085d91dSPatrick Venture #endif
55f085d91dSPatrick Venture 
56f085d91dSPatrick Venture // To deal with receiving a string without quotes.
57f085d91dSPatrick Venture #define QUOTE(name) #name
58f085d91dSPatrick Venture #define STR(macro) QUOTE(macro)
59f085d91dSPatrick Venture #define NCSI_IF_NAME_STR STR(NCSI_IF_NAME)
60f085d91dSPatrick Venture 
61f085d91dSPatrick Venture namespace google
62f085d91dSPatrick Venture {
63f085d91dSPatrick Venture namespace ipmi
64f085d91dSPatrick Venture {
65d2037c6aSPatrick Venture namespace fs = std::filesystem;
6607f85150SPatrick Venture using Json = nlohmann::json;
6707f85150SPatrick Venture using namespace phosphor::logging;
6807f85150SPatrick Venture using InternalFailure =
6907f85150SPatrick Venture     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
70f085d91dSPatrick Venture 
71f085d91dSPatrick Venture std::tuple<std::uint8_t, std::string> Handler::getEthDetails() const
72f085d91dSPatrick Venture {
73f085d91dSPatrick Venture     return std::make_tuple(NCSI_IPMI_CHANNEL, NCSI_IF_NAME_STR);
74f085d91dSPatrick Venture }
75f085d91dSPatrick Venture 
76d2037c6aSPatrick Venture std::int64_t Handler::getRxPackets(const std::string& name) const
77d2037c6aSPatrick Venture {
78d2037c6aSPatrick Venture     std::ostringstream opath;
79d2037c6aSPatrick Venture     opath << "/sys/class/net/" << name << "/statistics/rx_packets";
80d2037c6aSPatrick Venture     std::string path = opath.str();
81d2037c6aSPatrick Venture 
82d2037c6aSPatrick Venture     // Minor sanity & security check (of course, I'm less certain if unicode
83d2037c6aSPatrick Venture     // comes into play here.
84d2037c6aSPatrick Venture     //
85d2037c6aSPatrick Venture     // Basically you can't easily inject ../ or /../ into the path below.
86d2037c6aSPatrick Venture     if (name.find("/") != std::string::npos)
87d2037c6aSPatrick Venture     {
88d2037c6aSPatrick Venture         std::fprintf(stderr, "Invalid or illegal name: '%s'\n", name.c_str());
89d2037c6aSPatrick Venture         throw IpmiException(IPMI_CC_INVALID_FIELD_REQUEST);
90d2037c6aSPatrick Venture     }
91d2037c6aSPatrick Venture 
92d2037c6aSPatrick Venture     std::error_code ec;
93d2037c6aSPatrick Venture     if (!fs::exists(path, ec))
94d2037c6aSPatrick Venture     {
95d2037c6aSPatrick Venture         std::fprintf(stderr, "Path: '%s' doesn't exist.\n", path.c_str());
96d2037c6aSPatrick Venture         throw IpmiException(IPMI_CC_INVALID_FIELD_REQUEST);
97d2037c6aSPatrick Venture     }
98d2037c6aSPatrick Venture     // We're uninterested in the state of ec.
99d2037c6aSPatrick Venture 
100d2037c6aSPatrick Venture     int64_t count = 0;
101d2037c6aSPatrick Venture     std::ifstream ifs;
102d2037c6aSPatrick Venture     ifs.exceptions(std::ifstream::failbit);
103d2037c6aSPatrick Venture     try
104d2037c6aSPatrick Venture     {
105d2037c6aSPatrick Venture         ifs.open(path);
106d2037c6aSPatrick Venture         ifs >> count;
107d2037c6aSPatrick Venture     }
108d2037c6aSPatrick Venture     catch (std::ios_base::failure& fail)
109d2037c6aSPatrick Venture     {
110d2037c6aSPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
111d2037c6aSPatrick Venture     }
112d2037c6aSPatrick Venture 
113d2037c6aSPatrick Venture     return count;
114d2037c6aSPatrick Venture }
115d2037c6aSPatrick Venture 
116bb90d4fdSPatrick Venture VersionTuple Handler::getCpldVersion(unsigned int id) const
117bb90d4fdSPatrick Venture {
118bb90d4fdSPatrick Venture     std::ostringstream opath;
119bb90d4fdSPatrick Venture     opath << "/run/cpld" << id << ".version";
120bb90d4fdSPatrick Venture     // Check for file
121bb90d4fdSPatrick Venture 
122bb90d4fdSPatrick Venture     std::error_code ec;
123bb90d4fdSPatrick Venture     if (!fs::exists(opath.str(), ec))
124bb90d4fdSPatrick Venture     {
125bb90d4fdSPatrick Venture         std::fprintf(stderr, "Path: '%s' doesn't exist.\n",
126bb90d4fdSPatrick Venture                      opath.str().c_str());
127bb90d4fdSPatrick Venture         throw IpmiException(IPMI_CC_INVALID_FIELD_REQUEST);
128bb90d4fdSPatrick Venture     }
129bb90d4fdSPatrick Venture     // We're uninterested in the state of ec.
130bb90d4fdSPatrick Venture 
131bb90d4fdSPatrick Venture     // If file exists, read.
132bb90d4fdSPatrick Venture     std::ifstream ifs;
133bb90d4fdSPatrick Venture     ifs.exceptions(std::ifstream::failbit);
134bb90d4fdSPatrick Venture     std::string value;
135bb90d4fdSPatrick Venture     try
136bb90d4fdSPatrick Venture     {
137bb90d4fdSPatrick Venture         ifs.open(opath.str());
138bb90d4fdSPatrick Venture         ifs >> value;
139bb90d4fdSPatrick Venture     }
140bb90d4fdSPatrick Venture     catch (std::ios_base::failure& fail)
141bb90d4fdSPatrick Venture     {
142bb90d4fdSPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
143bb90d4fdSPatrick Venture     }
144bb90d4fdSPatrick Venture 
145bb90d4fdSPatrick Venture     // If value parses as expected, return version.
146bb90d4fdSPatrick Venture     VersionTuple version = std::make_tuple(0, 0, 0, 0);
147bb90d4fdSPatrick Venture 
148bb90d4fdSPatrick Venture     int num_fields =
149bb90d4fdSPatrick Venture         std::sscanf(value.c_str(), "%" SCNu8 ".%" SCNu8 ".%" SCNu8 ".%" SCNu8,
150bb90d4fdSPatrick Venture                     &std::get<0>(version), &std::get<1>(version),
151bb90d4fdSPatrick Venture                     &std::get<2>(version), &std::get<3>(version));
152bb90d4fdSPatrick Venture     if (num_fields == 0)
153bb90d4fdSPatrick Venture     {
154bb90d4fdSPatrick Venture         std::fprintf(stderr, "Invalid version.\n");
155bb90d4fdSPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
156bb90d4fdSPatrick Venture     }
157bb90d4fdSPatrick Venture 
158bb90d4fdSPatrick Venture     return version;
159bb90d4fdSPatrick Venture }
160bb90d4fdSPatrick Venture 
161aa374120SPatrick Venture static constexpr auto TIME_DELAY_FILENAME = "/run/psu_timedelay";
162aa374120SPatrick Venture static constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
163aa374120SPatrick Venture static constexpr auto SYSTEMD_ROOT = "/org/freedesktop/systemd1";
164aa374120SPatrick Venture static constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
165aa374120SPatrick Venture static constexpr auto PSU_HARDRESET_TARGET = "gbmc-psu-hardreset.target";
166aa374120SPatrick Venture 
167aa374120SPatrick Venture void Handler::psuResetDelay(std::uint32_t delay) const
168aa374120SPatrick Venture {
169aa374120SPatrick Venture     std::ofstream ofs;
170aa374120SPatrick Venture     ofs.open(TIME_DELAY_FILENAME, std::ofstream::out);
171aa374120SPatrick Venture     if (!ofs.good())
172aa374120SPatrick Venture     {
173aa374120SPatrick Venture         std::fprintf(stderr, "Unable to open file for output.\n");
174aa374120SPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
175aa374120SPatrick Venture     }
176aa374120SPatrick Venture 
177aa374120SPatrick Venture     ofs << "PSU_HARDRESET_DELAY=" << delay << std::endl;
178aa374120SPatrick Venture     if (ofs.fail())
179aa374120SPatrick Venture     {
180aa374120SPatrick Venture         std::fprintf(stderr, "Write failed\n");
181aa374120SPatrick Venture         ofs.close();
182aa374120SPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
183aa374120SPatrick Venture     }
184aa374120SPatrick Venture 
185aa374120SPatrick Venture     // Write succeeded, please continue.
186aa374120SPatrick Venture     ofs.flush();
187aa374120SPatrick Venture     ofs.close();
188aa374120SPatrick Venture 
189aa374120SPatrick Venture     auto bus = sdbusplus::bus::new_default();
190aa374120SPatrick Venture     auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_ROOT,
191aa374120SPatrick Venture                                       SYSTEMD_INTERFACE, "StartUnit");
192aa374120SPatrick Venture 
193aa374120SPatrick Venture     method.append(PSU_HARDRESET_TARGET);
194aa374120SPatrick Venture     method.append("replace");
195aa374120SPatrick Venture 
196aa374120SPatrick Venture     try
197aa374120SPatrick Venture     {
198aa374120SPatrick Venture         bus.call_noreply(method);
199aa374120SPatrick Venture     }
200aa374120SPatrick Venture     catch (const sdbusplus::exception::SdBusError& ex)
201aa374120SPatrick Venture     {
202aa374120SPatrick Venture         log<level::ERR>("Failed to call PSU hard reset");
203aa374120SPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
204aa374120SPatrick Venture     }
205aa374120SPatrick Venture }
206aa374120SPatrick Venture 
207ac4a16f7SShounak Mitra static constexpr auto RESET_ON_SHUTDOWN_FILENAME = "/run/powercycle_on_s5";
208ac4a16f7SShounak Mitra 
209ac4a16f7SShounak Mitra void Handler::psuResetOnShutdown() const
210ac4a16f7SShounak Mitra {
211ac4a16f7SShounak Mitra     std::ofstream ofs;
212ac4a16f7SShounak Mitra     ofs.open(RESET_ON_SHUTDOWN_FILENAME, std::ofstream::out);
213ac4a16f7SShounak Mitra     if (!ofs.good())
214ac4a16f7SShounak Mitra     {
215ac4a16f7SShounak Mitra         std::fprintf(stderr, "Unable to open file for output.\n");
216ac4a16f7SShounak Mitra         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
217ac4a16f7SShounak Mitra     }
218ac4a16f7SShounak Mitra     ofs.close();
219ac4a16f7SShounak Mitra }
220ac4a16f7SShounak Mitra 
2213b1b427cSWilly Tu uint32_t Handler::getFlashSize()
2223b1b427cSWilly Tu {
2233b1b427cSWilly Tu     mtd_info_t info;
2243b1b427cSWilly Tu     int fd = open("/dev/mtd0", O_RDONLY);
2253b1b427cSWilly Tu     int err = ioctl(fd, MEMGETINFO, &info);
2263b1b427cSWilly Tu     close(fd);
2273b1b427cSWilly Tu 
2283b1b427cSWilly Tu     if (err)
2293b1b427cSWilly Tu     {
2303b1b427cSWilly Tu         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
2313b1b427cSWilly Tu     }
2323b1b427cSWilly Tu     return info.size;
2333b1b427cSWilly Tu }
2343b1b427cSWilly Tu 
235ab650004SPatrick Venture std::string Handler::getEntityName(std::uint8_t id, std::uint8_t instance)
23607f85150SPatrick Venture {
237ab650004SPatrick Venture     // Check if we support this Entity ID.
238ab650004SPatrick Venture     auto it = _entityIdToName.find(id);
239ab650004SPatrick Venture     if (it == _entityIdToName.end())
24007f85150SPatrick Venture     {
241ab650004SPatrick Venture         log<level::ERR>("Unknown Entity ID", entry("ENTITY_ID=%d", id));
242ab650004SPatrick Venture         throw IpmiException(IPMI_CC_INVALID_FIELD_REQUEST);
24307f85150SPatrick Venture     }
24407f85150SPatrick Venture 
245ab650004SPatrick Venture     std::string entityName;
246ab650004SPatrick Venture     try
24707f85150SPatrick Venture     {
248ab650004SPatrick Venture         // Parse the JSON config file.
249ab650004SPatrick Venture         if (!_entityConfigParsed)
250ab650004SPatrick Venture         {
251ab650004SPatrick Venture             _entityConfig = parseConfig(_configFile);
252ab650004SPatrick Venture             _entityConfigParsed = true;
25307f85150SPatrick Venture         }
25407f85150SPatrick Venture 
255ab650004SPatrick Venture         // Find the "entity id:entity instance" mapping to entity name.
256ab650004SPatrick Venture         entityName = readNameFromConfig(it->second, instance, _entityConfig);
257ab650004SPatrick Venture         if (entityName.empty())
258ab650004SPatrick Venture         {
259ab650004SPatrick Venture             throw IpmiException(IPMI_CC_INVALID_FIELD_REQUEST);
260ab650004SPatrick Venture         }
261ab650004SPatrick Venture     }
262ab650004SPatrick Venture     catch (InternalFailure& e)
263ab650004SPatrick Venture     {
264ab650004SPatrick Venture         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
26507f85150SPatrick Venture     }
26607f85150SPatrick Venture 
267ab650004SPatrick Venture     return entityName;
268ab650004SPatrick Venture }
269ab650004SPatrick Venture 
27029f35bceSWilliam A. Kennington III std::string Handler::getMachineName()
27129f35bceSWilliam A. Kennington III {
27229f35bceSWilliam A. Kennington III     const char* path = "/etc/os-release";
27329f35bceSWilliam A. Kennington III     std::ifstream ifs(path);
27429f35bceSWilliam A. Kennington III     if (ifs.fail())
27529f35bceSWilliam A. Kennington III     {
27629f35bceSWilliam A. Kennington III         std::fprintf(stderr, "Failed to open: %s\n", path);
27729f35bceSWilliam A. Kennington III         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
27829f35bceSWilliam A. Kennington III     }
27929f35bceSWilliam A. Kennington III 
28029f35bceSWilliam A. Kennington III     std::string line;
28129f35bceSWilliam A. Kennington III     while (true)
28229f35bceSWilliam A. Kennington III     {
28329f35bceSWilliam A. Kennington III         std::getline(ifs, line);
28429f35bceSWilliam A. Kennington III         if (ifs.eof())
28529f35bceSWilliam A. Kennington III         {
28629f35bceSWilliam A. Kennington III             std::fprintf(stderr, "Failed to find OPENBMC_TARGET_MACHINE: %s\n",
28729f35bceSWilliam A. Kennington III                          path);
28829f35bceSWilliam A. Kennington III             throw IpmiException(IPMI_CC_INVALID);
28929f35bceSWilliam A. Kennington III         }
29029f35bceSWilliam A. Kennington III         if (ifs.fail())
29129f35bceSWilliam A. Kennington III         {
29229f35bceSWilliam A. Kennington III             std::fprintf(stderr, "Failed to read: %s\n", path);
29329f35bceSWilliam A. Kennington III             throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
29429f35bceSWilliam A. Kennington III         }
29529f35bceSWilliam A. Kennington III         std::string_view lineView(line);
29629f35bceSWilliam A. Kennington III         constexpr std::string_view prefix = "OPENBMC_TARGET_MACHINE=";
29729f35bceSWilliam A. Kennington III         if (lineView.substr(0, prefix.size()) != prefix)
29829f35bceSWilliam A. Kennington III         {
29929f35bceSWilliam A. Kennington III             continue;
30029f35bceSWilliam A. Kennington III         }
30129f35bceSWilliam A. Kennington III         lineView.remove_prefix(prefix.size());
30229f35bceSWilliam A. Kennington III         lineView.remove_prefix(
30329f35bceSWilliam A. Kennington III             std::min(lineView.find_first_not_of('"'), lineView.size()));
30429f35bceSWilliam A. Kennington III         lineView.remove_suffix(
30529f35bceSWilliam A. Kennington III             lineView.size() - 1 -
30629f35bceSWilliam A. Kennington III             std::min(lineView.find_last_not_of('"'), lineView.size() - 1));
30729f35bceSWilliam A. Kennington III         return std::string(lineView);
30829f35bceSWilliam A. Kennington III     }
30929f35bceSWilliam A. Kennington III }
31029f35bceSWilliam A. Kennington III 
311*8cfa4c44Slinyuny static constexpr auto HOST_TIME_DELAY_FILENAME = "/run/host_poweroff_delay";
312*8cfa4c44Slinyuny static constexpr auto HOST_POWEROFF_TARGET = "gbmc-host-poweroff.target";
313*8cfa4c44Slinyuny 
314*8cfa4c44Slinyuny void Handler::hostPowerOffDelay(std::uint32_t delay) const
315*8cfa4c44Slinyuny {
316*8cfa4c44Slinyuny     // Set time delay
317*8cfa4c44Slinyuny     std::ofstream ofs;
318*8cfa4c44Slinyuny     ofs.open(HOST_TIME_DELAY_FILENAME, std::ofstream::out);
319*8cfa4c44Slinyuny     if (!ofs.good())
320*8cfa4c44Slinyuny     {
321*8cfa4c44Slinyuny         std::fprintf(stderr, "Unable to open file for output.\n");
322*8cfa4c44Slinyuny         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
323*8cfa4c44Slinyuny     }
324*8cfa4c44Slinyuny 
325*8cfa4c44Slinyuny     ofs << "HOST_POWEROFF_DELAY=" << delay << std::endl;
326*8cfa4c44Slinyuny     ofs.close();
327*8cfa4c44Slinyuny     if (ofs.fail())
328*8cfa4c44Slinyuny     {
329*8cfa4c44Slinyuny         std::fprintf(stderr, "Write failed\n");
330*8cfa4c44Slinyuny         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
331*8cfa4c44Slinyuny     }
332*8cfa4c44Slinyuny 
333*8cfa4c44Slinyuny     // Write succeeded, please continue.
334*8cfa4c44Slinyuny     auto bus = sdbusplus::bus::new_default();
335*8cfa4c44Slinyuny     auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_ROOT,
336*8cfa4c44Slinyuny                                       SYSTEMD_INTERFACE, "StartUnit");
337*8cfa4c44Slinyuny 
338*8cfa4c44Slinyuny     method.append(HOST_POWEROFF_TARGET);
339*8cfa4c44Slinyuny     method.append("replace");
340*8cfa4c44Slinyuny 
341*8cfa4c44Slinyuny     try
342*8cfa4c44Slinyuny     {
343*8cfa4c44Slinyuny         bus.call_noreply(method);
344*8cfa4c44Slinyuny     }
345*8cfa4c44Slinyuny     catch (const sdbusplus::exception::SdBusError& ex)
346*8cfa4c44Slinyuny     {
347*8cfa4c44Slinyuny         log<level::ERR>("Failed to call Power Off",
348*8cfa4c44Slinyuny                         entry("WHAT=%s", ex.what()));
349*8cfa4c44Slinyuny         throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
350*8cfa4c44Slinyuny     }
351*8cfa4c44Slinyuny }
352*8cfa4c44Slinyuny 
353ab650004SPatrick Venture std::string readNameFromConfig(const std::string& type, uint8_t instance,
354ab650004SPatrick Venture                                const Json& config)
35507f85150SPatrick Venture {
35607f85150SPatrick Venture     static const std::vector<Json> empty{};
35707f85150SPatrick Venture     std::vector<Json> readings = config.value(type, empty);
35807f85150SPatrick Venture     std::string name = "";
359ab650004SPatrick Venture 
36007f85150SPatrick Venture     for (const auto& j : readings)
36107f85150SPatrick Venture     {
36207f85150SPatrick Venture         uint8_t instanceNum = j.value("instance", 0);
36307f85150SPatrick Venture         // Not the instance we're interested in
36407f85150SPatrick Venture         if (instanceNum != instance)
36507f85150SPatrick Venture         {
36607f85150SPatrick Venture             continue;
36707f85150SPatrick Venture         }
36807f85150SPatrick Venture 
36907f85150SPatrick Venture         // Found the instance we're interested in
37007f85150SPatrick Venture         name = j.value("name", "");
37107f85150SPatrick Venture 
37207f85150SPatrick Venture         break;
37307f85150SPatrick Venture     }
374ab650004SPatrick Venture 
37507f85150SPatrick Venture     return name;
37607f85150SPatrick Venture }
37707f85150SPatrick Venture 
37849f23ad9SPatrick Venture void Handler::buildI2cPcieMapping()
37949f23ad9SPatrick Venture {
38049f23ad9SPatrick Venture     _pcie_i2c_map = buildPcieMap();
38149f23ad9SPatrick Venture }
38249f23ad9SPatrick Venture 
38349f23ad9SPatrick Venture size_t Handler::getI2cPcieMappingSize() const
38449f23ad9SPatrick Venture {
38549f23ad9SPatrick Venture     return _pcie_i2c_map.size();
38649f23ad9SPatrick Venture }
38749f23ad9SPatrick Venture 
38849f23ad9SPatrick Venture std::tuple<std::uint32_t, std::string>
38949f23ad9SPatrick Venture     Handler::getI2cEntry(unsigned int entry) const
39049f23ad9SPatrick Venture {
39149f23ad9SPatrick Venture     return _pcie_i2c_map[entry];
39249f23ad9SPatrick Venture }
39349f23ad9SPatrick Venture 
394f085d91dSPatrick Venture } // namespace ipmi
395f085d91dSPatrick Venture } // namespace google
396