blob: bddd6b50469444e0bfd36846b513d0580383604f [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
Sumanth Bhate4e633e2019-05-14 12:13:57 +000017#include <array>
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000018#include <ipmid/api.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053019#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;
Vernon Mauery735ee952019-02-15 13:38:52 -080026static constexpr uint8_t invalidChannel = 0xff;
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +000027static constexpr const uint8_t ccActionNotSupportedForChannel = 0x82;
28static constexpr const uint8_t ccAccessModeNotSupportedForChannel = 0x83;
AppaRao Puli071f3f22018-05-24 16:45:30 +053029
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053030/**
Sumanth Bhate4e633e2019-05-14 12:13:57 +000031 * @array of privilege levels
32 */
33extern const std::array<std::string, PRIVILEGE_OEM + 1> privList;
34
35/**
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053036 * @enum Channel Protocol Type (refer spec sec 6.4)
37 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053038enum class EChannelProtocolType : uint8_t
39{
40 na = 0x00,
41 ipmbV10 = 0x01,
42 icmbV11 = 0x02,
43 reserved = 0x03,
44 ipmiSmbus = 0x04,
45 kcs = 0x05,
46 smic = 0x06,
47 bt10 = 0x07,
48 bt15 = 0x08,
49 tMode = 0x09,
50 oem = 0x1C,
51};
52
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053053/**
54 * @enum Channel Medium Type (refer spec sec 6.5)
55 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053056enum class EChannelMediumType : uint8_t
57{
58 reserved = 0x00,
59 ipmb = 0x01,
60 icmbV10 = 0x02,
61 icmbV09 = 0x03,
62 lan8032 = 0x04,
63 serial = 0x05,
64 otherLan = 0x06,
65 pciSmbus = 0x07,
66 smbusV11 = 0x08,
67 smbusV20 = 0x09,
68 usbV1x = 0x0A,
69 usbV2x = 0x0B,
70 systemInterface = 0x0C,
71 oem = 0x60,
72 unknown = 0x82,
73};
74
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053075/**
76 * @enum Channel Session Type (refer spec sec 22.24 -
77 * response data byte 5)
78 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053079enum class EChannelSessSupported : uint8_t
80{
81 none = 0,
82 single = 1,
83 multi = 2,
84 any = 3,
85};
86
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053087/**
88 * @enum Channel Access Mode (refer spec sec 6.6)
89 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053090enum class EChannelAccessMode : uint8_t
91{
92 disabled = 0,
93 preboot = 1,
94 alwaysAvail = 2,
95 shared = 3,
96};
97
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053098/**
99 * @enum Authentication Types (refer spec sec 13.6 - IPMI
100 * Session Header)
101 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530102enum class EAuthType : uint8_t
103{
104 none = (1 << 0x0),
105 md2 = (1 << 0x1),
106 md5 = (1 << 0x2),
107 reserved = (1 << 0x3),
108 straightPasswd = (1 << 0x4),
109 oem = (1 << 0x5),
110};
111
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530112// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
113// to phosphor-ipmi-host/include
114/**
115 * @enum Payload Types (refer spec sec 13.27.3)
116 */
117enum class PayloadType : uint8_t
118{
119 IPMI = 0x00,
120 SOL = 0x01,
121 OPEN_SESSION_REQUEST = 0x10,
122 OPEN_SESSION_RESPONSE = 0x11,
123 RAKP1 = 0x12,
124 RAKP2 = 0x13,
125 RAKP3 = 0x14,
126 RAKP4 = 0x15,
127 INVALID = 0xFF,
128};
129
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530130/**
131 * @enum Access mode for channel access set/get (refer spec
132 * sec 22.22 - request byte 2[7:6])
133 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530134typedef enum
135{
136 doNotSet = 0x00,
137 nvData = 0x01,
138 activeData = 0x02,
139 reserved = 0x03,
140} EChannelActionType;
141
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530142/**
143 * @enum Access set flag to determine changes that has to be updated
144 * in channel access data configuration.
145 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530146enum AccessSetFlag
147{
148 setAccessMode = (1 << 0),
149 setUserAuthEnabled = (1 << 1),
150 setMsgAuthEnabled = (1 << 2),
151 setAlertingEnabled = (1 << 3),
152 setPrivLimit = (1 << 4),
153};
154
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530155/** @struct ChannelAccess
156 *
157 * Structure to store channel access related information, defined in IPMI
158 * specification and used in Get / Set channel access (refer spec sec 22.22
159 * & 22.23)
160 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530161struct ChannelAccess
162{
163 uint8_t accessMode;
164 bool userAuthDisabled;
165 bool perMsgAuthDisabled;
166 bool alertingDisabled;
167 uint8_t privLimit;
168};
169
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530170/** @struct ChannelInfo
171 *
172 * Structure to store data about channel information, which identifies each
173 * channel type and information as defined in IPMI specification. (refer spec
174 * sec 22.22 & 22.23)
175 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530176struct ChannelInfo
177{
178 uint8_t mediumType;
179 uint8_t protocolType;
180 uint8_t sessionSupported;
181 bool isIpmi; // Is session IPMI
182 // This is used in Get LAN Configuration parameter.
183 // This holds the supported AuthTypes for a given channel.
184 uint8_t authTypeSupported;
185};
186
187/** @brief determines valid channel
188 *
189 * @param[in] chNum- channel number
190 *
191 * @return true if valid, false otherwise
192 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530193bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530194
195/** @brief determines whether channel device exist
196 *
197 * @param[in] chNum - channel number
198 *
199 * @return true if valid, false otherwise
200 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530201bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530202
203/** @brief determines whether privilege limit is valid
204 *
205 * @param[in] privLimit - Privilege limit
206 *
207 * @return true if valid, false otherwise
208 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530209bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530210
211/** @brief determines whether access mode is valid
212 *
213 * @param[in] accessMode - Access mode
214 *
215 * @return true if valid, false otherwise
216 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530217bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530218
219/** @brief determines valid authentication type based on channel number
220 *
221 * @param[in] chNum - channel number
222 * @param[in] authType - authentication type
223 *
224 * @return true if valid, false otherwise
225 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530226bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530227
228/** @brief determines supported session type of a channel
229 *
230 * @param[in] chNum - channel number
231 *
232 * @return EChannelSessSupported - supported session type
233 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530234EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530235
236/** @brief determines number of active sessions on a channel
237 *
238 * @param[in] chNum - channel number
239 *
240 * @return numer of active sessions
241 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530242int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530243
Vernon Mauery58317122018-11-28 11:02:43 -0800244/** @brief determines maximum transfer size for a channel
245 *
246 * @param[in] chNum - channel number
247 *
248 * @return maximum bytes that can be transferred on this channel
249 */
250size_t getChannelMaxTransferSize(uint8_t chNum);
251
AppaRao Puli071f3f22018-05-24 16:45:30 +0530252/** @brief initializes channel management
253 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000254 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530255 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000256Cc ipmiChannelInit();
AppaRao Puli071f3f22018-05-24 16:45:30 +0530257
258/** @brief provides channel info details
259 *
260 * @param[in] chNum - channel number
261 * @param[out] chInfo - channel info details
262 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000263 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530264 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000265Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530266
267/** @brief provides channel access data
268 *
269 * @param[in] chNum - channel number
270 * @param[out] chAccessData -channel access data
271 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000272 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530273 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000274Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530275
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530276/** @brief provides function to convert current channel number (0xE)
277 *
278 * @param[in] chNum - channel number as requested in commands.
Vernon Mauery5ed39592019-05-14 09:16:53 -0700279 * @param[in] devChannel - channel number as provided by device (not 0xE)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530280 *
281 * @return same channel number or proper channel number for current channel
282 * number (0xE).
283 */
Vernon Mauery5ed39592019-05-14 09:16:53 -0700284static inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
285 const uint8_t devChannel)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530286{
287 if (chNum == currentChNum)
288 {
Vernon Mauery5ed39592019-05-14 09:16:53 -0700289 return devChannel;
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530290 }
291 return chNum;
292}
293
AppaRao Puli071f3f22018-05-24 16:45:30 +0530294/** @brief to set channel access data
295 *
296 * @param[in] chNum - channel number
297 * @param[in] chAccessData - channel access data
298 * @param[in] setFlag - flag to indicate updatable fields
299 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000300 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530301 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000302Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
303 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530304
305/** @brief to get channel access data persistent data
306 *
307 * @param[in] chNum - channel number
308 * @param[out] chAccessData - channel access data
309 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000310 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530311 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000312Cc getChannelAccessPersistData(const uint8_t chNum,
313 ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530314
315/** @brief to set channel access data persistent data
316 *
317 * @param[in] chNum - channel number
318 * @param[in] chAccessData - channel access data
319 * @param[in] setFlag - flag to indicate updatable fields
320 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000321 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530322 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000323Cc setChannelAccessPersistData(const uint8_t chNum,
324 const ChannelAccess& chAccessData,
325 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530326
327/** @brief provides supported authentication type for the channel
328 *
329 * @param[in] chNum - channel number
330 * @param[out] authTypeSupported - supported authentication type
331 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000332 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530333 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000334Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530335
336/** @brief provides enabled authentication type for the channel
337 *
338 * @param[in] chNum - channel number
339 * @param[in] priv - privilege
340 * @param[out] authType - enabled authentication type
341 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000342 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530343 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000344Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
345 EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530346
Johnathan Mantey74a21022018-12-13 13:17:56 -0800347/** @brief Retrieves the LAN channel name from the IPMI channel number
348 *
349 * @param[in] chNum - IPMI channel number
350 *
351 * @return the LAN channel name (i.e. eth0)
352 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530353std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800354
Vernon Mauery735ee952019-02-15 13:38:52 -0800355/** @brief Retrieves the LAN channel number from the IPMI channel name
356 *
357 * @param[in] chName - IPMI channel name (i.e. eth0)
358 *
359 * @return the LAN channel number
360 */
361uint8_t getChannelByName(const std::string& chName);
362
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000363/** @brief determines whether payload type is valid
364 *
365 * @param[in] payload type - Payload Type
366 *
367 * @return true if valid, false otherwise
368 */
369bool isValidPayloadType(const PayloadType payloadType);
370
AppaRao Puli071f3f22018-05-24 16:45:30 +0530371} // namespace ipmi