AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1 | /* |
| 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 III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 17 | #include <ipmid/api.h> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 18 | |
Richard Marian Thomaiyar | 30b0112 | 2019-04-03 15:46:03 +0530 | [diff] [blame] | 19 | #include <ipmid/message.hpp> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 20 | #include <string> |
| 21 | |
| 22 | namespace ipmi |
| 23 | { |
| 24 | |
| 25 | static constexpr uint8_t maxIpmiChannels = 16; |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 26 | static constexpr uint8_t currentChNum = 0xE; |
Vernon Mauery | 735ee95 | 2019-02-15 13:38:52 -0800 | [diff] [blame] | 27 | static constexpr uint8_t invalidChannel = 0xff; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 28 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 29 | /** |
| 30 | * @enum IPMI return codes specific to channel (refer spec se 22.22 response |
| 31 | * data) |
| 32 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 33 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 39 | /** |
| 40 | * @enum Channel Protocol Type (refer spec sec 6.4) |
| 41 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 42 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 57 | /** |
| 58 | * @enum Channel Medium Type (refer spec sec 6.5) |
| 59 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 60 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 79 | /** |
| 80 | * @enum Channel Session Type (refer spec sec 22.24 - |
| 81 | * response data byte 5) |
| 82 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 83 | enum class EChannelSessSupported : uint8_t |
| 84 | { |
| 85 | none = 0, |
| 86 | single = 1, |
| 87 | multi = 2, |
| 88 | any = 3, |
| 89 | }; |
| 90 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 91 | /** |
| 92 | * @enum Channel Access Mode (refer spec sec 6.6) |
| 93 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 94 | enum class EChannelAccessMode : uint8_t |
| 95 | { |
| 96 | disabled = 0, |
| 97 | preboot = 1, |
| 98 | alwaysAvail = 2, |
| 99 | shared = 3, |
| 100 | }; |
| 101 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 102 | /** |
| 103 | * @enum Authentication Types (refer spec sec 13.6 - IPMI |
| 104 | * Session Header) |
| 105 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 106 | enum 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 | |
Saravanan Palanisamy | b5a0f16 | 2019-03-04 18:34:44 +0530 | [diff] [blame] | 116 | // TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp |
| 117 | // to phosphor-ipmi-host/include |
| 118 | /** |
| 119 | * @enum Payload Types (refer spec sec 13.27.3) |
| 120 | */ |
| 121 | enum class PayloadType : uint8_t |
| 122 | { |
| 123 | IPMI = 0x00, |
| 124 | SOL = 0x01, |
| 125 | OPEN_SESSION_REQUEST = 0x10, |
| 126 | OPEN_SESSION_RESPONSE = 0x11, |
| 127 | RAKP1 = 0x12, |
| 128 | RAKP2 = 0x13, |
| 129 | RAKP3 = 0x14, |
| 130 | RAKP4 = 0x15, |
| 131 | INVALID = 0xFF, |
| 132 | }; |
| 133 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 134 | /** |
| 135 | * @enum Access mode for channel access set/get (refer spec |
| 136 | * sec 22.22 - request byte 2[7:6]) |
| 137 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 138 | typedef enum |
| 139 | { |
| 140 | doNotSet = 0x00, |
| 141 | nvData = 0x01, |
| 142 | activeData = 0x02, |
| 143 | reserved = 0x03, |
| 144 | } EChannelActionType; |
| 145 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 146 | /** |
| 147 | * @enum Access set flag to determine changes that has to be updated |
| 148 | * in channel access data configuration. |
| 149 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 150 | enum AccessSetFlag |
| 151 | { |
| 152 | setAccessMode = (1 << 0), |
| 153 | setUserAuthEnabled = (1 << 1), |
| 154 | setMsgAuthEnabled = (1 << 2), |
| 155 | setAlertingEnabled = (1 << 3), |
| 156 | setPrivLimit = (1 << 4), |
| 157 | }; |
| 158 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 159 | /** @struct ChannelAccess |
| 160 | * |
| 161 | * Structure to store channel access related information, defined in IPMI |
| 162 | * specification and used in Get / Set channel access (refer spec sec 22.22 |
| 163 | * & 22.23) |
| 164 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 165 | struct ChannelAccess |
| 166 | { |
| 167 | uint8_t accessMode; |
| 168 | bool userAuthDisabled; |
| 169 | bool perMsgAuthDisabled; |
| 170 | bool alertingDisabled; |
| 171 | uint8_t privLimit; |
| 172 | }; |
| 173 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 174 | /** @struct ChannelInfo |
| 175 | * |
| 176 | * Structure to store data about channel information, which identifies each |
| 177 | * channel type and information as defined in IPMI specification. (refer spec |
| 178 | * sec 22.22 & 22.23) |
| 179 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 180 | struct ChannelInfo |
| 181 | { |
| 182 | uint8_t mediumType; |
| 183 | uint8_t protocolType; |
| 184 | uint8_t sessionSupported; |
| 185 | bool isIpmi; // Is session IPMI |
| 186 | // This is used in Get LAN Configuration parameter. |
| 187 | // This holds the supported AuthTypes for a given channel. |
| 188 | uint8_t authTypeSupported; |
| 189 | }; |
| 190 | |
| 191 | /** @brief determines valid channel |
| 192 | * |
| 193 | * @param[in] chNum- channel number |
| 194 | * |
| 195 | * @return true if valid, false otherwise |
| 196 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 197 | bool isValidChannel(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 198 | |
| 199 | /** @brief determines whether channel device exist |
| 200 | * |
| 201 | * @param[in] chNum - channel number |
| 202 | * |
| 203 | * @return true if valid, false otherwise |
| 204 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 205 | bool doesDeviceExist(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 206 | |
| 207 | /** @brief determines whether privilege limit is valid |
| 208 | * |
| 209 | * @param[in] privLimit - Privilege limit |
| 210 | * |
| 211 | * @return true if valid, false otherwise |
| 212 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 213 | bool isValidPrivLimit(const uint8_t privLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 214 | |
| 215 | /** @brief determines whether access mode is valid |
| 216 | * |
| 217 | * @param[in] accessMode - Access mode |
| 218 | * |
| 219 | * @return true if valid, false otherwise |
| 220 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 221 | bool isValidAccessMode(const uint8_t accessMode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 222 | |
| 223 | /** @brief determines valid authentication type based on channel number |
| 224 | * |
| 225 | * @param[in] chNum - channel number |
| 226 | * @param[in] authType - authentication type |
| 227 | * |
| 228 | * @return true if valid, false otherwise |
| 229 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 230 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 231 | |
| 232 | /** @brief determines supported session type of a channel |
| 233 | * |
| 234 | * @param[in] chNum - channel number |
| 235 | * |
| 236 | * @return EChannelSessSupported - supported session type |
| 237 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 238 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 239 | |
| 240 | /** @brief determines number of active sessions on a channel |
| 241 | * |
| 242 | * @param[in] chNum - channel number |
| 243 | * |
| 244 | * @return numer of active sessions |
| 245 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 246 | int getChannelActiveSessions(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 247 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 248 | /** @brief determines maximum transfer size for a channel |
| 249 | * |
| 250 | * @param[in] chNum - channel number |
| 251 | * |
| 252 | * @return maximum bytes that can be transferred on this channel |
| 253 | */ |
| 254 | size_t getChannelMaxTransferSize(uint8_t chNum); |
| 255 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 256 | /** @brief initializes channel management |
| 257 | * |
| 258 | * @return IPMI_CC_OK for success, others for failure. |
| 259 | */ |
| 260 | ipmi_ret_t ipmiChannelInit(); |
| 261 | |
| 262 | /** @brief provides channel info details |
| 263 | * |
| 264 | * @param[in] chNum - channel number |
| 265 | * @param[out] chInfo - channel info details |
| 266 | * |
| 267 | * @return IPMI_CC_OK for success, others for failure. |
| 268 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 269 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 270 | |
| 271 | /** @brief provides channel access data |
| 272 | * |
| 273 | * @param[in] chNum - channel number |
| 274 | * @param[out] chAccessData -channel access data |
| 275 | * |
| 276 | * @return IPMI_CC_OK for success, others for failure. |
| 277 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 278 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 279 | ChannelAccess& chAccessData); |
| 280 | |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 281 | /** @brief provides function to convert current channel number (0xE) |
| 282 | * |
| 283 | * @param[in] chNum - channel number as requested in commands. |
Richard Marian Thomaiyar | 30b0112 | 2019-04-03 15:46:03 +0530 | [diff] [blame] | 284 | * @param[in] ipmi::context - ipmi context ptr, which has more details |
| 285 | * |
| 286 | * @return same channel number or proper channel number for current channel |
| 287 | * number (0xE). |
| 288 | */ |
| 289 | inline uint8_t convertCurrentChannelNum(const uint8_t chNum, |
| 290 | ipmi::Context::ptr ctx) |
| 291 | { |
| 292 | if (chNum == currentChNum) |
| 293 | { |
| 294 | return ctx->channel; |
| 295 | } |
| 296 | return chNum; |
| 297 | } |
| 298 | |
| 299 | /** @brief provides function to convert current channel number (0xE) |
| 300 | * |
| 301 | * @param[in] chNum - channel number as requested in commands. |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 302 | * |
| 303 | * @return same channel number or proper channel number for current channel |
| 304 | * number (0xE). |
| 305 | */ |
| 306 | uint8_t convertCurrentChannelNum(const uint8_t chNum); |
| 307 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 308 | /** @brief to set channel access data |
| 309 | * |
| 310 | * @param[in] chNum - channel number |
| 311 | * @param[in] chAccessData - channel access data |
| 312 | * @param[in] setFlag - flag to indicate updatable fields |
| 313 | * |
| 314 | * @return IPMI_CC_OK for success, others for failure. |
| 315 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 316 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 317 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 318 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 319 | |
| 320 | /** @brief to get channel access data persistent data |
| 321 | * |
| 322 | * @param[in] chNum - channel number |
| 323 | * @param[out] chAccessData - channel access data |
| 324 | * |
| 325 | * @return IPMI_CC_OK for success, others for failure. |
| 326 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 327 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 328 | ChannelAccess& chAccessData); |
| 329 | |
| 330 | /** @brief to set channel access data persistent data |
| 331 | * |
| 332 | * @param[in] chNum - channel number |
| 333 | * @param[in] chAccessData - channel access data |
| 334 | * @param[in] setFlag - flag to indicate updatable fields |
| 335 | * |
| 336 | * @return IPMI_CC_OK for success, others for failure. |
| 337 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 338 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 339 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 340 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 341 | |
| 342 | /** @brief provides supported authentication type for the channel |
| 343 | * |
| 344 | * @param[in] chNum - channel number |
| 345 | * @param[out] authTypeSupported - supported authentication type |
| 346 | * |
| 347 | * @return IPMI_CC_OK for success, others for failure. |
| 348 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 349 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 350 | uint8_t& authTypeSupported); |
| 351 | |
| 352 | /** @brief provides enabled authentication type for the channel |
| 353 | * |
| 354 | * @param[in] chNum - channel number |
| 355 | * @param[in] priv - privilege |
| 356 | * @param[out] authType - enabled authentication type |
| 357 | * |
| 358 | * @return IPMI_CC_OK for success, others for failure. |
| 359 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 360 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 361 | EAuthType& authType); |
| 362 | |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 363 | /** @brief Retrieves the LAN channel name from the IPMI channel number |
| 364 | * |
| 365 | * @param[in] chNum - IPMI channel number |
| 366 | * |
| 367 | * @return the LAN channel name (i.e. eth0) |
| 368 | */ |
Richard Marian Thomaiyar | 55768e3 | 2019-03-02 22:54:37 +0530 | [diff] [blame] | 369 | std::string getChannelName(const uint8_t chNum); |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 370 | |
Vernon Mauery | 735ee95 | 2019-02-15 13:38:52 -0800 | [diff] [blame] | 371 | /** @brief Retrieves the LAN channel number from the IPMI channel name |
| 372 | * |
| 373 | * @param[in] chName - IPMI channel name (i.e. eth0) |
| 374 | * |
| 375 | * @return the LAN channel number |
| 376 | */ |
| 377 | uint8_t getChannelByName(const std::string& chName); |
| 378 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 379 | } // namespace ipmi |