Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 1 | #include "write.hpp" |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 2 | |
| 3 | #include "defines.hpp" |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 4 | #include "writefru.hpp" |
| 5 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 6 | #include <algorithm> |
| 7 | #include <exception> |
| 8 | |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 9 | namespace openpower |
| 10 | { |
| 11 | namespace vpd |
| 12 | { |
| 13 | namespace inventory |
| 14 | { |
| 15 | |
Alvin Wang | 18197ae | 2019-08-29 22:56:18 +0800 | [diff] [blame] | 16 | // Some systems have two MAC addresses |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 17 | static const std::unordered_map<std::string, Fru> supportedFrus = { |
Alvin Wang | 18197ae | 2019-08-29 22:56:18 +0800 | [diff] [blame] | 18 | {"BMC", Fru::BMC}, |
| 19 | {"ETHERNET", Fru::ETHERNET}, |
| 20 | {"ETHERNET1", Fru::ETHERNET1}}; |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 21 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 22 | void write(const std::string& type, const Store& vpdStore, |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 23 | const std::string& path) |
| 24 | { |
| 25 | // Get the enum corresponding to type, and call |
| 26 | // appropriate write FRU method. |
| 27 | |
| 28 | std::string fru = type; |
| 29 | std::transform(fru.begin(), fru.end(), fru.begin(), |
| 30 | [](unsigned char c) { return std::toupper(c); }); |
| 31 | auto iterator = supportedFrus.find(fru); |
| 32 | if (supportedFrus.end() == iterator) |
| 33 | { |
| 34 | throw std::runtime_error("Unsupported FRU: " + std::move(fru)); |
| 35 | } |
| 36 | else |
| 37 | { |
| 38 | switch (iterator->second) |
| 39 | { |
| 40 | case Fru::BMC: |
| 41 | { |
| 42 | writeFru<Fru::BMC>(vpdStore, path); |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | case Fru::ETHERNET: |
| 47 | { |
| 48 | writeFru<Fru::ETHERNET>(vpdStore, path); |
| 49 | break; |
| 50 | } |
| 51 | |
Alvin Wang | 18197ae | 2019-08-29 22:56:18 +0800 | [diff] [blame] | 52 | case Fru::ETHERNET1: |
| 53 | { |
| 54 | writeFru<Fru::ETHERNET1>(vpdStore, path); |
| 55 | break; |
| 56 | } |
| 57 | |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 58 | default: |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 64 | } // namespace inventory |
Deepak Kodihalli | 82c1e56 | 2016-11-28 06:06:50 -0600 | [diff] [blame] | 65 | } // namespace vpd |
| 66 | } // namespace openpower |