blob: 3dc1a76f48c2a4a7a8eb70999fd44cd4058f0256 [file] [log] [blame]
Dawid Fryckia642a942018-06-12 10:44:23 -07001/* Copyright 2018 Intel
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "ipmbbridged.hpp"
17
18#include "ipmbdefines.hpp"
19#include "ipmbutils.hpp"
20
Qiang XU8edcf1a2019-06-14 22:18:15 +080021#include <boost/algorithm/string/replace.hpp>
Ed Tanous09027c02020-08-31 17:28:36 -070022#include <boost/asio/write.hpp>
Qiang XU8edcf1a2019-06-14 22:18:15 +080023#include <filesystem>
Amithash Prasad314862d2019-03-26 11:14:03 -070024#include <fstream>
25#include <nlohmann/json.hpp>
Dawid Fryckia642a942018-06-12 10:44:23 -070026#include <phosphor-logging/log.hpp>
27#include <tuple>
Amithash Prasad314862d2019-03-26 11:14:03 -070028#include <unordered_map>
Dawid Fryckia642a942018-06-12 10:44:23 -070029
Dawid Fryckia642a942018-06-12 10:44:23 -070030/**
31 * @brief Dbus
32 */
33static constexpr const char *ipmbBus = "xyz.openbmc_project.Ipmi.Channel.Ipmb";
34static constexpr const char *ipmbObj = "/xyz/openbmc_project/Ipmi/Channel/Ipmb";
Dawid Fryckia642a942018-06-12 10:44:23 -070035static constexpr const char *ipmbDbusIntf = "org.openbmc.Ipmb";
36
37boost::asio::io_service io;
38auto conn = std::make_shared<sdbusplus::asio::connection>(io);
39
Dawid Fryckia642a942018-06-12 10:44:23 -070040static std::list<IpmbChannel> ipmbChannels;
Amithash Prasad314862d2019-03-26 11:14:03 -070041static const std::unordered_map<std::string, ipmbChannelType>
42 ipmbChannelTypeMap = {{"me", ipmbChannelType::me},
43 {"ipmb", ipmbChannelType::ipmb}};
Dawid Fryckia642a942018-06-12 10:44:23 -070044
45/**
46 * @brief Ipmb request class methods
47 */
48IpmbRequest::IpmbRequest()
49{
50 data.reserve(ipmbMaxDataSize);
51}
52
53IpmbRequest::IpmbRequest(uint8_t address, uint8_t netFn, uint8_t rsLun,
54 uint8_t rqSA, uint8_t seq, uint8_t rqLun, uint8_t cmd,
Dawid Frycki8188d762019-04-01 18:03:48 -070055 const std::vector<uint8_t> &inputData) :
Dawid Fryckia642a942018-06-12 10:44:23 -070056 address(address),
57 netFn(netFn), rsLun(rsLun), rqSA(rqSA), seq(seq), rqLun(rqLun), cmd(cmd),
58 timer(io)
59{
60 data.reserve(ipmbMaxDataSize);
61 state = ipmbRequestState::invalid;
62
63 if (inputData.size() > 0)
64 {
65 data = std::move(inputData);
66 }
67}
68
Dawid Fryckia642a942018-06-12 10:44:23 -070069void IpmbRequest::i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer,
70 size_t bufferLength)
71{
72 // constructing ipmb request from i2c buffer
73 netFn = ipmbNetFnGet(ipmbBuffer->Header.Req.rsNetFnLUN);
74 rsLun = ipmbLunFromNetFnLunGet(ipmbBuffer->Header.Req.rsNetFnLUN);
75 rqSA = ipmbBuffer->Header.Req.rqSA;
76 seq = ipmbSeqGet(ipmbBuffer->Header.Req.rqSeqLUN);
77 rqLun = ipmbLunFromSeqLunGet(ipmbBuffer->Header.Req.rqSeqLUN);
78 cmd = ipmbBuffer->Header.Req.cmd;
79
80 size_t dataLength =
81 bufferLength - (ipmbConnectionHeaderLength +
82 ipmbRequestDataHeaderLength + ipmbChecksumSize);
83
84 if (dataLength > 0)
85 {
86 data.insert(data.end(), ipmbBuffer->Header.Req.data,
87 &ipmbBuffer->Header.Req.data[dataLength]);
88 }
89}
90
91int IpmbRequest::ipmbToi2cConstruct(std::vector<uint8_t> &buffer)
92{
Vijay Khemka37a7eac2019-12-06 13:52:28 -080093 /* Add one byte for length byte as per required by driver */
94 size_t bufferLength = 1 + data.size() + ipmbRequestDataHeaderLength +
Dawid Fryckia642a942018-06-12 10:44:23 -070095 ipmbConnectionHeaderLength + ipmbChecksumSize;
96
97 if (bufferLength > ipmbMaxFrameLength)
98 {
99 return -1;
100 }
101
102 buffer.resize(bufferLength);
103 static_assert(ipmbMaxFrameLength >= sizeof(IPMB_HEADER));
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800104 IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer.data());
105 ipmbPkt->len = bufferLength - 1;
106 IPMB_HEADER *ipmbBuffer = &(ipmbPkt->hdr);
Dawid Fryckia642a942018-06-12 10:44:23 -0700107
108 // constructing buffer from ipmb request
109 ipmbBuffer->Header.Req.address = address;
110 ipmbBuffer->Header.Req.rsNetFnLUN = ipmbNetFnLunSet(netFn, rsLun);
111 ipmbBuffer->Header.Req.rqSA = rqSA;
112 ipmbBuffer->Header.Req.rqSeqLUN = ipmbSeqLunSet(seq, rqLun);
113 ipmbBuffer->Header.Req.cmd = cmd;
114
Qiang XUbbfd00a2019-06-27 21:10:06 +0800115 ipmbBuffer->Header.Req.checksum1 = ipmbChecksumCompute(
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800116 (uint8_t *)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
Dawid Fryckia642a942018-06-12 10:44:23 -0700117
118 if (data.size() > 0)
119 {
120 std::copy(data.begin(), data.end(), ipmbBuffer->Header.Req.data);
121 }
122
123 buffer[bufferLength - ipmbChecksumSize] =
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800124 ipmbChecksumCompute((uint8_t *)ipmbBuffer + ipmbChecksum2StartOffset,
Dawid Fryckia642a942018-06-12 10:44:23 -0700125 (ipmbRequestDataHeaderLength + data.size()));
126
127 return 0;
128}
129
130std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
131 IpmbRequest::returnMatchedResponse()
132{
133 return std::make_tuple(
134 static_cast<int>(ipmbResponseStatus::success), matchedResponse->netFn,
135 matchedResponse->rsLun, matchedResponse->cmd,
136 matchedResponse->completionCode, matchedResponse->data);
137}
138
139static std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
140 returnStatus(ipmbResponseStatus status)
141{
142 // we only want to send status here, other fields are not relevant
143 return std::make_tuple(static_cast<int>(status), 0, 0, 0, 0,
144 std::vector<uint8_t>(0));
145}
146
Dawid Fryckia642a942018-06-12 10:44:23 -0700147/**
148 * @brief Ipmb response class methods
149 */
150IpmbResponse::IpmbResponse()
151{
152 data.reserve(ipmbMaxDataSize);
153}
154
155IpmbResponse::IpmbResponse(uint8_t address, uint8_t netFn, uint8_t rqLun,
156 uint8_t rsSA, uint8_t seq, uint8_t rsLun,
157 uint8_t cmd, uint8_t completionCode,
Dawid Frycki8188d762019-04-01 18:03:48 -0700158 const std::vector<uint8_t> &inputData) :
Dawid Fryckia642a942018-06-12 10:44:23 -0700159 address(address),
160 netFn(netFn), rqLun(rqLun), rsSA(rsSA), seq(seq), rsLun(rsLun), cmd(cmd),
161 completionCode(completionCode)
162{
163 data.reserve(ipmbMaxDataSize);
164
165 if (inputData.size() > 0)
166 {
167 data = std::move(inputData);
168 }
169}
170
171void IpmbResponse::i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer,
172 size_t bufferLength)
173{
174 netFn = ipmbNetFnGet(ipmbBuffer->Header.Resp.rqNetFnLUN);
175 rqLun = ipmbLunFromNetFnLunGet(ipmbBuffer->Header.Resp.rqNetFnLUN);
176 rsSA = ipmbBuffer->Header.Resp.rsSA;
177 seq = ipmbSeqGet(ipmbBuffer->Header.Resp.rsSeqLUN);
178 rsLun = ipmbLunFromSeqLunGet(ipmbBuffer->Header.Resp.rsSeqLUN);
179 cmd = ipmbBuffer->Header.Resp.cmd;
180 completionCode = ipmbBuffer->Header.Resp.completionCode;
181
182 size_t dataLength =
183 bufferLength - (ipmbConnectionHeaderLength +
184 ipmbResponseDataHeaderLength + ipmbChecksumSize);
185
186 if (dataLength > 0)
187 {
188 data.insert(data.end(), ipmbBuffer->Header.Resp.data,
189 &ipmbBuffer->Header.Resp.data[dataLength]);
190 }
191}
192
Dawid Frycki8188d762019-04-01 18:03:48 -0700193std::shared_ptr<std::vector<uint8_t>> IpmbResponse::ipmbToi2cConstruct()
Dawid Fryckia642a942018-06-12 10:44:23 -0700194{
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800195 /* Add one byte for length byte as per required by driver */
196 size_t bufferLength = 1 + data.size() + ipmbResponseDataHeaderLength +
Dawid Fryckia642a942018-06-12 10:44:23 -0700197 ipmbConnectionHeaderLength + ipmbChecksumSize;
198
199 if (bufferLength > ipmbMaxFrameLength)
200 {
Dawid Frycki8188d762019-04-01 18:03:48 -0700201 return nullptr;
Dawid Fryckia642a942018-06-12 10:44:23 -0700202 }
203
Dawid Frycki8188d762019-04-01 18:03:48 -0700204 std::shared_ptr<std::vector<uint8_t>> buffer =
205 std::make_shared<std::vector<uint8_t>>(bufferLength);
206
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800207 IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer->data());
208 ipmbPkt->len = bufferLength - 1;
209 IPMB_HEADER *ipmbBuffer = &(ipmbPkt->hdr);
Dawid Fryckia642a942018-06-12 10:44:23 -0700210
211 ipmbBuffer->Header.Resp.address = address;
212 ipmbBuffer->Header.Resp.rqNetFnLUN = ipmbNetFnLunSet(netFn, rqLun);
213 ipmbBuffer->Header.Resp.rsSA = rsSA;
214 ipmbBuffer->Header.Resp.rsSeqLUN = ipmbSeqLunSet(seq, rsLun);
215 ipmbBuffer->Header.Resp.cmd = cmd;
216 ipmbBuffer->Header.Resp.completionCode = completionCode;
217
218 ipmbBuffer->Header.Resp.checksum1 = ipmbChecksumCompute(
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800219 (uint8_t *)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
Dawid Fryckia642a942018-06-12 10:44:23 -0700220
221 if (data.size() > 0)
222 {
223 std::copy(data.begin(), data.end(), ipmbBuffer->Header.Resp.data);
224 }
225
Dawid Frycki8188d762019-04-01 18:03:48 -0700226 (*buffer)[bufferLength - ipmbChecksumSize] =
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800227 ipmbChecksumCompute((uint8_t *)ipmbBuffer + ipmbChecksum2StartOffset,
Dawid Fryckia642a942018-06-12 10:44:23 -0700228 (ipmbResponseDataHeaderLength + data.size()));
229
Dawid Frycki8188d762019-04-01 18:03:48 -0700230 return buffer;
Dawid Fryckia642a942018-06-12 10:44:23 -0700231}
232
233bool IpmbCommandFilter::isBlocked(const uint8_t reqNetFn, const uint8_t cmd)
234{
235 auto blockedCmd = unhandledCommands.find({reqNetFn, cmd});
236
237 if (blockedCmd != unhandledCommands.end())
238 {
239 return true;
240 }
241
242 return false;
243}
244
245void IpmbCommandFilter::addFilter(const uint8_t reqNetFn, const uint8_t cmd)
246{
247 if (unhandledCommands.insert({reqNetFn, cmd}).second)
248 {
249 phosphor::logging::log<phosphor::logging::level::INFO>(
250 "addFilter: added command to filter",
251 phosphor::logging::entry("netFn = %d", reqNetFn),
252 phosphor::logging::entry("cmd = %d", cmd));
253 }
254}
255
256/**
257 * @brief Ipmb channel
258 */
Qiang XUbbfd00a2019-06-27 21:10:06 +0800259void IpmbChannel::ipmbSendI2cFrame(std::shared_ptr<std::vector<uint8_t>> buffer,
Dawid Fryckia642a942018-06-12 10:44:23 -0700260 size_t retriesAttempted = 0)
261{
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800262 IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer->data());
263 uint8_t targetAddr = ipmbIsResponse(&(ipmbPkt->hdr))
264 ? ipmbPkt->hdr.Header.Resp.address
265 : ipmbPkt->hdr.Header.Req.address;
266 boost::asio::async_write(
267 i2cSlaveDescriptor, boost::asio::buffer(*buffer),
268 [this, buffer, retriesAttempted,
269 targetAddr](const boost::system::error_code &ec, size_t bytesSent) {
270 if (ec)
Dawid Fryckia642a942018-06-12 10:44:23 -0700271 {
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800272 size_t currentRetryCnt = retriesAttempted;
273
274 if (currentRetryCnt > ipmbI2cNumberOfRetries)
275 {
276 std::string msgToLog =
277 "ipmbSendI2cFrame: send to I2C failed after retries."
278 " busId=" +
279 std::to_string(ipmbBusId) +
280 ", targetAddr=" + std::to_string(targetAddr) +
281 ", error=" + ec.message();
282 phosphor::logging::log<phosphor::logging::level::ERR>(
283 msgToLog.c_str());
284 return;
285 }
286 currentRetryCnt++;
287 ipmbSendI2cFrame(buffer, currentRetryCnt);
Dawid Fryckia642a942018-06-12 10:44:23 -0700288 }
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800289 });
Dawid Fryckia642a942018-06-12 10:44:23 -0700290}
291
292/**
293 * @brief Ipmb Outstanding Requests
294 */
295void IpmbChannel::makeRequestInvalid(IpmbRequest &request)
296{
297 // change request state to invalid and remove it from outstanding requests
298 // list
299 request.state = ipmbRequestState::invalid;
300 outstandingRequests[request.seq] = nullptr;
301}
302
303void IpmbChannel::makeRequestValid(std::shared_ptr<IpmbRequest> request)
304{
305 // change request state to valid and add it to outstanding requests list
306 request->state = ipmbRequestState::valid;
307 outstandingRequests[request->seq] = request;
308}
309
310bool IpmbChannel::seqNumGet(uint8_t &seq)
311{
312 static uint8_t seqNum = 0;
313
314 for (int i = 0; i < ipmbMaxOutstandingRequestsCount; i++)
315 {
316 seqNum = ++seqNum & ipmbSeqMask;
317 if (seqNum == ipmbMaxOutstandingRequestsCount)
318 {
319 seqNum = 0;
320 }
321
322 if (outstandingRequests[seqNum] == nullptr)
323 {
324 seq = seqNum;
325 return true;
326 }
327 }
328
329 return false;
330}
331
332void IpmbChannel::responseMatch(std::unique_ptr<IpmbResponse> &response)
333{
334 std::shared_ptr<IpmbRequest> request = outstandingRequests[response->seq];
335
336 if (request != nullptr)
337 {
338 if (((ipmbRespNetFn(request->netFn)) == (response->netFn)) &&
339 ((request->rqLun) == (response->rqLun)) &&
340 ((request->rsLun) == (response->rsLun)) &&
341 ((request->cmd) == (response->cmd)))
342 {
343 // match, response is corresponding to previously sent request
344 request->state = ipmbRequestState::matched;
345 request->timer->cancel();
346 request->matchedResponse = std::move(response);
347 }
348 }
349}
350
351void IpmbChannel::processI2cEvent()
352{
353 std::array<uint8_t, ipmbMaxFrameLength> buffer{};
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800354 IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer.data());
355 IPMB_HEADER *ipmbFrame = &(ipmbPkt->hdr);
Dawid Fryckia642a942018-06-12 10:44:23 -0700356
357 lseek(ipmbi2cSlaveFd, 0, SEEK_SET);
358 int r = read(ipmbi2cSlaveFd, buffer.data(), ipmbMaxFrameLength);
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800359
360 /* Substract first byte len size from total frame length */
361 r--;
362
Dawid Fryckia642a942018-06-12 10:44:23 -0700363 if ((r < ipmbMinFrameLength) || (r > ipmbMaxFrameLength))
364 {
365 goto end;
366 }
367
368 // valiate the frame
369 if (!isFrameValid(ipmbFrame, r))
370 {
371 goto end;
372 }
373
Chen Yugang15185ff2020-09-01 09:20:33 +0800374 // if it is message received from ipmb channel, send out dbus signal
375 if (getChannelType() == ipmbChannelType::ipmb)
Qiang XUbbfd00a2019-06-27 21:10:06 +0800376 {
377 auto ipmbMessageReceived = IpmbRequest();
378 ipmbMessageReceived.i2cToIpmbConstruct(ipmbFrame, r);
379 sdbusplus::message::message msg =
380 conn->new_signal(ipmbObj, ipmbDbusIntf, "receiveBroadcast");
381 msg.append(ipmbMessageReceived.netFn, ipmbMessageReceived.cmd,
382 ipmbMessageReceived.data);
383 msg.signal_send();
384 }
385
Dawid Fryckia642a942018-06-12 10:44:23 -0700386 // copy frame to ipmib message buffer
Chen Yugang3e07b9e2020-10-13 16:14:04 +0800387 if (ipmbIsResponse(ipmbFrame))
Dawid Fryckia642a942018-06-12 10:44:23 -0700388 {
389 std::unique_ptr<IpmbResponse> ipmbMessageReceived =
390 std::make_unique<IpmbResponse>();
391
392 ipmbMessageReceived->i2cToIpmbConstruct(ipmbFrame, r);
393
394 // try to match response with outstanding request
395 responseMatch(ipmbMessageReceived);
396 }
397 else
398 {
399 // if command is blocked - respond with 'invalid command'
400 // completion code
401 if (commandFilter)
402 {
403 uint8_t netFn = ipmbNetFnGet(ipmbFrame->Header.Req.rsNetFnLUN);
404 uint8_t cmd = ipmbFrame->Header.Req.cmd;
Qiang XUbbfd00a2019-06-27 21:10:06 +0800405 uint8_t rqSA = ipmbFrame->Header.Req.rqSA;
Dawid Fryckia642a942018-06-12 10:44:23 -0700406
407 if (commandFilter->isBlocked(netFn, cmd))
408 {
409 uint8_t seq = ipmbSeqGet(ipmbFrame->Header.Req.rqSeqLUN);
410 uint8_t lun =
411 ipmbLunFromSeqLunGet(ipmbFrame->Header.Req.rqSeqLUN);
Dawid Fryckia642a942018-06-12 10:44:23 -0700412
413 // prepare generic response
Qiang XUbbfd00a2019-06-27 21:10:06 +0800414 auto ipmbResponse = IpmbResponse(
415 rqSA, ipmbRespNetFn(netFn), lun, ipmbBmcSlaveAddress, seq,
416 ipmbRsLun, cmd, ipmbIpmiInvalidCmd, {});
Dawid Fryckia642a942018-06-12 10:44:23 -0700417
Dawid Frycki8188d762019-04-01 18:03:48 -0700418 auto buffer = ipmbResponse.ipmbToi2cConstruct();
419 if (buffer)
Dawid Fryckia642a942018-06-12 10:44:23 -0700420 {
Qiang XUbbfd00a2019-06-27 21:10:06 +0800421 ipmbSendI2cFrame(buffer);
Dawid Fryckia642a942018-06-12 10:44:23 -0700422 }
423
424 goto end;
425 }
426 }
427
428 auto ipmbMessageReceived = IpmbRequest();
Dawid Fryckia642a942018-06-12 10:44:23 -0700429 ipmbMessageReceived.i2cToIpmbConstruct(ipmbFrame, r);
430
Dawid Frycki8188d762019-04-01 18:03:48 -0700431 std::map<std::string, std::variant<int>> options{
Qiang XUbbfd00a2019-06-27 21:10:06 +0800432 {"rqSA", ipmbAddressTo7BitSet(ipmbMessageReceived.rqSA)}};
Dawid Frycki8188d762019-04-01 18:03:48 -0700433 using IpmiDbusRspType = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t,
434 std::vector<uint8_t>>;
435 conn->async_method_call(
436 [this, rqLun{ipmbMessageReceived.rqLun},
Qiang XUbbfd00a2019-06-27 21:10:06 +0800437 seq{ipmbMessageReceived.seq}, address{ipmbMessageReceived.rqSA}](
438 const boost::system::error_code &ec,
439 const IpmiDbusRspType &response) {
Dawid Frycki8188d762019-04-01 18:03:48 -0700440 const auto &[netfn, lun, cmd, cc, payload] = response;
441 if (ec)
442 {
443 phosphor::logging::log<phosphor::logging::level::ERR>(
444 "processI2cEvent: error getting response from IPMI");
445 return;
446 }
Dawid Fryckia642a942018-06-12 10:44:23 -0700447
Dawid Frycki8188d762019-04-01 18:03:48 -0700448 uint8_t bmcSlaveAddress = getBmcSlaveAddress();
449
450 if (payload.size() > ipmbMaxDataSize)
451 {
452 phosphor::logging::log<phosphor::logging::level::ERR>(
453 "processI2cEvent: response exceeding maximum size");
454
455 // prepare generic response
456 auto ipmbResponse = IpmbResponse(
Qiang XUbbfd00a2019-06-27 21:10:06 +0800457 address, netfn, rqLun, bmcSlaveAddress, seq, ipmbRsLun,
458 cmd, ipmbIpmiCmdRespNotProvided, {});
Dawid Frycki8188d762019-04-01 18:03:48 -0700459
460 auto buffer = ipmbResponse.ipmbToi2cConstruct();
461 if (buffer)
462 {
Qiang XUbbfd00a2019-06-27 21:10:06 +0800463 ipmbSendI2cFrame(buffer);
Dawid Frycki8188d762019-04-01 18:03:48 -0700464 }
465
466 return;
467 }
468
469 if (!(netfn & ipmbNetFnResponseMask))
470 {
471 // we are not expecting request here
472 phosphor::logging::log<phosphor::logging::level::ERR>(
473 "processI2cEvent: got a request instead of response");
474 return;
475 }
476
477 // if command is not supported, add it to filter
478 if (cc == ipmbIpmiInvalidCmd)
479 {
480 addFilter(ipmbReqNetFnFromRespNetFn(netfn), cmd);
481 }
482
483 // payload is empty after constructor invocation
484 auto ipmbResponse =
Qiang XUbbfd00a2019-06-27 21:10:06 +0800485 IpmbResponse(address, netfn, rqLun, bmcSlaveAddress, seq,
486 lun, cmd, cc, payload);
Dawid Frycki8188d762019-04-01 18:03:48 -0700487
488 auto buffer = ipmbResponse.ipmbToi2cConstruct();
489 if (!buffer)
490 {
491 phosphor::logging::log<phosphor::logging::level::ERR>(
492 "processI2cEvent: error constructing a request");
493 return;
494 }
495
Qiang XUbbfd00a2019-06-27 21:10:06 +0800496 ipmbSendI2cFrame(buffer);
Dawid Frycki8188d762019-04-01 18:03:48 -0700497 },
498 "xyz.openbmc_project.Ipmi.Host", "/xyz/openbmc_project/Ipmi",
499 "xyz.openbmc_project.Ipmi.Server", "execute",
500 ipmbMessageReceived.netFn, ipmbMessageReceived.rsLun,
501 ipmbMessageReceived.cmd, ipmbMessageReceived.data, options);
Dawid Fryckia642a942018-06-12 10:44:23 -0700502 }
503
504end:
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800505 i2cSlaveDescriptor.async_wait(
506 boost::asio::posix::descriptor_base::wait_read,
Dawid Fryckia642a942018-06-12 10:44:23 -0700507 [this](const boost::system::error_code &ec) {
508 if (ec)
509 {
510 phosphor::logging::log<phosphor::logging::level::ERR>(
511 "Error: processI2cEvent()");
512 return;
513 }
514
515 processI2cEvent();
516 });
517}
518
519IpmbChannel::IpmbChannel(boost::asio::io_service &io,
520 uint8_t ipmbBmcSlaveAddress,
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530521 uint8_t ipmbRqSlaveAddress, uint8_t channelIdx,
Dawid Fryckia642a942018-06-12 10:44:23 -0700522 std::shared_ptr<IpmbCommandFilter> commandFilter) :
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800523 i2cSlaveDescriptor(io),
524 ipmbBmcSlaveAddress(ipmbBmcSlaveAddress),
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530525 ipmbRqSlaveAddress(ipmbRqSlaveAddress), channelIdx(channelIdx),
Dawid Fryckia642a942018-06-12 10:44:23 -0700526 commandFilter(commandFilter)
527{
528}
529
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800530int IpmbChannel::ipmbChannelInit(const char *ipmbI2cSlave)
Dawid Fryckia642a942018-06-12 10:44:23 -0700531{
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800532 // extract bus id from slave path and save
533 std::string ipmbI2cSlaveStr(ipmbI2cSlave);
534 auto findHyphen = ipmbI2cSlaveStr.find("-");
535 std::string busStr = ipmbI2cSlaveStr.substr(findHyphen + 1);
Qiang XU8edcf1a2019-06-14 22:18:15 +0800536 try
537 {
538 ipmbBusId = std::stoi(busStr);
539 }
540 catch (std::invalid_argument)
541 {
542 phosphor::logging::log<phosphor::logging::level::ERR>(
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800543 "ipmbChannelInit: invalid bus id in slave-path config");
Qiang XU8edcf1a2019-06-14 22:18:15 +0800544 return -1;
545 }
546
547 // Check if sysfs has device. If not, enable I2C slave driver by command
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800548 // echo "ipmb-dev 0x1010" > /sys/bus/i2c/devices/i2c-0/new_device
Qiang XU8edcf1a2019-06-14 22:18:15 +0800549 bool hasSysfs = std::filesystem::exists(ipmbI2cSlave);
550 if (!hasSysfs)
551 {
552 std::string deviceFileName =
553 "/sys/bus/i2c/devices/i2c-" + busStr + "/new_device";
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800554 std::string para = "ipmb-dev 0x1010"; // init with BMC addr 0x20
Qiang XU8edcf1a2019-06-14 22:18:15 +0800555 std::fstream deviceFile;
556 deviceFile.open(deviceFileName, std::ios::out);
557 if (!deviceFile.good())
558 {
559 phosphor::logging::log<phosphor::logging::level::ERR>(
560 "ipmbChannelInit: error opening deviceFile");
561 return -1;
562 }
563 deviceFile << para;
564 deviceFile.close();
565 }
566
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800567 // open fd to i2c slave device for read write
568 ipmbi2cSlaveFd = open(ipmbI2cSlave, O_RDWR | O_NONBLOCK | O_CLOEXEC);
Dawid Fryckia642a942018-06-12 10:44:23 -0700569 if (ipmbi2cSlaveFd < 0)
570 {
571 phosphor::logging::log<phosphor::logging::level::ERR>(
572 "ipmbChannelInit: error opening ipmbI2cSlave");
573 return -1;
574 }
575
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800576 i2cSlaveDescriptor.assign(ipmbi2cSlaveFd);
Dawid Fryckia642a942018-06-12 10:44:23 -0700577
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800578 i2cSlaveDescriptor.async_wait(
579 boost::asio::posix::descriptor_base::wait_read,
Dawid Fryckia642a942018-06-12 10:44:23 -0700580 [this](const boost::system::error_code &ec) {
581 if (ec)
582 {
583 phosphor::logging::log<phosphor::logging::level::ERR>(
584 "Error: processI2cEvent()");
585 return;
586 }
587
588 processI2cEvent();
589 });
590
591 return 0;
592}
593
Qiang XU8edcf1a2019-06-14 22:18:15 +0800594int IpmbChannel::ipmbChannelUpdateSlaveAddress(const uint8_t newBmcSlaveAddr)
595{
596 if (ipmbi2cSlaveFd > 0)
597 {
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800598 i2cSlaveDescriptor.close();
Qiang XU8edcf1a2019-06-14 22:18:15 +0800599 close(ipmbi2cSlaveFd);
600 ipmbi2cSlaveFd = 0;
601 }
602
603 // disable old I2C slave driver by command:
604 // echo "0x1010" > /sys/bus/i2c/devices/i2c-0/delete_device
605 std::string deviceFileName;
606 std::string para;
607 std::fstream deviceFile;
608 deviceFileName = "/sys/bus/i2c/devices/i2c-" + std::to_string(ipmbBusId) +
609 "/delete_device";
610 para = "0x1010"; // align with removed ipmb0 definition in dts file
611 deviceFile.open(deviceFileName, std::ios::out);
612 if (!deviceFile.good())
613 {
614 phosphor::logging::log<phosphor::logging::level::ERR>(
615 "ipmbChannelUpdateSlaveAddress: error opening deviceFile to delete "
616 "sysfs");
617 return -1;
618 }
619 deviceFile << para;
620 deviceFile.close();
621
622 // enable new I2C slave driver by command:
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800623 // echo "ipmb-dev 0x1012" > /sys/bus/i2c/devices/i2c-0/new_device
Qiang XU8edcf1a2019-06-14 22:18:15 +0800624 deviceFileName =
625 "/sys/bus/i2c/devices/i2c-" + std::to_string(ipmbBusId) + "/new_device";
626 std::ostringstream hex;
627 uint16_t addr = 0x1000 + (newBmcSlaveAddr >> 1);
628 hex << std::hex << static_cast<uint16_t>(addr);
629 const std::string &addressHexStr = hex.str();
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800630 para = "ipmb-dev 0x" + addressHexStr;
Qiang XU8edcf1a2019-06-14 22:18:15 +0800631 deviceFile.open(deviceFileName, std::ios::out);
632 if (!deviceFile.good())
633 {
634 phosphor::logging::log<phosphor::logging::level::ERR>(
635 "ipmbChannelUpdateSlaveAddress: error opening deviceFile to create "
636 "sysfs");
637 return -1;
638 }
639 deviceFile << para;
640 deviceFile.close();
641
642 // open fd to i2c slave device
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800643 std::string ipmbI2cSlaveStr = "/dev/ipmb-" + std::to_string(ipmbBusId);
644 ipmbi2cSlaveFd = open(ipmbI2cSlaveStr.c_str(), O_RDWR | O_NONBLOCK);
Qiang XU8edcf1a2019-06-14 22:18:15 +0800645 if (ipmbi2cSlaveFd < 0)
646 {
647 phosphor::logging::log<phosphor::logging::level::ERR>(
648 "ipmbChannelInit: error opening ipmbI2cSlave");
649 return -1;
650 }
651
652 // start to receive i2c data as slave
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800653 i2cSlaveDescriptor.assign(ipmbi2cSlaveFd);
654 i2cSlaveDescriptor.async_wait(
655 boost::asio::posix::descriptor_base::wait_read,
Qiang XU8edcf1a2019-06-14 22:18:15 +0800656 [this](const boost::system::error_code &ec) {
657 if (ec)
658 {
659 phosphor::logging::log<phosphor::logging::level::ERR>(
660 "Error: processI2cEvent()");
661 return;
662 }
663
664 processI2cEvent();
665 });
666
Qiang XUbbfd00a2019-06-27 21:10:06 +0800667 ipmbBmcSlaveAddress = newBmcSlaveAddr;
668
Qiang XU8edcf1a2019-06-14 22:18:15 +0800669 return 0;
670}
671
672uint8_t IpmbChannel::getBusId()
673{
674 return ipmbBusId;
675}
676
Dawid Fryckia642a942018-06-12 10:44:23 -0700677uint8_t IpmbChannel::getBmcSlaveAddress()
678{
679 return ipmbBmcSlaveAddress;
680}
681
682uint8_t IpmbChannel::getRqSlaveAddress()
683{
684 return ipmbRqSlaveAddress;
685}
686
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530687uint8_t IpmbChannel::getDevIndex()
688{
689 return channelIdx >> 2;
690}
691
692uint8_t IpmbChannel::getChannelIdx()
693{
694 return channelIdx;
695}
696
Dawid Fryckia642a942018-06-12 10:44:23 -0700697ipmbChannelType IpmbChannel::getChannelType()
698{
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530699 return static_cast<ipmbChannelType>((channelIdx & 3));
Dawid Fryckia642a942018-06-12 10:44:23 -0700700}
701
702void IpmbChannel::addFilter(const uint8_t respNetFn, const uint8_t cmd)
703{
704 if (commandFilter)
705 {
706 commandFilter->addFilter(respNetFn, cmd);
707 }
708}
709
710std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
711 IpmbChannel::requestAdd(boost::asio::yield_context &yield,
712 std::shared_ptr<IpmbRequest> request)
713{
714 makeRequestValid(request);
715
716 std::vector<uint8_t> buffer(0);
717 if (request->ipmbToi2cConstruct(buffer) != 0)
718 {
719 return returnStatus(ipmbResponseStatus::error);
720 }
721
722 for (int i = 0; i < ipmbNumberOfTries; i++)
723 {
724 boost::system::error_code ec;
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800725 int i2cRetryCnt = 0;
Dawid Fryckia642a942018-06-12 10:44:23 -0700726
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800727 for (; i2cRetryCnt < ipmbI2cNumberOfRetries; i2cRetryCnt++)
Dawid Fryckia642a942018-06-12 10:44:23 -0700728 {
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800729 boost::asio::async_write(i2cSlaveDescriptor,
730 boost::asio::buffer(buffer), yield[ec]);
Dawid Fryckia642a942018-06-12 10:44:23 -0700731
732 if (ec)
733 {
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800734 continue; // retry
Dawid Fryckia642a942018-06-12 10:44:23 -0700735 }
736 break;
737 }
738
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800739 if (i2cRetryCnt == ipmbI2cNumberOfRetries)
740 {
Qiang XUbbfd00a2019-06-27 21:10:06 +0800741 std::string msgToLog =
742 "requestAdd: Sent to I2C failed after retries."
743 " busId=" +
744 std::to_string(ipmbBusId) + ", error=" + ec.message();
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800745 phosphor::logging::log<phosphor::logging::level::INFO>(
Qiang XUbbfd00a2019-06-27 21:10:06 +0800746 msgToLog.c_str());
Jae Hyun Yoo25e85c72019-03-05 14:28:13 -0800747 }
748
Dawid Fryckia642a942018-06-12 10:44:23 -0700749 request->timer->expires_after(
750 std::chrono::milliseconds(ipmbRequestRetryTimeout));
751 request->timer->async_wait(yield[ec]);
752
753 if (ec && ec != boost::asio::error::operation_aborted)
754 {
755 // unexpected error - invalidate request and return generic error
756 phosphor::logging::log<phosphor::logging::level::ERR>(
757 "requestAdd: async_wait error");
758 makeRequestInvalid(*request);
759 return returnStatus(ipmbResponseStatus::error);
760 }
761
762 if (request->state == ipmbRequestState::matched)
763 {
764 // matched response, send it to client application
765 makeRequestInvalid(*request);
766 return request->returnMatchedResponse();
767 }
768 }
769
770 makeRequestInvalid(*request);
771 return returnStatus(ipmbResponseStatus::timeout);
772}
773
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530774static IpmbChannel *getChannel(uint8_t reqChannel)
Dawid Fryckia642a942018-06-12 10:44:23 -0700775{
776 auto channel =
777 std::find_if(ipmbChannels.begin(), ipmbChannels.end(),
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530778 [reqChannel](IpmbChannel &channel) {
779 return channel.getChannelIdx() == reqChannel;
Dawid Fryckia642a942018-06-12 10:44:23 -0700780 });
781 if (channel != ipmbChannels.end())
782 {
783 return &(*channel);
784 }
785
786 return nullptr;
787}
788
789static int initializeChannels()
790{
791 std::shared_ptr<IpmbCommandFilter> commandFilter =
792 std::make_shared<IpmbCommandFilter>();
793
Amithash Prasad314862d2019-03-26 11:14:03 -0700794 constexpr const char *configFilePath =
795 "/usr/share/ipmbbridge/ipmb-channels.json";
796 std::ifstream configFile(configFilePath);
797 if (!configFile.is_open())
Dawid Fryckia642a942018-06-12 10:44:23 -0700798 {
Amithash Prasad314862d2019-03-26 11:14:03 -0700799 phosphor::logging::log<phosphor::logging::level::ERR>(
800 "initializeChannels: Cannot open config path");
801 return -1;
802 }
803 try
804 {
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530805 uint8_t devIndex = 0;
Amithash Prasad314862d2019-03-26 11:14:03 -0700806 auto data = nlohmann::json::parse(configFile, nullptr);
807 for (const auto &channelConfig : data["channels"])
Dawid Fryckia642a942018-06-12 10:44:23 -0700808 {
Amithash Prasad314862d2019-03-26 11:14:03 -0700809 const std::string &typeConfig = channelConfig["type"];
Amithash Prasad314862d2019-03-26 11:14:03 -0700810 const std::string &slavePath = channelConfig["slave-path"];
811 uint8_t bmcAddr = channelConfig["bmc-addr"];
812 uint8_t reqAddr = channelConfig["remote-addr"];
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530813
Amithash Prasad314862d2019-03-26 11:14:03 -0700814 ipmbChannelType type = ipmbChannelTypeMap.at(typeConfig);
815
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530816 if (channelConfig.contains("devIndex"))
817 {
818 devIndex = channelConfig["devIndex"];
819 }
820
821 auto channel = ipmbChannels.emplace(
822 ipmbChannels.end(), io, bmcAddr, reqAddr,
823 ((devIndex << 2) | static_cast<uint8_t>(type)), commandFilter);
Vijay Khemka37a7eac2019-12-06 13:52:28 -0800824 if (channel->ipmbChannelInit(slavePath.c_str()) < 0)
Amithash Prasad314862d2019-03-26 11:14:03 -0700825 {
826 phosphor::logging::log<phosphor::logging::level::ERR>(
827 "initializeChannels: channel initialization failed");
828 return -1;
829 }
Dawid Fryckia642a942018-06-12 10:44:23 -0700830 }
831 }
Amithash Prasad314862d2019-03-26 11:14:03 -0700832 catch (nlohmann::json::exception &e)
833 {
834 phosphor::logging::log<phosphor::logging::level::ERR>(
835 "initializeChannels: Error parsing config file");
836 return -1;
837 }
838 catch (std::out_of_range &e)
839 {
840 phosphor::logging::log<phosphor::logging::level::ERR>(
841 "initializeChannels: Error invalid type");
842 return -1;
843 }
Dawid Fryckia642a942018-06-12 10:44:23 -0700844 return 0;
845}
846
Dawid Fryckia642a942018-06-12 10:44:23 -0700847auto ipmbHandleRequest = [](boost::asio::yield_context yield,
848 uint8_t reqChannel, uint8_t netfn, uint8_t lun,
849 uint8_t cmd, std::vector<uint8_t> dataReceived) {
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530850 IpmbChannel *channel = getChannel(reqChannel);
851
Dawid Fryckia642a942018-06-12 10:44:23 -0700852 if (channel == nullptr)
853 {
854 phosphor::logging::log<phosphor::logging::level::ERR>(
855 "ipmbHandleRequest: requested channel does not exist");
856 return returnStatus(ipmbResponseStatus::invalid_param);
857 }
858
859 // check outstanding request list for valid sequence number
860 uint8_t seqNum = 0;
861 bool seqValid = channel->seqNumGet(seqNum);
862 if (!seqValid)
863 {
864 phosphor::logging::log<phosphor::logging::level::WARNING>(
865 "ipmbHandleRequest: cannot add more requests to the list");
866 return returnStatus(ipmbResponseStatus::busy);
867 }
868
869 uint8_t bmcSlaveAddress = channel->getBmcSlaveAddress();
870 uint8_t rqSlaveAddress = channel->getRqSlaveAddress();
871
872 // construct the request to add it to outstanding request list
873 std::shared_ptr<IpmbRequest> request = std::make_shared<IpmbRequest>(
874 rqSlaveAddress, netfn, ipmbRsLun, bmcSlaveAddress, seqNum, lun, cmd,
875 dataReceived);
876
877 if (!request->timer)
878 {
879 phosphor::logging::log<phosphor::logging::level::ERR>(
880 "ipmbHandleRequest: timer object does not exist");
881 return returnStatus(ipmbResponseStatus::error);
882 }
883
884 return channel->requestAdd(yield, request);
885};
886
Qiang XU8edcf1a2019-06-14 22:18:15 +0800887void addUpdateSlaveAddrHandler()
888{
889 // callback to handle dbus signal of updating slave addr
890 std::function<void(sdbusplus::message::message &)> updateSlaveAddrHandler =
891 [](sdbusplus::message::message &message) {
892 uint8_t reqChannel, busId, slaveAddr;
893
894 // valid source of signal, check whether from multi-node manager
895 std::string pathName = message.get_path();
896 if (pathName != "/xyz/openbmc_project/MultiNode/Status")
897 {
898 phosphor::logging::log<phosphor::logging::level::ERR>(
899 "addUpdateSlaveAddrHandler: invalid obj path");
900 return;
901 }
902
903 message.read(reqChannel, busId, slaveAddr);
904
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530905 IpmbChannel *channel = getChannel(reqChannel);
906
Qiang XU8edcf1a2019-06-14 22:18:15 +0800907 if (channel == nullptr ||
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530908 channel->getChannelType() != ipmbChannelType::ipmb)
Qiang XU8edcf1a2019-06-14 22:18:15 +0800909 {
910 phosphor::logging::log<phosphor::logging::level::ERR>(
911 "addUpdateSlaveAddrHandler: invalid channel");
912 return;
913 }
914 if (busId != channel->getBusId())
915 {
916 phosphor::logging::log<phosphor::logging::level::ERR>(
917 "addUpdateSlaveAddrHandler: invalid busId");
918 return;
919 }
920 if (channel->getBmcSlaveAddress() == slaveAddr)
921 {
922 phosphor::logging::log<phosphor::logging::level::INFO>(
923 "addUpdateSlaveAddrHandler: channel bmc slave addr is "
924 "unchanged, do nothing");
925 return;
926 }
927
928 channel->ipmbChannelUpdateSlaveAddress(slaveAddr);
929 };
930
931 static auto match = std::make_unique<sdbusplus::bus::match::match>(
932 static_cast<sdbusplus::bus::bus &>(*conn),
933 "type='signal',member='updateBmcSlaveAddr',", updateSlaveAddrHandler);
934}
935
Qiang XUbbfd00a2019-06-27 21:10:06 +0800936void addSendBroadcastHandler()
937{
938 // callback to handle dbus signal of sending broadcast message
939 std::function<void(sdbusplus::message::message &)> sendBroadcastHandler =
940 [](sdbusplus::message::message &message) {
941 uint8_t reqChannel, netFn, lun, cmd;
942 std::vector<uint8_t> dataReceived;
943 message.read(reqChannel, netFn, lun, cmd, dataReceived);
944
Kumar Thangavel950a2e82020-07-10 18:07:33 +0530945 IpmbChannel *channel = getChannel(reqChannel);
946
Qiang XUbbfd00a2019-06-27 21:10:06 +0800947 if (channel == nullptr)
948 {
949 phosphor::logging::log<phosphor::logging::level::ERR>(
950 "addSendBroadcastMsgHandler: requested channel does not "
951 "exist");
952 return;
953 }
954
955 uint8_t bmcSlaveAddress = channel->getBmcSlaveAddress();
956 uint8_t seqNum = 0; // seqNum is not used in broadcast msg
957 uint8_t targetAddr = broadcastAddress;
958
959 std::shared_ptr<IpmbRequest> request =
960 std::make_shared<IpmbRequest>(targetAddr, netFn, ipmbRsLun,
961 bmcSlaveAddress, seqNum, lun, cmd,
962 dataReceived);
963
964 std::shared_ptr<std::vector<uint8_t>> buffer =
965 std::make_shared<std::vector<uint8_t>>();
966
967 if (request->ipmbToi2cConstruct(*buffer) != 0)
968 {
969 return;
970 }
971
972 channel->ipmbSendI2cFrame(buffer);
973 };
974
975 static auto match = std::make_unique<sdbusplus::bus::match::match>(
976 static_cast<sdbusplus::bus::bus &>(*conn),
977 "type='signal',member='sendBroadcast',", sendBroadcastHandler);
978}
979
Dawid Fryckia642a942018-06-12 10:44:23 -0700980/**
981 * @brief Main
982 */
983int main(int argc, char *argv[])
984{
985 conn->request_name(ipmbBus);
986
987 auto server = sdbusplus::asio::object_server(conn);
988
Dawid Fryckia642a942018-06-12 10:44:23 -0700989 std::shared_ptr<sdbusplus::asio::dbus_interface> ipmbIface =
990 server.add_interface(ipmbObj, ipmbDbusIntf);
991
Dawid Fryckia642a942018-06-12 10:44:23 -0700992 ipmbIface->register_method("sendRequest", std::move(ipmbHandleRequest));
Dawid Fryckia642a942018-06-12 10:44:23 -0700993 ipmbIface->initialize();
994
995 if (initializeChannels() < 0)
996 {
997 phosphor::logging::log<phosphor::logging::level::ERR>(
998 "Error initializeChannels");
999 return -1;
1000 }
1001
Qiang XU8edcf1a2019-06-14 22:18:15 +08001002 addUpdateSlaveAddrHandler();
1003
Qiang XUbbfd00a2019-06-27 21:10:06 +08001004 addSendBroadcastHandler();
1005
Dawid Fryckia642a942018-06-12 10:44:23 -07001006 io.run();
1007 return 0;
1008}