Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Ampere Computing LLC |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * This is a daemon that forwards requests and receive responses from SSIF over |
| 17 | * the D-Bus IPMI Interface. |
| 18 | */ |
| 19 | |
| 20 | #include <getopt.h> |
| 21 | #include <linux/ipmi_bmc.h> |
| 22 | |
| 23 | #include <CLI/CLI.hpp> |
| 24 | #include <boost/algorithm/string/replace.hpp> |
| 25 | #include <boost/asio.hpp> |
| 26 | #include <phosphor-logging/log.hpp> |
| 27 | #include <sdbusplus/asio/connection.hpp> |
| 28 | #include <sdbusplus/asio/object_server.hpp> |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 29 | #include <sdbusplus/timer.hpp> |
| 30 | #include <sdbusplus/asio/sd_event.hpp> |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 31 | |
| 32 | #include <iostream> |
| 33 | |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 34 | /* Max length of ipmi ssif message included netfn and cmd field */ |
| 35 | #define IPMI_SSIF_PAYLOAD_MAX 254 |
| 36 | |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 37 | using namespace phosphor::logging; |
| 38 | |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 39 | struct ipmi_cmd { |
| 40 | uint8_t netfn; |
| 41 | uint8_t lun; |
| 42 | uint8_t cmd; |
| 43 | } prev_req_cmd; |
| 44 | |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 45 | static constexpr const char devBase[] = "/dev/ipmi-ssif-host"; |
| 46 | /* SSIF use IPMI SSIF channel */ |
| 47 | static constexpr const char* ssifBus = |
| 48 | "xyz.openbmc_project.Ipmi.Channel.ipmi_ssif"; |
| 49 | static constexpr const char* ssifObj = |
| 50 | "/xyz/openbmc_project/Ipmi/Channel/ipmi_ssif"; |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 51 | /* The timer of driver is set to 15 seconds, need to send |
| 52 | * response before timeout occurs |
| 53 | */ |
| 54 | static constexpr const unsigned int hostReqTimeout = 14000000; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 55 | |
| 56 | class SsifChannel |
| 57 | { |
| 58 | public: |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 59 | static constexpr size_t ssifMessageSize = IPMI_SSIF_PAYLOAD_MAX + |
| 60 | sizeof(unsigned int); |
| 61 | size_t sizeofLenField = sizeof(unsigned int); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 62 | static constexpr uint8_t netFnShift = 2; |
| 63 | static constexpr uint8_t lunMask = (1 << netFnShift) - 1; |
| 64 | |
| 65 | SsifChannel(std::shared_ptr<boost::asio::io_context>& io, |
| 66 | std::shared_ptr<sdbusplus::asio::connection>& bus, |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 67 | const std::string& channel, bool verbose, |
| 68 | int numberOfReqNotRsp); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 69 | bool initOK() const |
| 70 | { |
| 71 | return !!dev; |
| 72 | } |
| 73 | void channelAbort(const char* msg, const boost::system::error_code& ec); |
| 74 | void async_read(); |
| 75 | void processMessage(const boost::system::error_code& ecRd, size_t rlen); |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 76 | int showNumOfReqNotRsp(); |
| 77 | std::unique_ptr<boost::asio::posix::stream_descriptor> dev = nullptr; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 78 | |
| 79 | protected: |
| 80 | std::array<uint8_t, ssifMessageSize> xferBuffer; |
| 81 | std::shared_ptr<boost::asio::io_context> io; |
| 82 | std::shared_ptr<sdbusplus::asio::connection> bus; |
| 83 | std::shared_ptr<sdbusplus::asio::object_server> server; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 84 | bool verbose; |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 85 | /* This variable is always 0 when a request is responsed properly, |
| 86 | * any value larger than 0 meaning there is/are request(s) which |
| 87 | * not processed properly |
| 88 | * */ |
| 89 | int numberOfReqNotRsp; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 92 | std::unique_ptr<phosphor::Timer> rspTimer |
| 93 | __attribute__((init_priority(101))); |
| 94 | std::unique_ptr<SsifChannel> ssifchannel = nullptr; |
| 95 | |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 96 | SsifChannel::SsifChannel(std::shared_ptr<boost::asio::io_context>& io, |
| 97 | std::shared_ptr<sdbusplus::asio::connection>& bus, |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 98 | const std::string& device, bool verbose, int numberOfReqNotRsp) : |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 99 | io(io), |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 100 | bus(bus), verbose(verbose), numberOfReqNotRsp(numberOfReqNotRsp) |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 101 | { |
| 102 | std::string devName = devBase; |
| 103 | if (!device.empty()) |
| 104 | { |
| 105 | devName = device; |
| 106 | } |
| 107 | |
| 108 | // open device |
| 109 | int fd = open(devName.c_str(), O_RDWR | O_NONBLOCK); |
| 110 | if (fd < 0) |
| 111 | { |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 112 | std::string msgToLog = "Couldn't open SSIF driver with flags O_RDWR." |
| 113 | " FILENAME=" + devName + |
| 114 | " ERROR=" + strerror(errno); |
| 115 | log<level::ERR>(msgToLog.c_str()); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | dev = std::make_unique<boost::asio::posix::stream_descriptor>(*io, |
| 121 | fd); |
| 122 | } |
| 123 | |
| 124 | async_read(); |
| 125 | // register interfaces... |
| 126 | server = std::make_shared<sdbusplus::asio::object_server>(bus); |
| 127 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
| 128 | server->add_interface(ssifObj, ssifBus); |
| 129 | iface->initialize(); |
| 130 | } |
| 131 | |
| 132 | void SsifChannel::channelAbort(const char* msg, |
| 133 | const boost::system::error_code& ec) |
| 134 | { |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 135 | std::string msgToLog = std::string(msg) + " ERROR=" + ec.message(); |
| 136 | log<level::ERR>(msgToLog.c_str()); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 137 | // bail; maybe a restart from systemd can clear the error |
| 138 | io->stop(); |
| 139 | } |
| 140 | |
| 141 | void SsifChannel::async_read() |
| 142 | { |
| 143 | boost::asio::async_read(*dev, |
| 144 | boost::asio::buffer(xferBuffer, xferBuffer.size()), |
| 145 | boost::asio::transfer_at_least(2), |
| 146 | [this](const boost::system::error_code& ec, |
| 147 | size_t rlen) { |
| 148 | processMessage(ec, rlen); |
| 149 | }); |
| 150 | } |
| 151 | |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 152 | int SsifChannel::showNumOfReqNotRsp() |
| 153 | { |
| 154 | return numberOfReqNotRsp; |
| 155 | } |
| 156 | |
| 157 | void rspTimerHandler() |
| 158 | { |
| 159 | std::vector<uint8_t> rsp; |
| 160 | constexpr uint8_t ccResponseNotAvailable = 0xce; |
| 161 | |
| 162 | rsp.resize(ssifchannel->sizeofLenField + |
| 163 | sizeof(prev_req_cmd.cmd) + |
| 164 | sizeof(prev_req_cmd.netfn) + |
| 165 | sizeof(ccResponseNotAvailable)); |
| 166 | std::string msgToLog = "timeout, send response to keep host alive" |
| 167 | " netfn=" + std::to_string(prev_req_cmd.netfn) + |
| 168 | " lun=" + std::to_string(prev_req_cmd.lun) + |
| 169 | " cmd=" + std::to_string(prev_req_cmd.cmd) + |
| 170 | " cc=" + std::to_string(ccResponseNotAvailable) + |
| 171 | " numberOfReqNotRsp=" + |
| 172 | std::to_string(ssifchannel->showNumOfReqNotRsp()); |
| 173 | log<level::INFO>(msgToLog.c_str()); |
| 174 | |
| 175 | unsigned int *t = (unsigned int *)&rsp[0]; |
| 176 | *t = 3; |
| 177 | rsp[ssifchannel->sizeofLenField] = |
| 178 | ((prev_req_cmd.netfn + 1) << ssifchannel->netFnShift) | |
| 179 | (prev_req_cmd.lun & ssifchannel->lunMask); |
| 180 | rsp[ssifchannel->sizeofLenField + 1] = prev_req_cmd.cmd; |
| 181 | rsp[ssifchannel->sizeofLenField + 2] = ccResponseNotAvailable; |
| 182 | |
| 183 | boost::system::error_code ecWr; |
| 184 | |
| 185 | size_t wlen = |
| 186 | boost::asio::write(*(ssifchannel->dev), |
| 187 | boost::asio::buffer(rsp), ecWr); |
| 188 | if (ecWr || wlen != rsp.size()) |
| 189 | { |
| 190 | msgToLog = "Failed to send ssif respond message:" |
| 191 | " size=" + std::to_string(wlen) + |
| 192 | " expect=" + std::to_string(rsp.size()) + |
| 193 | " error=" + ecWr.message() + |
| 194 | " netfn=" + std::to_string(prev_req_cmd.netfn + 1) + |
| 195 | " lun=" + std::to_string(prev_req_cmd.lun) + |
| 196 | " cmd=" + |
| 197 | std::to_string(rsp[ssifchannel->sizeofLenField + 1]) + |
| 198 | " cc=" + std::to_string(ccResponseNotAvailable); |
| 199 | log<level::ERR>(msgToLog.c_str()); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | void initTimer() |
| 204 | { |
| 205 | if (!rspTimer) |
| 206 | { |
| 207 | rspTimer = |
| 208 | std::make_unique<phosphor::Timer>(rspTimerHandler); |
| 209 | } |
| 210 | } |
| 211 | |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 212 | void SsifChannel::processMessage(const boost::system::error_code& ecRd, |
| 213 | size_t rlen) |
| 214 | { |
| 215 | if (ecRd || rlen < 2) |
| 216 | { |
| 217 | channelAbort("Failed to read req msg", ecRd); |
| 218 | return; |
| 219 | } |
| 220 | async_read(); |
| 221 | |
| 222 | auto rawIter = xferBuffer.cbegin(); |
| 223 | auto rawEnd = rawIter + rlen; |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 224 | uint8_t netfn = rawIter[sizeofLenField] >> netFnShift; |
| 225 | uint8_t lun = rawIter[sizeofLenField] & lunMask; |
| 226 | uint8_t cmd = rawIter[sizeofLenField + 1]; |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 227 | |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 228 | /* keep track of previous request */ |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 229 | prev_req_cmd.netfn = netfn; |
| 230 | prev_req_cmd.lun = lun; |
| 231 | prev_req_cmd.cmd = cmd; |
| 232 | |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 233 | /* there is a request coming */ |
| 234 | numberOfReqNotRsp++; |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 235 | /* start response timer */ |
| 236 | rspTimer->start(std::chrono::microseconds(hostReqTimeout), false); |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 237 | |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 238 | if (verbose) |
| 239 | { |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 240 | unsigned int lenRecv; |
| 241 | unsigned int *p = (unsigned int *) rawIter; |
| 242 | lenRecv = p[0]; |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 243 | std::string msgToLog = "Read ssif request message with" |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 244 | " len=" + std::to_string(lenRecv) + |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 245 | " netfn=" + std::to_string(netfn) + |
| 246 | " lun=" + std::to_string(lun) + |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 247 | " cmd=" + std::to_string(cmd) + |
| 248 | " numberOfReqNotRsp=" + |
| 249 | std::to_string(numberOfReqNotRsp); |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 250 | log<level::INFO>(msgToLog.c_str()); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 251 | } |
| 252 | // copy out payload |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 253 | std::vector<uint8_t> data(rawIter + sizeofLenField + 2, rawEnd); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 254 | // non-session bridges still need to pass an empty options map |
| 255 | std::map<std::string, std::variant<int>> options; |
| 256 | // the response is a tuple because dbus can only return a single value |
| 257 | using IpmiDbusRspType = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t, |
| 258 | std::vector<uint8_t>>; |
| 259 | static constexpr const char ipmiQueueService[] = |
| 260 | "xyz.openbmc_project.Ipmi.Host"; |
| 261 | static constexpr const char ipmiQueuePath[] = |
| 262 | "/xyz/openbmc_project/Ipmi"; |
| 263 | static constexpr const char ipmiQueueIntf[] = |
| 264 | "xyz.openbmc_project.Ipmi.Server"; |
| 265 | static constexpr const char ipmiQueueMethod[] = "execute"; |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 266 | /* now, we do not care dbus timeout, since we already have actions |
| 267 | * before dbus timeout occurs |
| 268 | */ |
| 269 | static constexpr unsigned int dbusTimeout = 60000000; |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 270 | bus->async_method_call_timed( |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 271 | [this, netfnCap{netfn}, lunCap{lun}, |
| 272 | cmdCap{cmd}](const boost::system::error_code& ec, |
| 273 | const IpmiDbusRspType& response) { |
| 274 | std::vector<uint8_t> rsp; |
| 275 | const auto& [netfn, lun, cmd, cc, payload] = response; |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 276 | numberOfReqNotRsp--; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 277 | if (ec) |
| 278 | { |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 279 | std::string msgToLog = "ssif<->ipmid bus error:" |
| 280 | " netfn=" + std::to_string(netfn) + |
| 281 | " lun=" + std::to_string(lun) + |
| 282 | " cmd=" + std::to_string(cmd) + |
| 283 | " error=" + ec.message(); |
| 284 | log<level::ERR>(msgToLog.c_str()); |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 285 | rsp.resize(sizeofLenField + sizeof(netfn) + sizeof(cmd) + |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 286 | sizeof(cc)); |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 287 | /* if dbusTimeout, just return and do not send any response |
| 288 | * to let host continue with other commands, response here |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 289 | * is potentially make the response duplicated |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 290 | * */ |
| 291 | return; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 292 | } |
| 293 | else |
| 294 | { |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 295 | if ((prev_req_cmd.netfn != (netfn-1) || |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 296 | prev_req_cmd.lun != lun || |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 297 | prev_req_cmd.cmd != cmd) || |
| 298 | ((prev_req_cmd.netfn == (netfn-1) && |
| 299 | prev_req_cmd.lun == lun && |
| 300 | prev_req_cmd.cmd == cmd) && |
| 301 | numberOfReqNotRsp != 0)) |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 302 | { |
| 303 | /* Only send response to the last request command to void |
| 304 | * duplicated response which makes host driver confused and |
| 305 | * failed to create interface |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 306 | * |
| 307 | * Drop responses which are (1) different from the request |
| 308 | * (2) parameters are the same as request but handshake flow |
| 309 | * are in dupplicate request state |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 310 | * */ |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 311 | if (verbose) |
| 312 | { |
| 313 | std::string msgToLog = "Drop ssif respond message with" |
| 314 | " len=" + std::to_string(payload.size() + 3) + |
| 315 | " netfn=" + std::to_string(netfn) + |
| 316 | " lun=" + std::to_string(lun) + |
| 317 | " cmd=" + std::to_string(cmd) + |
| 318 | " cc=" + std::to_string(cc) + |
| 319 | " numberOfReqNotRsp=" + |
| 320 | std::to_string(numberOfReqNotRsp); |
| 321 | log<level::INFO>(msgToLog.c_str()); |
| 322 | } |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 323 | return; |
| 324 | } |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 325 | rsp.resize(sizeofLenField + sizeof(netfn) + sizeof(cmd) + |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 326 | sizeof(cc) + payload.size()); |
| 327 | |
| 328 | // write the response |
| 329 | auto rspIter = rsp.begin(); |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 330 | unsigned int *p = (unsigned int *) &rspIter[0]; |
| 331 | *p = payload.size() + 3; |
| 332 | rspIter[sizeofLenField] = (netfn << netFnShift) | (lun & lunMask); |
| 333 | rspIter[sizeofLenField + 1] = cmd; |
| 334 | rspIter[sizeofLenField + 2] = cc; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 335 | if (payload.size()) |
| 336 | { |
| 337 | std::copy(payload.cbegin(), payload.cend(), |
Dung Cao | 5183539 | 2022-10-27 04:29:54 +0000 | [diff] [blame] | 338 | rspIter + sizeofLenField + 3); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | if (verbose) |
| 342 | { |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 343 | std::string msgToLog = "Send ssif respond message with" |
| 344 | " len=" + std::to_string(payload.size() + 3) + |
| 345 | " netfn=" + std::to_string(netfn) + |
| 346 | " lun=" + std::to_string(lun) + |
| 347 | " cmd=" + std::to_string(cmd) + |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 348 | " cc=" + std::to_string(cc) + |
| 349 | " numberOfReqNotRsp=" + |
| 350 | std::to_string(numberOfReqNotRsp); |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 351 | log<level::INFO>(msgToLog.c_str()); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 352 | } |
| 353 | boost::system::error_code ecWr; |
| 354 | size_t wlen = |
| 355 | boost::asio::write(*dev, boost::asio::buffer(rsp), ecWr); |
| 356 | if (ecWr || wlen != rsp.size()) |
| 357 | { |
Dung Cao | f06b8fd | 2021-01-29 03:31:43 +0000 | [diff] [blame] | 358 | std::string msgToLog = "Failed to send ssif respond message:" |
| 359 | " size=" + std::to_string(wlen) + |
| 360 | " expect=" + std::to_string(rsp.size()) + |
| 361 | " error=" + ecWr.message() + |
| 362 | " netfn=" + std::to_string(netfn) + |
| 363 | " lun=" + std::to_string(lun) + |
| 364 | " cmd=" + std::to_string(cmd) + |
| 365 | " cc=" + std::to_string(cc); |
| 366 | log<level::ERR>(msgToLog.c_str()); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 367 | } |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 368 | rspTimer->stop(); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 369 | }, |
quang.ampere | 14480ee | 2022-10-18 09:04:51 +0700 | [diff] [blame] | 370 | ipmiQueueService, ipmiQueuePath, ipmiQueueIntf, ipmiQueueMethod, dbusTimeout, |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 371 | netfn, lun, cmd, data, options); |
| 372 | } |
| 373 | |
| 374 | |
| 375 | int main(int argc, char* argv[]) |
| 376 | { |
| 377 | CLI::App app("SSIF IPMI bridge"); |
| 378 | std::string device; |
| 379 | app.add_option("-d,--device", device, |
| 380 | "use <DEVICE> file. Default is /dev/ipmi-ssif-host"); |
| 381 | bool verbose = false; |
quang.name | 507782a | 2022-11-20 17:05:20 +0700 | [diff] [blame] | 382 | int numberOfReqNotRsp = 0; |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 383 | app.add_option("-v,--verbose", verbose, "print more verbose output"); |
| 384 | CLI11_PARSE(app, argc, argv); |
| 385 | |
| 386 | // Connect to system bus |
| 387 | auto io = std::make_shared<boost::asio::io_context>(); |
| 388 | sd_bus* dbus; |
| 389 | sd_bus_default_system(&dbus); |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 390 | |
| 391 | /* This might be a phosphor::Timer bug, without timer t2, rspTimer |
| 392 | * will not work |
| 393 | * */ |
| 394 | phosphor::Timer t2([]() { ; }); |
| 395 | t2.start(std::chrono::microseconds(500000), true); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 396 | auto bus = std::make_shared<sdbusplus::asio::connection>(*io, dbus); |
| 397 | bus->request_name(ssifBus); |
| 398 | // Create the SSIF channel, listening on D-Bus and on the SSIF device |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 399 | ssifchannel = make_unique<SsifChannel> |
| 400 | (io, bus, device, verbose, numberOfReqNotRsp); |
| 401 | if (!ssifchannel->initOK()) |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 402 | { |
| 403 | return EXIT_FAILURE; |
| 404 | } |
Quang Nguyen | f2994dc | 2022-11-25 16:31:49 +0700 | [diff] [blame^] | 405 | initTimer(); |
| 406 | sdbusplus::asio::sd_event_wrapper sdEvents(*io); |
Dung Cao | faf6a6a | 2020-12-28 04:44:45 +0000 | [diff] [blame] | 407 | io->run(); |
| 408 | |
| 409 | return 0; |
| 410 | } |