blob: abaa0bf6eff8762b84f0e3c6c0d795a3644de70d [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
17#include <host-ipmid/ipmid-api.h>
18
19#include <string>
20
21namespace ipmi
22{
23
24static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053025static constexpr uint8_t currentChNum = 0xE;
AppaRao Puli071f3f22018-05-24 16:45:30 +053026
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053027/**
28 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
29 * data)
30 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053031enum ipmi_channel_return_codes
32{
33 IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
34 IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
35};
36
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053037/**
38 * @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
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530114/**
115 * @enum Access mode for channel access set/get (refer spec
116 * sec 22.22 - request byte 2[7:6])
117 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530118typedef enum
119{
120 doNotSet = 0x00,
121 nvData = 0x01,
122 activeData = 0x02,
123 reserved = 0x03,
124} EChannelActionType;
125
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530126/**
127 * @enum Access set flag to determine changes that has to be updated
128 * in channel access data configuration.
129 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530130enum AccessSetFlag
131{
132 setAccessMode = (1 << 0),
133 setUserAuthEnabled = (1 << 1),
134 setMsgAuthEnabled = (1 << 2),
135 setAlertingEnabled = (1 << 3),
136 setPrivLimit = (1 << 4),
137};
138
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530139/** @struct ChannelAccess
140 *
141 * Structure to store channel access related information, defined in IPMI
142 * specification and used in Get / Set channel access (refer spec sec 22.22
143 * & 22.23)
144 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530145struct ChannelAccess
146{
147 uint8_t accessMode;
148 bool userAuthDisabled;
149 bool perMsgAuthDisabled;
150 bool alertingDisabled;
151 uint8_t privLimit;
152};
153
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530154/** @struct ChannelInfo
155 *
156 * Structure to store data about channel information, which identifies each
157 * channel type and information as defined in IPMI specification. (refer spec
158 * sec 22.22 & 22.23)
159 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530160struct ChannelInfo
161{
162 uint8_t mediumType;
163 uint8_t protocolType;
164 uint8_t sessionSupported;
165 bool isIpmi; // Is session IPMI
166 // This is used in Get LAN Configuration parameter.
167 // This holds the supported AuthTypes for a given channel.
168 uint8_t authTypeSupported;
169};
170
171/** @brief determines valid channel
172 *
173 * @param[in] chNum- channel number
174 *
175 * @return true if valid, false otherwise
176 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530177bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530178
179/** @brief determines whether channel device exist
180 *
181 * @param[in] chNum - channel number
182 *
183 * @return true if valid, false otherwise
184 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530185bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530186
187/** @brief determines whether privilege limit is valid
188 *
189 * @param[in] privLimit - Privilege limit
190 *
191 * @return true if valid, false otherwise
192 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530193bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530194
195/** @brief determines whether access mode is valid
196 *
197 * @param[in] accessMode - Access mode
198 *
199 * @return true if valid, false otherwise
200 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530201bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530202
203/** @brief determines valid authentication type based on channel number
204 *
205 * @param[in] chNum - channel number
206 * @param[in] authType - authentication type
207 *
208 * @return true if valid, false otherwise
209 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530210bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530211
212/** @brief determines supported session type of a channel
213 *
214 * @param[in] chNum - channel number
215 *
216 * @return EChannelSessSupported - supported session type
217 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530218EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530219
220/** @brief determines number of active sessions on a channel
221 *
222 * @param[in] chNum - channel number
223 *
224 * @return numer of active sessions
225 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530226int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530227
228/** @brief initializes channel management
229 *
230 * @return IPMI_CC_OK for success, others for failure.
231 */
232ipmi_ret_t ipmiChannelInit();
233
234/** @brief provides channel info details
235 *
236 * @param[in] chNum - channel number
237 * @param[out] chInfo - channel info details
238 *
239 * @return IPMI_CC_OK for success, others for failure.
240 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530241ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530242
243/** @brief provides channel access data
244 *
245 * @param[in] chNum - channel number
246 * @param[out] chAccessData -channel access data
247 *
248 * @return IPMI_CC_OK for success, others for failure.
249 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530250ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530251 ChannelAccess& chAccessData);
252
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530253/** @brief provides function to convert current channel number (0xE)
254 *
255 * @param[in] chNum - channel number as requested in commands.
256 *
257 * @return same channel number or proper channel number for current channel
258 * number (0xE).
259 */
260uint8_t convertCurrentChannelNum(const uint8_t chNum);
261
AppaRao Puli071f3f22018-05-24 16:45:30 +0530262/** @brief to set channel access data
263 *
264 * @param[in] chNum - channel number
265 * @param[in] chAccessData - channel access data
266 * @param[in] setFlag - flag to indicate updatable fields
267 *
268 * @return IPMI_CC_OK for success, others for failure.
269 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530270ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530271 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530272 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530273
274/** @brief to get channel access data persistent data
275 *
276 * @param[in] chNum - channel number
277 * @param[out] chAccessData - channel access data
278 *
279 * @return IPMI_CC_OK for success, others for failure.
280 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530281ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530282 ChannelAccess& chAccessData);
283
284/** @brief to set channel access data persistent data
285 *
286 * @param[in] chNum - channel number
287 * @param[in] chAccessData - channel access data
288 * @param[in] setFlag - flag to indicate updatable fields
289 *
290 * @return IPMI_CC_OK for success, others for failure.
291 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530292ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530293 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530294 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530295
296/** @brief provides supported authentication type for the channel
297 *
298 * @param[in] chNum - channel number
299 * @param[out] authTypeSupported - supported authentication type
300 *
301 * @return IPMI_CC_OK for success, others for failure.
302 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530303ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530304 uint8_t& authTypeSupported);
305
306/** @brief provides enabled authentication type for the channel
307 *
308 * @param[in] chNum - channel number
309 * @param[in] priv - privilege
310 * @param[out] authType - enabled authentication type
311 *
312 * @return IPMI_CC_OK for success, others for failure.
313 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530314ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530315 EAuthType& authType);
316
317} // namespace ipmi