blob: eaf631c594ca4a79a0f06c07f5123f3d7ba116ba [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
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000017#include <ipmid/api.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053018#include <string>
19
20namespace ipmi
21{
22
23static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053024static constexpr uint8_t currentChNum = 0xE;
Vernon Mauery735ee952019-02-15 13:38:52 -080025static constexpr uint8_t invalidChannel = 0xff;
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 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000031constexpr Cc ccActionNotSupportedForChannel = 0x82;
32constexpr Cc ccAccessModeNotSupportedForChannel = 0x83;
AppaRao Puli071f3f22018-05-24 16:45:30 +053033
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053034/**
35 * @enum Channel Protocol Type (refer spec sec 6.4)
36 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053037enum class EChannelProtocolType : uint8_t
38{
39 na = 0x00,
40 ipmbV10 = 0x01,
41 icmbV11 = 0x02,
42 reserved = 0x03,
43 ipmiSmbus = 0x04,
44 kcs = 0x05,
45 smic = 0x06,
46 bt10 = 0x07,
47 bt15 = 0x08,
48 tMode = 0x09,
49 oem = 0x1C,
50};
51
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053052/**
53 * @enum Channel Medium Type (refer spec sec 6.5)
54 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053055enum class EChannelMediumType : uint8_t
56{
57 reserved = 0x00,
58 ipmb = 0x01,
59 icmbV10 = 0x02,
60 icmbV09 = 0x03,
61 lan8032 = 0x04,
62 serial = 0x05,
63 otherLan = 0x06,
64 pciSmbus = 0x07,
65 smbusV11 = 0x08,
66 smbusV20 = 0x09,
67 usbV1x = 0x0A,
68 usbV2x = 0x0B,
69 systemInterface = 0x0C,
70 oem = 0x60,
71 unknown = 0x82,
72};
73
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053074/**
75 * @enum Channel Session Type (refer spec sec 22.24 -
76 * response data byte 5)
77 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053078enum class EChannelSessSupported : uint8_t
79{
80 none = 0,
81 single = 1,
82 multi = 2,
83 any = 3,
84};
85
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053086/**
87 * @enum Channel Access Mode (refer spec sec 6.6)
88 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053089enum class EChannelAccessMode : uint8_t
90{
91 disabled = 0,
92 preboot = 1,
93 alwaysAvail = 2,
94 shared = 3,
95};
96
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053097/**
98 * @enum Authentication Types (refer spec sec 13.6 - IPMI
99 * Session Header)
100 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530101enum class EAuthType : uint8_t
102{
103 none = (1 << 0x0),
104 md2 = (1 << 0x1),
105 md5 = (1 << 0x2),
106 reserved = (1 << 0x3),
107 straightPasswd = (1 << 0x4),
108 oem = (1 << 0x5),
109};
110
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530111// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
112// to phosphor-ipmi-host/include
113/**
114 * @enum Payload Types (refer spec sec 13.27.3)
115 */
116enum class PayloadType : uint8_t
117{
118 IPMI = 0x00,
119 SOL = 0x01,
120 OPEN_SESSION_REQUEST = 0x10,
121 OPEN_SESSION_RESPONSE = 0x11,
122 RAKP1 = 0x12,
123 RAKP2 = 0x13,
124 RAKP3 = 0x14,
125 RAKP4 = 0x15,
126 INVALID = 0xFF,
127};
128
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530129/**
130 * @enum Access mode for channel access set/get (refer spec
131 * sec 22.22 - request byte 2[7:6])
132 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530133typedef enum
134{
135 doNotSet = 0x00,
136 nvData = 0x01,
137 activeData = 0x02,
138 reserved = 0x03,
139} EChannelActionType;
140
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530141/**
142 * @enum Access set flag to determine changes that has to be updated
143 * in channel access data configuration.
144 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530145enum AccessSetFlag
146{
147 setAccessMode = (1 << 0),
148 setUserAuthEnabled = (1 << 1),
149 setMsgAuthEnabled = (1 << 2),
150 setAlertingEnabled = (1 << 3),
151 setPrivLimit = (1 << 4),
152};
153
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530154/** @struct ChannelAccess
155 *
156 * Structure to store channel access related information, defined in IPMI
157 * specification and used in Get / Set channel access (refer spec sec 22.22
158 * & 22.23)
159 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530160struct ChannelAccess
161{
162 uint8_t accessMode;
163 bool userAuthDisabled;
164 bool perMsgAuthDisabled;
165 bool alertingDisabled;
166 uint8_t privLimit;
167};
168
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530169/** @struct ChannelInfo
170 *
171 * Structure to store data about channel information, which identifies each
172 * channel type and information as defined in IPMI specification. (refer spec
173 * sec 22.22 & 22.23)
174 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530175struct ChannelInfo
176{
177 uint8_t mediumType;
178 uint8_t protocolType;
179 uint8_t sessionSupported;
180 bool isIpmi; // Is session IPMI
181 // This is used in Get LAN Configuration parameter.
182 // This holds the supported AuthTypes for a given channel.
183 uint8_t authTypeSupported;
184};
185
186/** @brief determines valid channel
187 *
188 * @param[in] chNum- channel number
189 *
190 * @return true if valid, false otherwise
191 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530192bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530193
194/** @brief determines whether channel device exist
195 *
196 * @param[in] chNum - channel number
197 *
198 * @return true if valid, false otherwise
199 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530200bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530201
202/** @brief determines whether privilege limit is valid
203 *
204 * @param[in] privLimit - Privilege limit
205 *
206 * @return true if valid, false otherwise
207 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530208bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530209
210/** @brief determines whether access mode is valid
211 *
212 * @param[in] accessMode - Access mode
213 *
214 * @return true if valid, false otherwise
215 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530216bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530217
218/** @brief determines valid authentication type based on channel number
219 *
220 * @param[in] chNum - channel number
221 * @param[in] authType - authentication type
222 *
223 * @return true if valid, false otherwise
224 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530225bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530226
227/** @brief determines supported session type of a channel
228 *
229 * @param[in] chNum - channel number
230 *
231 * @return EChannelSessSupported - supported session type
232 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530233EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530234
235/** @brief determines number of active sessions on a channel
236 *
237 * @param[in] chNum - channel number
238 *
239 * @return numer of active sessions
240 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530241int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530242
Vernon Mauery58317122018-11-28 11:02:43 -0800243/** @brief determines maximum transfer size for a channel
244 *
245 * @param[in] chNum - channel number
246 *
247 * @return maximum bytes that can be transferred on this channel
248 */
249size_t getChannelMaxTransferSize(uint8_t chNum);
250
AppaRao Puli071f3f22018-05-24 16:45:30 +0530251/** @brief initializes channel management
252 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000253 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530254 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000255Cc ipmiChannelInit();
AppaRao Puli071f3f22018-05-24 16:45:30 +0530256
257/** @brief provides channel info details
258 *
259 * @param[in] chNum - channel number
260 * @param[out] chInfo - channel info details
261 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000262 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530263 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000264Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530265
266/** @brief provides channel access data
267 *
268 * @param[in] chNum - channel number
269 * @param[out] chAccessData -channel access data
270 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000271 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530272 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000273Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530274
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530275/** @brief provides function to convert current channel number (0xE)
276 *
277 * @param[in] chNum - channel number as requested in commands.
Vernon Mauery5ed39592019-05-14 09:16:53 -0700278 * @param[in] devChannel - channel number as provided by device (not 0xE)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530279 *
280 * @return same channel number or proper channel number for current channel
281 * number (0xE).
282 */
Vernon Mauery5ed39592019-05-14 09:16:53 -0700283static inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
284 const uint8_t devChannel)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530285{
286 if (chNum == currentChNum)
287 {
Vernon Mauery5ed39592019-05-14 09:16:53 -0700288 return devChannel;
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530289 }
290 return chNum;
291}
292
AppaRao Puli071f3f22018-05-24 16:45:30 +0530293/** @brief to set channel access data
294 *
295 * @param[in] chNum - channel number
296 * @param[in] chAccessData - channel access data
297 * @param[in] setFlag - flag to indicate updatable fields
298 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000299 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530300 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000301Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
302 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530303
304/** @brief to get channel access data persistent data
305 *
306 * @param[in] chNum - channel number
307 * @param[out] chAccessData - channel access data
308 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000309 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530310 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000311Cc getChannelAccessPersistData(const uint8_t chNum,
312 ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530313
314/** @brief to set channel access data persistent data
315 *
316 * @param[in] chNum - channel number
317 * @param[in] chAccessData - channel access data
318 * @param[in] setFlag - flag to indicate updatable fields
319 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000320 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530321 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000322Cc setChannelAccessPersistData(const uint8_t chNum,
323 const ChannelAccess& chAccessData,
324 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530325
326/** @brief provides supported authentication type for the channel
327 *
328 * @param[in] chNum - channel number
329 * @param[out] authTypeSupported - supported authentication type
330 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000331 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530332 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000333Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530334
335/** @brief provides enabled authentication type for the channel
336 *
337 * @param[in] chNum - channel number
338 * @param[in] priv - privilege
339 * @param[out] authType - enabled authentication type
340 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000341 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530342 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000343Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
344 EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530345
Johnathan Mantey74a21022018-12-13 13:17:56 -0800346/** @brief Retrieves the LAN channel name from the IPMI channel number
347 *
348 * @param[in] chNum - IPMI channel number
349 *
350 * @return the LAN channel name (i.e. eth0)
351 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530352std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800353
Vernon Mauery735ee952019-02-15 13:38:52 -0800354/** @brief Retrieves the LAN channel number from the IPMI channel name
355 *
356 * @param[in] chName - IPMI channel name (i.e. eth0)
357 *
358 * @return the LAN channel number
359 */
360uint8_t getChannelByName(const std::string& chName);
361
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000362/** @brief determines whether payload type is valid
363 *
364 * @param[in] payload type - Payload Type
365 *
366 * @return true if valid, false otherwise
367 */
368bool isValidPayloadType(const PayloadType payloadType);
369
AppaRao Puli071f3f22018-05-24 16:45:30 +0530370} // namespace ipmi