blob: 31ff22981fa928804535f6ad51346784fe15e8ce [file] [log] [blame]
Deepak Kodihalli82c1e562016-11-28 06:06:50 -06001#include "write.hpp"
Patrick Venturec83c4dc2018-11-01 16:29:18 -07002
3#include "defines.hpp"
Deepak Kodihalli82c1e562016-11-28 06:06:50 -06004#include "writefru.hpp"
5
Patrick Venturec83c4dc2018-11-01 16:29:18 -07006#include <algorithm>
7#include <exception>
8
Deepak Kodihalli82c1e562016-11-28 06:06:50 -06009namespace openpower
10{
11namespace vpd
12{
13namespace inventory
14{
15
Alvin Wang18197ae2019-08-29 22:56:18 +080016// Some systems have two MAC addresses
Patrick Venturec83c4dc2018-11-01 16:29:18 -070017static const std::unordered_map<std::string, Fru> supportedFrus = {
Alvin Wang18197ae2019-08-29 22:56:18 +080018 {"BMC", Fru::BMC},
19 {"ETHERNET", Fru::ETHERNET},
20 {"ETHERNET1", Fru::ETHERNET1}};
Deepak Kodihalli82c1e562016-11-28 06:06:50 -060021
Patrick Venturec83c4dc2018-11-01 16:29:18 -070022void write(const std::string& type, const Store& vpdStore,
Deepak Kodihalli82c1e562016-11-28 06:06:50 -060023 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 Wang18197ae2019-08-29 22:56:18 +080052 case Fru::ETHERNET1:
53 {
54 writeFru<Fru::ETHERNET1>(vpdStore, path);
55 break;
56 }
57
Deepak Kodihalli82c1e562016-11-28 06:06:50 -060058 default:
59 break;
60 }
61 }
62}
63
Patrick Venturec83c4dc2018-11-01 16:29:18 -070064} // namespace inventory
Deepak Kodihalli82c1e562016-11-28 06:06:50 -060065} // namespace vpd
66} // namespace openpower