1 #pragma once 2 3 #include "stream.hpp" 4 5 #include <array> 6 #include <optional> 7 8 namespace openpower 9 { 10 namespace pels 11 { 12 namespace src 13 { 14 15 /** 16 * @brief Specifies if the incoming maintenance procedure or 17 * symbolic FRU is the registry name or the raw name. 18 */ 19 enum class CalloutValueType 20 { 21 raw, 22 registryName 23 }; 24 25 /** 26 * @class FRUIdentity 27 * 28 * This represents the FRU Identity substructure in the 29 * callout subsection of the SRC PEL section. 30 * 31 * It provides information about the FRU being called out, 32 * such as serial number and part number. A maintenance 33 * procedure name may be used instead of the part number, 34 * and this would be indicated in the flags field. 35 */ 36 class FRUIdentity 37 { 38 public: 39 /** 40 * @brief The failing component type 41 * 42 * Upper nibble of the flags byte 43 */ 44 enum FailingComponentType 45 { 46 hardwareFRU = 0x10, 47 codeFRU = 0x20, 48 configError = 0x30, 49 maintenanceProc = 0x40, 50 externalFRU = 0x90, 51 externalCodeFRU = 0xA0, 52 toolFRU = 0xB0, 53 symbolicFRU = 0xC0, 54 symbolicFRUTrustedLocCode = 0xE0 55 }; 56 57 /** 58 * @brief The lower nibble of the flags byte 59 */ 60 enum Flags 61 { 62 pnSupplied = 0x08, 63 ccinSupplied = 0x04, 64 maintProcSupplied = 0x02, 65 snSupplied = 0x01 66 }; 67 68 FRUIdentity() = delete; 69 ~FRUIdentity() = default; 70 FRUIdentity(const FRUIdentity&) = default; 71 FRUIdentity& operator=(const FRUIdentity&) = default; 72 FRUIdentity(FRUIdentity&&) = default; 73 FRUIdentity& operator=(FRUIdentity&&) = default; 74 75 /** 76 * @brief Constructor 77 * 78 * Fills in this class's data fields from the stream. 79 * 80 * @param[in] pel - the PEL data stream 81 */ 82 explicit FRUIdentity(Stream& pel); 83 84 /** 85 * Constructor 86 * 87 * Creates the object as a hardware callout with the part number, 88 * CCIN, and serial number fields supplied. 89 * 90 * @param[in] partNumber - The part number of the FRU 91 * @param[in] ccin - The CCIN of the FRU 92 * @param[in] serialNumber - The serial number of the FRU 93 */ 94 FRUIdentity(const std::string& partNumber, const std::string& ccin, 95 const std::string& serialNumber); 96 97 /** 98 * @brief Constructor 99 * 100 * Creates the object with a maintenance procedure callout. 101 * 102 * @param[in] procedureFromRegistry - The maintenance procedure name 103 * as defined in the message registry. 104 */ FRUIdentity(const std::string & procedureFromRegistry)105 explicit FRUIdentity(const std::string& procedureFromRegistry) : 106 FRUIdentity(procedureFromRegistry, CalloutValueType::registryName) 107 {} 108 109 /** 110 * @brief Constructor 111 * 112 * Creates the object with a maintenance procedure callout. 113 * 114 * @param[in] procedure - The maintenance procedure name. 115 * @param[in] type - If the procedure is the raw name or the registry name. 116 */ 117 FRUIdentity(const std::string& procedure, CalloutValueType type); 118 119 /** 120 * @brief Constructor 121 * 122 * Creates the object with a symbolic FRU callout. 123 * 124 * @param[in] symbolicFRUFromRegistry - The symbolic FRU name as 125 * defined in the message registry. 126 * @param[in] trustedLocationCode - If this FRU callout's location code 127 * can be trusted to be correct. 128 */ FRUIdentity(const std::string & symbolicFRUFromRegistry,bool trustedLocationCode)129 FRUIdentity(const std::string& symbolicFRUFromRegistry, 130 bool trustedLocationCode) : 131 FRUIdentity(symbolicFRUFromRegistry, CalloutValueType::registryName, 132 trustedLocationCode) 133 {} 134 135 /** 136 * @brief Constructor 137 * 138 * Creates the object with a symbolic FRU callout. 139 * 140 * @param[in] fru - The symbolic FRU name. 141 * @param[in] type - If the FRU is the raw name or the registry name. 142 * @param[in] trustedLocationCode - If this FRU callout's location code 143 * can be trusted to be correct. 144 */ 145 FRUIdentity(const std::string& fru, CalloutValueType type, 146 bool trustedLocationCode); 147 148 /** 149 * @brief Flatten the object into the stream 150 * 151 * @param[in] stream - The stream to write to 152 */ 153 void flatten(Stream& pel) const; 154 155 /** 156 * @brief Returns the size of this structure when flattened into a PEL 157 * 158 * @return size_t - The size of the section 159 */ 160 size_t flattenedSize() const; 161 162 /** 163 * @brief Returns the type field 164 * 165 * @return uint16_t - The type, always 0x4944 "ID". 166 */ type() const167 uint16_t type() const 168 { 169 return _type; 170 } 171 /** 172 * @brief The failing component type for this FRU callout. 173 * 174 * @return FailingComponentType 175 */ failingComponentType() const176 FailingComponentType failingComponentType() const 177 { 178 return static_cast<FailingComponentType>(_flags & 0xF0); 179 } 180 181 /** 182 * @brief Returns the part number, if supplied 183 * 184 * @return std::optional<std::string> 185 */ 186 std::optional<std::string> getPN() const; 187 188 /** 189 * @brief Returns the maintenance procedure, if supplied 190 * 191 * @return std::optional<std::string> 192 */ 193 std::optional<std::string> getMaintProc() const; 194 195 /** 196 * @brief Returns the CCIN, if supplied 197 * 198 * @return std::optional<std::string> 199 */ 200 std::optional<std::string> getCCIN() const; 201 202 /** 203 * @brief Returns the serial number, if supplied 204 * 205 * @return std::optional<std::string> 206 */ 207 std::optional<std::string> getSN() const; 208 209 /** 210 * @brief The type identifier value of this structure. 211 */ 212 static const uint16_t substructureType = 0x4944; // "ID" 213 214 private: 215 /** 216 * @brief If the part number is contained in this structure. 217 * 218 * It takes the place of the maintenance procedure ID. 219 * 220 * @return bool 221 */ hasPN() const222 bool hasPN() const 223 { 224 return _flags & pnSupplied; 225 } 226 227 /** 228 * @brief If the CCIN is contained in this structure. 229 * 230 * @return bool 231 */ hasCCIN() const232 bool hasCCIN() const 233 { 234 return _flags & ccinSupplied; 235 } 236 237 /** 238 * @brief If a maintenance procedure is contained in this structure. 239 * 240 * It takes the place of the part number. 241 * 242 * @return bool 243 */ hasMP() const244 bool hasMP() const 245 { 246 return _flags & maintProcSupplied; 247 } 248 249 /** 250 * @brief If the serial number is contained in this structure. 251 * 252 * @return bool 253 */ hasSN() const254 bool hasSN() const 255 { 256 return _flags & snSupplied; 257 } 258 259 /** 260 * @brief Sets the 8 character null terminated part 261 * number field to the string passed in. 262 * 263 * @param[in] partNumber - The part number string. 264 */ 265 void setPartNumber(const std::string& partNumber); 266 267 /** 268 * @brief Sets the 4 character CCIN field. 269 * 270 * @param[in] ccin - The CCIN string 271 */ 272 void setCCIN(const std::string& ccin); 273 274 /** 275 * @brief Sets the 12 character serial number field. 276 * 277 * @param[in] serialNumber - The serial number string 278 */ 279 void setSerialNumber(const std::string& serialNumber); 280 281 /** 282 * @brief Sets the 8 character null terminated procedure 283 * field. This is in the same field as the part 284 * number since they are mutually exclusive. 285 * 286 * @param procedure - The procedure name. 287 * @param[in] type - If the procedure is the raw name or 288 * the registry name. 289 */ 290 void setMaintenanceProcedure(const std::string& procedure, 291 CalloutValueType type); 292 293 /** 294 * @brief Sets the 8 character null terminated symbolic FRU 295 * field. This is in the same field as the part 296 * number since they are mutually exclusive. 297 * 298 * @param[in] symbolicFRU - The symbolic FRU name. 299 * @param[in] type - If the FRU is the raw name or 300 * the registry name. 301 */ 302 void setSymbolicFRU(const std::string& symbolicFRU, CalloutValueType type); 303 304 /** 305 * @brief The callout substructure type field. Will be "ID". 306 */ 307 uint16_t _type; 308 309 /** 310 * @brief The size of this callout structure. 311 * 312 * Always a multiple of 4. 313 */ 314 uint8_t _size; 315 316 /** 317 * @brief The flags byte of this substructure. 318 * 319 * See the FailingComponentType and Flags enums 320 */ 321 uint8_t _flags; 322 323 /** 324 * @brief The part number OR maintenance procedure ID, 325 * depending on what the flags field specifies. 326 * 327 * A NULL terminated ASCII string. 328 */ 329 std::array<char, 8> _pnOrProcedureID; 330 331 /** 332 * @brief The CCIN VPD keyword 333 * 334 * Four ASCII characters, not NULL terminated. 335 */ 336 std::array<char, 4> _ccin; 337 338 /** 339 * @brief The serial number 340 * 341 * Twelve ASCII characters, not NULL terminated. 342 */ 343 std::array<char, 12> _sn; 344 }; 345 346 } // namespace src 347 } // namespace pels 348 } // namespace openpower 349