clang-format: copy latest and re-format
clang-format-16 has some backwards incompatible changes that require
additional settings for best compatibility and re-running the formatter.
Copy the latest .clang-format from the docs repository and reformat the
repository.
Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: I2036388cb6505a6516b57014fd0dbed121230a07
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..38daa66
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Originally from Linux v5.6
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: true
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ #AfterExternBlock: false # Unknown to clang-format-5.0
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ #SplitEmptyFunction: true # Unknown to clang-format-4.0
+ #SplitEmptyRecord: true # Unknown to clang-format-4.0
+ #SplitEmptyNamespace: true # Unknown to clang-format-4.0
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+#CompactNamespaces: false # Unknown to clang-format-4.0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+#FixNamespaceComments: false # Unknown to clang-format-4.0
+#IncludeBlocks: Preserve # Unknown to clang-format-5.0
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+#IndentPPDirectives: None # Unknown to clang-format-5.0
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: Inner
+#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+#SortUsingDeclarations: false # Unknown to clang-format-4.0
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
+#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
+SpaceBeforeParens: ControlStatements
+#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/ssifbridged.cpp b/ssifbridged.cpp
index 3a07add..ee30df9 100644
--- a/ssifbridged.cpp
+++ b/ssifbridged.cpp
@@ -32,379 +32,379 @@
#include <iostream>
/* Max length of ipmi ssif message included netfn and cmd field */
-#define IPMI_SSIF_PAYLOAD_MAX 254
+#define IPMI_SSIF_PAYLOAD_MAX 254
using namespace phosphor::logging;
struct ipmi_cmd {
- uint8_t netfn;
- uint8_t lun;
- uint8_t cmd;
+ uint8_t netfn;
+ uint8_t lun;
+ uint8_t cmd;
} prev_req_cmd;
static constexpr const char devBase[] = "/dev/ipmi-ssif-host";
/* SSIF use IPMI SSIF channel */
-static constexpr const char* ssifBus =
- "xyz.openbmc_project.Ipmi.Channel.ipmi_ssif";
-static constexpr const char* ssifObj =
- "/xyz/openbmc_project/Ipmi/Channel/ipmi_ssif";
+static constexpr const char *ssifBus =
+ "xyz.openbmc_project.Ipmi.Channel.ipmi_ssif";
+static constexpr const char *ssifObj =
+ "/xyz/openbmc_project/Ipmi/Channel/ipmi_ssif";
/* The timer of driver is set to 15 seconds, need to send
* response before timeout occurs
*/
static constexpr const unsigned int hostReqTimeout = 14000000;
-class SsifChannel
-{
- public:
- static constexpr size_t ssifMessageSize = IPMI_SSIF_PAYLOAD_MAX +
- sizeof(unsigned int);
- size_t sizeofLenField = sizeof(unsigned int);
- static constexpr uint8_t netFnShift = 2;
- static constexpr uint8_t lunMask = (1 << netFnShift) - 1;
+class SsifChannel {
+ public:
+ static constexpr size_t ssifMessageSize =
+ IPMI_SSIF_PAYLOAD_MAX + sizeof(unsigned int);
+ size_t sizeofLenField = sizeof(unsigned int);
+ static constexpr uint8_t netFnShift = 2;
+ static constexpr uint8_t lunMask = (1 << netFnShift) - 1;
- SsifChannel(std::shared_ptr<boost::asio::io_context>& io,
- std::shared_ptr<sdbusplus::asio::connection>& bus,
- const std::string& channel, bool verbose,
- int numberOfReqNotRsp);
- bool initOK() const
- {
- return !!dev;
- }
- void channelAbort(const char* msg, const boost::system::error_code& ec);
- void async_read();
- void processMessage(const boost::system::error_code& ecRd, size_t rlen);
- int showNumOfReqNotRsp();
- std::unique_ptr<boost::asio::posix::stream_descriptor> dev = nullptr;
+ SsifChannel(std::shared_ptr<boost::asio::io_context> &io,
+ std::shared_ptr<sdbusplus::asio::connection> &bus,
+ const std::string &channel, bool verbose,
+ int numberOfReqNotRsp);
+ bool initOK() const
+ {
+ return !!dev;
+ }
+ void channelAbort(const char *msg, const boost::system::error_code &ec);
+ void async_read();
+ void processMessage(const boost::system::error_code &ecRd, size_t rlen);
+ int showNumOfReqNotRsp();
+ std::unique_ptr<boost::asio::posix::stream_descriptor> dev = nullptr;
- protected:
- std::array<uint8_t, ssifMessageSize> xferBuffer;
- std::shared_ptr<boost::asio::io_context> io;
- std::shared_ptr<sdbusplus::asio::connection> bus;
- std::shared_ptr<sdbusplus::asio::object_server> server;
- bool verbose;
- /* This variable is always 0 when a request is responsed properly,
- * any value larger than 0 meaning there is/are request(s) which
- * not processed properly
- * */
- int numberOfReqNotRsp;
+ protected:
+ std::array<uint8_t, ssifMessageSize> xferBuffer;
+ std::shared_ptr<boost::asio::io_context> io;
+ std::shared_ptr<sdbusplus::asio::connection> bus;
+ std::shared_ptr<sdbusplus::asio::object_server> server;
+ bool verbose;
+ /* This variable is always 0 when a request is responsed properly,
+ * any value larger than 0 meaning there is/are request(s) which
+ * not processed properly
+ * */
+ int numberOfReqNotRsp;
};
-std::unique_ptr<phosphor::Timer> rspTimer
- __attribute__((init_priority(101)));
+std::unique_ptr<phosphor::Timer> rspTimer __attribute__((init_priority(101)));
std::unique_ptr<SsifChannel> ssifchannel = nullptr;
-SsifChannel::SsifChannel(std::shared_ptr<boost::asio::io_context>& io,
- std::shared_ptr<sdbusplus::asio::connection>& bus,
- const std::string& device, bool verbose, int numberOfReqNotRsp) :
- io(io),
- bus(bus), verbose(verbose), numberOfReqNotRsp(numberOfReqNotRsp)
+SsifChannel::SsifChannel(std::shared_ptr<boost::asio::io_context> &io,
+ std::shared_ptr<sdbusplus::asio::connection> &bus,
+ const std::string &device, bool verbose,
+ int numberOfReqNotRsp)
+ : io(io), bus(bus), verbose(verbose),
+ numberOfReqNotRsp(numberOfReqNotRsp)
{
- std::string devName = devBase;
- if (!device.empty())
- {
- devName = device;
- }
+ std::string devName = devBase;
+ if (!device.empty()) {
+ devName = device;
+ }
- // open device
- int fd = open(devName.c_str(), O_RDWR | O_NONBLOCK);
- if (fd < 0)
- {
- std::string msgToLog = "Couldn't open SSIF driver with flags O_RDWR."
- " FILENAME=" + devName +
- " ERROR=" + strerror(errno);
- log<level::ERR>(msgToLog.c_str());
- return;
- }
- else
- {
- dev = std::make_unique<boost::asio::posix::stream_descriptor>(*io,
- fd);
- }
+ // open device
+ int fd = open(devName.c_str(), O_RDWR | O_NONBLOCK);
+ if (fd < 0) {
+ std::string msgToLog =
+ "Couldn't open SSIF driver with flags O_RDWR."
+ " FILENAME=" +
+ devName + " ERROR=" + strerror(errno);
+ log<level::ERR>(msgToLog.c_str());
+ return;
+ } else {
+ dev = std::make_unique<boost::asio::posix::stream_descriptor>(
+ *io, fd);
+ }
- async_read();
- // register interfaces...
- server = std::make_shared<sdbusplus::asio::object_server>(bus);
- std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
- server->add_interface(ssifObj, ssifBus);
- iface->initialize();
+ async_read();
+ // register interfaces...
+ server = std::make_shared<sdbusplus::asio::object_server>(bus);
+ std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
+ server->add_interface(ssifObj, ssifBus);
+ iface->initialize();
}
-void SsifChannel::channelAbort(const char* msg,
- const boost::system::error_code& ec)
+void SsifChannel::channelAbort(const char *msg,
+ const boost::system::error_code &ec)
{
- std::string msgToLog = std::string(msg) + " ERROR=" + ec.message();
- log<level::ERR>(msgToLog.c_str());
- // bail; maybe a restart from systemd can clear the error
- io->stop();
+ std::string msgToLog = std::string(msg) + " ERROR=" + ec.message();
+ log<level::ERR>(msgToLog.c_str());
+ // bail; maybe a restart from systemd can clear the error
+ io->stop();
}
void SsifChannel::async_read()
{
- boost::asio::async_read(*dev,
- boost::asio::buffer(xferBuffer, xferBuffer.size()),
- boost::asio::transfer_at_least(2),
- [this](const boost::system::error_code& ec,
- size_t rlen) {
- processMessage(ec, rlen);
- });
+ boost::asio::async_read(
+ *dev, boost::asio::buffer(xferBuffer, xferBuffer.size()),
+ boost::asio::transfer_at_least(2),
+ [this](const boost::system::error_code &ec, size_t rlen) {
+ processMessage(ec, rlen);
+ });
}
int SsifChannel::showNumOfReqNotRsp()
{
- return numberOfReqNotRsp;
+ return numberOfReqNotRsp;
}
void rspTimerHandler()
{
- std::vector<uint8_t> rsp;
- constexpr uint8_t ccResponseNotAvailable = 0xce;
+ std::vector<uint8_t> rsp;
+ constexpr uint8_t ccResponseNotAvailable = 0xce;
- rsp.resize(ssifchannel->sizeofLenField +
- sizeof(prev_req_cmd.cmd) +
- sizeof(prev_req_cmd.netfn) +
- sizeof(ccResponseNotAvailable));
- std::string msgToLog = "timeout, send response to keep host alive"
- " netfn=" + std::to_string(prev_req_cmd.netfn) +
- " lun=" + std::to_string(prev_req_cmd.lun) +
- " cmd=" + std::to_string(prev_req_cmd.cmd) +
- " cc=" + std::to_string(ccResponseNotAvailable) +
- " numberOfReqNotRsp=" +
- std::to_string(ssifchannel->showNumOfReqNotRsp());
- log<level::INFO>(msgToLog.c_str());
+ rsp.resize(ssifchannel->sizeofLenField + sizeof(prev_req_cmd.cmd) +
+ sizeof(prev_req_cmd.netfn) + sizeof(ccResponseNotAvailable));
+ std::string msgToLog =
+ "timeout, send response to keep host alive"
+ " netfn=" +
+ std::to_string(prev_req_cmd.netfn) +
+ " lun=" + std::to_string(prev_req_cmd.lun) +
+ " cmd=" + std::to_string(prev_req_cmd.cmd) +
+ " cc=" + std::to_string(ccResponseNotAvailable) +
+ " numberOfReqNotRsp=" +
+ std::to_string(ssifchannel->showNumOfReqNotRsp());
+ log<level::INFO>(msgToLog.c_str());
- unsigned int *t = (unsigned int *)&rsp[0];
- *t = 3;
- rsp[ssifchannel->sizeofLenField] =
- ((prev_req_cmd.netfn + 1) << ssifchannel->netFnShift) |
- (prev_req_cmd.lun & ssifchannel->lunMask);
- rsp[ssifchannel->sizeofLenField + 1] = prev_req_cmd.cmd;
- rsp[ssifchannel->sizeofLenField + 2] = ccResponseNotAvailable;
+ unsigned int *t = (unsigned int *)&rsp[0];
+ *t = 3;
+ rsp[ssifchannel->sizeofLenField] =
+ ((prev_req_cmd.netfn + 1) << ssifchannel->netFnShift) |
+ (prev_req_cmd.lun & ssifchannel->lunMask);
+ rsp[ssifchannel->sizeofLenField + 1] = prev_req_cmd.cmd;
+ rsp[ssifchannel->sizeofLenField + 2] = ccResponseNotAvailable;
- boost::system::error_code ecWr;
+ boost::system::error_code ecWr;
- size_t wlen =
- boost::asio::write(*(ssifchannel->dev),
- boost::asio::buffer(rsp), ecWr);
- if (ecWr || wlen != rsp.size())
- {
- msgToLog = "Failed to send ssif respond message:"
- " size=" + std::to_string(wlen) +
- " expect=" + std::to_string(rsp.size()) +
- " error=" + ecWr.message() +
- " netfn=" + std::to_string(prev_req_cmd.netfn + 1) +
- " lun=" + std::to_string(prev_req_cmd.lun) +
- " cmd=" +
- std::to_string(rsp[ssifchannel->sizeofLenField + 1]) +
- " cc=" + std::to_string(ccResponseNotAvailable);
- log<level::ERR>(msgToLog.c_str());
- }
+ size_t wlen = boost::asio::write(*(ssifchannel->dev),
+ boost::asio::buffer(rsp), ecWr);
+ if (ecWr || wlen != rsp.size()) {
+ msgToLog =
+ "Failed to send ssif respond message:"
+ " size=" +
+ std::to_string(wlen) +
+ " expect=" + std::to_string(rsp.size()) +
+ " error=" + ecWr.message() +
+ " netfn=" + std::to_string(prev_req_cmd.netfn + 1) +
+ " lun=" + std::to_string(prev_req_cmd.lun) + " cmd=" +
+ std::to_string(rsp[ssifchannel->sizeofLenField + 1]) +
+ " cc=" + std::to_string(ccResponseNotAvailable);
+ log<level::ERR>(msgToLog.c_str());
+ }
}
void initTimer()
{
- if (!rspTimer)
- {
- rspTimer =
- std::make_unique<phosphor::Timer>(rspTimerHandler);
- }
+ if (!rspTimer) {
+ rspTimer = std::make_unique<phosphor::Timer>(rspTimerHandler);
+ }
}
-void SsifChannel::processMessage(const boost::system::error_code& ecRd,
- size_t rlen)
+void SsifChannel::processMessage(const boost::system::error_code &ecRd,
+ size_t rlen)
{
- if (ecRd || rlen < 2)
- {
- channelAbort("Failed to read req msg", ecRd);
- return;
- }
- async_read();
+ if (ecRd || rlen < 2) {
+ channelAbort("Failed to read req msg", ecRd);
+ return;
+ }
+ async_read();
- auto rawIter = xferBuffer.cbegin();
- auto rawEnd = rawIter + rlen;
- uint8_t netfn = rawIter[sizeofLenField] >> netFnShift;
- uint8_t lun = rawIter[sizeofLenField] & lunMask;
- uint8_t cmd = rawIter[sizeofLenField + 1];
+ auto rawIter = xferBuffer.cbegin();
+ auto rawEnd = rawIter + rlen;
+ uint8_t netfn = rawIter[sizeofLenField] >> netFnShift;
+ uint8_t lun = rawIter[sizeofLenField] & lunMask;
+ uint8_t cmd = rawIter[sizeofLenField + 1];
- /* keep track of previous request */
- prev_req_cmd.netfn = netfn;
- prev_req_cmd.lun = lun;
- prev_req_cmd.cmd = cmd;
+ /* keep track of previous request */
+ prev_req_cmd.netfn = netfn;
+ prev_req_cmd.lun = lun;
+ prev_req_cmd.cmd = cmd;
- /* there is a request coming */
- numberOfReqNotRsp++;
- /* start response timer */
- rspTimer->start(std::chrono::microseconds(hostReqTimeout), false);
+ /* there is a request coming */
+ numberOfReqNotRsp++;
+ /* start response timer */
+ rspTimer->start(std::chrono::microseconds(hostReqTimeout), false);
- if (verbose)
- {
- unsigned int lenRecv;
- unsigned int *p = (unsigned int *) rawIter;
- lenRecv = p[0];
- std::string msgToLog = "Read ssif request message with"
- " len=" + std::to_string(lenRecv) +
- " netfn=" + std::to_string(netfn) +
- " lun=" + std::to_string(lun) +
- " cmd=" + std::to_string(cmd) +
- " numberOfReqNotRsp=" +
- std::to_string(numberOfReqNotRsp);
- log<level::INFO>(msgToLog.c_str());
- }
- // copy out payload
- std::vector<uint8_t> data(rawIter + sizeofLenField + 2, rawEnd);
- // non-session bridges still need to pass an empty options map
- std::map<std::string, std::variant<int>> options;
- // the response is a tuple because dbus can only return a single value
- using IpmiDbusRspType = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t,
- std::vector<uint8_t>>;
- static constexpr const char ipmiQueueService[] =
- "xyz.openbmc_project.Ipmi.Host";
- static constexpr const char ipmiQueuePath[] =
- "/xyz/openbmc_project/Ipmi";
- static constexpr const char ipmiQueueIntf[] =
- "xyz.openbmc_project.Ipmi.Server";
- static constexpr const char ipmiQueueMethod[] = "execute";
- /* now, we do not care dbus timeout, since we already have actions
- * before dbus timeout occurs
- */
- static constexpr unsigned int dbusTimeout = 60000000;
- bus->async_method_call_timed(
- [this, netfnCap{netfn}, lunCap{lun},
- cmdCap{cmd}](const boost::system::error_code& ec,
- const IpmiDbusRspType& response) {
- std::vector<uint8_t> rsp;
- const auto& [netfn, lun, cmd, cc, payload] = response;
- numberOfReqNotRsp--;
- if (ec)
- {
- std::string msgToLog = "ssif<->ipmid bus error:"
- " netfn=" + std::to_string(netfn) +
- " lun=" + std::to_string(lun) +
- " cmd=" + std::to_string(cmd) +
- " error=" + ec.message();
- log<level::ERR>(msgToLog.c_str());
- rsp.resize(sizeofLenField + sizeof(netfn) + sizeof(cmd) +
- sizeof(cc));
- /* if dbusTimeout, just return and do not send any response
- * to let host continue with other commands, response here
- * is potentially make the response duplicated
- * */
- return;
- }
- else
- {
- if ((prev_req_cmd.netfn != (netfn-1) ||
- prev_req_cmd.lun != lun ||
- prev_req_cmd.cmd != cmd) ||
- ((prev_req_cmd.netfn == (netfn-1) &&
- prev_req_cmd.lun == lun &&
- prev_req_cmd.cmd == cmd) &&
- numberOfReqNotRsp != 0))
- {
- /* Only send response to the last request command to void
- * duplicated response which makes host driver confused and
- * failed to create interface
- *
- * Drop responses which are (1) different from the request
- * (2) parameters are the same as request but handshake flow
- * are in dupplicate request state
- * */
- if (verbose)
- {
- std::string msgToLog = "Drop ssif respond message with"
- " len=" + std::to_string(payload.size() + 3) +
- " netfn=" + std::to_string(netfn) +
- " lun=" + std::to_string(lun) +
- " cmd=" + std::to_string(cmd) +
- " cc=" + std::to_string(cc) +
- " numberOfReqNotRsp=" +
- std::to_string(numberOfReqNotRsp);
- log<level::INFO>(msgToLog.c_str());
- }
- return;
- }
- rsp.resize(sizeofLenField + sizeof(netfn) + sizeof(cmd) +
- sizeof(cc) + payload.size());
+ if (verbose) {
+ unsigned int lenRecv;
+ unsigned int *p = (unsigned int *)rawIter;
+ lenRecv = p[0];
+ std::string msgToLog = "Read ssif request message with"
+ " len=" +
+ std::to_string(lenRecv) +
+ " netfn=" + std::to_string(netfn) +
+ " lun=" + std::to_string(lun) +
+ " cmd=" + std::to_string(cmd) +
+ " numberOfReqNotRsp=" +
+ std::to_string(numberOfReqNotRsp);
+ log<level::INFO>(msgToLog.c_str());
+ }
+ // copy out payload
+ std::vector<uint8_t> data(rawIter + sizeofLenField + 2, rawEnd);
+ // non-session bridges still need to pass an empty options map
+ std::map<std::string, std::variant<int> > options;
+ // the response is a tuple because dbus can only return a single value
+ using IpmiDbusRspType = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t,
+ std::vector<uint8_t> >;
+ static constexpr const char ipmiQueueService[] =
+ "xyz.openbmc_project.Ipmi.Host";
+ static constexpr const char ipmiQueuePath[] =
+ "/xyz/openbmc_project/Ipmi";
+ static constexpr const char ipmiQueueIntf[] =
+ "xyz.openbmc_project.Ipmi.Server";
+ static constexpr const char ipmiQueueMethod[] = "execute";
+ /* now, we do not care dbus timeout, since we already have actions
+ * before dbus timeout occurs
+ */
+ static constexpr unsigned int dbusTimeout = 60000000;
+ bus->async_method_call_timed(
+ [this, netfnCap{ netfn }, lunCap{ lun },
+ cmdCap{ cmd }](const boost::system::error_code &ec,
+ const IpmiDbusRspType &response) {
+ std::vector<uint8_t> rsp;
+ const auto &[netfn, lun, cmd, cc, payload] = response;
+ numberOfReqNotRsp--;
+ if (ec) {
+ std::string msgToLog =
+ "ssif<->ipmid bus error:"
+ " netfn=" +
+ std::to_string(netfn) +
+ " lun=" + std::to_string(lun) +
+ " cmd=" + std::to_string(cmd) +
+ " error=" + ec.message();
+ log<level::ERR>(msgToLog.c_str());
+ rsp.resize(sizeofLenField + sizeof(netfn) +
+ sizeof(cmd) + sizeof(cc));
+ /* if dbusTimeout, just return and do not send any response
+ * to let host continue with other commands, response here
+ * is potentially make the response duplicated
+ * */
+ return;
+ } else {
+ if ((prev_req_cmd.netfn != (netfn - 1) ||
+ prev_req_cmd.lun != lun ||
+ prev_req_cmd.cmd != cmd) ||
+ ((prev_req_cmd.netfn == (netfn - 1) &&
+ prev_req_cmd.lun == lun &&
+ prev_req_cmd.cmd == cmd) &&
+ numberOfReqNotRsp != 0)) {
+ /* Only send response to the last request command to void
+ * duplicated response which makes host driver confused and
+ * failed to create interface
+ *
+ * Drop responses which are (1) different from the request
+ * (2) parameters are the same as request but handshake flow
+ * are in dupplicate request state
+ * */
+ if (verbose) {
+ std::string msgToLog =
+ "Drop ssif respond message with"
+ " len=" +
+ std::to_string(
+ payload.size() +
+ 3) +
+ " netfn=" +
+ std::to_string(netfn) +
+ " lun=" +
+ std::to_string(lun) +
+ " cmd=" +
+ std::to_string(cmd) +
+ " cc=" +
+ std::to_string(cc) +
+ " numberOfReqNotRsp=" +
+ std::to_string(
+ numberOfReqNotRsp);
+ log<level::INFO>(
+ msgToLog.c_str());
+ }
+ return;
+ }
+ rsp.resize(sizeofLenField + sizeof(netfn) +
+ sizeof(cmd) + sizeof(cc) +
+ payload.size());
- // write the response
- auto rspIter = rsp.begin();
- unsigned int *p = (unsigned int *) &rspIter[0];
- *p = payload.size() + 3;
- rspIter[sizeofLenField] = (netfn << netFnShift) | (lun & lunMask);
- rspIter[sizeofLenField + 1] = cmd;
- rspIter[sizeofLenField + 2] = cc;
- if (payload.size())
- {
- std::copy(payload.cbegin(), payload.cend(),
- rspIter + sizeofLenField + 3);
- }
- }
- if (verbose)
- {
- std::string msgToLog = "Send ssif respond message with"
- " len=" + std::to_string(payload.size() + 3) +
- " netfn=" + std::to_string(netfn) +
- " lun=" + std::to_string(lun) +
- " cmd=" + std::to_string(cmd) +
- " cc=" + std::to_string(cc) +
- " numberOfReqNotRsp=" +
- std::to_string(numberOfReqNotRsp);
- log<level::INFO>(msgToLog.c_str());
- }
- boost::system::error_code ecWr;
- size_t wlen =
- boost::asio::write(*dev, boost::asio::buffer(rsp), ecWr);
- if (ecWr || wlen != rsp.size())
- {
- std::string msgToLog = "Failed to send ssif respond message:"
- " size=" + std::to_string(wlen) +
- " expect=" + std::to_string(rsp.size()) +
- " error=" + ecWr.message() +
- " netfn=" + std::to_string(netfn) +
- " lun=" + std::to_string(lun) +
- " cmd=" + std::to_string(cmd) +
- " cc=" + std::to_string(cc);
- log<level::ERR>(msgToLog.c_str());
- }
- rspTimer->stop();
- },
- ipmiQueueService, ipmiQueuePath, ipmiQueueIntf, ipmiQueueMethod, dbusTimeout,
- netfn, lun, cmd, data, options);
+ // write the response
+ auto rspIter = rsp.begin();
+ unsigned int *p = (unsigned int *)&rspIter[0];
+ *p = payload.size() + 3;
+ rspIter[sizeofLenField] =
+ (netfn << netFnShift) | (lun & lunMask);
+ rspIter[sizeofLenField + 1] = cmd;
+ rspIter[sizeofLenField + 2] = cc;
+ if (payload.size()) {
+ std::copy(payload.cbegin(),
+ payload.cend(),
+ rspIter + sizeofLenField + 3);
+ }
+ }
+ if (verbose) {
+ std::string msgToLog =
+ "Send ssif respond message with"
+ " len=" +
+ std::to_string(payload.size() + 3) +
+ " netfn=" + std::to_string(netfn) +
+ " lun=" + std::to_string(lun) +
+ " cmd=" + std::to_string(cmd) +
+ " cc=" + std::to_string(cc) +
+ " numberOfReqNotRsp=" +
+ std::to_string(numberOfReqNotRsp);
+ log<level::INFO>(msgToLog.c_str());
+ }
+ boost::system::error_code ecWr;
+ size_t wlen = boost::asio::write(
+ *dev, boost::asio::buffer(rsp), ecWr);
+ if (ecWr || wlen != rsp.size()) {
+ std::string msgToLog =
+ "Failed to send ssif respond message:"
+ " size=" +
+ std::to_string(wlen) + " expect=" +
+ std::to_string(rsp.size()) +
+ " error=" + ecWr.message() +
+ " netfn=" + std::to_string(netfn) +
+ " lun=" + std::to_string(lun) +
+ " cmd=" + std::to_string(cmd) +
+ " cc=" + std::to_string(cc);
+ log<level::ERR>(msgToLog.c_str());
+ }
+ rspTimer->stop();
+ },
+ ipmiQueueService, ipmiQueuePath, ipmiQueueIntf, ipmiQueueMethod,
+ dbusTimeout, netfn, lun, cmd, data, options);
}
-
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- CLI::App app("SSIF IPMI bridge");
- std::string device;
- app.add_option("-d,--device", device,
- "use <DEVICE> file. Default is /dev/ipmi-ssif-host");
- bool verbose = false;
- int numberOfReqNotRsp = 0;
- app.add_option("-v,--verbose", verbose, "print more verbose output");
- CLI11_PARSE(app, argc, argv);
+ CLI::App app("SSIF IPMI bridge");
+ std::string device;
+ app.add_option("-d,--device", device,
+ "use <DEVICE> file. Default is /dev/ipmi-ssif-host");
+ bool verbose = false;
+ int numberOfReqNotRsp = 0;
+ app.add_option("-v,--verbose", verbose, "print more verbose output");
+ CLI11_PARSE(app, argc, argv);
- // Connect to system bus
- auto io = std::make_shared<boost::asio::io_context>();
- sd_bus* dbus;
- sd_bus_default_system(&dbus);
-
- /* This might be a phosphor::Timer bug, without timer t2, rspTimer
- * will not work
- * */
- phosphor::Timer t2([]() { ; });
- t2.start(std::chrono::microseconds(500000), true);
- auto bus = std::make_shared<sdbusplus::asio::connection>(*io, dbus);
- bus->request_name(ssifBus);
- // Create the SSIF channel, listening on D-Bus and on the SSIF device
- ssifchannel = make_unique<SsifChannel>
- (io, bus, device, verbose, numberOfReqNotRsp);
- if (!ssifchannel->initOK())
- {
- return EXIT_FAILURE;
- }
- initTimer();
- sdbusplus::asio::sd_event_wrapper sdEvents(*io);
- io->run();
+ // Connect to system bus
+ auto io = std::make_shared<boost::asio::io_context>();
+ sd_bus *dbus;
+ sd_bus_default_system(&dbus);
- return 0;
+ /* This might be a phosphor::Timer bug, without timer t2, rspTimer
+ * will not work
+ */
+ phosphor::Timer t2([]() { ; });
+ t2.start(std::chrono::microseconds(500000), true);
+ auto bus = std::make_shared<sdbusplus::asio::connection>(*io, dbus);
+ bus->request_name(ssifBus);
+ // Create the SSIF channel, listening on D-Bus and on the SSIF device
+ ssifchannel = make_unique<SsifChannel>(io, bus, device, verbose,
+ numberOfReqNotRsp);
+ if (!ssifchannel->initOK()) {
+ return EXIT_FAILURE;
+ }
+ initTimer();
+ sdbusplus::asio::sd_event_wrapper sdEvents(*io);
+ io->run();
+
+ return 0;
}