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 |
| 17 | #include <host-ipmid/ipmid-api.h> |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | namespace ipmi |
| 22 | { |
| 23 | |
| 24 | static constexpr uint8_t maxIpmiChannels = 16; |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 25 | static constexpr uint8_t currentChNum = 0xE; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 26 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 27 | /** |
| 28 | * @enum IPMI return codes specific to channel (refer spec se 22.22 response |
| 29 | * data) |
| 30 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 31 | enum ipmi_channel_return_codes |
| 32 | { |
| 33 | IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82, |
| 34 | IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83 |
| 35 | }; |
| 36 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 37 | /** |
| 38 | * @enum Channel Protocol Type (refer spec sec 6.4) |
| 39 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 40 | enum class EChannelProtocolType : uint8_t |
| 41 | { |
| 42 | na = 0x00, |
| 43 | ipmbV10 = 0x01, |
| 44 | icmbV11 = 0x02, |
| 45 | reserved = 0x03, |
| 46 | ipmiSmbus = 0x04, |
| 47 | kcs = 0x05, |
| 48 | smic = 0x06, |
| 49 | bt10 = 0x07, |
| 50 | bt15 = 0x08, |
| 51 | tMode = 0x09, |
| 52 | oem = 0x1C, |
| 53 | }; |
| 54 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 55 | /** |
| 56 | * @enum Channel Medium Type (refer spec sec 6.5) |
| 57 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 58 | enum class EChannelMediumType : uint8_t |
| 59 | { |
| 60 | reserved = 0x00, |
| 61 | ipmb = 0x01, |
| 62 | icmbV10 = 0x02, |
| 63 | icmbV09 = 0x03, |
| 64 | lan8032 = 0x04, |
| 65 | serial = 0x05, |
| 66 | otherLan = 0x06, |
| 67 | pciSmbus = 0x07, |
| 68 | smbusV11 = 0x08, |
| 69 | smbusV20 = 0x09, |
| 70 | usbV1x = 0x0A, |
| 71 | usbV2x = 0x0B, |
| 72 | systemInterface = 0x0C, |
| 73 | oem = 0x60, |
| 74 | unknown = 0x82, |
| 75 | }; |
| 76 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 77 | /** |
| 78 | * @enum Channel Session Type (refer spec sec 22.24 - |
| 79 | * response data byte 5) |
| 80 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 81 | enum class EChannelSessSupported : uint8_t |
| 82 | { |
| 83 | none = 0, |
| 84 | single = 1, |
| 85 | multi = 2, |
| 86 | any = 3, |
| 87 | }; |
| 88 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 89 | /** |
| 90 | * @enum Channel Access Mode (refer spec sec 6.6) |
| 91 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 92 | enum class EChannelAccessMode : uint8_t |
| 93 | { |
| 94 | disabled = 0, |
| 95 | preboot = 1, |
| 96 | alwaysAvail = 2, |
| 97 | shared = 3, |
| 98 | }; |
| 99 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 100 | /** |
| 101 | * @enum Authentication Types (refer spec sec 13.6 - IPMI |
| 102 | * Session Header) |
| 103 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 104 | enum class EAuthType : uint8_t |
| 105 | { |
| 106 | none = (1 << 0x0), |
| 107 | md2 = (1 << 0x1), |
| 108 | md5 = (1 << 0x2), |
| 109 | reserved = (1 << 0x3), |
| 110 | straightPasswd = (1 << 0x4), |
| 111 | oem = (1 << 0x5), |
| 112 | }; |
| 113 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 114 | /** |
| 115 | * @enum Access mode for channel access set/get (refer spec |
| 116 | * sec 22.22 - request byte 2[7:6]) |
| 117 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 118 | typedef enum |
| 119 | { |
| 120 | doNotSet = 0x00, |
| 121 | nvData = 0x01, |
| 122 | activeData = 0x02, |
| 123 | reserved = 0x03, |
| 124 | } EChannelActionType; |
| 125 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 126 | /** |
| 127 | * @enum Access set flag to determine changes that has to be updated |
| 128 | * in channel access data configuration. |
| 129 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 130 | enum AccessSetFlag |
| 131 | { |
| 132 | setAccessMode = (1 << 0), |
| 133 | setUserAuthEnabled = (1 << 1), |
| 134 | setMsgAuthEnabled = (1 << 2), |
| 135 | setAlertingEnabled = (1 << 3), |
| 136 | setPrivLimit = (1 << 4), |
| 137 | }; |
| 138 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 139 | /** @struct ChannelAccess |
| 140 | * |
| 141 | * Structure to store channel access related information, defined in IPMI |
| 142 | * specification and used in Get / Set channel access (refer spec sec 22.22 |
| 143 | * & 22.23) |
| 144 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 145 | struct ChannelAccess |
| 146 | { |
| 147 | uint8_t accessMode; |
| 148 | bool userAuthDisabled; |
| 149 | bool perMsgAuthDisabled; |
| 150 | bool alertingDisabled; |
| 151 | uint8_t privLimit; |
| 152 | }; |
| 153 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 154 | /** @struct ChannelInfo |
| 155 | * |
| 156 | * Structure to store data about channel information, which identifies each |
| 157 | * channel type and information as defined in IPMI specification. (refer spec |
| 158 | * sec 22.22 & 22.23) |
| 159 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 160 | struct ChannelInfo |
| 161 | { |
| 162 | uint8_t mediumType; |
| 163 | uint8_t protocolType; |
| 164 | uint8_t sessionSupported; |
| 165 | bool isIpmi; // Is session IPMI |
| 166 | // This is used in Get LAN Configuration parameter. |
| 167 | // This holds the supported AuthTypes for a given channel. |
| 168 | uint8_t authTypeSupported; |
| 169 | }; |
| 170 | |
| 171 | /** @brief determines valid channel |
| 172 | * |
| 173 | * @param[in] chNum- channel number |
| 174 | * |
| 175 | * @return true if valid, false otherwise |
| 176 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 177 | bool isValidChannel(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 178 | |
| 179 | /** @brief determines whether channel device exist |
| 180 | * |
| 181 | * @param[in] chNum - channel number |
| 182 | * |
| 183 | * @return true if valid, false otherwise |
| 184 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 185 | bool doesDeviceExist(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 186 | |
| 187 | /** @brief determines whether privilege limit is valid |
| 188 | * |
| 189 | * @param[in] privLimit - Privilege limit |
| 190 | * |
| 191 | * @return true if valid, false otherwise |
| 192 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 193 | bool isValidPrivLimit(const uint8_t privLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 194 | |
| 195 | /** @brief determines whether access mode is valid |
| 196 | * |
| 197 | * @param[in] accessMode - Access mode |
| 198 | * |
| 199 | * @return true if valid, false otherwise |
| 200 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 201 | bool isValidAccessMode(const uint8_t accessMode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 202 | |
| 203 | /** @brief determines valid authentication type based on channel number |
| 204 | * |
| 205 | * @param[in] chNum - channel number |
| 206 | * @param[in] authType - authentication type |
| 207 | * |
| 208 | * @return true if valid, false otherwise |
| 209 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 210 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 211 | |
| 212 | /** @brief determines supported session type of a channel |
| 213 | * |
| 214 | * @param[in] chNum - channel number |
| 215 | * |
| 216 | * @return EChannelSessSupported - supported session type |
| 217 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 218 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 219 | |
| 220 | /** @brief determines number of active sessions on a channel |
| 221 | * |
| 222 | * @param[in] chNum - channel number |
| 223 | * |
| 224 | * @return numer of active sessions |
| 225 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 226 | int getChannelActiveSessions(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 227 | |
| 228 | /** @brief initializes channel management |
| 229 | * |
| 230 | * @return IPMI_CC_OK for success, others for failure. |
| 231 | */ |
| 232 | ipmi_ret_t ipmiChannelInit(); |
| 233 | |
| 234 | /** @brief provides channel info details |
| 235 | * |
| 236 | * @param[in] chNum - channel number |
| 237 | * @param[out] chInfo - channel info details |
| 238 | * |
| 239 | * @return IPMI_CC_OK for success, others for failure. |
| 240 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 241 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 242 | |
| 243 | /** @brief provides channel access data |
| 244 | * |
| 245 | * @param[in] chNum - channel number |
| 246 | * @param[out] chAccessData -channel access data |
| 247 | * |
| 248 | * @return IPMI_CC_OK for success, others for failure. |
| 249 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 250 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 251 | ChannelAccess& chAccessData); |
| 252 | |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 253 | /** @brief provides function to convert current channel number (0xE) |
| 254 | * |
| 255 | * @param[in] chNum - channel number as requested in commands. |
| 256 | * |
| 257 | * @return same channel number or proper channel number for current channel |
| 258 | * number (0xE). |
| 259 | */ |
| 260 | uint8_t convertCurrentChannelNum(const uint8_t chNum); |
| 261 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 262 | /** @brief to set channel access data |
| 263 | * |
| 264 | * @param[in] chNum - channel number |
| 265 | * @param[in] chAccessData - channel access data |
| 266 | * @param[in] setFlag - flag to indicate updatable fields |
| 267 | * |
| 268 | * @return IPMI_CC_OK for success, others for failure. |
| 269 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 270 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 271 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 272 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 273 | |
| 274 | /** @brief to get channel access data persistent data |
| 275 | * |
| 276 | * @param[in] chNum - channel number |
| 277 | * @param[out] chAccessData - channel access data |
| 278 | * |
| 279 | * @return IPMI_CC_OK for success, others for failure. |
| 280 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 281 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 282 | ChannelAccess& chAccessData); |
| 283 | |
| 284 | /** @brief to set channel access data persistent data |
| 285 | * |
| 286 | * @param[in] chNum - channel number |
| 287 | * @param[in] chAccessData - channel access data |
| 288 | * @param[in] setFlag - flag to indicate updatable fields |
| 289 | * |
| 290 | * @return IPMI_CC_OK for success, others for failure. |
| 291 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 292 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 293 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 294 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 295 | |
| 296 | /** @brief provides supported authentication type for the channel |
| 297 | * |
| 298 | * @param[in] chNum - channel number |
| 299 | * @param[out] authTypeSupported - supported authentication type |
| 300 | * |
| 301 | * @return IPMI_CC_OK for success, others for failure. |
| 302 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 303 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 304 | uint8_t& authTypeSupported); |
| 305 | |
| 306 | /** @brief provides enabled authentication type for the channel |
| 307 | * |
| 308 | * @param[in] chNum - channel number |
| 309 | * @param[in] priv - privilege |
| 310 | * @param[out] authType - enabled authentication type |
| 311 | * |
| 312 | * @return IPMI_CC_OK for success, others for failure. |
| 313 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 314 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 315 | EAuthType& authType); |
| 316 | |
| 317 | } // namespace ipmi |