Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 1 | #include "fru_area.hpp" |
| 2 | |
| 3 | #include "frup.hpp" |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include <cstring> |
| 7 | #include <phosphor-logging/log.hpp> |
| 8 | |
| 9 | using namespace phosphor::logging; |
| 10 | |
| 11 | //---------------------------------------------------------------- |
| 12 | // Constructor |
| 13 | //---------------------------------------------------------------- |
| 14 | IPMIFruArea::IPMIFruArea(const uint8_t fruid, const ipmi_fru_area_type type, |
Patrick Venture | 98de3b3 | 2018-10-20 20:32:14 -0700 | [diff] [blame] | 15 | bool bmc_fru) : |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 16 | fruid(fruid), |
| 17 | type(type), bmc_fru(bmc_fru) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 18 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 19 | if (type == IPMI_FRU_AREA_INTERNAL_USE) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 20 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 21 | name = "INTERNAL_"; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 22 | } |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 23 | else if (type == IPMI_FRU_AREA_CHASSIS_INFO) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 24 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 25 | name = "CHASSIS_"; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 26 | } |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 27 | else if (type == IPMI_FRU_AREA_BOARD_INFO) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 28 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 29 | name = "BOARD_"; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 30 | } |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 31 | else if (type == IPMI_FRU_AREA_PRODUCT_INFO) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 32 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 33 | name = "PRODUCT_"; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 34 | } |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 35 | else if (type == IPMI_FRU_AREA_MULTI_RECORD) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 36 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 37 | name = "MULTI_"; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 38 | } |
| 39 | else |
| 40 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 41 | name = IPMI_FRU_AREA_TYPE_MAX; |
| 42 | log<level::ERR>("Invalid Area", entry("TYPE=%d", type)); |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | //----------------------------------------------------- |
| 47 | // For a FRU area type, accepts the data and updates |
| 48 | // area specific data. |
| 49 | //----------------------------------------------------- |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 50 | void IPMIFruArea::set_data(const uint8_t* value, const size_t length) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 51 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 52 | len = length; |
| 53 | data = new uint8_t[len]; |
| 54 | std::memcpy(data, value, len); |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | //----------------------------------------------------- |
| 58 | // Sets the dbus parameters |
| 59 | //----------------------------------------------------- |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 60 | void IPMIFruArea::update_dbus_paths(const char* bus, const char* path, |
| 61 | const char* intf) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 62 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 63 | bus_name = bus; |
| 64 | obj_path = path; |
| 65 | intf_name = intf; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //------------------- |
| 69 | // Destructor |
| 70 | //------------------- |
| 71 | IPMIFruArea::~IPMIFruArea() |
| 72 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 73 | if (data != NULL) |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 74 | { |
Patrick Venture | b9d3373 | 2018-10-20 20:41:57 -0700 | [diff] [blame] | 75 | delete[] data; |
| 76 | data = NULL; |
Patrick Venture | a19bd0c | 2018-10-20 20:09:42 -0700 | [diff] [blame] | 77 | } |
| 78 | } |