clang-format: update with latest
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ie5bec2584d7e8914e333cdb3be28eb96ac786b29
diff --git a/.clang-format b/.clang-format
index dd27708..82c0e2c 100644
--- a/.clang-format
+++ b/.clang-format
@@ -5,22 +5,22 @@
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
-AlignEscapedNewlinesLeft: false
-AlignOperands: true
+AlignEscapedNewlines: Right
+AlignOperands: Align
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
+AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
+AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
-AlwaysBreakTemplateDeclarations: false
+AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
+ AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
@@ -29,20 +29,28 @@
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
+ AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
+BreakInheritanceList: AfterColon
+BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
-DerivePointerAlignment: true
+DeriveLineEnding: false
+DerivePointerAlignment: false
PointerAlignment: Left
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
@@ -51,21 +59,27 @@
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"](gtest|gmock)'
- Priority: 5
+ Priority: 7
- Regex: '^"config.h"'
Priority: -1
- - Regex: '^".*\.hpp"'
+ - Regex: '^".*\.h"'
Priority: 1
- - Regex: '^<.*\.h>'
+ - Regex: '^".*\.hpp"'
Priority: 2
- - Regex: '^<.*'
+ - Regex: '^<.*\.h>'
Priority: 3
- - Regex: '.*'
+ - Regex: '^<.*\.hpp>'
Priority: 4
+ - Regex: '^<.*'
+ Priority: 5
+ - Regex: '.*'
+ Priority: 6
IndentCaseLabels: true
+IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: true
-KeepEmptyLinesAtTheStartOfBlocks: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: OuterScope
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
@@ -73,18 +87,28 @@
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 25
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PointerAlignment: Right
+PenaltyIndentedWhitespace: 0
+QualifierAlignment: Left
+ReferenceAlignment: Left
ReflowComments: true
+RequiresClausePosition: OwnLine
SortIncludes: true
+SortUsingDeclarations: true
SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
@@ -92,7 +116,9 @@
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
-Standard: Cpp11
+Standard: Latest
TabWidth: 4
+UseCRLF: false
UseTab: Never
...
+
diff --git a/ipmbbridged.cpp b/ipmbbridged.cpp
index 366707f..78b1c7f 100644
--- a/ipmbbridged.cpp
+++ b/ipmbbridged.cpp
@@ -21,20 +21,21 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/write.hpp>
+#include <nlohmann/json.hpp>
+#include <phosphor-logging/log.hpp>
+
#include <filesystem>
#include <fstream>
#include <list>
-#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
#include <tuple>
#include <unordered_map>
/**
* @brief Dbus
*/
-static constexpr const char *ipmbBus = "xyz.openbmc_project.Ipmi.Channel.Ipmb";
-static constexpr const char *ipmbObj = "/xyz/openbmc_project/Ipmi/Channel/Ipmb";
-static constexpr const char *ipmbDbusIntf = "org.openbmc.Ipmb";
+static constexpr const char* ipmbBus = "xyz.openbmc_project.Ipmi.Channel.Ipmb";
+static constexpr const char* ipmbObj = "/xyz/openbmc_project/Ipmi/Channel/Ipmb";
+static constexpr const char* ipmbDbusIntf = "org.openbmc.Ipmb";
boost::asio::io_context io;
auto conn = std::make_shared<sdbusplus::asio::connection>(io);
@@ -54,7 +55,7 @@
IpmbRequest::IpmbRequest(uint8_t address, uint8_t netFn, uint8_t rsLun,
uint8_t rqSA, uint8_t seq, uint8_t rqLun, uint8_t cmd,
- const std::vector<uint8_t> &inputData) :
+ const std::vector<uint8_t>& inputData) :
address(address),
netFn(netFn), rsLun(rsLun), rqSA(rqSA), seq(seq), rqLun(rqLun), cmd(cmd),
timer(io)
@@ -68,7 +69,7 @@
}
}
-void IpmbRequest::i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer,
+void IpmbRequest::i2cToIpmbConstruct(IPMB_HEADER* ipmbBuffer,
size_t bufferLength)
{
// constructing ipmb request from i2c buffer
@@ -79,9 +80,9 @@
rqLun = ipmbLunFromSeqLunGet(ipmbBuffer->Header.Req.rqSeqLUN);
cmd = ipmbBuffer->Header.Req.cmd;
- size_t dataLength =
- bufferLength - (ipmbConnectionHeaderLength +
- ipmbRequestDataHeaderLength + ipmbChecksumSize);
+ size_t dataLength = bufferLength -
+ (ipmbConnectionHeaderLength +
+ ipmbRequestDataHeaderLength + ipmbChecksumSize);
if (dataLength > 0)
{
@@ -90,7 +91,7 @@
}
}
-int IpmbRequest::ipmbToi2cConstruct(std::vector<uint8_t> &buffer)
+int IpmbRequest::ipmbToi2cConstruct(std::vector<uint8_t>& buffer)
{
/* Add one byte for length byte as per required by driver */
size_t bufferLength = 1 + data.size() + ipmbRequestDataHeaderLength +
@@ -103,9 +104,9 @@
buffer.resize(bufferLength);
static_assert(ipmbMaxFrameLength >= sizeof(IPMB_HEADER));
- IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer.data());
+ IPMB_PKT* ipmbPkt = reinterpret_cast<IPMB_PKT*>(buffer.data());
ipmbPkt->len = bufferLength - 1;
- IPMB_HEADER *ipmbBuffer = &(ipmbPkt->hdr);
+ IPMB_HEADER* ipmbBuffer = &(ipmbPkt->hdr);
// constructing buffer from ipmb request
ipmbBuffer->Header.Req.address = address;
@@ -115,7 +116,7 @@
ipmbBuffer->Header.Req.cmd = cmd;
ipmbBuffer->Header.Req.checksum1 = ipmbChecksumCompute(
- (uint8_t *)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
+ (uint8_t*)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
if (data.size() > 0)
{
@@ -123,7 +124,7 @@
}
buffer[bufferLength - ipmbChecksumSize] =
- ipmbChecksumCompute((uint8_t *)ipmbBuffer + ipmbChecksum2StartOffset,
+ ipmbChecksumCompute((uint8_t*)ipmbBuffer + ipmbChecksum2StartOffset,
(ipmbRequestDataHeaderLength + data.size()));
return 0;
@@ -157,7 +158,7 @@
IpmbResponse::IpmbResponse(uint8_t address, uint8_t netFn, uint8_t rqLun,
uint8_t rsSA, uint8_t seq, uint8_t rsLun,
uint8_t cmd, uint8_t completionCode,
- const std::vector<uint8_t> &inputData) :
+ const std::vector<uint8_t>& inputData) :
address(address),
netFn(netFn), rqLun(rqLun), rsSA(rsSA), seq(seq), rsLun(rsLun), cmd(cmd),
completionCode(completionCode)
@@ -170,7 +171,7 @@
}
}
-void IpmbResponse::i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer,
+void IpmbResponse::i2cToIpmbConstruct(IPMB_HEADER* ipmbBuffer,
size_t bufferLength)
{
netFn = ipmbNetFnGet(ipmbBuffer->Header.Resp.rqNetFnLUN);
@@ -181,9 +182,9 @@
cmd = ipmbBuffer->Header.Resp.cmd;
completionCode = ipmbBuffer->Header.Resp.completionCode;
- size_t dataLength =
- bufferLength - (ipmbConnectionHeaderLength +
- ipmbResponseDataHeaderLength + ipmbChecksumSize);
+ size_t dataLength = bufferLength -
+ (ipmbConnectionHeaderLength +
+ ipmbResponseDataHeaderLength + ipmbChecksumSize);
if (dataLength > 0)
{
@@ -206,9 +207,9 @@
std::shared_ptr<std::vector<uint8_t>> buffer =
std::make_shared<std::vector<uint8_t>>(bufferLength);
- IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer->data());
+ IPMB_PKT* ipmbPkt = reinterpret_cast<IPMB_PKT*>(buffer->data());
ipmbPkt->len = bufferLength - 1;
- IPMB_HEADER *ipmbBuffer = &(ipmbPkt->hdr);
+ IPMB_HEADER* ipmbBuffer = &(ipmbPkt->hdr);
ipmbBuffer->Header.Resp.address = address;
ipmbBuffer->Header.Resp.rqNetFnLUN = ipmbNetFnLunSet(netFn, rqLun);
@@ -218,7 +219,7 @@
ipmbBuffer->Header.Resp.completionCode = completionCode;
ipmbBuffer->Header.Resp.checksum1 = ipmbChecksumCompute(
- (uint8_t *)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
+ (uint8_t*)ipmbBuffer, ipmbConnectionHeaderLength - ipmbChecksumSize);
if (data.size() > 0)
{
@@ -226,7 +227,7 @@
}
(*buffer)[bufferLength - ipmbChecksumSize] =
- ipmbChecksumCompute((uint8_t *)ipmbBuffer + ipmbChecksum2StartOffset,
+ ipmbChecksumCompute((uint8_t*)ipmbBuffer + ipmbChecksum2StartOffset,
(ipmbResponseDataHeaderLength + data.size()));
return buffer;
@@ -261,40 +262,40 @@
void IpmbChannel::ipmbSendI2cFrame(std::shared_ptr<std::vector<uint8_t>> buffer,
size_t retriesAttempted = 0)
{
- IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer->data());
+ IPMB_PKT* ipmbPkt = reinterpret_cast<IPMB_PKT*>(buffer->data());
uint8_t targetAddr = ipmbIsResponse(&(ipmbPkt->hdr))
? ipmbPkt->hdr.Header.Resp.address
: ipmbPkt->hdr.Header.Req.address;
boost::asio::async_write(
i2cSlaveDescriptor, boost::asio::buffer(*buffer),
[this, buffer, retriesAttempted,
- targetAddr](const boost::system::error_code &ec, size_t bytesSent) {
- if (ec)
- {
- size_t currentRetryCnt = retriesAttempted;
+ targetAddr](const boost::system::error_code& ec, size_t bytesSent) {
+ if (ec)
+ {
+ size_t currentRetryCnt = retriesAttempted;
- if (currentRetryCnt > ipmbI2cNumberOfRetries)
- {
- std::string msgToLog =
- "ipmbSendI2cFrame: send to I2C failed after retries."
- " busId=" +
- std::to_string(ipmbBusId) +
- ", targetAddr=" + std::to_string(targetAddr) +
- ", error=" + ec.message();
- phosphor::logging::log<phosphor::logging::level::ERR>(
- msgToLog.c_str());
- return;
- }
- currentRetryCnt++;
- ipmbSendI2cFrame(buffer, currentRetryCnt);
+ if (currentRetryCnt > ipmbI2cNumberOfRetries)
+ {
+ std::string msgToLog =
+ "ipmbSendI2cFrame: send to I2C failed after retries."
+ " busId=" +
+ std::to_string(ipmbBusId) +
+ ", targetAddr=" + std::to_string(targetAddr) +
+ ", error=" + ec.message();
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ msgToLog.c_str());
+ return;
}
+ currentRetryCnt++;
+ ipmbSendI2cFrame(buffer, currentRetryCnt);
+ }
});
}
/**
* @brief Ipmb Outstanding Requests
*/
-void IpmbChannel::makeRequestInvalid(IpmbRequest &request)
+void IpmbChannel::makeRequestInvalid(IpmbRequest& request)
{
// change request state to invalid and remove it from outstanding requests
// list
@@ -309,7 +310,7 @@
outstandingRequests[request->seq] = request;
}
-bool IpmbChannel::seqNumGet(uint8_t &seq)
+bool IpmbChannel::seqNumGet(uint8_t& seq)
{
static uint8_t seqNum = 0;
@@ -331,7 +332,7 @@
return false;
}
-void IpmbChannel::responseMatch(std::unique_ptr<IpmbResponse> &response)
+void IpmbChannel::responseMatch(std::unique_ptr<IpmbResponse>& response)
{
std::shared_ptr<IpmbRequest> request = outstandingRequests[response->seq];
@@ -353,8 +354,8 @@
void IpmbChannel::processI2cEvent()
{
std::array<uint8_t, ipmbMaxFrameLength> buffer{};
- IPMB_PKT *ipmbPkt = reinterpret_cast<IPMB_PKT *>(buffer.data());
- IPMB_HEADER *ipmbFrame = &(ipmbPkt->hdr);
+ IPMB_PKT* ipmbPkt = reinterpret_cast<IPMB_PKT*>(buffer.data());
+ IPMB_HEADER* ipmbFrame = &(ipmbPkt->hdr);
lseek(ipmbi2cSlaveFd, 0, SEEK_SET);
int r = read(ipmbi2cSlaveFd, buffer.data(), ipmbMaxFrameLength);
@@ -378,8 +379,8 @@
{
auto ipmbMessageReceived = IpmbRequest();
ipmbMessageReceived.i2cToIpmbConstruct(ipmbFrame, r);
- sdbusplus::message_t msg =
- conn->new_signal(ipmbObj, ipmbDbusIntf, "receiveBroadcast");
+ sdbusplus::message_t msg = conn->new_signal(ipmbObj, ipmbDbusIntf,
+ "receiveBroadcast");
msg.append(ipmbMessageReceived.netFn, ipmbMessageReceived.cmd,
ipmbMessageReceived.data);
msg.signal_send();
@@ -441,65 +442,65 @@
conn->async_method_call(
[this, rqLun{ipmbMessageReceived.rqLun},
seq{ipmbMessageReceived.seq}, address{ipmbMessageReceived.rqSA}](
- const boost::system::error_code &ec,
- const IpmiDbusRspType &response) {
- const auto &[netfn, lun, cmd, cc, payload] = response;
- if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "processI2cEvent: error getting response from IPMI");
- return;
- }
+ const boost::system::error_code& ec,
+ const IpmiDbusRspType& response) {
+ const auto& [netfn, lun, cmd, cc, payload] = response;
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "processI2cEvent: error getting response from IPMI");
+ return;
+ }
- uint8_t bmcSlaveAddress = getBmcSlaveAddress();
+ uint8_t bmcSlaveAddress = getBmcSlaveAddress();
- if (payload.size() > ipmbMaxDataSize)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "processI2cEvent: response exceeding maximum size");
+ if (payload.size() > ipmbMaxDataSize)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "processI2cEvent: response exceeding maximum size");
- // prepare generic response
- auto ipmbResponse = IpmbResponse(
- address, netfn, rqLun, bmcSlaveAddress, seq, ipmbRsLun,
- cmd, ipmbIpmiCmdRespNotProvided, {});
-
- auto buffer = ipmbResponse.ipmbToi2cConstruct();
- if (buffer)
- {
- ipmbSendI2cFrame(buffer);
- }
-
- return;
- }
-
- if (!(netfn & ipmbNetFnResponseMask))
- {
- // we are not expecting request here
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "processI2cEvent: got a request instead of response");
- return;
- }
-
- // if command is not supported, add it to filter
- if (cc == ipmbIpmiInvalidCmd)
- {
- addFilter(ipmbReqNetFnFromRespNetFn(netfn), cmd);
- }
-
- // payload is empty after constructor invocation
- auto ipmbResponse =
- IpmbResponse(address, netfn, rqLun, bmcSlaveAddress, seq,
- lun, cmd, cc, payload);
+ // prepare generic response
+ auto ipmbResponse = IpmbResponse(
+ address, netfn, rqLun, bmcSlaveAddress, seq, ipmbRsLun, cmd,
+ ipmbIpmiCmdRespNotProvided, {});
auto buffer = ipmbResponse.ipmbToi2cConstruct();
- if (!buffer)
+ if (buffer)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "processI2cEvent: error constructing a request");
- return;
+ ipmbSendI2cFrame(buffer);
}
- ipmbSendI2cFrame(buffer);
+ return;
+ }
+
+ if (!(netfn & ipmbNetFnResponseMask))
+ {
+ // we are not expecting request here
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "processI2cEvent: got a request instead of response");
+ return;
+ }
+
+ // if command is not supported, add it to filter
+ if (cc == ipmbIpmiInvalidCmd)
+ {
+ addFilter(ipmbReqNetFnFromRespNetFn(netfn), cmd);
+ }
+
+ // payload is empty after constructor invocation
+ auto ipmbResponse = IpmbResponse(address, netfn, rqLun,
+ bmcSlaveAddress, seq, lun, cmd, cc,
+ payload);
+
+ auto buffer = ipmbResponse.ipmbToi2cConstruct();
+ if (!buffer)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "processI2cEvent: error constructing a request");
+ return;
+ }
+
+ ipmbSendI2cFrame(buffer);
},
"xyz.openbmc_project.Ipmi.Host", "/xyz/openbmc_project/Ipmi",
"xyz.openbmc_project.Ipmi.Server", "execute",
@@ -510,19 +511,19 @@
end:
i2cSlaveDescriptor.async_wait(
boost::asio::posix::descriptor_base::wait_read,
- [this](const boost::system::error_code &ec) {
- if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error: processI2cEvent()");
- return;
- }
+ [this](const boost::system::error_code& ec) {
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error: processI2cEvent()");
+ return;
+ }
- processI2cEvent();
+ processI2cEvent();
});
}
-IpmbChannel::IpmbChannel(boost::asio::io_context &io,
+IpmbChannel::IpmbChannel(boost::asio::io_context& io,
uint8_t ipmbBmcSlaveAddress,
uint8_t ipmbRqSlaveAddress, uint8_t channelIdx,
std::shared_ptr<IpmbCommandFilter> commandFilter) :
@@ -530,10 +531,9 @@
ipmbBmcSlaveAddress(ipmbBmcSlaveAddress),
ipmbRqSlaveAddress(ipmbRqSlaveAddress), channelIdx(channelIdx),
commandFilter(commandFilter)
-{
-}
+{}
-int IpmbChannel::ipmbChannelInit(const char *ipmbI2cSlave)
+int IpmbChannel::ipmbChannelInit(const char* ipmbI2cSlave)
{
// extract bus id from slave path and save
std::string ipmbI2cSlaveStr(ipmbI2cSlave);
@@ -543,7 +543,7 @@
{
ipmbBusId = std::stoi(busStr);
}
- catch (const std::invalid_argument &)
+ catch (const std::invalid_argument&)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ipmbChannelInit: invalid bus id in slave-path config");
@@ -555,8 +555,8 @@
bool hasSysfs = std::filesystem::exists(ipmbI2cSlave);
if (!hasSysfs)
{
- std::string deviceFileName =
- "/sys/bus/i2c/devices/i2c-" + busStr + "/new_device";
+ std::string deviceFileName = "/sys/bus/i2c/devices/i2c-" + busStr +
+ "/new_device";
std::string para = "ipmb-dev 0x1010"; // init with BMC addr 0x20
std::fstream deviceFile;
deviceFile.open(deviceFileName, std::ios::out);
@@ -583,15 +583,15 @@
i2cSlaveDescriptor.async_wait(
boost::asio::posix::descriptor_base::wait_read,
- [this](const boost::system::error_code &ec) {
- if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error: processI2cEvent()");
- return;
- }
+ [this](const boost::system::error_code& ec) {
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error: processI2cEvent()");
+ return;
+ }
- processI2cEvent();
+ processI2cEvent();
});
return 0;
@@ -627,12 +627,12 @@
// enable new I2C slave driver by command:
// echo "ipmb-dev 0x1012" > /sys/bus/i2c/devices/i2c-0/new_device
- deviceFileName =
- "/sys/bus/i2c/devices/i2c-" + std::to_string(ipmbBusId) + "/new_device";
+ deviceFileName = "/sys/bus/i2c/devices/i2c-" + std::to_string(ipmbBusId) +
+ "/new_device";
std::ostringstream hex;
uint16_t addr = 0x1000 + (newBmcSlaveAddr >> 1);
hex << std::hex << static_cast<uint16_t>(addr);
- const std::string &addressHexStr = hex.str();
+ const std::string& addressHexStr = hex.str();
para = "ipmb-dev 0x" + addressHexStr;
deviceFile.open(deviceFileName, std::ios::out);
if (!deviceFile.good())
@@ -659,15 +659,15 @@
i2cSlaveDescriptor.assign(ipmbi2cSlaveFd);
i2cSlaveDescriptor.async_wait(
boost::asio::posix::descriptor_base::wait_read,
- [this](const boost::system::error_code &ec) {
- if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error: processI2cEvent()");
- return;
- }
+ [this](const boost::system::error_code& ec) {
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error: processI2cEvent()");
+ return;
+ }
- processI2cEvent();
+ processI2cEvent();
});
ipmbBmcSlaveAddress = newBmcSlaveAddr;
@@ -714,7 +714,7 @@
}
std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
- IpmbChannel::requestAdd(boost::asio::yield_context &yield,
+ IpmbChannel::requestAdd(boost::asio::yield_context& yield,
std::shared_ptr<IpmbRequest> request)
{
makeRequestValid(request);
@@ -777,13 +777,12 @@
return returnStatus(ipmbResponseStatus::timeout);
}
-static IpmbChannel *getChannel(uint8_t reqChannel)
+static IpmbChannel* getChannel(uint8_t reqChannel)
{
- auto channel =
- std::find_if(ipmbChannels.begin(), ipmbChannels.end(),
- [reqChannel](IpmbChannel &channel) {
- return channel.getChannelIdx() == reqChannel;
- });
+ auto channel = std::find_if(ipmbChannels.begin(), ipmbChannels.end(),
+ [reqChannel](IpmbChannel& channel) {
+ return channel.getChannelIdx() == reqChannel;
+ });
if (channel != ipmbChannels.end())
{
return &(*channel);
@@ -797,7 +796,7 @@
std::shared_ptr<IpmbCommandFilter> commandFilter =
std::make_shared<IpmbCommandFilter>();
- constexpr const char *configFilePath =
+ constexpr const char* configFilePath =
"/usr/share/ipmbbridge/ipmb-channels.json";
std::ifstream configFile(configFilePath);
if (!configFile.is_open())
@@ -810,10 +809,10 @@
{
uint8_t devIndex = 0;
auto data = nlohmann::json::parse(configFile, nullptr);
- for (const auto &channelConfig : data["channels"])
+ for (const auto& channelConfig : data["channels"])
{
- const std::string &typeConfig = channelConfig["type"];
- const std::string &slavePath = channelConfig["slave-path"];
+ const std::string& typeConfig = channelConfig["type"];
+ const std::string& slavePath = channelConfig["slave-path"];
uint8_t bmcAddr = channelConfig["bmc-addr"];
uint8_t reqAddr = channelConfig["remote-addr"];
@@ -835,13 +834,13 @@
}
}
}
- catch (const nlohmann::json::exception &e)
+ catch (const nlohmann::json::exception& e)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"initializeChannels: Error parsing config file");
return -1;
}
- catch (const std::out_of_range &e)
+ catch (const std::out_of_range& e)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"initializeChannels: Error invalid type");
@@ -853,7 +852,7 @@
auto ipmbHandleRequest = [](boost::asio::yield_context yield,
uint8_t reqChannel, uint8_t netfn, uint8_t lun,
uint8_t cmd, std::vector<uint8_t> dataReceived) {
- IpmbChannel *channel = getChannel(reqChannel);
+ IpmbChannel* channel = getChannel(reqChannel);
if (channel == nullptr)
{
@@ -893,100 +892,99 @@
void addUpdateSlaveAddrHandler()
{
// callback to handle dbus signal of updating slave addr
- std::function<void(sdbusplus::message_t &)> updateSlaveAddrHandler =
- [](sdbusplus::message_t &message) {
- uint8_t reqChannel, busId, slaveAddr;
+ std::function<void(sdbusplus::message_t&)> updateSlaveAddrHandler =
+ [](sdbusplus::message_t& message) {
+ uint8_t reqChannel, busId, slaveAddr;
- // valid source of signal, check whether from multi-node manager
- std::string pathName = message.get_path();
- if (pathName != "/xyz/openbmc_project/MultiNode/Status")
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "addUpdateSlaveAddrHandler: invalid obj path");
- return;
- }
+ // valid source of signal, check whether from multi-node manager
+ std::string pathName = message.get_path();
+ if (pathName != "/xyz/openbmc_project/MultiNode/Status")
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "addUpdateSlaveAddrHandler: invalid obj path");
+ return;
+ }
- message.read(reqChannel, busId, slaveAddr);
+ message.read(reqChannel, busId, slaveAddr);
- IpmbChannel *channel = getChannel(reqChannel);
+ IpmbChannel* channel = getChannel(reqChannel);
- if (channel == nullptr ||
- channel->getChannelType() != ipmbChannelType::ipmb)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "addUpdateSlaveAddrHandler: invalid channel");
- return;
- }
- if (busId != channel->getBusId())
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "addUpdateSlaveAddrHandler: invalid busId");
- return;
- }
- if (channel->getBmcSlaveAddress() == slaveAddr)
- {
- phosphor::logging::log<phosphor::logging::level::INFO>(
- "addUpdateSlaveAddrHandler: channel bmc slave addr is "
- "unchanged, do nothing");
- return;
- }
+ if (channel == nullptr ||
+ channel->getChannelType() != ipmbChannelType::ipmb)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "addUpdateSlaveAddrHandler: invalid channel");
+ return;
+ }
+ if (busId != channel->getBusId())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "addUpdateSlaveAddrHandler: invalid busId");
+ return;
+ }
+ if (channel->getBmcSlaveAddress() == slaveAddr)
+ {
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "addUpdateSlaveAddrHandler: channel bmc slave addr is "
+ "unchanged, do nothing");
+ return;
+ }
- channel->ipmbChannelUpdateSlaveAddress(slaveAddr);
- };
+ channel->ipmbChannelUpdateSlaveAddress(slaveAddr);
+ };
static auto match = std::make_unique<sdbusplus::bus::match_t>(
- static_cast<sdbusplus::bus_t &>(*conn),
+ static_cast<sdbusplus::bus_t&>(*conn),
"type='signal',member='updateBmcSlaveAddr',", updateSlaveAddrHandler);
}
void addSendBroadcastHandler()
{
// callback to handle dbus signal of sending broadcast message
- std::function<void(sdbusplus::message_t &)> sendBroadcastHandler =
- [](sdbusplus::message_t &message) {
- uint8_t reqChannel, netFn, lun, cmd;
- std::vector<uint8_t> dataReceived;
- message.read(reqChannel, netFn, lun, cmd, dataReceived);
+ std::function<void(sdbusplus::message_t&)> sendBroadcastHandler =
+ [](sdbusplus::message_t& message) {
+ uint8_t reqChannel, netFn, lun, cmd;
+ std::vector<uint8_t> dataReceived;
+ message.read(reqChannel, netFn, lun, cmd, dataReceived);
- IpmbChannel *channel = getChannel(reqChannel);
+ IpmbChannel* channel = getChannel(reqChannel);
- if (channel == nullptr)
- {
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "addSendBroadcastMsgHandler: requested channel does not "
- "exist");
- return;
- }
+ if (channel == nullptr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "addSendBroadcastMsgHandler: requested channel does not "
+ "exist");
+ return;
+ }
- uint8_t bmcSlaveAddress = channel->getBmcSlaveAddress();
- uint8_t seqNum = 0; // seqNum is not used in broadcast msg
- uint8_t targetAddr = broadcastAddress;
+ uint8_t bmcSlaveAddress = channel->getBmcSlaveAddress();
+ uint8_t seqNum = 0; // seqNum is not used in broadcast msg
+ uint8_t targetAddr = broadcastAddress;
- std::shared_ptr<IpmbRequest> request =
- std::make_shared<IpmbRequest>(targetAddr, netFn, ipmbRsLun,
- bmcSlaveAddress, seqNum, lun, cmd,
- dataReceived);
+ std::shared_ptr<IpmbRequest> request = std::make_shared<IpmbRequest>(
+ targetAddr, netFn, ipmbRsLun, bmcSlaveAddress, seqNum, lun, cmd,
+ dataReceived);
- std::shared_ptr<std::vector<uint8_t>> buffer =
- std::make_shared<std::vector<uint8_t>>();
+ std::shared_ptr<std::vector<uint8_t>> buffer =
+ std::make_shared<std::vector<uint8_t>>();
- if (request->ipmbToi2cConstruct(*buffer) != 0)
- {
- return;
- }
+ if (request->ipmbToi2cConstruct(*buffer) != 0)
+ {
+ return;
+ }
- channel->ipmbSendI2cFrame(buffer);
- };
+ channel->ipmbSendI2cFrame(buffer);
+ };
static auto match = std::make_unique<sdbusplus::bus::match_t>(
- static_cast<sdbusplus::bus_t &>(*conn),
+ static_cast<sdbusplus::bus_t&>(*conn),
"type='signal',member='sendBroadcast',", sendBroadcastHandler);
}
/**
* @brief Main
*/
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
conn->request_name(ipmbBus);
diff --git a/ipmbbridged.hpp b/ipmbbridged.hpp
index f13ec8f..77c1dbd 100644
--- a/ipmbbridged.hpp
+++ b/ipmbbridged.hpp
@@ -18,12 +18,14 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/container/flat_set.hpp>
-#include <optional>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/message.hpp>
+
+#include <optional>
#include <vector>
-extern "C" {
+extern "C"
+{
#include <i2c/smbus.h>
#include <linux/i2c-dev.h>
}
@@ -133,7 +135,7 @@
/**
* @brief Ipmb checkers
*/
-constexpr bool ipmbIsResponse(IPMB_HEADER *ipmbHeader)
+constexpr bool ipmbIsResponse(IPMB_HEADER* ipmbHeader)
{
return ipmbNetFnGet(ipmbHeader->Header.Resp.rqNetFnLUN) &
ipmbNetFnResponseMask;
@@ -177,9 +179,9 @@
IpmbResponse(uint8_t address, uint8_t netFn, uint8_t rqLun, uint8_t rsSA,
uint8_t seq, uint8_t rsLun, uint8_t cmd,
- uint8_t completionCode, const std::vector<uint8_t> &inputData);
+ uint8_t completionCode, const std::vector<uint8_t>& inputData);
- void i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer, size_t bufferLength);
+ void i2cToIpmbConstruct(IPMB_HEADER* ipmbBuffer, size_t bufferLength);
std::shared_ptr<std::vector<uint8_t>> ipmbToi2cConstruct();
};
@@ -208,10 +210,10 @@
IpmbRequest(uint8_t address, uint8_t netFn, uint8_t rsLun, uint8_t rqSA,
uint8_t seq, uint8_t rqLun, uint8_t cmd,
- const std::vector<uint8_t> &inputData);
+ const std::vector<uint8_t>& inputData);
- IpmbRequest(const IpmbRequest &) = delete;
- IpmbRequest &operator=(IpmbRequest const &) = delete;
+ IpmbRequest(const IpmbRequest&) = delete;
+ IpmbRequest& operator=(const IpmbRequest&) = delete;
std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
returnMatchedResponse();
@@ -219,9 +221,9 @@
std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
returnStatusResponse(int status);
- void i2cToIpmbConstruct(IPMB_HEADER *ipmbBuffer, size_t bufferLength);
+ void i2cToIpmbConstruct(IPMB_HEADER* ipmbBuffer, size_t bufferLength);
- int ipmbToi2cConstruct(std::vector<uint8_t> &buffer);
+ int ipmbToi2cConstruct(std::vector<uint8_t>& buffer);
};
/**
@@ -261,18 +263,18 @@
class IpmbChannel
{
public:
- IpmbChannel(boost::asio::io_context &io, uint8_t ipmbBmcSlaveAddress,
+ IpmbChannel(boost::asio::io_context& io, uint8_t ipmbBmcSlaveAddress,
uint8_t ipmbRqSlaveAddress, uint8_t channelIdx,
std::shared_ptr<IpmbCommandFilter> commandFilter);
- IpmbChannel(const IpmbChannel &) = delete;
- IpmbChannel &operator=(IpmbChannel const &) = delete;
+ IpmbChannel(const IpmbChannel&) = delete;
+ IpmbChannel& operator=(const IpmbChannel&) = delete;
- int ipmbChannelInit(const char *ipmbI2cSlave);
+ int ipmbChannelInit(const char* ipmbI2cSlave);
int ipmbChannelUpdateSlaveAddress(const uint8_t newBmcSlaveAddr);
- bool seqNumGet(uint8_t &seq);
+ bool seqNumGet(uint8_t& seq);
ipmbChannelType getChannelType();
@@ -294,7 +296,7 @@
size_t retriesAttempted);
std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>
- requestAdd(boost::asio::yield_context &yield,
+ requestAdd(boost::asio::yield_context& yield,
std::shared_ptr<IpmbRequest> requestToSend);
private:
@@ -316,9 +318,9 @@
void requestTimerCallback(std::shared_ptr<IpmbRequest> request,
std::shared_ptr<std::vector<uint8_t>> buffer);
- void responseMatch(std::unique_ptr<IpmbResponse> &response);
+ void responseMatch(std::unique_ptr<IpmbResponse>& response);
- void makeRequestInvalid(IpmbRequest &request);
+ void makeRequestInvalid(IpmbRequest& request);
void makeRequestValid(std::shared_ptr<IpmbRequest> request);
};
@@ -329,7 +331,7 @@
class ioWrite
{
public:
- ioWrite(std::vector<uint8_t> &buffer)
+ ioWrite(std::vector<uint8_t>& buffer)
{
i2cmsg[0].addr = ipmbAddressTo7BitSet(buffer[0]);
i2cmsg[0].len = buffer.size() - ipmbAddressSize;
@@ -344,7 +346,7 @@
return static_cast<int>(I2C_RDWR);
}
- void *data()
+ void* data()
{
return &msgRdwr;
}
diff --git a/ipmbutils.cpp b/ipmbutils.cpp
index d9a440e..466172b 100644
--- a/ipmbutils.cpp
+++ b/ipmbutils.cpp
@@ -24,7 +24,7 @@
/**
* @brief Ipmb utils for checksum
*/
-bool ipmbChecksumValidate(uint8_t *data, uint8_t length)
+bool ipmbChecksumValidate(uint8_t* data, uint8_t length)
{
uint8_t checksum = 0;
@@ -47,7 +47,7 @@
}
}
-uint8_t ipmbChecksumCompute(uint8_t *data, uint8_t length)
+uint8_t ipmbChecksumCompute(uint8_t* data, uint8_t length)
{
uint8_t checksum = 0;
@@ -63,20 +63,20 @@
return checksum;
}
-inline bool ipmbConnectionHeaderChecksumValidate(IPMB_HEADER *ipmbHeader)
+inline bool ipmbConnectionHeaderChecksumValidate(IPMB_HEADER* ipmbHeader)
{
- return ipmbChecksumValidate(reinterpret_cast<uint8_t *>(ipmbHeader),
+ return ipmbChecksumValidate(reinterpret_cast<uint8_t*>(ipmbHeader),
ipmbConnectionHeaderLength);
}
-inline bool ipmbDataChecksumValidate(IPMB_HEADER *ipmbHeader, uint8_t length)
+inline bool ipmbDataChecksumValidate(IPMB_HEADER* ipmbHeader, uint8_t length)
{
return ipmbChecksumValidate(
- (reinterpret_cast<uint8_t *>(ipmbHeader) + ipmbConnectionHeaderLength),
+ (reinterpret_cast<uint8_t*>(ipmbHeader) + ipmbConnectionHeaderLength),
(length - ipmbConnectionHeaderLength));
}
-bool isFrameValid(IPMB_HEADER *frame, uint8_t length)
+bool isFrameValid(IPMB_HEADER* frame, uint8_t length)
{
bool frameValid = ipmbConnectionHeaderChecksumValidate(frame);
if (false == frameValid)
diff --git a/ipmbutils.hpp b/ipmbutils.hpp
index b6c2139..07b466d 100644
--- a/ipmbutils.hpp
+++ b/ipmbutils.hpp
@@ -19,11 +19,11 @@
/**
* @brief function performing IPMB header and data checksum validation
*/
-bool isFrameValid(IPMB_HEADER *frame, uint8_t length);
+bool isFrameValid(IPMB_HEADER* frame, uint8_t length);
/**
* @brief function computing IPMB layer checksum
*/
-uint8_t ipmbChecksumCompute(uint8_t *data, uint8_t length);
+uint8_t ipmbChecksumCompute(uint8_t* data, uint8_t length);
#endif