blob: 42e5b5e8bcb96ba96c7bbac2c9ebe11068e5dcf6 [file] [log] [blame]
AppaRao Puli071f3f22018-05-24 16:45:30 +05301/*
2// Copyright (c) 2018 Intel Corporation
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#pragma once
Jayaprakash Mutyala70bd0632020-10-23 06:24:55 +000017#include <openssl/crypto.h>
18
Sumanth Bhate4e633e2019-05-14 12:13:57 +000019#include <array>
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000020#include <ipmid/api.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053021#include <string>
22
23namespace ipmi
24{
25
26static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053027static constexpr uint8_t currentChNum = 0xE;
Vernon Mauery735ee952019-02-15 13:38:52 -080028static constexpr uint8_t invalidChannel = 0xff;
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +000029static constexpr const uint8_t ccActionNotSupportedForChannel = 0x82;
30static constexpr const uint8_t ccAccessModeNotSupportedForChannel = 0x83;
AppaRao Puli071f3f22018-05-24 16:45:30 +053031
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053032/**
Sumanth Bhate4e633e2019-05-14 12:13:57 +000033 * @array of privilege levels
34 */
35extern const std::array<std::string, PRIVILEGE_OEM + 1> privList;
36
37/**
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053038 * @enum Channel Protocol Type (refer spec sec 6.4)
39 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053040enum class EChannelProtocolType : uint8_t
41{
42 na = 0x00,
43 ipmbV10 = 0x01,
44 icmbV11 = 0x02,
45 reserved = 0x03,
46 ipmiSmbus = 0x04,
47 kcs = 0x05,
48 smic = 0x06,
49 bt10 = 0x07,
50 bt15 = 0x08,
51 tMode = 0x09,
52 oem = 0x1C,
53};
54
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053055/**
56 * @enum Channel Medium Type (refer spec sec 6.5)
57 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053058enum class EChannelMediumType : uint8_t
59{
60 reserved = 0x00,
61 ipmb = 0x01,
62 icmbV10 = 0x02,
63 icmbV09 = 0x03,
64 lan8032 = 0x04,
65 serial = 0x05,
66 otherLan = 0x06,
67 pciSmbus = 0x07,
68 smbusV11 = 0x08,
69 smbusV20 = 0x09,
70 usbV1x = 0x0A,
71 usbV2x = 0x0B,
72 systemInterface = 0x0C,
73 oem = 0x60,
74 unknown = 0x82,
75};
76
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053077/**
78 * @enum Channel Session Type (refer spec sec 22.24 -
79 * response data byte 5)
80 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053081enum class EChannelSessSupported : uint8_t
82{
83 none = 0,
84 single = 1,
85 multi = 2,
86 any = 3,
87};
88
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053089/**
90 * @enum Channel Access Mode (refer spec sec 6.6)
91 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053092enum class EChannelAccessMode : uint8_t
93{
94 disabled = 0,
95 preboot = 1,
96 alwaysAvail = 2,
97 shared = 3,
98};
99
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530100/**
101 * @enum Authentication Types (refer spec sec 13.6 - IPMI
102 * Session Header)
103 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530104enum class EAuthType : uint8_t
105{
106 none = (1 << 0x0),
107 md2 = (1 << 0x1),
108 md5 = (1 << 0x2),
109 reserved = (1 << 0x3),
110 straightPasswd = (1 << 0x4),
111 oem = (1 << 0x5),
112};
113
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530114// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
115// to phosphor-ipmi-host/include
116/**
117 * @enum Payload Types (refer spec sec 13.27.3)
118 */
119enum class PayloadType : uint8_t
120{
121 IPMI = 0x00,
122 SOL = 0x01,
123 OPEN_SESSION_REQUEST = 0x10,
124 OPEN_SESSION_RESPONSE = 0x11,
125 RAKP1 = 0x12,
126 RAKP2 = 0x13,
127 RAKP3 = 0x14,
128 RAKP4 = 0x15,
129 INVALID = 0xFF,
130};
131
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530132/**
133 * @enum Access mode for channel access set/get (refer spec
134 * sec 22.22 - request byte 2[7:6])
135 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530136typedef enum
137{
138 doNotSet = 0x00,
139 nvData = 0x01,
140 activeData = 0x02,
141 reserved = 0x03,
142} EChannelActionType;
143
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530144/**
145 * @enum Access set flag to determine changes that has to be updated
146 * in channel access data configuration.
147 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530148enum AccessSetFlag
149{
150 setAccessMode = (1 << 0),
151 setUserAuthEnabled = (1 << 1),
152 setMsgAuthEnabled = (1 << 2),
153 setAlertingEnabled = (1 << 3),
154 setPrivLimit = (1 << 4),
155};
156
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530157/** @struct ChannelAccess
158 *
159 * Structure to store channel access related information, defined in IPMI
160 * specification and used in Get / Set channel access (refer spec sec 22.22
161 * & 22.23)
162 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530163struct ChannelAccess
164{
165 uint8_t accessMode;
166 bool userAuthDisabled;
167 bool perMsgAuthDisabled;
168 bool alertingDisabled;
169 uint8_t privLimit;
170};
171
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530172/** @struct ChannelInfo
173 *
174 * Structure to store data about channel information, which identifies each
175 * channel type and information as defined in IPMI specification. (refer spec
176 * sec 22.22 & 22.23)
177 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530178struct ChannelInfo
179{
180 uint8_t mediumType;
181 uint8_t protocolType;
182 uint8_t sessionSupported;
183 bool isIpmi; // Is session IPMI
184 // This is used in Get LAN Configuration parameter.
185 // This holds the supported AuthTypes for a given channel.
186 uint8_t authTypeSupported;
187};
188
189/** @brief determines valid channel
190 *
191 * @param[in] chNum- channel number
192 *
193 * @return true if valid, false otherwise
194 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530195bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530196
197/** @brief determines whether channel device exist
198 *
199 * @param[in] chNum - channel number
200 *
201 * @return true if valid, false otherwise
202 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530203bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530204
205/** @brief determines whether privilege limit is valid
206 *
207 * @param[in] privLimit - Privilege limit
208 *
209 * @return true if valid, false otherwise
210 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530211bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530212
213/** @brief determines whether access mode is valid
214 *
215 * @param[in] accessMode - Access mode
216 *
217 * @return true if valid, false otherwise
218 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530219bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530220
221/** @brief determines valid authentication type based on channel number
222 *
223 * @param[in] chNum - channel number
224 * @param[in] authType - authentication type
225 *
226 * @return true if valid, false otherwise
227 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530228bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530229
230/** @brief determines supported session type of a channel
231 *
232 * @param[in] chNum - channel number
233 *
234 * @return EChannelSessSupported - supported session type
235 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530236EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530237
238/** @brief determines number of active sessions on a channel
239 *
240 * @param[in] chNum - channel number
241 *
242 * @return numer of active sessions
243 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530244int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530245
Vernon Mauery58317122018-11-28 11:02:43 -0800246/** @brief determines maximum transfer size for a channel
247 *
248 * @param[in] chNum - channel number
249 *
250 * @return maximum bytes that can be transferred on this channel
251 */
252size_t getChannelMaxTransferSize(uint8_t chNum);
253
AppaRao Puli071f3f22018-05-24 16:45:30 +0530254/** @brief initializes channel management
255 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000256 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530257 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000258Cc ipmiChannelInit();
AppaRao Puli071f3f22018-05-24 16:45:30 +0530259
260/** @brief provides channel info details
261 *
262 * @param[in] chNum - channel number
263 * @param[out] chInfo - channel info details
264 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000265 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530266 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000267Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530268
269/** @brief provides channel access data
270 *
271 * @param[in] chNum - channel number
272 * @param[out] chAccessData -channel access data
273 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000274 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530275 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000276Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530277
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530278/** @brief provides function to convert current channel number (0xE)
279 *
280 * @param[in] chNum - channel number as requested in commands.
Vernon Mauery5ed39592019-05-14 09:16:53 -0700281 * @param[in] devChannel - channel number as provided by device (not 0xE)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530282 *
283 * @return same channel number or proper channel number for current channel
284 * number (0xE).
285 */
Vernon Mauery5ed39592019-05-14 09:16:53 -0700286static inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
287 const uint8_t devChannel)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530288{
289 if (chNum == currentChNum)
290 {
Vernon Mauery5ed39592019-05-14 09:16:53 -0700291 return devChannel;
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530292 }
293 return chNum;
294}
295
AppaRao Puli071f3f22018-05-24 16:45:30 +0530296/** @brief to set channel access data
297 *
298 * @param[in] chNum - channel number
299 * @param[in] chAccessData - channel access data
300 * @param[in] setFlag - flag to indicate updatable fields
301 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000302 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530303 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000304Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
305 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530306
307/** @brief to get channel access data persistent data
308 *
309 * @param[in] chNum - channel number
310 * @param[out] chAccessData - channel access data
311 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000312 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530313 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000314Cc getChannelAccessPersistData(const uint8_t chNum,
315 ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530316
317/** @brief to set channel access data persistent data
318 *
319 * @param[in] chNum - channel number
320 * @param[in] chAccessData - channel access data
321 * @param[in] setFlag - flag to indicate updatable fields
322 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000323 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530324 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000325Cc setChannelAccessPersistData(const uint8_t chNum,
326 const ChannelAccess& chAccessData,
327 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530328
329/** @brief provides supported authentication type for the channel
330 *
331 * @param[in] chNum - channel number
332 * @param[out] authTypeSupported - supported authentication type
333 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000334 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530335 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000336Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530337
338/** @brief provides enabled authentication type for the channel
339 *
340 * @param[in] chNum - channel number
341 * @param[in] priv - privilege
342 * @param[out] authType - enabled authentication type
343 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000344 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530345 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000346Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
347 EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530348
Johnathan Mantey74a21022018-12-13 13:17:56 -0800349/** @brief Retrieves the LAN channel name from the IPMI channel number
350 *
351 * @param[in] chNum - IPMI channel number
352 *
353 * @return the LAN channel name (i.e. eth0)
354 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530355std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800356
Vernon Mauery735ee952019-02-15 13:38:52 -0800357/** @brief Retrieves the LAN channel number from the IPMI channel name
358 *
359 * @param[in] chName - IPMI channel name (i.e. eth0)
360 *
361 * @return the LAN channel number
362 */
363uint8_t getChannelByName(const std::string& chName);
364
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000365/** @brief determines whether payload type is valid
366 *
367 * @param[in] payload type - Payload Type
368 *
369 * @return true if valid, false otherwise
370 */
371bool isValidPayloadType(const PayloadType payloadType);
372
AppaRao Puli071f3f22018-05-24 16:45:30 +0530373} // namespace ipmi