1 /*
2 // Copyright (c) 2019 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 
17 #pragma once
18 #include <boost/algorithm/string/join.hpp>
19 #include <phosphor-logging/log.hpp>
20 #include <storagecommands.hpp>
21 
22 namespace intel_oem::ipmi::sel
23 {
24 bool checkRedfishHooks(uint16_t recordID, uint8_t recordType,
25                        uint32_t timestamp, uint16_t generatorID, uint8_t evmRev,
26                        uint8_t sensorType, uint8_t sensorNum, uint8_t eventType,
27                        uint8_t eventData1, uint8_t eventData2,
28                        uint8_t eventData3);
29 bool checkRedfishHooks(uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
30                        uint8_t sensorNum, uint8_t eventType, uint8_t eventData1,
31                        uint8_t eventData2, uint8_t eventData3);
32 namespace redfish_hooks
33 {
34 struct SELData
35 {
36     int generatorID;
37     int sensorNum;
38     int eventType;
39     int offset;
40     int eventData2;
41     int eventData3;
42 };
43 
44 enum class BIOSSensors
45 {
46     memoryRASConfigStatus = 0x02,
47     biosPOSTError = 0x06,
48     intelUPILinkWidthReduced = 0x09,
49     memoryRASModeSelect = 0x12,
50     bootEvent = 0x83,
51 };
52 
53 enum class BIOSSMISensors
54 {
55     mirroringRedundancyState = 0x01,
56     memoryECCError = 0x02,
57     legacyPCIError = 0x03,
58     pcieFatalError = 0x04,
59     pcieCorrectableError = 0x05,
60     sparingRedundancyState = 0x11,
61     memoryParityError = 0x13,
62     pcieFatalError2 = 0x14,
63     biosRecovery = 0x15,
64     adddcError = 0x20,
65 };
66 
67 enum class BIOSEventTypes
68 {
69     digitalDiscrete = 0x09,
70     discreteRedundancyStates = 0x0b,
71     sensorSpecificOffset = 0x6f,
72     oemDiscrete0 = 0x70,
73     oemDiscrete1 = 0x71,
74     oemDiscrete6 = 0x76,
75     oemDiscrete7 = 0x77,
76     reservedA0 = 0xa0,
77     reservedF0 = 0xf0,
78 };
79 
defaultMessageHook(const std::string & ipmiRaw)80 static inline bool defaultMessageHook(const std::string& ipmiRaw)
81 {
82     // Log the record as a default Redfish message instead of a SEL record
83 
84     static const std::string openBMCMessageRegistryVersion("0.1");
85     std::string messageID =
86         "OpenBMC." + openBMCMessageRegistryVersion + ".SELEntryAdded";
87 
88     std::vector<std::string> messageArgs;
89     messageArgs.push_back(ipmiRaw);
90 
91     // Log the Redfish message to the journal with the appropriate metadata
92     std::string journalMsg = "SEL Entry Added: " + ipmiRaw;
93     std::string messageArgsString = boost::algorithm::join(messageArgs, ",");
94     phosphor::logging::log<phosphor::logging::level::INFO>(
95         journalMsg.c_str(),
96         phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageID.c_str()),
97         phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s",
98                                  messageArgsString.c_str()));
99 
100     return true;
101 }
102 
103 } // namespace redfish_hooks
104 } // namespace intel_oem::ipmi::sel
105