diff options
| author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-10-12 13:20:49 -0700 |
|---|---|---|
| committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2018-11-02 15:44:15 -0700 |
| commit | 9e801a2b5b36acd307606af5eafdb885dfe8daee (patch) | |
| tree | 87d6cdef2c9008d76e9a99784e83f2b3af90ebc0 /sol | |
| parent | f6110552bd0e940efe51eb11c0415bebb2ab883f (diff) | |
| download | phosphor-net-ipmid-9e801a2b5b36acd307606af5eafdb885dfe8daee.tar.gz phosphor-net-ipmid-9e801a2b5b36acd307606af5eafdb885dfe8daee.zip | |
netipmid: apply clang-format rules
Lots of whitespace change. Let clang-format do its job and keep the code
looking nice.
Change-Id: Idfcad1a99cab8170d55a06163de8ad3f420b68b7
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'sol')
| -rw-r--r-- | sol/console_buffer.hpp | 92 | ||||
| -rw-r--r-- | sol/sol_context.cpp | 73 | ||||
| -rw-r--r-- | sol/sol_context.hpp | 295 | ||||
| -rw-r--r-- | sol/sol_manager.cpp | 40 | ||||
| -rw-r--r-- | sol/sol_manager.hpp | 411 |
5 files changed, 455 insertions, 456 deletions
diff --git a/sol/console_buffer.hpp b/sol/console_buffer.hpp index fe4bfe8..51383cf 100644 --- a/sol/console_buffer.hpp +++ b/sol/console_buffer.hpp @@ -1,6 +1,7 @@ #pragma once #include <algorithm> +#include <cstdint> #include <deque> #include <vector> @@ -18,56 +19,55 @@ using ConsoleBuffer = std::deque<uint8_t>; */ class ConsoleData { - public: - /** @brief Get the current size of the host console buffer. - * - * @return size of the host console buffer. - */ - auto size() const noexcept - { - return data.size(); - } + public: + /** @brief Get the current size of the host console buffer. + * + * @return size of the host console buffer. + */ + auto size() const noexcept + { + return data.size(); + } - /** @brief Read host console data. - * - * This API would return the iterator to the read data from the - * console data buffer. - * - * @return iterator to read data from the buffer - */ - auto read() const - { - return data.cbegin(); - } + /** @brief Read host console data. + * + * This API would return the iterator to the read data from the + * console data buffer. + * + * @return iterator to read data from the buffer + */ + auto read() const + { + return data.cbegin(); + } - /** @brief Write host console data. - * - * This API would append the input data to the host console buffer. - * - * @param[in] input - data to be written to the console buffer. - */ - void write(const std::vector<uint8_t>& input) - { - data.insert(data.end(), input.begin(), input.end()); - } + /** @brief Write host console data. + * + * This API would append the input data to the host console buffer. + * + * @param[in] input - data to be written to the console buffer. + */ + void write(const std::vector<uint8_t>& input) + { + data.insert(data.end(), input.begin(), input.end()); + } - /** @brief Erase console buffer. - * - * @param[in] size - the number of bytes to be erased from the console - * buffer. - * - * @note If the console buffer has less bytes that that was requested, - * then the available size is erased. - */ - void erase(size_t size) noexcept - { - data.erase(data.begin(), data.begin() + std::min(data.size(), - size)); - } + /** @brief Erase console buffer. + * + * @param[in] size - the number of bytes to be erased from the console + * buffer. + * + * @note If the console buffer has less bytes that that was requested, + * then the available size is erased. + */ + void erase(size_t size) noexcept + { + data.erase(data.begin(), data.begin() + std::min(data.size(), size)); + } - private: - /** @brief Storage for host console data. */ - ConsoleBuffer data; + private: + /** @brief Storage for host console data. */ + ConsoleBuffer data; }; } // namespace sol diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp index ffa6834..7329ed2 100644 --- a/sol/sol_context.cpp +++ b/sol/sol_context.cpp @@ -1,18 +1,18 @@ -#include <phosphor-logging/log.hpp> +#include "sol_context.hpp" + #include "main.hpp" #include "sd_event_loop.hpp" -#include "sol_context.hpp" #include "sol_manager.hpp" +#include <phosphor-logging/log.hpp> + namespace sol { using namespace phosphor::logging; -void Context::processInboundPayload(uint8_t seqNum, - uint8_t ackSeqNum, - uint8_t count, - bool status, +void Context::processInboundPayload(uint8_t seqNum, uint8_t ackSeqNum, + uint8_t count, bool status, const std::vector<uint8_t>& input) { uint8_t respAckSeqNum = 0; @@ -26,7 +26,7 @@ void Context::processInboundPayload(uint8_t seqNum, * specification. Retried packets use the same sequence number as the first * packet. */ - if(seqNum && (seqNum != seqNums.get(true))) + if (seqNum && (seqNum != seqNums.get(true))) { log<level::INFO>("Out of sequence SOL packet - packet is dropped"); return; @@ -54,10 +54,10 @@ void Context::processInboundPayload(uint8_t seqNum, if (status || ((count != expectedCharCount) && ackSeqNum)) { resendPayload(noClear); - std::get<eventloop::EventLoop&>(singletonPool).switchTimer - (payloadInstance, eventloop::Timers::RETRY, false); - std::get<eventloop::EventLoop&>(singletonPool).switchTimer - (payloadInstance, eventloop::Timers::RETRY, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::RETRY, false); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::RETRY, true); return; } /* @@ -70,8 +70,8 @@ void Context::processInboundPayload(uint8_t seqNum, std::get<sol::Manager&>(singletonPool).dataBuffer.erase(count); // Once it is acknowledged stop the retry interval timer - std::get<eventloop::EventLoop&>(singletonPool).switchTimer( - payloadInstance, eventloop::Timers::RETRY, false); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::RETRY, false); retryCounter = maxRetryCount; expectedCharCount = 0; @@ -81,8 +81,8 @@ void Context::processInboundPayload(uint8_t seqNum, // Write character data to the Host Console if (!input.empty() && seqNum) { - auto rc = std::get<sol::Manager&>(singletonPool).writeConsoleSocket( - input); + auto rc = + std::get<sol::Manager&>(singletonPool).writeConsoleSocket(input); if (rc) { log<level::ERR>("Writing to console socket descriptor failed"); @@ -111,21 +111,20 @@ void Context::processInboundPayload(uint8_t seqNum, } else { - std::get<eventloop::EventLoop&>(singletonPool).switchTimer - (payloadInstance, eventloop::Timers::ACCUMULATE, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::ACCUMULATE, true); } } void Context::prepareResponse(uint8_t ackSeqNum, uint8_t count, bool ack) { - auto bufferSize = std::get<sol::Manager&>(singletonPool).dataBuffer. - size(); + auto bufferSize = std::get<sol::Manager&>(singletonPool).dataBuffer.size(); /* Sent a ACK only response */ if (payloadCache.size() != 0 || (bufferSize < sendThreshold)) { - std::get<eventloop::EventLoop&>(singletonPool).switchTimer - (payloadInstance, eventloop::Timers::ACCUMULATE, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::ACCUMULATE, true); std::vector<uint8_t> outPayload(sizeof(Payload)); auto response = reinterpret_cast<Payload*>(outPayload.data()); @@ -145,15 +144,14 @@ void Context::prepareResponse(uint8_t ackSeqNum, uint8_t count, bool ack) response->outOperation.ack = ack; response->packetSeqNum = seqNums.incOutboundSeqNum(); - auto handle = std::get<sol::Manager&>(singletonPool).dataBuffer.read(); std::copy_n(handle, readSize, payloadCache.data() + sizeof(Payload)); expectedCharCount = readSize; - std::get<eventloop::EventLoop&>(singletonPool).switchTimer( - payloadInstance, eventloop::Timers::RETRY, true); - std::get<eventloop::EventLoop&>(singletonPool).switchTimer - (payloadInstance, eventloop::Timers::ACCUMULATE, false); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::RETRY, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::ACCUMULATE, false); sendPayload(payloadCache); } @@ -162,8 +160,8 @@ int Context::sendOutboundPayload() { if (payloadCache.size() != 0) { - std::get<eventloop::EventLoop&>(singletonPool).switchTimer( - payloadInstance, eventloop::Timers::ACCUMULATE, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::ACCUMULATE, true); return -1; } @@ -181,10 +179,10 @@ int Context::sendOutboundPayload() std::copy_n(handle, readSize, payloadCache.data() + sizeof(Payload)); expectedCharCount = readSize; - std::get<eventloop::EventLoop&>(singletonPool).switchTimer( - payloadInstance, eventloop::Timers::RETRY, true); - std::get<eventloop::EventLoop&>(singletonPool).switchTimer( - payloadInstance, eventloop::Timers::ACCUMULATE, false); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::RETRY, true); + std::get<eventloop::EventLoop&>(singletonPool) + .switchTimer(payloadInstance, eventloop::Timers::ACCUMULATE, false); sendPayload(payloadCache); @@ -195,19 +193,20 @@ void Context::resendPayload(bool clear) { sendPayload(payloadCache); - if(clear) + if (clear) { payloadCache.clear(); expectedCharCount = 0; - std::get<sol::Manager&>(singletonPool).dataBuffer.erase( - expectedCharCount); + std::get<sol::Manager&>(singletonPool) + .dataBuffer.erase(expectedCharCount); } } void Context::sendPayload(const std::vector<uint8_t>& out) const { - auto session = (std::get<session::Manager&>(singletonPool).getSession( - sessionID)).lock(); + auto session = + (std::get<session::Manager&>(singletonPool).getSession(sessionID)) + .lock(); message::Handler msgHandler(session->channelPtr, sessionID); diff --git a/sol/sol_context.hpp b/sol/sol_context.hpp index dadf492..220040b 100644 --- a/sol/sol_context.hpp +++ b/sol/sol_context.hpp @@ -13,23 +13,23 @@ namespace sol struct Outbound { #if BYTE_ORDER == LITTLE_ENDIAN - uint8_t testMode: 2; //!< Not supported. - uint8_t breakDetected: 1; //!< Not supported. - uint8_t transmitOverrun: 1; //!< Not supported. - uint8_t SOLDeactivating: 1; //!< 0 : SOL is active, 1 : SOL deactivated. - uint8_t charUnavailable: 1; //!< 0 : Available, 1 : Unavailable. - uint8_t ack: 1; //!< 0 : ACK, 1 : NACK. - uint8_t reserved: 1; //!< Reserved. + uint8_t testMode : 2; //!< Not supported. + uint8_t breakDetected : 1; //!< Not supported. + uint8_t transmitOverrun : 1; //!< Not supported. + uint8_t SOLDeactivating : 1; //!< 0 : SOL is active, 1 : SOL deactivated. + uint8_t charUnavailable : 1; //!< 0 : Available, 1 : Unavailable. + uint8_t ack : 1; //!< 0 : ACK, 1 : NACK. + uint8_t reserved : 1; //!< Reserved. #endif #if BYTE_ORDER == BIG_ENDIAN - uint8_t reserved: 1; //!< Reserved. - uint8_t ack: 1; //!< 0 : ACK, 1 : NACK. - uint8_t charUnavailable: 1; //!< 0 : Available, 1 : Unavailable. - uint8_t SOLDeactivating: 1; //!< 0 : SOL is active, 1 : SOL deactivated. - uint8_t transmitOverrun: 1; //!< Not supported. - uint8_t breakDetected: 1; //!< Not supported. - uint8_t testMode: 2; //!< Not supported. + uint8_t reserved : 1; //!< Reserved. + uint8_t ack : 1; //!< 0 : ACK, 1 : NACK. + uint8_t charUnavailable : 1; //!< 0 : Available, 1 : Unavailable. + uint8_t SOLDeactivating : 1; //!< 0 : SOL is active, 1 : SOL deactivated. + uint8_t transmitOverrun : 1; //!< Not supported. + uint8_t breakDetected : 1; //!< Not supported. + uint8_t testMode : 2; //!< Not supported. #endif } __attribute__((packed)); @@ -40,25 +40,25 @@ struct Outbound struct Inbound { #if BYTE_ORDER == LITTLE_ENDIAN - uint8_t flushOut: 1; //!< Not supported. - uint8_t flushIn: 1; //!< Not supported. - uint8_t dcd: 1; //!< Not supported. - uint8_t cts: 1; //!< Not supported. - uint8_t generateBreak: 1; //!< Not supported. - uint8_t ring: 1; //!< Not supported. - uint8_t ack: 1; //!< 0 : ACK, 1 : NACK. - uint8_t reserved: 1; //!< Reserved. + uint8_t flushOut : 1; //!< Not supported. + uint8_t flushIn : 1; //!< Not supported. + uint8_t dcd : 1; //!< Not supported. + uint8_t cts : 1; //!< Not supported. + uint8_t generateBreak : 1; //!< Not supported. + uint8_t ring : 1; //!< Not supported. + uint8_t ack : 1; //!< 0 : ACK, 1 : NACK. + uint8_t reserved : 1; //!< Reserved. #endif #if BYTE_ORDER == BIG_ENDIAN - uint8_t reserved: 1; //!< Reserved. - uint8_t ack: 1; //!< 0 : ACK, 1 : NACK. - uint8_t ring: 1; //!< Not supported. - uint8_t generateBreak: 1; //!< Not supported. - uint8_t cts: 1; //!< Not supported. - uint8_t dcd: 1; //!< Not supported. - uint8_t flushIn: 1; //!< Not supported. - uint8_t flushOut: 1; //!< Not supported. + uint8_t reserved : 1; //!< Reserved. + uint8_t ack : 1; //!< 0 : ACK, 1 : NACK. + uint8_t ring : 1; //!< Not supported. + uint8_t generateBreak : 1; //!< Not supported. + uint8_t cts : 1; //!< Not supported. + uint8_t dcd : 1; //!< Not supported. + uint8_t flushIn : 1; //!< Not supported. + uint8_t flushOut : 1; //!< Not supported. #endif } __attribute__((packed)); @@ -69,14 +69,14 @@ struct Inbound */ struct Payload { - uint8_t packetSeqNum; //!< Packet sequence number - uint8_t packetAckSeqNum; //!< Packet ACK/NACK sequence number - uint8_t acceptedCharCount; //!< Accepted character count + uint8_t packetSeqNum; //!< Packet sequence number + uint8_t packetAckSeqNum; //!< Packet ACK/NACK sequence number + uint8_t acceptedCharCount; //!< Accepted character count union { - uint8_t operation; //!<Operation/Status - struct Outbound outOperation; //!<BMC to Remote Console - struct Inbound inOperation; //!<Remote Console to BMC + uint8_t operation; //!< Operation/Status + struct Outbound outOperation; //!< BMC to Remote Console + struct Inbound inOperation; //!< Remote Console to BMC }; } __attribute__((packed)); @@ -131,10 +131,10 @@ struct SequenceNumbers return out; } - private: - uint8_t in = 1; //!< Inbound sequence number. - uint8_t out = 0; //!< Outbound sequence number, since the first - //!< operation is increment, it is initialised to 0 + private: + uint8_t in = 1; //!< Inbound sequence number. + uint8_t out = 0; //!< Outbound sequence number, since the first + //!< operation is increment, it is initialised to 0 }; } // namespace internal @@ -148,116 +148,111 @@ struct SequenceNumbers */ class Context { - public: - Context() = default; - ~Context() = default; - Context(const Context&) = delete; - Context& operator=(const Context&) = delete; - Context(Context&&) = default; - Context& operator=(Context&&) = default; - - /** @brief Context Constructor. - * - * This is issued by the SOL Manager when a SOL payload instance is - * started for the activate payload command. - * - * @param[in] maxRetryCount - Retry count max value. - * @param[in] sendThreshold - Character send threshold. - * @param[in] instance - SOL payload instance. - * @param[in] sessionID - BMC session ID. - */ - Context(uint8_t maxRetryCount, - uint8_t sendThreshold, - uint8_t instance, - session::SessionID sessionID): - maxRetryCount(maxRetryCount), - retryCounter(maxRetryCount), - sendThreshold(sendThreshold), - payloadInstance(instance), - sessionID(sessionID) {} - - static constexpr auto clear = true; - static constexpr auto noClear = false; - - /** @brief Retry count max value. */ - const uint8_t maxRetryCount = 0; - - /** @brief Retry counter. */ - uint8_t retryCounter = 0; - - /** @brief Character send threshold. */ - const uint8_t sendThreshold = 0; - - /** @brief SOL payload instance. */ - const uint8_t payloadInstance = 0; - - /** @brief Session ID. */ - const session::SessionID sessionID = 0; - - /** @brief Process the Inbound SOL payload. - * - * The SOL payload from the remote console is processed and the - * acknowledgment handling is done. - * - * @param[in] seqNum - Packet sequence number. - * @param[in] ackSeqNum - Packet ACK/NACK sequence number. - * @param[in] count - Accepted character count. - * @param[in] operation - ACK is false, NACK is true - * @param[in] input - Incoming SOL character data. - */ - void processInboundPayload(uint8_t seqNum, - uint8_t ackSeqNum, - uint8_t count, - bool status, - const std::vector<uint8_t>& input); - - /** @brief Send the outbound SOL payload. - * - * @return zero on success and negative value if condition for sending - * the payload fails. - */ - int sendOutboundPayload(); - - /** @brief Resend the SOL payload. - * - * @param[in] clear - if true then send the payload and clear the - * cached payload, if false only send the payload. - */ - void resendPayload(bool clear); - - private: - /** @brief Expected character count. - * - * Expected Sequence number and expected character count is set before - * sending the SOL payload. The check is done against these values when - * an incoming SOL payload is received. - */ - size_t expectedCharCount = 0; - - /** @brief Inbound and Outbound sequence numbers. */ - internal::SequenceNumbers seqNums; - - /** @brief Copy of the last sent SOL payload. - * - * A copy of the SOL payload is kept here, so that when a retry needs - * to be attempted the payload is sent again. - */ - std::vector<uint8_t> payloadCache; - - /** - * @brief Send Response for Incoming SOL payload. - * - * @param[in] ackSeqNum - Packet ACK/NACK Sequence Number. - * @param[in] count - Accepted Character Count. - * @param[in] ack - Set ACK/NACK in the Operation. - */ - void prepareResponse(uint8_t ackSeqNum, uint8_t count, bool ack); - - /** @brief Send the outgoing SOL payload. - * - * @param[in] out - buffer containing the SOL payload. - */ - void sendPayload(const std::vector<uint8_t>& out) const; + public: + Context() = default; + ~Context() = default; + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + Context(Context&&) = default; + Context& operator=(Context&&) = default; + + /** @brief Context Constructor. + * + * This is issued by the SOL Manager when a SOL payload instance is + * started for the activate payload command. + * + * @param[in] maxRetryCount - Retry count max value. + * @param[in] sendThreshold - Character send threshold. + * @param[in] instance - SOL payload instance. + * @param[in] sessionID - BMC session ID. + */ + Context(uint8_t maxRetryCount, uint8_t sendThreshold, uint8_t instance, + session::SessionID sessionID) : + maxRetryCount(maxRetryCount), + retryCounter(maxRetryCount), sendThreshold(sendThreshold), + payloadInstance(instance), sessionID(sessionID) + { + } + + static constexpr auto clear = true; + static constexpr auto noClear = false; + + /** @brief Retry count max value. */ + const uint8_t maxRetryCount = 0; + + /** @brief Retry counter. */ + uint8_t retryCounter = 0; + + /** @brief Character send threshold. */ + const uint8_t sendThreshold = 0; + + /** @brief SOL payload instance. */ + const uint8_t payloadInstance = 0; + + /** @brief Session ID. */ + const session::SessionID sessionID = 0; + + /** @brief Process the Inbound SOL payload. + * + * The SOL payload from the remote console is processed and the + * acknowledgment handling is done. + * + * @param[in] seqNum - Packet sequence number. + * @param[in] ackSeqNum - Packet ACK/NACK sequence number. + * @param[in] count - Accepted character count. + * @param[in] operation - ACK is false, NACK is true + * @param[in] input - Incoming SOL character data. + */ + void processInboundPayload(uint8_t seqNum, uint8_t ackSeqNum, uint8_t count, + bool status, const std::vector<uint8_t>& input); + + /** @brief Send the outbound SOL payload. + * + * @return zero on success and negative value if condition for sending + * the payload fails. + */ + int sendOutboundPayload(); + + /** @brief Resend the SOL payload. + * + * @param[in] clear - if true then send the payload and clear the + * cached payload, if false only send the payload. + */ + void resendPayload(bool clear); + + private: + /** @brief Expected character count. + * + * Expected Sequence number and expected character count is set before + * sending the SOL payload. The check is done against these values when + * an incoming SOL payload is received. + */ + size_t expectedCharCount = 0; + + /** @brief Inbound and Outbound sequence numbers. */ + internal::SequenceNumbers seqNums; + + /** @brief Copy of the last sent SOL payload. + * + * A copy of the SOL payload is kept here, so that when a retry needs + * to be attempted the payload is sent again. + */ + std::vector<uint8_t> payloadCache; + + /** + * @brief Send Response for Incoming SOL payload. + * + * @param[in] ackSeqNum - Packet ACK/NACK Sequence Number. + * @param[in] count - Accepted Character Count. + * @param[in] ack - Set ACK/NACK in the Operation. + */ + void prepareResponse(uint8_t ackSeqNum, uint8_t count, bool ack); + + /** @brief Send the outgoing SOL payload. + * + * @param[in] out - buffer containing the SOL payload. + */ + void sendPayload(const std::vector<uint8_t>& out) const; }; } // namespace sol diff --git a/sol/sol_manager.cpp b/sol/sol_manager.cpp index b6cf31d..66d2b49 100644 --- a/sol/sol_manager.cpp +++ b/sol/sol_manager.cpp @@ -1,11 +1,14 @@ +#include "sol_manager.hpp" + +#include "main.hpp" +#include "sol_context.hpp" + #include <sys/socket.h> #include <sys/un.h> + #include <chrono> #include <cmath> #include <phosphor-logging/log.hpp> -#include "main.hpp" -#include "sol_context.hpp" -#include "sol_manager.hpp" namespace sol { @@ -14,7 +17,7 @@ using namespace phosphor::logging; CustomFD::~CustomFD() { - if(fd >= 0) + if (fd >= 0) { // Remove the host console descriptor from the sd_event_loop std::get<eventloop::EventLoop&>(singletonPool).stopHostConsole(); @@ -32,7 +35,7 @@ void Manager::initHostConsoleFd() if (fd < 0) { log<level::ERR>("Failed to open the host console socket", - entry("ERRNO=%d", errno)); + entry("ERRNO=%d", errno)); throw std::runtime_error("Failed to open the host console socket"); } @@ -42,11 +45,11 @@ void Manager::initHostConsoleFd() consoleFD = std::make_unique<CustomFD>(fd); auto& conFD = *(consoleFD.get()); - rc = connect(conFD(), (struct sockaddr *)&addr, sizeof(addr)); + rc = connect(conFD(), (struct sockaddr*)&addr, sizeof(addr)); if (rc < 0) { log<level::ERR>("Failed to connect to host console socket address", - entry("ERRNO=%d", errno)); + entry("ERRNO=%d", errno)); consoleFD.reset(); throw std::runtime_error("Failed to connect to console server"); } @@ -69,7 +72,7 @@ int Manager::writeConsoleSocket(const std::vector<uint8_t>& input) const if (errno == EINTR) { log<level::INFO>(" Retrying to handle EINTR", - entry("ERRNO=%d", errno)); + entry("ERRNO=%d", errno)); rc = 0; continue; } @@ -77,7 +80,7 @@ int Manager::writeConsoleSocket(const std::vector<uint8_t>& input) const { errVal = errno; log<level::ERR>("Failed to write to host console socket", - entry("ERRNO=%d", errno)); + entry("ERRNO=%d", errno)); return -errVal; } } @@ -94,18 +97,19 @@ void Manager::startPayloadInstance(uint8_t payloadInstance, initHostConsoleFd(); // Register the fd in the sd_event_loop - std::get<eventloop::EventLoop&>(singletonPool).startHostConsole( - *(consoleFD.get())); + std::get<eventloop::EventLoop&>(singletonPool) + .startHostConsole(*(consoleFD.get())); } // Create the SOL Context data for payload instance - auto context = std::make_unique<Context>( - retryCount, sendThreshold, payloadInstance, sessionID); + auto context = std::make_unique<Context>(retryCount, sendThreshold, + payloadInstance, sessionID); - std::get<eventloop::EventLoop&>(singletonPool).startSOLPayloadInstance( + std::get<eventloop::EventLoop&>(singletonPool) + .startSOLPayloadInstance( payloadInstance, - std::chrono::duration_cast<eventloop::IntervalType> - (accumulateInterval), + std::chrono::duration_cast<eventloop::IntervalType>( + accumulateInterval), std::chrono::duration_cast<eventloop::IntervalType>(retryInterval)); payloadMap.emplace(payloadInstance, std::move(context)); @@ -121,8 +125,8 @@ void Manager::stopPayloadInstance(uint8_t payloadInstance) payloadMap.erase(iter); - std::get<eventloop::EventLoop&>(singletonPool).stopSOLPayloadInstance( - payloadInstance); + std::get<eventloop::EventLoop&>(singletonPool) + .stopSOLPayloadInstance(payloadInstance); if (payloadMap.empty()) { diff --git a/sol/sol_manager.hpp b/sol/sol_manager.hpp index a244431..5a0c18c 100644 --- a/sol/sol_manager.hpp +++ b/sol/sol_manager.hpp @@ -1,11 +1,12 @@ #pragma once -#include <map> -#include <memory> #include "console_buffer.hpp" #include "session.hpp" #include "sol_context.hpp" +#include <map> +#include <memory> + namespace sol { @@ -33,8 +34,9 @@ struct CustomFD CustomFD(CustomFD&&) = delete; CustomFD& operator=(CustomFD&&) = delete; - CustomFD(int fd) : - fd(fd) {} + CustomFD(int fd) : fd(fd) + { + } ~CustomFD(); @@ -43,8 +45,8 @@ struct CustomFD return fd; } - private: - int fd = -1; + private: + int fd = -1; }; using namespace std::chrono_literals; @@ -57,216 +59,215 @@ using namespace std::chrono_literals; */ class Manager { - public: - - /** @brief SOL Payload Instance is the key for the map, the value is the - * SOL context. - */ - using SOLPayloadMap = std::map<Instance, std::unique_ptr<Context>>; - - Manager() = default; - ~Manager() = default; - Manager(const Manager&) = delete; - Manager& operator=(const Manager&) = delete; - Manager(Manager&&) = default; - Manager& operator=(Manager&&) = default; - - /** @brief Host Console Buffer. */ - ConsoleData dataBuffer; - - /** @brief Set in Progress. - * - * This parameter is used to indicate when any of the SOL parameters - * are being updated, and when the changes are completed. The bit is - * primarily provided to alert software than some other software or - * utility is in the process of making changes to the data. This field - * is initialized to set complete. - */ - uint8_t progress = 0; - - /** @brief SOL enable - * - * This controls whether the SOL payload can be activated. By default - * the SOL is enabled. - */ - bool enable = true; - - /** @brief SOL payload encryption. - * - * Force encryption: if the cipher suite for the session supports - * encryption, then this setting will force the use of encryption for - * all SOL payload data. Encryption controlled by remote console: - * Whether SOL packets are encrypted or not is selectable by the remote - * console at the time the payload is activated. The default is force - * encryption. - */ - bool forceEncrypt = true; - - /** @brief SOL payload authentication. - * - * Force authentication: if the cipher suite for the session supports - * authentication, then this setting will force the use of for - * authentication for all SOL payload data. Authentication controlled - * by remote console: Note that for the standard Cipher Suites, - * if encryption is used authentication must also be used. Therefore, - * while encryption is being used software will not be able to select - * using unauthenticated payloads. - */ - bool forceAuth = true; - - /** @brief SOL privilege level. - * - * Sets the minimum operating privilege level that is required to be - * able to activate SOL using the Activate Payload command. - */ - session::Privilege solMinPrivilege = session::Privilege::USER; - - /** @brief Character Accumulate Interval - * - * This sets the typical amount of time that the BMC will wait before - * transmitting a partial SOL character data packet. (Where a partial - * packet is defined as a packet that has fewer characters to transmit - * than the number of characters specified by the character send - * threshold. This parameter can be modified by the set SOL - * configuration parameters command. The SOL configuration parameter, - * Character Accumulate Interval is 5 ms increments, 1-based value. The - * parameter value is accumulateInterval/5. The accumulateInterval - * needs to be a multiple of 5. - */ - std::chrono::milliseconds accumulateInterval = 100ms; - - /** @brief Character Send Threshold - * - * The BMC will automatically send an SOL character data packet - * containing this number of characters as soon as this number of - * characters (or greater) has been accepted from the baseboard serial - * controller into the BMC. This provides a mechanism to tune the - * buffer to reduce latency to when the first characters are received - * after an idle interval. In the degenerate case, setting this value - * to a ‘1’ would cause the BMC to send a packet as soon as the first - * character was received. This parameter can be modified by the set - * SOL configuration parameters command. - */ - uint8_t sendThreshold = 1; - - /** @brief Retry Count - * - * 1-based. 0 = no retries after packet is transmitted. Packet will be - * dropped if no ACK/NACK received by time retries expire. The maximum - * value for retry count is 7. This parameter can be modified by the - * set SOL configuration parameters command. - */ - uint8_t retryCount = 7; - - /** @brief Retry Interval - * - * Sets the time that the BMC will wait before the first retry and the - * time between retries when sending SOL packets to the remote console. - * This parameter can be modified by the set SOL configuration - * parameters command. The SOL configuration parameter Retry Interval - * is 10 ms increments, 1-based value. The parameter value is - * retryInterval/10. The retryInterval needs to be a multiple of 10. - */ - std::chrono::milliseconds retryInterval = 100ms; - - /** @brief Channel Number - * - * This parameter indicates which IPMI channel is being used for the - * communication parameters (e.g. IP address, MAC address) for the SOL - * Payload. Typically, these parameters will come from the same channel - * that the Activate Payload command for SOL was accepted over. The - * network channel number is defaulted to 1. - */ - uint8_t channel = 1; - - /** @brief Start a SOL payload instance. - * - * Starting a payload instance involves creating the context object, - * add the accumulate interval timer and retry interval timer to the - * event loop. - * - * @param[in] payloadInstance - SOL payload instance. - * @param[in] sessionID - BMC session ID. - */ - void startPayloadInstance(uint8_t payloadInstance, - session::SessionID sessionID); - - /** @brief Stop SOL payload instance. - * - * Stopping a payload instance involves stopping and removing the - * accumulate interval timer and retry interval timer from the event - * loop, delete the context object. - * - * @param[in] payloadInstance - SOL payload instance - */ - void stopPayloadInstance(uint8_t payloadInstance); - - /** @brief Get SOL Context by Payload Instance. - * - * @param[in] payloadInstance - SOL payload instance. - * - * @return reference to the SOL payload context. - */ - Context& getContext(uint8_t payloadInstance) + public: + /** @brief SOL Payload Instance is the key for the map, the value is the + * SOL context. + */ + using SOLPayloadMap = std::map<Instance, std::unique_ptr<Context>>; + + Manager() = default; + ~Manager() = default; + Manager(const Manager&) = delete; + Manager& operator=(const Manager&) = delete; + Manager(Manager&&) = default; + Manager& operator=(Manager&&) = default; + + /** @brief Host Console Buffer. */ + ConsoleData dataBuffer; + + /** @brief Set in Progress. + * + * This parameter is used to indicate when any of the SOL parameters + * are being updated, and when the changes are completed. The bit is + * primarily provided to alert software than some other software or + * utility is in the process of making changes to the data. This field + * is initialized to set complete. + */ + uint8_t progress = 0; + + /** @brief SOL enable + * + * This controls whether the SOL payload can be activated. By default + * the SOL is enabled. + */ + bool enable = true; + + /** @brief SOL payload encryption. + * + * Force encryption: if the cipher suite for the session supports + * encryption, then this setting will force the use of encryption for + * all SOL payload data. Encryption controlled by remote console: + * Whether SOL packets are encrypted or not is selectable by the remote + * console at the time the payload is activated. The default is force + * encryption. + */ + bool forceEncrypt = true; + + /** @brief SOL payload authentication. + * + * Force authentication: if the cipher suite for the session supports + * authentication, then this setting will force the use of for + * authentication for all SOL payload data. Authentication controlled + * by remote console: Note that for the standard Cipher Suites, + * if encryption is used authentication must also be used. Therefore, + * while encryption is being used software will not be able to select + * using unauthenticated payloads. + */ + bool forceAuth = true; + + /** @brief SOL privilege level. + * + * Sets the minimum operating privilege level that is required to be + * able to activate SOL using the Activate Payload command. + */ + session::Privilege solMinPrivilege = session::Privilege::USER; + + /** @brief Character Accumulate Interval + * + * This sets the typical amount of time that the BMC will wait before + * transmitting a partial SOL character data packet. (Where a partial + * packet is defined as a packet that has fewer characters to transmit + * than the number of characters specified by the character send + * threshold. This parameter can be modified by the set SOL + * configuration parameters command. The SOL configuration parameter, + * Character Accumulate Interval is 5 ms increments, 1-based value. The + * parameter value is accumulateInterval/5. The accumulateInterval + * needs to be a multiple of 5. + */ + std::chrono::milliseconds accumulateInterval = 100ms; + + /** @brief Character Send Threshold + * + * The BMC will automatically send an SOL character data packet + * containing this number of characters as soon as this number of + * characters (or greater) has been accepted from the baseboard serial + * controller into the BMC. This provides a mechanism to tune the + * buffer to reduce latency to when the first characters are received + * after an idle interval. In the degenerate case, setting this value + * to a ‘1’ would cause the BMC to send a packet as soon as the first + * character was received. This parameter can be modified by the set + * SOL configuration parameters command. + */ + uint8_t sendThreshold = 1; + + /** @brief Retry Count + * + * 1-based. 0 = no retries after packet is transmitted. Packet will be + * dropped if no ACK/NACK received by time retries expire. The maximum + * value for retry count is 7. This parameter can be modified by the + * set SOL configuration parameters command. + */ + uint8_t retryCount = 7; + + /** @brief Retry Interval + * + * Sets the time that the BMC will wait before the first retry and the + * time between retries when sending SOL packets to the remote console. + * This parameter can be modified by the set SOL configuration + * parameters command. The SOL configuration parameter Retry Interval + * is 10 ms increments, 1-based value. The parameter value is + * retryInterval/10. The retryInterval needs to be a multiple of 10. + */ + std::chrono::milliseconds retryInterval = 100ms; + + /** @brief Channel Number + * + * This parameter indicates which IPMI channel is being used for the + * communication parameters (e.g. IP address, MAC address) for the SOL + * Payload. Typically, these parameters will come from the same channel + * that the Activate Payload command for SOL was accepted over. The + * network channel number is defaulted to 1. + */ + uint8_t channel = 1; + + /** @brief Start a SOL payload instance. + * + * Starting a payload instance involves creating the context object, + * add the accumulate interval timer and retry interval timer to the + * event loop. + * + * @param[in] payloadInstance - SOL payload instance. + * @param[in] sessionID - BMC session ID. + */ + void startPayloadInstance(uint8_t payloadInstance, + session::SessionID sessionID); + + /** @brief Stop SOL payload instance. + * + * Stopping a payload instance involves stopping and removing the + * accumulate interval timer and retry interval timer from the event + * loop, delete the context object. + * + * @param[in] payloadInstance - SOL payload instance + */ + void stopPayloadInstance(uint8_t payloadInstance); + + /** @brief Get SOL Context by Payload Instance. + * + * @param[in] payloadInstance - SOL payload instance. + * + * @return reference to the SOL payload context. + */ + Context& getContext(uint8_t payloadInstance) + { + auto iter = payloadMap.find(payloadInstance); + + if (iter != payloadMap.end()) { - auto iter = payloadMap.find(payloadInstance); + return *(iter->second); + } - if (iter != payloadMap.end()) - { - return *(iter->second); - } + std::string msg = "Invalid SOL payload instance " + payloadInstance; + throw std::runtime_error(msg.c_str()); + } - std::string msg = "Invalid SOL payload instance " + payloadInstance; - throw std::runtime_error(msg.c_str()); - } - - /** @brief Get SOL Context by Session ID. - * - * @param[in] sessionID - IPMI Session ID. - * - * @return reference to the SOL payload context. - */ - Context& getContext(session::SessionID sessionID) + /** @brief Get SOL Context by Session ID. + * + * @param[in] sessionID - IPMI Session ID. + * + * @return reference to the SOL payload context. + */ + Context& getContext(session::SessionID sessionID) + { + for (const auto& kv : payloadMap) { - for (const auto& kv : payloadMap) + if (kv.second->sessionID == sessionID) { - if (kv.second->sessionID == sessionID) - { - return *kv.second; - } + return *kv.second; } - - std::string msg = "Invalid SOL SessionID " + sessionID; - throw std::runtime_error(msg.c_str()); } - /** @brief Check if SOL payload is active. - * - * @param[in] payloadInstance - SOL payload instance. - * - * @return true if the instance is active and false it is not active. - */ - auto isPayloadActive(uint8_t payloadInstance) const - { - return (0 != payloadMap.count(payloadInstance)); - } + std::string msg = "Invalid SOL SessionID " + sessionID; + throw std::runtime_error(msg.c_str()); + } + + /** @brief Check if SOL payload is active. + * + * @param[in] payloadInstance - SOL payload instance. + * + * @return true if the instance is active and false it is not active. + */ + auto isPayloadActive(uint8_t payloadInstance) const + { + return (0 != payloadMap.count(payloadInstance)); + } - /** @brief Write data to the host console unix socket. - * - * @param[in] input - Data from the remote console. - * - * @return 0 on success and errno on failure. - */ - int writeConsoleSocket(const std::vector<uint8_t>& input) const; + /** @brief Write data to the host console unix socket. + * + * @param[in] input - Data from the remote console. + * + * @return 0 on success and errno on failure. + */ + int writeConsoleSocket(const std::vector<uint8_t>& input) const; - private: - SOLPayloadMap payloadMap; + private: + SOLPayloadMap payloadMap; - /** @brief File descriptor for the host console. */ - std::unique_ptr<CustomFD> consoleFD = nullptr; + /** @brief File descriptor for the host console. */ + std::unique_ptr<CustomFD> consoleFD = nullptr; - /** @brief Initialize the host console file descriptor. */ - void initHostConsoleFd(); + /** @brief Initialize the host console file descriptor. */ + void initHostConsoleFd(); }; -} //namespace sol +} // namespace sol |

