blob: 5c82fba27285ec578510a9dd55330dd3d9692db6 [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
William A. Kennington III194375f2018-12-14 02:14:33 -080017#include <ipmid/api.h>
AppaRao Puli071f3f22018-05-24 16:45:30 +053018
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
Vernon Mauery58317122018-11-28 11:02:43 -0800228/** @brief determines maximum transfer size for a channel
229 *
230 * @param[in] chNum - channel number
231 *
232 * @return maximum bytes that can be transferred on this channel
233 */
234size_t getChannelMaxTransferSize(uint8_t chNum);
235
AppaRao Puli071f3f22018-05-24 16:45:30 +0530236/** @brief initializes channel management
237 *
238 * @return IPMI_CC_OK for success, others for failure.
239 */
240ipmi_ret_t ipmiChannelInit();
241
242/** @brief provides channel info details
243 *
244 * @param[in] chNum - channel number
245 * @param[out] chInfo - channel info details
246 *
247 * @return IPMI_CC_OK for success, others for failure.
248 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530249ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530250
251/** @brief provides channel access data
252 *
253 * @param[in] chNum - channel number
254 * @param[out] chAccessData -channel access data
255 *
256 * @return IPMI_CC_OK for success, others for failure.
257 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530258ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530259 ChannelAccess& chAccessData);
260
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530261/** @brief provides function to convert current channel number (0xE)
262 *
263 * @param[in] chNum - channel number as requested in commands.
264 *
265 * @return same channel number or proper channel number for current channel
266 * number (0xE).
267 */
268uint8_t convertCurrentChannelNum(const uint8_t chNum);
269
AppaRao Puli071f3f22018-05-24 16:45:30 +0530270/** @brief to set channel access data
271 *
272 * @param[in] chNum - channel number
273 * @param[in] chAccessData - channel access data
274 * @param[in] setFlag - flag to indicate updatable fields
275 *
276 * @return IPMI_CC_OK for success, others for failure.
277 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530278ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530279 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530280 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530281
282/** @brief to get channel access data persistent data
283 *
284 * @param[in] chNum - channel number
285 * @param[out] chAccessData - channel access data
286 *
287 * @return IPMI_CC_OK for success, others for failure.
288 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530289ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530290 ChannelAccess& chAccessData);
291
292/** @brief to set channel access data persistent data
293 *
294 * @param[in] chNum - channel number
295 * @param[in] chAccessData - channel access data
296 * @param[in] setFlag - flag to indicate updatable fields
297 *
298 * @return IPMI_CC_OK for success, others for failure.
299 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530300ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530301 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530302 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530303
304/** @brief provides supported authentication type for the channel
305 *
306 * @param[in] chNum - channel number
307 * @param[out] authTypeSupported - supported authentication type
308 *
309 * @return IPMI_CC_OK for success, others for failure.
310 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530311ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530312 uint8_t& authTypeSupported);
313
314/** @brief provides enabled authentication type for the channel
315 *
316 * @param[in] chNum - channel number
317 * @param[in] priv - privilege
318 * @param[out] authType - enabled authentication type
319 *
320 * @return IPMI_CC_OK for success, others for failure.
321 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530322ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530323 EAuthType& authType);
324
Johnathan Mantey74a21022018-12-13 13:17:56 -0800325/** @brief Retrieves the LAN channel name from the IPMI channel number
326 *
327 * @param[in] chNum - IPMI channel number
328 *
329 * @return the LAN channel name (i.e. eth0)
330 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530331std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800332
AppaRao Puli071f3f22018-05-24 16:45:30 +0530333} // namespace ipmi