blob: b983b53cd6f307790f13c39f5d9fb6ddc5537290 [file] [log] [blame]
Patrick Venturea19bd0c2018-10-20 20:09:42 -07001#include "fru_area.hpp"
2
3#include "frup.hpp"
4
5#include <cstdint>
6#include <cstring>
7#include <phosphor-logging/log.hpp>
8
9using namespace phosphor::logging;
10
11//----------------------------------------------------------------
12// Constructor
13//----------------------------------------------------------------
14IPMIFruArea::IPMIFruArea(const uint8_t fruid, const ipmi_fru_area_type type,
Patrick Venture98de3b32018-10-20 20:32:14 -070015 bool bmc_fru) :
Patrick Ventureb9d33732018-10-20 20:41:57 -070016 fruid(fruid),
17 type(type), bmc_fru(bmc_fru)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070018{
Patrick Ventureb9d33732018-10-20 20:41:57 -070019 if (type == IPMI_FRU_AREA_INTERNAL_USE)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070020 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070021 name = "INTERNAL_";
Patrick Venturea19bd0c2018-10-20 20:09:42 -070022 }
Patrick Ventureb9d33732018-10-20 20:41:57 -070023 else if (type == IPMI_FRU_AREA_CHASSIS_INFO)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070024 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070025 name = "CHASSIS_";
Patrick Venturea19bd0c2018-10-20 20:09:42 -070026 }
Patrick Ventureb9d33732018-10-20 20:41:57 -070027 else if (type == IPMI_FRU_AREA_BOARD_INFO)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070028 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070029 name = "BOARD_";
Patrick Venturea19bd0c2018-10-20 20:09:42 -070030 }
Patrick Ventureb9d33732018-10-20 20:41:57 -070031 else if (type == IPMI_FRU_AREA_PRODUCT_INFO)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070032 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070033 name = "PRODUCT_";
Patrick Venturea19bd0c2018-10-20 20:09:42 -070034 }
Patrick Ventureb9d33732018-10-20 20:41:57 -070035 else if (type == IPMI_FRU_AREA_MULTI_RECORD)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070036 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070037 name = "MULTI_";
Patrick Venturea19bd0c2018-10-20 20:09:42 -070038 }
39 else
40 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070041 name = IPMI_FRU_AREA_TYPE_MAX;
42 log<level::ERR>("Invalid Area", entry("TYPE=%d", type));
Patrick Venturea19bd0c2018-10-20 20:09:42 -070043 }
44}
45
46//-----------------------------------------------------
47// For a FRU area type, accepts the data and updates
48// area specific data.
49//-----------------------------------------------------
Patrick Venturef22b36a2018-10-20 20:59:07 -070050void IPMIFruArea::setData(const uint8_t* value, const size_t length)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070051{
Patrick Ventureb9d33732018-10-20 20:41:57 -070052 len = length;
53 data = new uint8_t[len];
54 std::memcpy(data, value, len);
Patrick Venturea19bd0c2018-10-20 20:09:42 -070055}
56
57//-----------------------------------------------------
58// Sets the dbus parameters
59//-----------------------------------------------------
Patrick Venturef22b36a2018-10-20 20:59:07 -070060void IPMIFruArea::updateDbusPaths(const char* bus, const char* path,
61 const char* intf)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070062{
Patrick Ventureb9d33732018-10-20 20:41:57 -070063 bus_name = bus;
64 obj_path = path;
65 intf_name = intf;
Patrick Venturea19bd0c2018-10-20 20:09:42 -070066}
67
68//-------------------
69// Destructor
70//-------------------
71IPMIFruArea::~IPMIFruArea()
72{
Patrick Ventureb9d33732018-10-20 20:41:57 -070073 if (data != NULL)
Patrick Venturea19bd0c2018-10-20 20:09:42 -070074 {
Patrick Ventureb9d33732018-10-20 20:41:57 -070075 delete[] data;
76 data = NULL;
Patrick Venturea19bd0c2018-10-20 20:09:42 -070077 }
78}