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