blob: b86d6bf8947d81ddc22330d7a8ad73e5455ac8eb [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
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +053019#include <ipmid/api.hpp>
20#include <ipmid/message.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;
AppaRao Puli071f3f22018-05-24 16:45:30 +053028
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053029/**
30 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
31 * data)
32 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053033enum ipmi_channel_return_codes
34{
35 IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
36 IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
37};
38
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053039/**
40 * @enum Channel Protocol Type (refer spec sec 6.4)
41 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053042enum class EChannelProtocolType : uint8_t
43{
44 na = 0x00,
45 ipmbV10 = 0x01,
46 icmbV11 = 0x02,
47 reserved = 0x03,
48 ipmiSmbus = 0x04,
49 kcs = 0x05,
50 smic = 0x06,
51 bt10 = 0x07,
52 bt15 = 0x08,
53 tMode = 0x09,
54 oem = 0x1C,
55};
56
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053057/**
58 * @enum Channel Medium Type (refer spec sec 6.5)
59 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053060enum class EChannelMediumType : uint8_t
61{
62 reserved = 0x00,
63 ipmb = 0x01,
64 icmbV10 = 0x02,
65 icmbV09 = 0x03,
66 lan8032 = 0x04,
67 serial = 0x05,
68 otherLan = 0x06,
69 pciSmbus = 0x07,
70 smbusV11 = 0x08,
71 smbusV20 = 0x09,
72 usbV1x = 0x0A,
73 usbV2x = 0x0B,
74 systemInterface = 0x0C,
75 oem = 0x60,
76 unknown = 0x82,
77};
78
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053079/**
80 * @enum Channel Session Type (refer spec sec 22.24 -
81 * response data byte 5)
82 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053083enum class EChannelSessSupported : uint8_t
84{
85 none = 0,
86 single = 1,
87 multi = 2,
88 any = 3,
89};
90
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053091/**
92 * @enum Channel Access Mode (refer spec sec 6.6)
93 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053094enum class EChannelAccessMode : uint8_t
95{
96 disabled = 0,
97 preboot = 1,
98 alwaysAvail = 2,
99 shared = 3,
100};
101
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530102/**
103 * @enum Authentication Types (refer spec sec 13.6 - IPMI
104 * Session Header)
105 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530106enum class EAuthType : uint8_t
107{
108 none = (1 << 0x0),
109 md2 = (1 << 0x1),
110 md5 = (1 << 0x2),
111 reserved = (1 << 0x3),
112 straightPasswd = (1 << 0x4),
113 oem = (1 << 0x5),
114};
115
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530116/**
117 * @enum Access mode for channel access set/get (refer spec
118 * sec 22.22 - request byte 2[7:6])
119 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530120typedef enum
121{
122 doNotSet = 0x00,
123 nvData = 0x01,
124 activeData = 0x02,
125 reserved = 0x03,
126} EChannelActionType;
127
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530128/**
129 * @enum Access set flag to determine changes that has to be updated
130 * in channel access data configuration.
131 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530132enum AccessSetFlag
133{
134 setAccessMode = (1 << 0),
135 setUserAuthEnabled = (1 << 1),
136 setMsgAuthEnabled = (1 << 2),
137 setAlertingEnabled = (1 << 3),
138 setPrivLimit = (1 << 4),
139};
140
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530141/** @struct ChannelAccess
142 *
143 * Structure to store channel access related information, defined in IPMI
144 * specification and used in Get / Set channel access (refer spec sec 22.22
145 * & 22.23)
146 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530147struct ChannelAccess
148{
149 uint8_t accessMode;
150 bool userAuthDisabled;
151 bool perMsgAuthDisabled;
152 bool alertingDisabled;
153 uint8_t privLimit;
154};
155
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530156/** @struct ChannelInfo
157 *
158 * Structure to store data about channel information, which identifies each
159 * channel type and information as defined in IPMI specification. (refer spec
160 * sec 22.22 & 22.23)
161 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530162struct ChannelInfo
163{
164 uint8_t mediumType;
165 uint8_t protocolType;
166 uint8_t sessionSupported;
167 bool isIpmi; // Is session IPMI
168 // This is used in Get LAN Configuration parameter.
169 // This holds the supported AuthTypes for a given channel.
170 uint8_t authTypeSupported;
171};
172
173/** @brief determines valid channel
174 *
175 * @param[in] chNum- channel number
176 *
177 * @return true if valid, false otherwise
178 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530179bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530180
181/** @brief determines whether channel device exist
182 *
183 * @param[in] chNum - channel number
184 *
185 * @return true if valid, false otherwise
186 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530187bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530188
189/** @brief determines whether privilege limit is valid
190 *
191 * @param[in] privLimit - Privilege limit
192 *
193 * @return true if valid, false otherwise
194 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530195bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530196
197/** @brief determines whether access mode is valid
198 *
199 * @param[in] accessMode - Access mode
200 *
201 * @return true if valid, false otherwise
202 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530203bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530204
205/** @brief determines valid authentication type based on channel number
206 *
207 * @param[in] chNum - channel number
208 * @param[in] authType - authentication type
209 *
210 * @return true if valid, false otherwise
211 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530212bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530213
214/** @brief determines supported session type of a channel
215 *
216 * @param[in] chNum - channel number
217 *
218 * @return EChannelSessSupported - supported session type
219 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530220EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530221
222/** @brief determines number of active sessions on a channel
223 *
224 * @param[in] chNum - channel number
225 *
226 * @return numer of active sessions
227 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530228int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530229
Vernon Mauery58317122018-11-28 11:02:43 -0800230/** @brief determines maximum transfer size for a channel
231 *
232 * @param[in] chNum - channel number
233 *
234 * @return maximum bytes that can be transferred on this channel
235 */
236size_t getChannelMaxTransferSize(uint8_t chNum);
237
AppaRao Puli071f3f22018-05-24 16:45:30 +0530238/** @brief initializes channel management
239 *
240 * @return IPMI_CC_OK for success, others for failure.
241 */
242ipmi_ret_t ipmiChannelInit();
243
244/** @brief provides channel info details
245 *
246 * @param[in] chNum - channel number
247 * @param[out] chInfo - channel info details
248 *
249 * @return IPMI_CC_OK for success, others for failure.
250 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530251ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530252
253/** @brief provides channel access data
254 *
255 * @param[in] chNum - channel number
256 * @param[out] chAccessData -channel access data
257 *
258 * @return IPMI_CC_OK for success, others for failure.
259 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530260ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530261 ChannelAccess& chAccessData);
262
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530263/** @brief provides function to convert current channel number (0xE)
264 *
265 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530266 * @param[in] ipmi::context - ipmi context ptr, which has more details
267 *
268 * @return same channel number or proper channel number for current channel
269 * number (0xE).
270 */
271inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
272 ipmi::Context::ptr ctx)
273{
274 if (chNum == currentChNum)
275 {
276 return ctx->channel;
277 }
278 return chNum;
279}
280
281/** @brief provides function to convert current channel number (0xE)
282 *
283 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530284 *
285 * @return same channel number or proper channel number for current channel
286 * number (0xE).
287 */
288uint8_t convertCurrentChannelNum(const uint8_t chNum);
289
AppaRao Puli071f3f22018-05-24 16:45:30 +0530290/** @brief to set channel access data
291 *
292 * @param[in] chNum - channel number
293 * @param[in] chAccessData - channel access data
294 * @param[in] setFlag - flag to indicate updatable fields
295 *
296 * @return IPMI_CC_OK for success, others for failure.
297 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530298ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530299 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530300 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530301
302/** @brief to get channel access data persistent data
303 *
304 * @param[in] chNum - channel number
305 * @param[out] chAccessData - channel access data
306 *
307 * @return IPMI_CC_OK for success, others for failure.
308 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530309ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530310 ChannelAccess& chAccessData);
311
312/** @brief to set channel access data persistent data
313 *
314 * @param[in] chNum - channel number
315 * @param[in] chAccessData - channel access data
316 * @param[in] setFlag - flag to indicate updatable fields
317 *
318 * @return IPMI_CC_OK for success, others for failure.
319 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530320ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530321 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530322 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530323
324/** @brief provides supported authentication type for the channel
325 *
326 * @param[in] chNum - channel number
327 * @param[out] authTypeSupported - supported authentication type
328 *
329 * @return IPMI_CC_OK for success, others for failure.
330 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530331ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530332 uint8_t& authTypeSupported);
333
334/** @brief provides enabled authentication type for the channel
335 *
336 * @param[in] chNum - channel number
337 * @param[in] priv - privilege
338 * @param[out] authType - enabled authentication type
339 *
340 * @return IPMI_CC_OK for success, others for failure.
341 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530342ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530343 EAuthType& authType);
344
Johnathan Mantey74a21022018-12-13 13:17:56 -0800345/** @brief Retrieves the LAN channel name from the IPMI channel number
346 *
347 * @param[in] chNum - IPMI channel number
348 *
349 * @return the LAN channel name (i.e. eth0)
350 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530351std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800352
AppaRao Puli071f3f22018-05-24 16:45:30 +0530353} // namespace ipmi