Lei YU | 3c341df | 2020-09-27 13:24:53 +0800 | [diff] [blame^] | 1 | #include "config.h" |
| 2 | |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 3 | #include "inspur_oem.hpp" |
| 4 | |
Lei YU | 3c341df | 2020-09-27 13:24:53 +0800 | [diff] [blame^] | 5 | #include "utils.hpp" |
| 6 | |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 7 | #include <ipmid/api.h> |
| 8 | |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
| 10 | #include <sdbusplus/bus.hpp> |
| 11 | |
| 12 | #include <optional> |
| 13 | |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 14 | namespace |
| 15 | { |
| 16 | constexpr auto FIRMWARE_TYPE_OFFSET = 0; |
| 17 | constexpr auto FIRMWARE_TYPE_SIZE = 1; |
| 18 | constexpr auto FIRMWARE_VERSION_OFFSET = |
| 19 | FIRMWARE_TYPE_OFFSET + FIRMWARE_TYPE_SIZE; |
| 20 | constexpr auto FIRMWARE_VERSION_SIZE = 15; |
| 21 | constexpr auto FIRMWARE_BUILDTIME_OFFSET = |
| 22 | FIRMWARE_VERSION_OFFSET + FIRMWARE_VERSION_SIZE; |
| 23 | constexpr auto FIRMWARE_BUILDTIME_SIZE = 20; |
| 24 | |
| 25 | static_assert(FIRMWARE_VERSION_OFFSET == 1); |
| 26 | static_assert(FIRMWARE_BUILDTIME_OFFSET == 16); |
| 27 | } // namespace |
| 28 | |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 29 | namespace ipmi |
| 30 | { |
| 31 | |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 32 | #define UNUSED(x) (void)(x) |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 33 | |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 34 | using namespace phosphor::logging; |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 35 | using namespace inspur; |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 36 | |
| 37 | static void registerOEMFunctions() __attribute__((constructor)); |
| 38 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 39 | |
| 40 | struct ParsedAssetInfo |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 41 | { |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 42 | uint8_t rwFlag; |
| 43 | uint8_t deviceType; |
| 44 | uint8_t infoType; |
| 45 | uint8_t maskAllPresentLen; |
| 46 | std::vector<uint8_t> enableStatus; |
| 47 | std::vector<uint8_t> maskPresent; |
| 48 | std::vector<uint8_t> maskAllPresent; |
| 49 | uint8_t allInfoDone; |
| 50 | uint16_t totalMessageLen; |
| 51 | std::vector<uint8_t> data; |
| 52 | }; |
| 53 | |
| 54 | void dumpAssetInfo(const ParsedAssetInfo& info) |
| 55 | { |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 56 | fprintf(stderr, |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 57 | "AssetInfo: rw %d, deviceType 0x%02x, infoType 0x%02x, " |
| 58 | "maskAllPresentLen %u\n", |
| 59 | info.rwFlag, info.deviceType, info.infoType, |
| 60 | info.maskAllPresentLen); |
| 61 | fprintf(stderr, "enableStatus "); |
| 62 | for (const auto& d : info.enableStatus) |
| 63 | { |
| 64 | fprintf(stderr, "0x%02x ", d); |
| 65 | } |
| 66 | fprintf(stderr, "\nmaskPresent "); |
| 67 | for (const auto& d : info.maskPresent) |
| 68 | { |
| 69 | fprintf(stderr, "0x%02x ", d); |
| 70 | } |
| 71 | fprintf(stderr, "\nmaskAllPresent "); |
| 72 | for (const auto& d : info.maskAllPresent) |
| 73 | { |
| 74 | fprintf(stderr, "0x%02x ", d); |
| 75 | } |
| 76 | fprintf(stderr, "\nallInfoDone %d, totalMessageLen %u\n", info.allInfoDone, |
| 77 | info.totalMessageLen); |
| 78 | fprintf(stderr, "data: "); |
| 79 | for (const auto& d : info.data) |
| 80 | { |
| 81 | fprintf(stderr, "0x%02x ", d); |
| 82 | } |
| 83 | fprintf(stderr, "\n"); |
| 84 | } |
| 85 | |
| 86 | std::optional<ParsedAssetInfo> parseAssetInfo(const AssetInfoHeader* h) |
| 87 | { |
| 88 | auto len = h->maskAllPresentLen; |
| 89 | if (len == 0) |
| 90 | { |
| 91 | // This is invalid |
| 92 | return {}; |
| 93 | } |
| 94 | |
| 95 | ParsedAssetInfo info; |
| 96 | info.rwFlag = h->rwFlag; |
| 97 | info.deviceType = h->deviceType; |
| 98 | info.infoType = h->infoType; |
| 99 | info.maskAllPresentLen = len; |
| 100 | info.enableStatus.resize(len); |
| 101 | info.maskPresent.resize(len); |
| 102 | info.maskAllPresent.resize(len); |
| 103 | const uint8_t* p = &h->enableStatus; |
| 104 | memcpy(info.enableStatus.data(), p, len); |
| 105 | p += len; |
| 106 | memcpy(info.maskPresent.data(), p, len); |
| 107 | p += len; |
| 108 | memcpy(info.maskAllPresent.data(), p, len); |
| 109 | p += len; |
| 110 | info.allInfoDone = *p++; |
| 111 | info.totalMessageLen = *reinterpret_cast<const uint16_t*>(p); |
| 112 | p += sizeof(uint16_t); |
| 113 | auto dataLen = info.totalMessageLen - (sizeof(AssetInfoHeader) + 3 * len); |
| 114 | info.data.resize(dataLen); |
| 115 | memcpy(info.data.data(), p, dataLen); |
| 116 | |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 117 | // dumpAssetInfo(info); |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 118 | return info; |
| 119 | } |
| 120 | |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 121 | void parseBIOSInfo(const std::vector<uint8_t>& data) |
| 122 | { |
| 123 | bios_version_devname dev = static_cast<bios_version_devname>(data[0]); |
| 124 | std::string version{data.data() + FIRMWARE_VERSION_OFFSET, |
| 125 | data.data() + FIRMWARE_VERSION_SIZE}; |
| 126 | std::string buildTime; |
| 127 | if (dev == bios_version_devname::BIOS) |
| 128 | { |
| 129 | buildTime.assign(reinterpret_cast<const char*>( |
| 130 | data.data() + FIRMWARE_BUILDTIME_OFFSET), |
| 131 | FIRMWARE_BUILDTIME_SIZE); |
Lei YU | 3c341df | 2020-09-27 13:24:53 +0800 | [diff] [blame^] | 132 | |
| 133 | // Set BIOS version |
| 134 | auto service = utils::getService(bus, BIOS_OBJPATH, VERSION_IFACE); |
| 135 | utils::setProperty(bus, service.c_str(), BIOS_OBJPATH, VERSION_IFACE, |
| 136 | VERSION, version); |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | printf("Dev %s, version %s, build time %s\n", |
| 140 | bios_devname[static_cast<int>(dev)].data(), version.c_str(), |
| 141 | buildTime.c_str()); |
| 142 | } |
| 143 | |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 144 | ipmi_ret_t ipmiOemInspurAssetInfo(ipmi_netfn_t /* netfn */, |
| 145 | ipmi_cmd_t /* cmd */, ipmi_request_t request, |
| 146 | ipmi_response_t response, |
| 147 | ipmi_data_len_t /* data_len */, |
| 148 | ipmi_context_t /* context */) |
| 149 | { |
| 150 | auto header = reinterpret_cast<AssetInfoHeader*>(request); |
| 151 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
| 152 | UNUSED(res); |
| 153 | |
| 154 | auto info = parseAssetInfo(header); |
| 155 | auto deviceType = info->deviceType; |
| 156 | if (deviceType != 0x05) |
| 157 | { |
| 158 | log<level::WARNING>("Device type not supported yet"); |
| 159 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 160 | } |
| 161 | |
| 162 | // For now we only support BIOS type |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 163 | parseBIOSInfo(info->data); |
Lei YU | 8a454c5 | 2020-09-23 16:52:46 +0800 | [diff] [blame] | 164 | |
Lei YU | 17bc93d | 2020-09-23 19:55:07 +0800 | [diff] [blame] | 165 | return IPMI_CC_OK; |
Lei YU | 6505e9d | 2020-09-21 17:34:32 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void registerOEMFunctions(void) |
| 169 | { |
| 170 | ipmi_register_callback(NETFN_OEM_INSPUR, CMD_OEM_ASSET_INFO, nullptr, |
| 171 | ipmiOemInspurAssetInfo, SYSTEM_INTERFACE); |
| 172 | } |
| 173 | |
| 174 | } // namespace ipmi |