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 <ipmid/api.hpp> 18 #include <string> 19 20 namespace ipmi 21 { 22 23 static constexpr uint8_t maxIpmiChannels = 16; 24 static constexpr uint8_t currentChNum = 0xE; 25 static constexpr uint8_t invalidChannel = 0xff; 26 27 /** 28 * @enum IPMI return codes specific to channel (refer spec se 22.22 response 29 * data) 30 */ 31 constexpr Cc ccActionNotSupportedForChannel = 0x82; 32 constexpr Cc ccAccessModeNotSupportedForChannel = 0x83; 33 34 /** 35 * @enum Channel Protocol Type (refer spec sec 6.4) 36 */ 37 enum 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 52 /** 53 * @enum Channel Medium Type (refer spec sec 6.5) 54 */ 55 enum 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 74 /** 75 * @enum Channel Session Type (refer spec sec 22.24 - 76 * response data byte 5) 77 */ 78 enum class EChannelSessSupported : uint8_t 79 { 80 none = 0, 81 single = 1, 82 multi = 2, 83 any = 3, 84 }; 85 86 /** 87 * @enum Channel Access Mode (refer spec sec 6.6) 88 */ 89 enum class EChannelAccessMode : uint8_t 90 { 91 disabled = 0, 92 preboot = 1, 93 alwaysAvail = 2, 94 shared = 3, 95 }; 96 97 /** 98 * @enum Authentication Types (refer spec sec 13.6 - IPMI 99 * Session Header) 100 */ 101 enum 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 111 // 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 */ 116 enum 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 129 /** 130 * @enum Access mode for channel access set/get (refer spec 131 * sec 22.22 - request byte 2[7:6]) 132 */ 133 typedef enum 134 { 135 doNotSet = 0x00, 136 nvData = 0x01, 137 activeData = 0x02, 138 reserved = 0x03, 139 } EChannelActionType; 140 141 /** 142 * @enum Access set flag to determine changes that has to be updated 143 * in channel access data configuration. 144 */ 145 enum AccessSetFlag 146 { 147 setAccessMode = (1 << 0), 148 setUserAuthEnabled = (1 << 1), 149 setMsgAuthEnabled = (1 << 2), 150 setAlertingEnabled = (1 << 3), 151 setPrivLimit = (1 << 4), 152 }; 153 154 /** @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 */ 160 struct ChannelAccess 161 { 162 uint8_t accessMode; 163 bool userAuthDisabled; 164 bool perMsgAuthDisabled; 165 bool alertingDisabled; 166 uint8_t privLimit; 167 }; 168 169 /** @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 */ 175 struct 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 */ 192 bool isValidChannel(const uint8_t chNum); 193 194 /** @brief determines whether channel device exist 195 * 196 * @param[in] chNum - channel number 197 * 198 * @return true if valid, false otherwise 199 */ 200 bool doesDeviceExist(const uint8_t chNum); 201 202 /** @brief determines whether privilege limit is valid 203 * 204 * @param[in] privLimit - Privilege limit 205 * 206 * @return true if valid, false otherwise 207 */ 208 bool isValidPrivLimit(const uint8_t privLimit); 209 210 /** @brief determines whether access mode is valid 211 * 212 * @param[in] accessMode - Access mode 213 * 214 * @return true if valid, false otherwise 215 */ 216 bool isValidAccessMode(const uint8_t accessMode); 217 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 */ 225 bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); 226 227 /** @brief determines supported session type of a channel 228 * 229 * @param[in] chNum - channel number 230 * 231 * @return EChannelSessSupported - supported session type 232 */ 233 EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); 234 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 */ 241 int getChannelActiveSessions(const uint8_t chNum); 242 243 /** @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 */ 249 size_t getChannelMaxTransferSize(uint8_t chNum); 250 251 /** @brief initializes channel management 252 * 253 * @return ccSuccess for success, others for failure. 254 */ 255 Cc ipmiChannelInit(); 256 257 /** @brief provides channel info details 258 * 259 * @param[in] chNum - channel number 260 * @param[out] chInfo - channel info details 261 * 262 * @return ccSuccess for success, others for failure. 263 */ 264 Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); 265 266 /** @brief provides channel access data 267 * 268 * @param[in] chNum - channel number 269 * @param[out] chAccessData -channel access data 270 * 271 * @return ccSuccess for success, others for failure. 272 */ 273 Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData); 274 275 /** @brief provides function to convert current channel number (0xE) 276 * 277 * @param[in] chNum - channel number as requested in commands. 278 * @param[in] devChannel - channel number as provided by device (not 0xE) 279 * 280 * @return same channel number or proper channel number for current channel 281 * number (0xE). 282 */ 283 static inline uint8_t convertCurrentChannelNum(const uint8_t chNum, 284 const uint8_t devChannel) 285 { 286 if (chNum == currentChNum) 287 { 288 return devChannel; 289 } 290 return chNum; 291 } 292 293 /** @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 * 299 * @return ccSuccess for success, others for failure. 300 */ 301 Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData, 302 const uint8_t setFlag); 303 304 /** @brief to get channel access data persistent data 305 * 306 * @param[in] chNum - channel number 307 * @param[out] chAccessData - channel access data 308 * 309 * @return ccSuccess for success, others for failure. 310 */ 311 Cc getChannelAccessPersistData(const uint8_t chNum, 312 ChannelAccess& chAccessData); 313 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 * 320 * @return ccSuccess for success, others for failure. 321 */ 322 Cc setChannelAccessPersistData(const uint8_t chNum, 323 const ChannelAccess& chAccessData, 324 const uint8_t setFlag); 325 326 /** @brief provides supported authentication type for the channel 327 * 328 * @param[in] chNum - channel number 329 * @param[out] authTypeSupported - supported authentication type 330 * 331 * @return ccSuccess for success, others for failure. 332 */ 333 Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported); 334 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 * 341 * @return ccSuccess for success, others for failure. 342 */ 343 Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, 344 EAuthType& authType); 345 346 /** @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 */ 352 std::string getChannelName(const uint8_t chNum); 353 354 /** @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 */ 360 uint8_t getChannelByName(const std::string& chName); 361 362 /** @brief determines whether payload type is valid 363 * 364 * @param[in] payload type - Payload Type 365 * 366 * @return true if valid, false otherwise 367 */ 368 bool isValidPayloadType(const PayloadType payloadType); 369 370 } // namespace ipmi 371