summaryrefslogtreecommitdiffstats
path: root/user_channel/channel_layer.hpp
blob: a3aebb8d7ecae9d7d0a93f77a1fd4d02caf4fbbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#pragma once
#include <host-ipmid/ipmid-api.h>

#include <string>

namespace ipmi
{

static constexpr uint8_t maxIpmiChannels = 16;
static constexpr uint8_t currentChNum = 0xE;

/**
 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
 * data)
 */
enum ipmi_channel_return_codes
{
    IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
    IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
};

/**
 * @enum Channel Protocol Type (refer spec sec 6.4)
 */
enum class EChannelProtocolType : uint8_t
{
    na = 0x00,
    ipmbV10 = 0x01,
    icmbV11 = 0x02,
    reserved = 0x03,
    ipmiSmbus = 0x04,
    kcs = 0x05,
    smic = 0x06,
    bt10 = 0x07,
    bt15 = 0x08,
    tMode = 0x09,
    oem = 0x1C,
};

/**
 * @enum Channel Medium Type (refer spec sec 6.5)
 */
enum class EChannelMediumType : uint8_t
{
    reserved = 0x00,
    ipmb = 0x01,
    icmbV10 = 0x02,
    icmbV09 = 0x03,
    lan8032 = 0x04,
    serial = 0x05,
    otherLan = 0x06,
    pciSmbus = 0x07,
    smbusV11 = 0x08,
    smbusV20 = 0x09,
    usbV1x = 0x0A,
    usbV2x = 0x0B,
    systemInterface = 0x0C,
    oem = 0x60,
    unknown = 0x82,
};

/**
 * @enum Channel Session Type (refer spec sec 22.24 -
 * response data byte 5)
 */
enum class EChannelSessSupported : uint8_t
{
    none = 0,
    single = 1,
    multi = 2,
    any = 3,
};

/**
 * @enum Channel Access Mode (refer spec sec 6.6)
 */
enum class EChannelAccessMode : uint8_t
{
    disabled = 0,
    preboot = 1,
    alwaysAvail = 2,
    shared = 3,
};

/**
 * @enum Authentication Types (refer spec sec 13.6 - IPMI
 * Session Header)
 */
enum class EAuthType : uint8_t
{
    none = (1 << 0x0),
    md2 = (1 << 0x1),
    md5 = (1 << 0x2),
    reserved = (1 << 0x3),
    straightPasswd = (1 << 0x4),
    oem = (1 << 0x5),
};

/**
 * @enum Access mode for channel access set/get (refer spec
 * sec 22.22 - request byte 2[7:6])
 */
typedef enum
{
    doNotSet = 0x00,
    nvData = 0x01,
    activeData = 0x02,
    reserved = 0x03,
} EChannelActionType;

/**
 * @enum Access set flag to determine changes that has to be updated
 * in channel access data configuration.
 */
enum AccessSetFlag
{
    setAccessMode = (1 << 0),
    setUserAuthEnabled = (1 << 1),
    setMsgAuthEnabled = (1 << 2),
    setAlertingEnabled = (1 << 3),
    setPrivLimit = (1 << 4),
};

/** @struct ChannelAccess
 *
 *  Structure to store channel access related information, defined in IPMI
 * specification and used in Get / Set channel access (refer spec sec 22.22
 * & 22.23)
 */
struct ChannelAccess
{
    uint8_t accessMode;
    bool userAuthDisabled;
    bool perMsgAuthDisabled;
    bool alertingDisabled;
    uint8_t privLimit;
};

/** @struct ChannelInfo
 *
 *  Structure to store data about channel information, which identifies each
 *  channel type and information as defined in IPMI specification. (refer spec
 * sec 22.22 & 22.23)
 */
struct ChannelInfo
{
    uint8_t mediumType;
    uint8_t protocolType;
    uint8_t sessionSupported;
    bool isIpmi; // Is session IPMI
    // This is used in Get LAN Configuration parameter.
    // This holds the supported AuthTypes for a given channel.
    uint8_t authTypeSupported;
};

/** @brief determines valid channel
 *
 *  @param[in] chNum- channel number
 *
 *  @return true if valid, false otherwise
 */
bool isValidChannel(const uint8_t chNum);

/** @brief determines whether channel device exist
 *
 *  @param[in] chNum - channel number
 *
 *  @return true if valid, false otherwise
 */
bool doesDeviceExist(const uint8_t chNum);

/** @brief determines whether privilege limit is valid
 *
 *  @param[in] privLimit - Privilege limit
 *
 *  @return true if valid, false otherwise
 */
bool isValidPrivLimit(const uint8_t privLimit);

/** @brief determines whether access mode  is valid
 *
 *  @param[in] accessMode - Access mode
 *
 *  @return true if valid, false otherwise
 */
bool isValidAccessMode(const uint8_t accessMode);

/** @brief determines valid authentication type based on channel number
 *
 *  @param[in] chNum - channel number
 *  @param[in] authType - authentication type
 *
 *  @return true if valid, false otherwise
 */
bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);

