Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include "elog-errors.hpp" |
| 2 | #include "error-HostEvent.hpp" |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 3 | #include "sensorhandler.hpp" |
| 4 | #include "storagehandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include "types.hpp" |
| 6 | |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 7 | #include <host-ipmid/ipmid-api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 8 | #include <mapper.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | #include <systemd/sd-bus.h> |
| 10 | |
| 11 | #include <algorithm> |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 12 | #include <cstdlib> |
| 13 | #include <cstring> |
| 14 | #include <fstream> |
| 15 | #include <iostream> |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 16 | #include <memory> |
Saqib Khan | d33a4af | 2017-02-20 15:23:27 -0600 | [diff] [blame] | 17 | #include <phosphor-logging/elog.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 20 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 21 | using namespace std; |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 22 | using namespace phosphor::logging; |
Deepak Kodihalli | 3d23048 | 2018-04-03 07:00:45 -0500 | [diff] [blame] | 23 | using namespace sdbusplus::xyz::openbmc_project::Logging::server; |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 24 | extern const ipmi::sensor::InvObjectIDMap invSensors; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 25 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 26 | ////////////////////////// |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 27 | struct esel_section_headers_t |
| 28 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 29 | uint8_t sectionid[2]; |
| 30 | uint8_t sectionlength[2]; |
| 31 | uint8_t version; |
| 32 | uint8_t subsectiontype; |
| 33 | uint8_t compid; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 34 | }; |
| 35 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 36 | struct severity_values_t |
| 37 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 38 | uint8_t type; |
| 39 | Entry::Level level; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 40 | }; |
| 41 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 42 | const std::vector<severity_values_t> g_sev_desc = { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 43 | {0x10, Entry::Level::Warning}, // recoverable error |
| 44 | {0x20, Entry::Level::Warning}, // predictive error |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 45 | // TODO via github issue 3066 : map level |
| 46 | // below to Level::Unrecoverable |
| 47 | {0x40, Entry::Level::Error}, // unrecoverable error |
| 48 | // TODO via github issue 3066 : map level below |
| 49 | // to Level::Critical |
| 50 | {0x50, Entry::Level::Error}, // critical error |
| 51 | {0x60, Entry::Level::Error}, // error from a diagnostic test |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 52 | {0x70, Entry::Level::Warning}, // recoverable symptom |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 53 | {0xFF, Entry::Level::Error}, // unknown error |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 54 | }; |
| 55 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 56 | Entry::Level sev_lookup(uint8_t n) |
| 57 | { |
| 58 | auto i = |
| 59 | std::find_if(std::begin(g_sev_desc), std::end(g_sev_desc), |
| 60 | [n](auto p) { return p.type == n || p.type == 0xFF; }); |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 61 | return i->level; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 64 | int find_sensor_type_string(uint8_t sensor_number, char** s) |
| 65 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 66 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 67 | dbus_interface_t a; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 68 | const char* p; |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 69 | int r; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 70 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 71 | r = find_openbmc_path(sensor_number, &a); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 72 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 73 | if ((r < 0) || (a.bus[0] == 0)) |
| 74 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 75 | // Just make a generic message for errors that |
| 76 | // occur on sensors that don't exist |
| 77 | r = asprintf(s, "Unknown Sensor (0x%02x)", sensor_number); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 78 | } |
| 79 | else |
| 80 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 81 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 82 | if ((p = strrchr(a.path, '/')) == NULL) |
| 83 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 84 | p = "/Unknown Sensor"; |
| 85 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 86 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 87 | *s = strdup(p + 1); |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 88 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 89 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 90 | return 0; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 93 | size_t getfilestream(const char* fn, uint8_t** buffer) |
| 94 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 95 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 96 | FILE* fp; |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 97 | ssize_t size = 0; |
| 98 | int r; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 99 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 100 | if ((fp = fopen(fn, "rb")) != NULL) |
| 101 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 102 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 103 | r = fseek(fp, 0, SEEK_END); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | if (r) |
| 105 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 106 | log<level::ERR>("Fseek failed"); |
| 107 | goto fclose_fp; |
| 108 | } |
Nan Li | dfe6e42 | 2016-05-13 21:46:26 +0800 | [diff] [blame] | 109 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 110 | size = ftell(fp); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 111 | if (size == -1L) |
| 112 | { |
| 113 | log<level::ERR>("Ftell failed", entry("ERROR=%s", strerror(errno))); |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 114 | size = 0; |
| 115 | goto fclose_fp; |
| 116 | } |
Nan Li | dfe6e42 | 2016-05-13 21:46:26 +0800 | [diff] [blame] | 117 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 118 | r = fseek(fp, 0, SEEK_SET); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 119 | if (r) |
| 120 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 121 | log<level::ERR>("Fseek failed"); |
| 122 | size = 0; |
| 123 | goto fclose_fp; |
| 124 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 125 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 126 | *buffer = new uint8_t[size]; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 127 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 128 | r = fread(*buffer, 1, size, fp); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 129 | if (r != size) |
| 130 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 131 | size = 0; |
| 132 | log<level::ERR>("Fread failed\n"); |
| 133 | } |
Nan Li | dfe6e42 | 2016-05-13 21:46:26 +0800 | [diff] [blame] | 134 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 135 | fclose_fp: |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 136 | fclose(fp); |
| 137 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 138 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 139 | return static_cast<size_t>(size); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 142 | Entry::Level create_esel_severity(const uint8_t* buffer) |
| 143 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 144 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 145 | uint8_t severity; |
| 146 | // Dive in to the IBM log to find the severity |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 147 | severity = (0xF0 & buffer[0x4A]); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 148 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 149 | return sev_lookup(severity); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 152 | int create_esel_association(const uint8_t* buffer, std::string& inventoryPath) |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 153 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 154 | uint8_t sensor; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 155 | |
Patrick Venture | d99148b | 2018-10-13 10:06:13 -0700 | [diff] [blame] | 156 | auto p = reinterpret_cast<const ipmi_add_sel_request_t*>(buffer); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 157 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 158 | sensor = p->sensornumber; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 159 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 160 | inventoryPath = {}; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 161 | |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 162 | /* |
| 163 | * Search the sensor number to inventory path mapping to figure out the |
| 164 | * inventory associated with the ESEL. |
| 165 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 166 | for (auto const& iter : invSensors) |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 167 | { |
| 168 | if (iter.second.sensorID == sensor) |
| 169 | { |
| 170 | inventoryPath = iter.first; |
| 171 | break; |
| 172 | } |
| 173 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 174 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 175 | return 0; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 178 | int create_esel_description(const uint8_t* buffer, Entry::Level level, |
| 179 | char** message) |
| 180 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 181 | char* m; |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 182 | int r; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 183 | |
Patrick Venture | d99148b | 2018-10-13 10:06:13 -0700 | [diff] [blame] | 184 | auto p = reinterpret_cast<const ipmi_add_sel_request_t*>(buffer); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 185 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 186 | find_sensor_type_string(p->sensornumber, &m); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 187 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 188 | r = asprintf(message, "A %s has experienced an error of level %d", m, |
| 189 | static_cast<uint32_t>(level)); |
| 190 | if (r == -1) |
| 191 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 192 | log<level::ERR>("Failed to allocate memory for ESEL description"); |
| 193 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 194 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 195 | free(m); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 196 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 197 | return 0; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 198 | } |
| 199 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 200 | int send_esel_to_dbus(const char* desc, Entry::Level level, |
| 201 | const std::string& inventoryPath, uint8_t* debug, |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 202 | size_t debuglen) |
| 203 | { |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 204 | |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 205 | // Allocate enough space to represent the data in hex separated by spaces, |
| 206 | // to mimic how IPMI would display the data. |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 207 | unique_ptr<char[]> selData(new char[(debuglen * 3) + 1]()); |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 208 | uint32_t i = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 209 | for (i = 0; i < debuglen; i++) |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 210 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 211 | sprintf(&selData[i * 3], "%02x ", 0xFF & ((char*)debug)[i]); |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 212 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 213 | selData[debuglen * 3] = '\0'; |
Tom Joseph | b9ac6a4 | 2017-02-28 19:56:33 +0530 | [diff] [blame] | 214 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 215 | using error = sdbusplus::org::open_power::Host::Error::Event; |
Marri Devender Rao | b0b395b | 2017-10-24 10:14:14 -0500 | [diff] [blame] | 216 | using metadata = org::open_power::Host::Event; |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 217 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 218 | report<error>(level, metadata::ESEL(selData.get()), |
Tom Joseph | 448e74e | 2017-07-24 23:08:56 +0530 | [diff] [blame] | 219 | metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); |
Adriana Kobylak | 2efb3e7 | 2017-02-06 21:43:59 -0600 | [diff] [blame] | 220 | |
Adriana Kobylak | 513d68e | 2017-02-15 11:36:28 -0600 | [diff] [blame] | 221 | return 0; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 224 | void send_esel(uint16_t recordid) |
| 225 | { |
| 226 | char* desc; |
| 227 | uint8_t* buffer = NULL; |
| 228 | const char* path = "/tmp/esel"; |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 229 | ssize_t sz; |
| 230 | int r; |
| 231 | std::string inventoryPath; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 232 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 233 | sz = getfilestream(path, &buffer); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 234 | if (sz == 0) |
| 235 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 236 | log<level::ERR>("Error file does not exist", |
| 237 | entry("FILENAME=%s", path)); |
| 238 | return; |
| 239 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 240 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 241 | auto sev = create_esel_severity(buffer); |
| 242 | create_esel_association(buffer, inventoryPath); |
| 243 | create_esel_description(buffer, sev, &desc); |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 244 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 245 | r = send_esel_to_dbus(desc, sev, inventoryPath, buffer, sz); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 246 | if (r < 0) |
| 247 | { |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 248 | log<level::ERR>("Failed to send esel to dbus"); |
| 249 | } |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 250 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 251 | free(desc); |
| 252 | delete[] buffer; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 253 | |
Nagaraju Goruganti | 2fa0e70 | 2018-04-16 05:25:21 -0500 | [diff] [blame] | 254 | return; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 255 | } |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 256 | |
| 257 | std::string readESEL(const char* fileName) |
| 258 | { |
| 259 | std::string content; |
| 260 | std::ifstream handle(fileName); |
| 261 | |
| 262 | if (handle.fail()) |
| 263 | { |
| 264 | log<level::ERR>("Failed to open eSEL", entry("FILENAME=%s", fileName)); |
| 265 | return content; |
| 266 | } |
| 267 | |
| 268 | handle.seekg(0, std::ios::end); |
| 269 | content.resize(handle.tellg()); |
| 270 | handle.seekg(0, std::ios::beg); |
| 271 | handle.read(&content[0], content.size()); |
| 272 | handle.close(); |
| 273 | |
| 274 | return content; |
| 275 | } |
| 276 | |
| 277 | void createProcedureLogEntry(uint8_t procedureNum) |
| 278 | { |
| 279 | // Read the eSEL data from the file. |
| 280 | static constexpr auto eSELFile = "/tmp/esel"; |
| 281 | auto eSELData = readESEL(eSELFile); |
| 282 | |
| 283 | // Each byte in eSEL is formatted as %02x with a space between bytes and |
| 284 | // insert '/0' at the end of the character array. |
| 285 | static constexpr auto byteSeparator = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 286 | std::unique_ptr<char[]> data( |
| 287 | new char[(eSELData.size() * byteSeparator) + 1]()); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 288 | |
| 289 | for (size_t i = 0; i < eSELData.size(); i++) |
| 290 | { |
| 291 | sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]); |
| 292 | } |
| 293 | data[eSELData.size() * byteSeparator] = '\0'; |
| 294 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 295 | using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure; |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 296 | using metadata = org::open_power::Host::MaintenanceProcedure; |
| 297 | |
| 298 | report<error>(metadata::ESEL(data.get()), |
| 299 | metadata::PROCEDURE(static_cast<uint32_t>(procedureNum))); |
| 300 | } |