blob: a23e94758fd726d0a6c8faa61792b563b10e77aa [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
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000019#include <ipmid/api.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050020
21#include <array>
AppaRao Puli071f3f22018-05-24 16:45:30 +053022#include <string>
23
24namespace ipmi
25{
26
27static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053028static constexpr uint8_t currentChNum = 0xE;
Vernon Mauery735ee952019-02-15 13:38:52 -080029static constexpr uint8_t invalidChannel = 0xff;
George Liu2543bd52025-07-08 15:29:42 +080030
31constexpr Cc ccActionNotSupportedForChannel = 0x82;
32constexpr Cc ccAccessModeNotSupportedForChannel = 0x83;
33
34static inline auto responseActionNotSupportedForChannel()
35{
36 return response(ccActionNotSupportedForChannel);
37}
38
39static inline auto responseAccessModeNotSupportedForChannel()
40{
41 return response(ccAccessModeNotSupportedForChannel);
42}
AppaRao Puli071f3f22018-05-24 16:45:30 +053043
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053044/**
Sumanth Bhate4e633e2019-05-14 12:13:57 +000045 * @array of privilege levels
46 */
47extern const std::array<std::string, PRIVILEGE_OEM + 1> privList;
48
49/**
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053050 * @enum Channel Protocol Type (refer spec sec 6.4)
51 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053052enum class EChannelProtocolType : uint8_t
53{
54 na = 0x00,
55 ipmbV10 = 0x01,
56 icmbV11 = 0x02,
57 reserved = 0x03,
58 ipmiSmbus = 0x04,
59 kcs = 0x05,
60 smic = 0x06,
61 bt10 = 0x07,
62 bt15 = 0x08,
63 tMode = 0x09,
64 oem = 0x1C,
65};
66
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053067/**
68 * @enum Channel Medium Type (refer spec sec 6.5)
69 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053070enum class EChannelMediumType : uint8_t
71{
72 reserved = 0x00,
73 ipmb = 0x01,
74 icmbV10 = 0x02,
75 icmbV09 = 0x03,
76 lan8032 = 0x04,
77 serial = 0x05,
78 otherLan = 0x06,
79 pciSmbus = 0x07,
80 smbusV11 = 0x08,
81 smbusV20 = 0x09,
82 usbV1x = 0x0A,
83 usbV2x = 0x0B,
84 systemInterface = 0x0C,
85 oem = 0x60,
86 unknown = 0x82,
87};
88
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053089/**
90 * @enum Channel Session Type (refer spec sec 22.24 -
91 * response data byte 5)
92 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053093enum class EChannelSessSupported : uint8_t
94{
95 none = 0,
96 single = 1,
97 multi = 2,
98 any = 3,
99};
100
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530101/**
102 * @enum Channel Access Mode (refer spec sec 6.6)
103 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530104enum class EChannelAccessMode : uint8_t
105{
106 disabled = 0,
107 preboot = 1,
108 alwaysAvail = 2,
109 shared = 3,
110};
111
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530112/**
113 * @enum Authentication Types (refer spec sec 13.6 - IPMI
114 * Session Header)
115 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530116enum class EAuthType : uint8_t
117{
118 none = (1 << 0x0),
119 md2 = (1 << 0x1),
120 md5 = (1 << 0x2),
121 reserved = (1 << 0x3),
122 straightPasswd = (1 << 0x4),
123 oem = (1 << 0x5),
124};
125
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530126// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
127// to phosphor-ipmi-host/include
128/**
129 * @enum Payload Types (refer spec sec 13.27.3)
130 */
131enum class PayloadType : uint8_t
132{
133 IPMI = 0x00,
134 SOL = 0x01,
135 OPEN_SESSION_REQUEST = 0x10,
136 OPEN_SESSION_RESPONSE = 0x11,
137 RAKP1 = 0x12,
138 RAKP2 = 0x13,
139 RAKP3 = 0x14,
140 RAKP4 = 0x15,
141 INVALID = 0xFF,
142};
143
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530144/**
145 * @enum Access mode for channel access set/get (refer spec
146 * sec 22.22 - request byte 2[7:6])
147 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530148typedef enum
149{
150 doNotSet = 0x00,
151 nvData = 0x01,
152 activeData = 0x02,
153 reserved = 0x03,
154} EChannelActionType;
155
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530156/**
157 * @enum Access set flag to determine changes that has to be updated
158 * in channel access data configuration.
159 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530160enum AccessSetFlag
161{
162 setAccessMode = (1 << 0),
163 setUserAuthEnabled = (1 << 1),
164 setMsgAuthEnabled = (1 << 2),
165 setAlertingEnabled = (1 << 3),
166 setPrivLimit = (1 << 4),
167};
168
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530169/** @struct ChannelAccess
170 *
171 * Structure to store channel access related information, defined in IPMI
172 * specification and used in Get / Set channel access (refer spec sec 22.22
173 * & 22.23)
174 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530175struct ChannelAccess
176{
177 uint8_t accessMode;
178 bool userAuthDisabled;
179 bool perMsgAuthDisabled;
180 bool alertingDisabled;
181 uint8_t privLimit;
182};
183
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530184/** @struct ChannelInfo
185 *
186 * Structure to store data about channel information, which identifies each
187 * channel type and information as defined in IPMI specification. (refer spec
188 * sec 22.22 & 22.23)
189 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530190struct ChannelInfo
191{
192 uint8_t mediumType;
193 uint8_t protocolType;
194 uint8_t sessionSupported;
195 bool isIpmi; // Is session IPMI
196 // This is used in Get LAN Configuration parameter.
197 // This holds the supported AuthTypes for a given channel.
198 uint8_t authTypeSupported;
199};
200
201/** @brief determines valid channel
202 *
203 * @param[in] chNum- channel number
204 *
205 * @return true if valid, false otherwise
206 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530207bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530208
209/** @brief determines whether channel device exist
210 *
211 * @param[in] chNum - channel number
212 *
213 * @return true if valid, false otherwise
214 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530215bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530216
217/** @brief determines whether privilege limit is valid
218 *
219 * @param[in] privLimit - Privilege limit
220 *
221 * @return true if valid, false otherwise
222 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530223bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530224
225/** @brief determines whether access mode is valid
226 *
227 * @param[in] accessMode - Access mode
228 *
229 * @return true if valid, false otherwise
230 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530231bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530232
233/** @brief determines valid authentication type based on channel number
234 *
235 * @param[in] chNum - channel number
236 * @param[in] authType - authentication type
237 *
238 * @return true if valid, false otherwise
239 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530240bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530241
242/** @brief determines supported session type of a channel
243 *
244 * @param[in] chNum - channel number
245 *
246 * @return EChannelSessSupported - supported session type
247 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530248EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530249
250/** @brief determines number of active sessions on a channel
251 *
252 * @param[in] chNum - channel number
253 *
254 * @return numer of active sessions
255 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530256int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530257
Vernon Mauery58317122018-11-28 11:02:43 -0800258/** @brief determines maximum transfer size for a channel
259 *
260 * @param[in] chNum - channel number
261 *
262 * @return maximum bytes that can be transferred on this channel
263 */
264size_t getChannelMaxTransferSize(uint8_t chNum);
265
AppaRao Puli071f3f22018-05-24 16:45:30 +0530266/** @brief initializes channel management
267 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000268 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530269 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000270Cc ipmiChannelInit();
AppaRao Puli071f3f22018-05-24 16:45:30 +0530271
272/** @brief provides channel info details
273 *
274 * @param[in] chNum - channel number
275 * @param[out] chInfo - channel info details
276 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000277 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530278 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000279Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530280
281/** @brief provides channel access data
282 *
283 * @param[in] chNum - channel number
284 * @param[out] chAccessData -channel access data
285 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000286 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530287 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000288Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530289
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530290/** @brief provides function to convert current channel number (0xE)
291 *
292 * @param[in] chNum - channel number as requested in commands.
Vernon Mauery5ed39592019-05-14 09:16:53 -0700293 * @param[in] devChannel - channel number as provided by device (not 0xE)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530294 *
295 * @return same channel number or proper channel number for current channel
296 * number (0xE).
297 */
Patrick Williams69b4c282025-03-03 11:19:13 -0500298static inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
299 const uint8_t devChannel)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530300{
301 if (chNum == currentChNum)
302 {
Vernon Mauery5ed39592019-05-14 09:16:53 -0700303 return devChannel;
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530304 }
305 return chNum;
306}
307
AppaRao Puli071f3f22018-05-24 16:45:30 +0530308/** @brief to set channel access data
309 *
310 * @param[in] chNum - channel number
311 * @param[in] chAccessData - channel access data
312 * @param[in] setFlag - flag to indicate updatable fields
313 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000314 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530315 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000316Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
317 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530318
319/** @brief to get channel access data persistent data
320 *
321 * @param[in] chNum - channel number
322 * @param[out] chAccessData - channel access data
323 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000324 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530325 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000326Cc getChannelAccessPersistData(const uint8_t chNum,
327 ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530328
329/** @brief to set channel access data persistent data
330 *
331 * @param[in] chNum - channel number
332 * @param[in] chAccessData - channel access data
333 * @param[in] setFlag - flag to indicate updatable fields
334 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000335 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530336 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000337Cc setChannelAccessPersistData(const uint8_t chNum,
338 const ChannelAccess& chAccessData,
339 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530340
341/** @brief provides supported authentication type for the channel
342 *
343 * @param[in] chNum - channel number
344 * @param[out] authTypeSupported - supported authentication type
345 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000346 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530347 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000348Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530349
350/** @brief provides enabled authentication type for the channel
351 *
352 * @param[in] chNum - channel number
353 * @param[in] priv - privilege
354 * @param[out] authType - enabled authentication type
355 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000356 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530357 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000358Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
359 EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530360
Johnathan Mantey74a21022018-12-13 13:17:56 -0800361/** @brief Retrieves the LAN channel name from the IPMI channel number
362 *
363 * @param[in] chNum - IPMI channel number
364 *
365 * @return the LAN channel name (i.e. eth0)
366 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530367std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800368
Vernon Mauery735ee952019-02-15 13:38:52 -0800369/** @brief Retrieves the LAN channel number from the IPMI channel name
370 *
371 * @param[in] chName - IPMI channel name (i.e. eth0)
372 *
373 * @return the LAN channel number
374 */
375uint8_t getChannelByName(const std::string& chName);
376
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000377/** @brief determines whether payload type is valid
378 *
379 * @param[in] payload type - Payload Type
380 *
381 * @return true if valid, false otherwise
382 */
383bool isValidPayloadType(const PayloadType payloadType);
384
AppaRao Puli071f3f22018-05-24 16:45:30 +0530385} // namespace ipmi