/** @brief determines supported session type of a channel
 *
 *  @param[in] chNum - channel number
 *
 *  @return EChannelSessSupported - supported session type
 */
EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);

/** @brief determines number of active sessions on a channel
 *
 *  @param[in] chNum - channel number
 *
 *  @return numer of active sessions
 */
int getChannelActiveSessions(const uint8_t chNum);

/** @brief determines maximum transfer size for a channel
 *
 *  @param[in] chNum - channel number
 *
 *  @return maximum bytes that can be transferred on this channel
 */
size_t getChannelMaxTransferSize(uint8_t chNum);

/** @brief initializes channel management
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t ipmiChannelInit();

/** @brief provides channel info details
 *
 *  @param[in] chNum - channel number
 *  @param[out] chInfo - channel info details
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);

/** @brief provides channel access data
 *
 *  @param[in] chNum - channel number
 *  @param[out] chAccessData -channel access data
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t getChannelAccessData(const uint8_t chNum,
                                ChannelAccess& chAccessData);

/** @brief provides function to convert current channel number (0xE)
 *
 *  @param[in] chNum - channel number as requested in commands.
 *
 *  @return same channel number or proper channel number for current channel
 * number (0xE).
 */
uint8_t convertCurrentChannelNum(const uint8_t chNum);

/** @brief to set channel access data
 *
 *  @param[in] chNum - channel number
 *  @param[in] chAccessData - channel access data
 *  @param[in] setFlag - flag to indicate updatable fields
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t setChannelAccessData(const uint8_t chNum,
                                const ChannelAccess& chAccessData,
                                const uint8_t setFlag);

/** @brief to get channel access data persistent data
 *
 *  @param[in] chNum - channel number
 *  @param[out] chAccessData - channel access data
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
                                       ChannelAccess& chAccessData);

/** @brief to set channel access data persistent data
 *
 *  @param[in] chNum - channel number
 *  @param[in] chAccessData - channel access data
 *  @param[in] setFlag - flag to indicate updatable fields
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
                                       const ChannelAccess& chAccessData,
                                       const uint8_t setFlag);

/** @brief provides supported authentication type for the channel
 *
 *  @param[in] chNum - channel number
 *  @param[out] authTypeSupported - supported authentication type
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
                                       uint8_t& authTypeSupported);

/** @brief provides enabled authentication type for the channel
 *
 *  @param[in] chNum - channel number
 *  @param[in] priv - privilege
 *  @param[out] authType - enabled authentication type
 *
 *  @return IPMI_CC_OK for success, others for failure.
 */
ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
                                     EAuthType& authType);

/** @brief Retrieves the LAN channel name from the IPMI channel number
 *
 *  @param[in] chNum - IPMI channel number
 *
 *  @return the LAN channel name (i.e. eth0)
 */
std::string getChannelName(const int chNum);

} // namespace ipmi
OpenPOWER on IntegriCloud