blob: caeaa39866ab50883bceac6a47c27b40ca224189 [file] [log] [blame]
Tom Joseph5a454a22017-02-15 14:51:42 +05301#pragma once
2
Tom Joseph5a454a22017-02-15 14:51:42 +05303#include "console_buffer.hpp"
4#include "session.hpp"
5#include "sol_context.hpp"
6
Vernon Mauery7e4a6512018-11-09 08:43:36 -08007#include <boost/asio/io_context.hpp>
8#include <boost/asio/local/stream_protocol.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -07009#include <map>
10#include <memory>
11
Tom Joseph5a454a22017-02-15 14:51:42 +053012namespace sol
13{
14
Tom Joseph5a454a22017-02-15 14:51:42 +053015constexpr size_t MAX_PAYLOAD_SIZE = 255;
16constexpr uint8_t MAJOR_VERSION = 0x01;
17constexpr uint8_t MINOR_VERSION = 0x00;
18
19constexpr char CONSOLE_SOCKET_PATH[] = "\0obmc-console";
20constexpr size_t CONSOLE_SOCKET_PATH_LEN = sizeof(CONSOLE_SOCKET_PATH) - 1;
21
Tom Joseph1967cf52017-04-28 01:24:22 +053022constexpr uint8_t accIntervalFactor = 5;
23constexpr uint8_t retryIntervalFactor = 10;
24
Tom Joseph5a454a22017-02-15 14:51:42 +053025using Instance = uint8_t;
26
Tom Joseph704f3422017-04-26 10:13:03 +053027using namespace std::chrono_literals;
Tom Joseph5a454a22017-02-15 14:51:42 +053028
29/** @class Manager
30 *
31 * Manager class acts a manager for the SOL payload instances and provides
32 * interfaces to start a payload instance, stop a payload instance and get
33 * reference to the context object.
34 */
35class Manager
36{
Vernon Mauery9e801a22018-10-12 13:20:49 -070037 public:
38 /** @brief SOL Payload Instance is the key for the map, the value is the
39 * SOL context.
40 */
Vernon Mauerya6ad5e12020-02-21 14:54:24 -080041 using SOLPayloadMap = std::map<Instance, std::shared_ptr<Context>>;
Tom Joseph5a454a22017-02-15 14:51:42 +053042
Vernon Mauery7e4a6512018-11-09 08:43:36 -080043 Manager() = delete;
Vernon Mauery9e801a22018-10-12 13:20:49 -070044 ~Manager() = default;
45 Manager(const Manager&) = delete;
46 Manager& operator=(const Manager&) = delete;
47 Manager(Manager&&) = default;
48 Manager& operator=(Manager&&) = default;
Tom Joseph5a454a22017-02-15 14:51:42 +053049
Vernon Mauery7e4a6512018-11-09 08:43:36 -080050 Manager(std::shared_ptr<boost::asio::io_context> io) : io(io)
51 {
52 }
53
54 /** @brief io context to add events to */
55 std::shared_ptr<boost::asio::io_context> io;
56
Vernon Mauery9e801a22018-10-12 13:20:49 -070057 /** @brief Host Console Buffer. */
58 ConsoleData dataBuffer;
Tom Joseph5a454a22017-02-15 14:51:42 +053059
Vernon Mauery9e801a22018-10-12 13:20:49 -070060 /** @brief Set in Progress.
61 *
62 * This parameter is used to indicate when any of the SOL parameters
63 * are being updated, and when the changes are completed. The bit is
64 * primarily provided to alert software than some other software or
65 * utility is in the process of making changes to the data. This field
66 * is initialized to set complete.
67 */
68 uint8_t progress = 0;
Tom Joseph5a454a22017-02-15 14:51:42 +053069
Vernon Mauery9e801a22018-10-12 13:20:49 -070070 /** @brief SOL enable
71 *
72 * This controls whether the SOL payload can be activated. By default
73 * the SOL is enabled.
74 */
75 bool enable = true;
Tom Joseph1967cf52017-04-28 01:24:22 +053076
Vernon Mauery9e801a22018-10-12 13:20:49 -070077 /** @brief SOL payload encryption.
78 *
79 * Force encryption: if the cipher suite for the session supports
80 * encryption, then this setting will force the use of encryption for
81 * all SOL payload data. Encryption controlled by remote console:
82 * Whether SOL packets are encrypted or not is selectable by the remote
83 * console at the time the payload is activated. The default is force
84 * encryption.
85 */
86 bool forceEncrypt = true;
Tom Joseph1967cf52017-04-28 01:24:22 +053087
Vernon Mauery9e801a22018-10-12 13:20:49 -070088 /** @brief SOL payload authentication.
89 *
90 * Force authentication: if the cipher suite for the session supports
91 * authentication, then this setting will force the use of for
92 * authentication for all SOL payload data. Authentication controlled
93 * by remote console: Note that for the standard Cipher Suites,
94 * if encryption is used authentication must also be used. Therefore,
95 * while encryption is being used software will not be able to select
96 * using unauthenticated payloads.
97 */
98 bool forceAuth = true;
Tom Joseph1967cf52017-04-28 01:24:22 +053099
Vernon Mauery9e801a22018-10-12 13:20:49 -0700100 /** @brief SOL privilege level.
101 *
102 * Sets the minimum operating privilege level that is required to be
103 * able to activate SOL using the Activate Payload command.
104 */
105 session::Privilege solMinPrivilege = session::Privilege::USER;
Tom Joseph1967cf52017-04-28 01:24:22 +0530106
Vernon Mauery9e801a22018-10-12 13:20:49 -0700107 /** @brief Character Accumulate Interval
108 *
109 * This sets the typical amount of time that the BMC will wait before
110 * transmitting a partial SOL character data packet. (Where a partial
111 * packet is defined as a packet that has fewer characters to transmit
112 * than the number of characters specified by the character send
113 * threshold. This parameter can be modified by the set SOL
114 * configuration parameters command. The SOL configuration parameter,
115 * Character Accumulate Interval is 5 ms increments, 1-based value. The
116 * parameter value is accumulateInterval/5. The accumulateInterval
117 * needs to be a multiple of 5.
118 */
119 std::chrono::milliseconds accumulateInterval = 100ms;
Tom Joseph1967cf52017-04-28 01:24:22 +0530120
Vernon Mauery9e801a22018-10-12 13:20:49 -0700121 /** @brief Character Send Threshold
122 *
123 * The BMC will automatically send an SOL character data packet
124 * containing this number of characters as soon as this number of
125 * characters (or greater) has been accepted from the baseboard serial
126 * controller into the BMC. This provides a mechanism to tune the
127 * buffer to reduce latency to when the first characters are received
128 * after an idle interval. In the degenerate case, setting this value
129 * to a ‘1’ would cause the BMC to send a packet as soon as the first
130 * character was received. This parameter can be modified by the set
131 * SOL configuration parameters command.
132 */
133 uint8_t sendThreshold = 1;
Tom Joseph5a454a22017-02-15 14:51:42 +0530134
Vernon Mauery9e801a22018-10-12 13:20:49 -0700135 /** @brief Retry Count
136 *
137 * 1-based. 0 = no retries after packet is transmitted. Packet will be
138 * dropped if no ACK/NACK received by time retries expire. The maximum
139 * value for retry count is 7. This parameter can be modified by the
140 * set SOL configuration parameters command.
141 */
142 uint8_t retryCount = 7;
Tom Joseph5a454a22017-02-15 14:51:42 +0530143
Vernon Mauery9e801a22018-10-12 13:20:49 -0700144 /** @brief Retry Interval
145 *
146 * Sets the time that the BMC will wait before the first retry and the
147 * time between retries when sending SOL packets to the remote console.
148 * This parameter can be modified by the set SOL configuration
149 * parameters command. The SOL configuration parameter Retry Interval
150 * is 10 ms increments, 1-based value. The parameter value is
151 * retryInterval/10. The retryInterval needs to be a multiple of 10.
152 */
153 std::chrono::milliseconds retryInterval = 100ms;
Tom Joseph5a454a22017-02-15 14:51:42 +0530154
Vernon Mauery9e801a22018-10-12 13:20:49 -0700155 /** @brief Channel Number
156 *
157 * This parameter indicates which IPMI channel is being used for the
158 * communication parameters (e.g. IP address, MAC address) for the SOL
159 * Payload. Typically, these parameters will come from the same channel
160 * that the Activate Payload command for SOL was accepted over. The
161 * network channel number is defaulted to 1.
162 */
163 uint8_t channel = 1;
Tom Joseph5a454a22017-02-15 14:51:42 +0530164
Vernon Mauery7e4a6512018-11-09 08:43:36 -0800165 /** @brief Add host console I/O event source to the event loop. */
166 void startHostConsole();
167
168 /** @brief Remove host console I/O event source. */
169 void stopHostConsole();
170
Vernon Mauery9e801a22018-10-12 13:20:49 -0700171 /** @brief Start a SOL payload instance.
172 *
173 * Starting a payload instance involves creating the context object,
174 * add the accumulate interval timer and retry interval timer to the
175 * event loop.
176 *
177 * @param[in] payloadInstance - SOL payload instance.
178 * @param[in] sessionID - BMC session ID.
179 */
180 void startPayloadInstance(uint8_t payloadInstance,
181 session::SessionID sessionID);
Tom Joseph6f83cbc2018-03-27 03:01:58 +0530182
Vernon Mauery9e801a22018-10-12 13:20:49 -0700183 /** @brief Stop SOL payload instance.
184 *
185 * Stopping a payload instance involves stopping and removing the
186 * accumulate interval timer and retry interval timer from the event
187 * loop, delete the context object.
188 *
189 * @param[in] payloadInstance - SOL payload instance
190 */
191 void stopPayloadInstance(uint8_t payloadInstance);
Tom Joseph5a454a22017-02-15 14:51:42 +0530192
Vernon Mauery9e801a22018-10-12 13:20:49 -0700193 /** @brief Get SOL Context by Payload Instance.
194 *
195 * @param[in] payloadInstance - SOL payload instance.
196 *
197 * @return reference to the SOL payload context.
198 */
199 Context& getContext(uint8_t payloadInstance)
200 {
201 auto iter = payloadMap.find(payloadInstance);
Tom Joseph5a454a22017-02-15 14:51:42 +0530202
Vernon Mauery9e801a22018-10-12 13:20:49 -0700203 if (iter != payloadMap.end())
Tom Joseph5a454a22017-02-15 14:51:42 +0530204 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700205 return *(iter->second);
Tom Joseph5a454a22017-02-15 14:51:42 +0530206 }
207
Vernon Mauery9e801a22018-10-12 13:20:49 -0700208 std::string msg = "Invalid SOL payload instance " + payloadInstance;
209 throw std::runtime_error(msg.c_str());
210 }
211
212 /** @brief Get SOL Context by Session ID.
213 *
214 * @param[in] sessionID - IPMI Session ID.
215 *
216 * @return reference to the SOL payload context.
217 */
218 Context& getContext(session::SessionID sessionID)
219 {
220 for (const auto& kv : payloadMap)
Tom Joseph5a454a22017-02-15 14:51:42 +0530221 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700222 if (kv.second->sessionID == sessionID)
223 {
224 return *kv.second;
225 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530226 }
227
Vernon Mauery9e801a22018-10-12 13:20:49 -0700228 std::string msg = "Invalid SOL SessionID " + sessionID;
229 throw std::runtime_error(msg.c_str());
230 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530231
Vernon Mauery9e801a22018-10-12 13:20:49 -0700232 /** @brief Check if SOL payload is active.
233 *
234 * @param[in] payloadInstance - SOL payload instance.
235 *
236 * @return true if the instance is active and false it is not active.
237 */
238 auto isPayloadActive(uint8_t payloadInstance) const
239 {
240 return (0 != payloadMap.count(payloadInstance));
241 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530242
Vernon Mauery9e801a22018-10-12 13:20:49 -0700243 /** @brief Write data to the host console unix socket.
244 *
245 * @param[in] input - Data from the remote console.
246 *
247 * @return 0 on success and errno on failure.
248 */
249 int writeConsoleSocket(const std::vector<uint8_t>& input) const;
Tom Joseph5a454a22017-02-15 14:51:42 +0530250
Vernon Mauery9e801a22018-10-12 13:20:49 -0700251 private:
252 SOLPayloadMap payloadMap;
253
Vernon Mauery7e4a6512018-11-09 08:43:36 -0800254 /** @brief Local stream socket for the host console. */
255 std::unique_ptr<boost::asio::local::stream_protocol::socket> consoleSocket =
256 nullptr;
Vernon Mauery9e801a22018-10-12 13:20:49 -0700257
258 /** @brief Initialize the host console file descriptor. */
Vernon Mauery7e4a6512018-11-09 08:43:36 -0800259 void initConsoleSocket();
260
261 /** @brief Handle incoming console data on the console socket */
262 void consoleInputHandler();
Tom Joseph5a454a22017-02-15 14:51:42 +0530263};
264
Vernon Mauery9e801a22018-10-12 13:20:49 -0700265} // namespace sol