blob: 5a0c18c46a120bbc28aa23d084d6258096186ee4 [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 Mauery9e801a22018-10-12 13:20:49 -07007#include <map>
8#include <memory>
9
Tom Joseph5a454a22017-02-15 14:51:42 +053010namespace sol
11{
12
13constexpr size_t MAX_PAYLOAD_INSTANCES = 16;
14constexpr size_t MAX_PAYLOAD_SIZE = 255;
15constexpr uint8_t MAJOR_VERSION = 0x01;
16constexpr uint8_t MINOR_VERSION = 0x00;
17
18constexpr char CONSOLE_SOCKET_PATH[] = "\0obmc-console";
19constexpr size_t CONSOLE_SOCKET_PATH_LEN = sizeof(CONSOLE_SOCKET_PATH) - 1;
20
Tom Joseph1967cf52017-04-28 01:24:22 +053021constexpr uint8_t accIntervalFactor = 5;
22constexpr uint8_t retryIntervalFactor = 10;
23
Tom Joseph5a454a22017-02-15 14:51:42 +053024using Instance = uint8_t;
25
26/** @struct CustomFD
27 *
28 * RAII wrapper for file descriptor.
29 */
30struct CustomFD
31{
32 CustomFD(const CustomFD&) = delete;
33 CustomFD& operator=(const CustomFD&) = delete;
34 CustomFD(CustomFD&&) = delete;
35 CustomFD& operator=(CustomFD&&) = delete;
36
Vernon Mauery9e801a22018-10-12 13:20:49 -070037 CustomFD(int fd) : fd(fd)
38 {
39 }
Tom Joseph5a454a22017-02-15 14:51:42 +053040
Tom Josephb81f7612017-04-25 17:59:02 +053041 ~CustomFD();
Tom Joseph5a454a22017-02-15 14:51:42 +053042
43 int operator()() const
44 {
45 return fd;
46 }
47
Vernon Mauery9e801a22018-10-12 13:20:49 -070048 private:
49 int fd = -1;
Tom Joseph5a454a22017-02-15 14:51:42 +053050};
51
Tom Joseph704f3422017-04-26 10:13:03 +053052using namespace std::chrono_literals;
Tom Joseph5a454a22017-02-15 14:51:42 +053053
54/** @class Manager
55 *
56 * Manager class acts a manager for the SOL payload instances and provides
57 * interfaces to start a payload instance, stop a payload instance and get
58 * reference to the context object.
59 */
60class Manager
61{
Vernon Mauery9e801a22018-10-12 13:20:49 -070062 public:
63 /** @brief SOL Payload Instance is the key for the map, the value is the
64 * SOL context.
65 */
66 using SOLPayloadMap = std::map<Instance, std::unique_ptr<Context>>;
Tom Joseph5a454a22017-02-15 14:51:42 +053067
Vernon Mauery9e801a22018-10-12 13:20:49 -070068 Manager() = default;
69 ~Manager() = default;
70 Manager(const Manager&) = delete;
71 Manager& operator=(const Manager&) = delete;
72 Manager(Manager&&) = default;
73 Manager& operator=(Manager&&) = default;
Tom Joseph5a454a22017-02-15 14:51:42 +053074
Vernon Mauery9e801a22018-10-12 13:20:49 -070075 /** @brief Host Console Buffer. */
76 ConsoleData dataBuffer;
Tom Joseph5a454a22017-02-15 14:51:42 +053077
Vernon Mauery9e801a22018-10-12 13:20:49 -070078 /** @brief Set in Progress.
79 *
80 * This parameter is used to indicate when any of the SOL parameters
81 * are being updated, and when the changes are completed. The bit is
82 * primarily provided to alert software than some other software or
83 * utility is in the process of making changes to the data. This field
84 * is initialized to set complete.
85 */
86 uint8_t progress = 0;
Tom Joseph5a454a22017-02-15 14:51:42 +053087
Vernon Mauery9e801a22018-10-12 13:20:49 -070088 /** @brief SOL enable
89 *
90 * This controls whether the SOL payload can be activated. By default
91 * the SOL is enabled.
92 */
93 bool enable = true;
Tom Joseph1967cf52017-04-28 01:24:22 +053094
Vernon Mauery9e801a22018-10-12 13:20:49 -070095 /** @brief SOL payload encryption.
96 *
97 * Force encryption: if the cipher suite for the session supports
98 * encryption, then this setting will force the use of encryption for
99 * all SOL payload data. Encryption controlled by remote console:
100 * Whether SOL packets are encrypted or not is selectable by the remote
101 * console at the time the payload is activated. The default is force
102 * encryption.
103 */
104 bool forceEncrypt = true;
Tom Joseph1967cf52017-04-28 01:24:22 +0530105
Vernon Mauery9e801a22018-10-12 13:20:49 -0700106 /** @brief SOL payload authentication.
107 *
108 * Force authentication: if the cipher suite for the session supports
109 * authentication, then this setting will force the use of for
110 * authentication for all SOL payload data. Authentication controlled
111 * by remote console: Note that for the standard Cipher Suites,
112 * if encryption is used authentication must also be used. Therefore,
113 * while encryption is being used software will not be able to select
114 * using unauthenticated payloads.
115 */
116 bool forceAuth = true;
Tom Joseph1967cf52017-04-28 01:24:22 +0530117
Vernon Mauery9e801a22018-10-12 13:20:49 -0700118 /** @brief SOL privilege level.
119 *
120 * Sets the minimum operating privilege level that is required to be
121 * able to activate SOL using the Activate Payload command.
122 */
123 session::Privilege solMinPrivilege = session::Privilege::USER;
Tom Joseph1967cf52017-04-28 01:24:22 +0530124
Vernon Mauery9e801a22018-10-12 13:20:49 -0700125 /** @brief Character Accumulate Interval
126 *
127 * This sets the typical amount of time that the BMC will wait before
128 * transmitting a partial SOL character data packet. (Where a partial
129 * packet is defined as a packet that has fewer characters to transmit
130 * than the number of characters specified by the character send
131 * threshold. This parameter can be modified by the set SOL
132 * configuration parameters command. The SOL configuration parameter,
133 * Character Accumulate Interval is 5 ms increments, 1-based value. The
134 * parameter value is accumulateInterval/5. The accumulateInterval
135 * needs to be a multiple of 5.
136 */
137 std::chrono::milliseconds accumulateInterval = 100ms;
Tom Joseph1967cf52017-04-28 01:24:22 +0530138
Vernon Mauery9e801a22018-10-12 13:20:49 -0700139 /** @brief Character Send Threshold
140 *
141 * The BMC will automatically send an SOL character data packet
142 * containing this number of characters as soon as this number of
143 * characters (or greater) has been accepted from the baseboard serial
144 * controller into the BMC. This provides a mechanism to tune the
145 * buffer to reduce latency to when the first characters are received
146 * after an idle interval. In the degenerate case, setting this value
147 * to a ‘1’ would cause the BMC to send a packet as soon as the first
148 * character was received. This parameter can be modified by the set
149 * SOL configuration parameters command.
150 */
151 uint8_t sendThreshold = 1;
Tom Joseph5a454a22017-02-15 14:51:42 +0530152
Vernon Mauery9e801a22018-10-12 13:20:49 -0700153 /** @brief Retry Count
154 *
155 * 1-based. 0 = no retries after packet is transmitted. Packet will be
156 * dropped if no ACK/NACK received by time retries expire. The maximum
157 * value for retry count is 7. This parameter can be modified by the
158 * set SOL configuration parameters command.
159 */
160 uint8_t retryCount = 7;
Tom Joseph5a454a22017-02-15 14:51:42 +0530161
Vernon Mauery9e801a22018-10-12 13:20:49 -0700162 /** @brief Retry Interval
163 *
164 * Sets the time that the BMC will wait before the first retry and the
165 * time between retries when sending SOL packets to the remote console.
166 * This parameter can be modified by the set SOL configuration
167 * parameters command. The SOL configuration parameter Retry Interval
168 * is 10 ms increments, 1-based value. The parameter value is
169 * retryInterval/10. The retryInterval needs to be a multiple of 10.
170 */
171 std::chrono::milliseconds retryInterval = 100ms;
Tom Joseph5a454a22017-02-15 14:51:42 +0530172
Vernon Mauery9e801a22018-10-12 13:20:49 -0700173 /** @brief Channel Number
174 *
175 * This parameter indicates which IPMI channel is being used for the
176 * communication parameters (e.g. IP address, MAC address) for the SOL
177 * Payload. Typically, these parameters will come from the same channel
178 * that the Activate Payload command for SOL was accepted over. The
179 * network channel number is defaulted to 1.
180 */
181 uint8_t channel = 1;
Tom Joseph5a454a22017-02-15 14:51:42 +0530182
Vernon Mauery9e801a22018-10-12 13:20:49 -0700183 /** @brief Start a SOL payload instance.
184 *
185 * Starting a payload instance involves creating the context object,
186 * add the accumulate interval timer and retry interval timer to the
187 * event loop.
188 *
189 * @param[in] payloadInstance - SOL payload instance.
190 * @param[in] sessionID - BMC session ID.
191 */
192 void startPayloadInstance(uint8_t payloadInstance,
193 session::SessionID sessionID);
Tom Joseph6f83cbc2018-03-27 03:01:58 +0530194
Vernon Mauery9e801a22018-10-12 13:20:49 -0700195 /** @brief Stop SOL payload instance.
196 *
197 * Stopping a payload instance involves stopping and removing the
198 * accumulate interval timer and retry interval timer from the event
199 * loop, delete the context object.
200 *
201 * @param[in] payloadInstance - SOL payload instance
202 */
203 void stopPayloadInstance(uint8_t payloadInstance);
Tom Joseph5a454a22017-02-15 14:51:42 +0530204
Vernon Mauery9e801a22018-10-12 13:20:49 -0700205 /** @brief Get SOL Context by Payload Instance.
206 *
207 * @param[in] payloadInstance - SOL payload instance.
208 *
209 * @return reference to the SOL payload context.
210 */
211 Context& getContext(uint8_t payloadInstance)
212 {
213 auto iter = payloadMap.find(payloadInstance);
Tom Joseph5a454a22017-02-15 14:51:42 +0530214
Vernon Mauery9e801a22018-10-12 13:20:49 -0700215 if (iter != payloadMap.end())
Tom Joseph5a454a22017-02-15 14:51:42 +0530216 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700217 return *(iter->second);
Tom Joseph5a454a22017-02-15 14:51:42 +0530218 }
219
Vernon Mauery9e801a22018-10-12 13:20:49 -0700220 std::string msg = "Invalid SOL payload instance " + payloadInstance;
221 throw std::runtime_error(msg.c_str());
222 }
223
224 /** @brief Get SOL Context by Session ID.
225 *
226 * @param[in] sessionID - IPMI Session ID.
227 *
228 * @return reference to the SOL payload context.
229 */
230 Context& getContext(session::SessionID sessionID)
231 {
232 for (const auto& kv : payloadMap)
Tom Joseph5a454a22017-02-15 14:51:42 +0530233 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700234 if (kv.second->sessionID == sessionID)
235 {
236 return *kv.second;
237 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530238 }
239
Vernon Mauery9e801a22018-10-12 13:20:49 -0700240 std::string msg = "Invalid SOL SessionID " + sessionID;
241 throw std::runtime_error(msg.c_str());
242 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530243
Vernon Mauery9e801a22018-10-12 13:20:49 -0700244 /** @brief Check if SOL payload is active.
245 *
246 * @param[in] payloadInstance - SOL payload instance.
247 *
248 * @return true if the instance is active and false it is not active.
249 */
250 auto isPayloadActive(uint8_t payloadInstance) const
251 {
252 return (0 != payloadMap.count(payloadInstance));
253 }
Tom Joseph5a454a22017-02-15 14:51:42 +0530254
Vernon Mauery9e801a22018-10-12 13:20:49 -0700255 /** @brief Write data to the host console unix socket.
256 *
257 * @param[in] input - Data from the remote console.
258 *
259 * @return 0 on success and errno on failure.
260 */
261 int writeConsoleSocket(const std::vector<uint8_t>& input) const;
Tom Joseph5a454a22017-02-15 14:51:42 +0530262
Vernon Mauery9e801a22018-10-12 13:20:49 -0700263 private:
264 SOLPayloadMap payloadMap;
265
266 /** @brief File descriptor for the host console. */
267 std::unique_ptr<CustomFD> consoleFD = nullptr;
268
269 /** @brief Initialize the host console file descriptor. */
270 void initHostConsoleFd();
Tom Joseph5a454a22017-02-15 14:51:42 +0530271};
272
Vernon Mauery9e801a22018-10-12 13:20:49 -0700273} // namespace sol