blob: 8f470fe5a3cf86045db967133ccaffc007b8fddf [file] [log] [blame]
Vijay Khemkaa2d52f12019-03-27 14:54:00 -07001/*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070018#include <fcntl.h>
Vijay Khemka63c99be2020-05-27 19:14:35 -070019#include <ipmid/api.h>
20#include <sys/stat.h>
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070021#include <unistd.h>
Vijay Khemka63c99be2020-05-27 19:14:35 -070022
23#include <appcommands.hpp>
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070024#include <commandutils.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050025#include <ipmid/api-types.hpp>
26#include <ipmid/api.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070027#include <nlohmann/json.hpp>
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070028#include <phosphor-logging/log.hpp>
29#include <sdbusplus/message/types.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070030
Kevin Tunge4e18ca2025-06-05 10:21:23 +080031#include <format>
Vijay Khemka63c99be2020-05-27 19:14:35 -070032#include <fstream>
33#include <iomanip>
34#include <iostream>
35#include <sstream>
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070036
37namespace ipmi
38{
39
40static void registerAPPFunctions() __attribute__((constructor));
41static constexpr size_t GUID_SIZE = 16;
42// TODO Make offset and location runtime configurable to ensure we
43// can make each define their own locations.
44static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
Vijay Khemka63c99be2020-05-27 19:14:35 -070045static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
Vijay Khemka666a4d92019-04-03 11:27:24 -070046
47// TODO: Need to store this info after identifying proper storage
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070048static uint8_t globEna = 0x09;
Vijay Khemka666a4d92019-04-03 11:27:24 -070049static SysInfoParam sysInfoParams;
Vijay Khemka802ccb12019-08-27 15:03:44 -070050nlohmann::json appData __attribute__((init_priority(101)));
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070051
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053052int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
53 std::vector<uint8_t>&);
54
Bonnie Loe9baaff2022-11-08 16:36:21 +080055static inline auto responseSystemInfoParamterNotSupportCommand()
56{
57 return response(IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED);
58}
59
Vijay Khemka63c99be2020-05-27 19:14:35 -070060void printGUID(uint8_t* guid, off_t offset)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070061{
62 std::cout << "Read GUID from offset : " << offset << " :\n";
Willy Tue39f9392022-06-15 13:24:20 -070063 for (size_t i = 0; i < GUID_SIZE; i++)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070064 {
65 int data = guid[i];
66 std::cout << std::hex << data << " ";
67 }
68 std::cout << std::endl;
69}
70
Vijay Khemka63c99be2020-05-27 19:14:35 -070071int getGUID(off_t offset, uint8_t* guid)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070072{
73 int fd = -1;
74 ssize_t bytes_rd;
75 int ret = 0;
cchouxb2ae88b2023-09-13 00:35:36 +080076 std::string eepromPath = FRU_EEPROM;
77
78 // find the eeprom path of MB FRU
79 auto device = getMbFruDevice();
80 if (device)
81 {
82 auto [bus, address] = *device;
83 std::stringstream ss;
84 ss << "/sys/bus/i2c/devices/" << static_cast<int>(bus) << "-"
85 << std::setw(4) << std::setfill('0') << std::hex
86 << static_cast<int>(address) << "/eeprom";
87 eepromPath = ss.str();
88 }
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070089
90 errno = 0;
91
92 // Check if file is present
cchouxb2ae88b2023-09-13 00:35:36 +080093 if (access(eepromPath.c_str(), F_OK) == -1)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070094 {
cchouxb2ae88b2023-09-13 00:35:36 +080095 std::cerr << "Unable to access: " << eepromPath << std::endl;
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070096 return errno;
97 }
98
99 // Open the file
cchouxb2ae88b2023-09-13 00:35:36 +0800100 fd = open(eepromPath.c_str(), O_RDONLY);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700101 if (fd == -1)
102 {
cchouxb2ae88b2023-09-13 00:35:36 +0800103 std::cerr << "Unable to open: " << eepromPath << std::endl;
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700104 return errno;
105 }
106
107 // seek to the offset
108 lseek(fd, offset, SEEK_SET);
109
110 // Read bytes from location
111 bytes_rd = read(fd, guid, GUID_SIZE);
112 if (bytes_rd != GUID_SIZE)
113 {
114 phosphor::logging::log<phosphor::logging::level::ERR>(
115 "GUID read data from EEPROM failed");
116 ret = errno;
117 }
118 else
119 {
120 printGUID(guid, offset);
121 }
122 close(fd);
123 return ret;
124}
125
Vijay Khemka63c99be2020-05-27 19:14:35 -0700126int getSystemGUID(uint8_t* guid)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700127{
128 return getGUID(OFFSET_SYS_GUID, guid);
129}
130
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700131//----------------------------------------------------------------------
Vijay Khemka666a4d92019-04-03 11:27:24 -0700132// Get Self Test Results (IPMI/Section 20.4) (CMD_APP_GET_SELFTEST_RESULTS)
133//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700134ipmi_ret_t ipmiAppGetSTResults(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
135 ipmi_response_t response,
136 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700137{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700138 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700139
140 // TODO: Following data needs to be updated based on self-test results
141 *res++ = 0x55; // Self-Test result
142 *res++ = 0x00; // Extra error info in case of failure
143
144 *data_len = 2;
145
146 return IPMI_CC_OK;
147}
148
149//----------------------------------------------------------------------
150// Manufacturing Test On (IPMI/Section 20.5) (CMD_APP_MFR_TEST_ON)
151//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700152ipmi_ret_t ipmiAppMfrTestOn(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
153 ipmi_response_t, ipmi_data_len_t data_len,
154 ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700155{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700156 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700157 std::string mfrTest = "sled-cycle";
Patrick Williams35208452022-06-24 06:12:15 -0500158 ipmi_ret_t rc = IPMI_CC_OK;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700159
160 if (!memcmp(req, mfrTest.data(), mfrTest.length()) &&
161 (*data_len == mfrTest.length()))
162 {
163 /* sled-cycle the BMC */
Patrick Williams35208452022-06-24 06:12:15 -0500164 auto ret = system("/usr/sbin/power-util sled-cycle");
165 if (ret)
166 {
167 rc = IPMI_CC_UNSPECIFIED_ERROR;
168 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700169 }
170 else
171 {
Patrick Williams35208452022-06-24 06:12:15 -0500172 rc = IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700173 }
174
175 *data_len = 0;
176
Patrick Williams35208452022-06-24 06:12:15 -0500177 return rc;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700178}
179
180//----------------------------------------------------------------------
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700181// Set Global Enables (CMD_APP_SET_GLOBAL_ENABLES)
182//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700183ipmi_ret_t ipmiAppSetGlobalEnables(ipmi_netfn_t, ipmi_cmd_t,
184 ipmi_request_t request, ipmi_response_t,
185 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700186{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700187 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700188
189 globEna = *req;
190 *data_len = 0;
191
192 return IPMI_CC_OK;
193}
194
195//----------------------------------------------------------------------
196// Get Global Enables (CMD_APP_GET_GLOBAL_ENABLES)
197//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700198ipmi_ret_t ipmiAppGetGlobalEnables(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700199 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700200 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700201{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700202 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700203
204 *data_len = 1;
205 *res++ = globEna;
206
207 return IPMI_CC_OK;
208}
209
210//----------------------------------------------------------------------
Vijay Khemka666a4d92019-04-03 11:27:24 -0700211// Clear Message flags (IPMI/Section 22.3) (CMD_APP_CLEAR_MESSAGE_FLAGS)
212//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700213ipmi_ret_t ipmiAppClearMsgFlags(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
214 ipmi_response_t, ipmi_data_len_t data_len,
215 ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700216{
217 // Do Nothing and just return success
218 *data_len = 0;
219
220 return IPMI_CC_OK;
221}
222
223//----------------------------------------------------------------------
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700224// Get System GUID (CMD_APP_GET_SYS_GUID)
225//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530226#if BIC_ENABLED
Patrick Williams1caf0482025-02-01 08:21:34 -0500227ipmi::RspType<std::vector<uint8_t>> ipmiAppGetSysGUID(
228 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530229
230{
231 std::vector<uint8_t> respData;
232
233 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
234
235 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
236 return ipmi::responseUnspecifiedError();
237
238 return ipmi::responseSuccess(respData);
239}
240
241#else
Willy Tue39f9392022-06-15 13:24:20 -0700242ipmi_ret_t ipmiAppGetSysGUID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
243 ipmi_response_t response, ipmi_data_len_t data_len,
244 ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700245{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700246 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700247 if (getSystemGUID(res))
248 {
249 return IPMI_CC_UNSPECIFIED_ERROR;
250 }
251 *data_len = GUID_SIZE;
252 return IPMI_CC_OK;
253}
254
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530255#endif
256
Vijay Khemka666a4d92019-04-03 11:27:24 -0700257//----------------------------------------------------------------------
258// Platform specific functions for storing app data
259//----------------------------------------------------------------------
260
261void flush_app_data()
262{
Vijay Khemka802ccb12019-08-27 15:03:44 -0700263 std::ofstream file(JSON_APP_DATA_FILE);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700264 file << appData;
Vijay Khemka802ccb12019-08-27 15:03:44 -0700265 file.close();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700266 return;
267}
268
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800269static int platSetSysFWVer(uint8_t* ver, const size_t hostId)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700270{
271 std::stringstream ss;
272 int i;
273
274 /* TODO: implement byte 1: Set selector
275 * byte 2: encodeing, currently only supported
276 * ASCII which is value 0, UTF and unicode are
277 * not supported yet.
278 */
279 if (ver[1] & 0x0f)
280 return -1;
281
282 for (i = 3; i < 3 + ver[2]; i++)
283 {
284 ss << (char)ver[i];
285 }
286
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800287 /* Save to legacy sysfw version file for backward compatibility */
288 appData[KEY_SYSFW_VER + std::to_string(hostId)] = ss.str();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700289 flush_app_data();
290
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800291 auto sysfwVersionFile = std::format(SYSFW_VER_FILE, hostId);
292 std::ofstream file(sysfwVersionFile);
293
294 if (!file)
295 {
296 phosphor::logging::log<phosphor::logging::level::ERR>(
297 "Failed to open system firmware version file for writing",
298 phosphor::logging::entry("FILE=%s", sysfwVersionFile.c_str()));
299 return -1;
300 }
301
302 file << ss.str();
303 file.close();
304
Vijay Khemka666a4d92019-04-03 11:27:24 -0700305 return 0;
306}
307
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800308static int platGetSysFWVer(std::vector<uint8_t>& respData, const size_t hostId)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700309{
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800310 constexpr size_t headerSize = 3; // selector + encoding + version size
Vijay Khemka666a4d92019-04-03 11:27:24 -0700311
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800312 std::string sysfwVersionFile = std::format(SYSFW_VER_FILE, hostId);
313 std::ifstream file(sysfwVersionFile);
314
315 if (!file)
Bonnie Loe9baaff2022-11-08 16:36:21 +0800316 {
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800317 phosphor::logging::log<phosphor::logging::level::ERR>(
318 "Failed to open system firmware version file for reading",
319 phosphor::logging::entry("FILE=%s", sysfwVersionFile.c_str()));
Bonnie Loe9baaff2022-11-08 16:36:21 +0800320 return -1;
321 }
Bonnie Loe9baaff2022-11-08 16:36:21 +0800322
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800323 std::string version;
324 std::getline(file, version);
325 file.close();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700326
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800327 // Truncate if longer than allowed
328 if (version.size() > SIZE_SYSFW_VER - headerSize)
329 {
330 version.resize(SIZE_SYSFW_VER - headerSize);
331 }
Bonnie Loe9baaff2022-11-08 16:36:21 +0800332
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800333 respData.push_back(0); // Byte 1: set selector not supported
334 respData.push_back(0); // Byte 2: only ASCII supported
335 respData.push_back(version.size()); // Byte 3: length of version
336
337 for (auto c : version)
Bonnie Loe9baaff2022-11-08 16:36:21 +0800338 {
339 respData.push_back(c);
340 }
341
342 // Remaining byte fill to 0
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800343 for (size_t i = 0; i < SIZE_SYSFW_VER - (version.size() + headerSize); i++)
Bonnie Loe9baaff2022-11-08 16:36:21 +0800344 {
345 respData.push_back(0);
346 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700347
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800348 return (version.size() + headerSize);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700349}
350
351//----------------------------------------------------------------------
352// Set Sys Info Params (IPMI/Sec 22.14a) (CMD_APP_SET_SYS_INFO_PARAMS)
353//----------------------------------------------------------------------
Patrick Williams1caf0482025-02-01 08:21:34 -0500354ipmi::RspType<uint8_t> ipmiAppSetSysInfoParams(ipmi::Context::ptr ctx,
355 std::vector<uint8_t> req)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700356{
Vijay Khemka666a4d92019-04-03 11:27:24 -0700357 uint8_t param = req[0];
Bonnie Loe9baaff2022-11-08 16:36:21 +0800358 uint8_t req_len = req.size();
359 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700360
Bonnie Loe9baaff2022-11-08 16:36:21 +0800361 if (!hostId)
362 {
363 phosphor::logging::log<phosphor::logging::level::ERR>(
364 "Invalid Host Id received");
365 return ipmi::responseInvalidCommand();
366 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700367
368 switch (param)
369 {
370 case SYS_INFO_PARAM_SET_IN_PROG:
371 sysInfoParams.set_in_prog = req[1];
372 break;
373 case SYS_INFO_PARAM_SYSFW_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800374 {
Vijay Khemka666a4d92019-04-03 11:27:24 -0700375 memcpy(sysInfoParams.sysfw_ver, &req[1], SIZE_SYSFW_VER);
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800376 if (platSetSysFWVer(sysInfoParams.sysfw_ver, *hostId))
Bonnie Loe9baaff2022-11-08 16:36:21 +0800377 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700378 break;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800379 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700380 case SYS_INFO_PARAM_SYS_NAME:
381 memcpy(sysInfoParams.sys_name, &req[1], SIZE_SYS_NAME);
382 break;
383 case SYS_INFO_PARAM_PRI_OS_NAME:
384 memcpy(sysInfoParams.pri_os_name, &req[1], SIZE_OS_NAME);
385 break;
386 case SYS_INFO_PARAM_PRESENT_OS_NAME:
387 memcpy(sysInfoParams.present_os_name, &req[1], SIZE_OS_NAME);
388 break;
389 case SYS_INFO_PARAM_PRESENT_OS_VER:
390 memcpy(sysInfoParams.present_os_ver, &req[1], SIZE_OS_VER);
391 break;
392 case SYS_INFO_PARAM_BMC_URL:
393 memcpy(sysInfoParams.bmc_url, &req[1], SIZE_BMC_URL);
394 break;
395 case SYS_INFO_PARAM_OS_HV_URL:
396 memcpy(sysInfoParams.os_hv_url, &req[1], SIZE_OS_HV_URL);
397 break;
398 case SYS_INFO_PARAM_BIOS_CURRENT_BOOT_LIST:
399 memcpy(sysInfoParams.bios_current_boot_list, &req[1], req_len);
400 appData[KEY_BIOS_BOOT_LEN] = req_len;
401 flush_app_data();
402 break;
403 case SYS_INFO_PARAM_BIOS_FIXED_BOOT_DEVICE:
404 if (SIZE_BIOS_FIXED_BOOT_DEVICE != req_len)
405 break;
406 memcpy(sysInfoParams.bios_fixed_boot_device, &req[1],
407 SIZE_BIOS_FIXED_BOOT_DEVICE);
408 break;
409 case SYS_INFO_PARAM_BIOS_RSTR_DFLT_SETTING:
410 if (SIZE_BIOS_RSTR_DFLT_SETTING != req_len)
411 break;
412 memcpy(sysInfoParams.bios_rstr_dflt_setting, &req[1],
413 SIZE_BIOS_RSTR_DFLT_SETTING);
414 break;
415 case SYS_INFO_PARAM_LAST_BOOT_TIME:
416 if (SIZE_LAST_BOOT_TIME != req_len)
417 break;
418 memcpy(sysInfoParams.last_boot_time, &req[1], SIZE_LAST_BOOT_TIME);
419 break;
420 default:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800421 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700422 break;
423 }
424
Bonnie Loe9baaff2022-11-08 16:36:21 +0800425 return ipmi::responseSuccess();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700426}
427
428//----------------------------------------------------------------------
429// Get Sys Info Params (IPMI/Sec 22.14b) (CMD_APP_GET_SYS_INFO_PARAMS)
430//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400431ipmi::RspType<std::vector<uint8_t>> ipmiAppGetSysInfoParams(
432 ipmi::Context::ptr ctx, uint8_t, uint8_t param, uint8_t, uint8_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700433{
Willy Tue39f9392022-06-15 13:24:20 -0700434 int len;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800435 std::vector<uint8_t> respData;
436 respData.push_back(1); // Parameter revision
Vijay Khemka666a4d92019-04-03 11:27:24 -0700437
Bonnie Loe9baaff2022-11-08 16:36:21 +0800438 std::optional<size_t> hostId = findHost(ctx->hostIdx);
439
440 if (!hostId)
441 {
442 phosphor::logging::log<phosphor::logging::level::ERR>(
443 "Invalid Host Id received");
444 return ipmi::responseInvalidCommand();
445 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700446
447 switch (param)
448 {
449 case SYS_INFO_PARAM_SET_IN_PROG:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800450 respData.push_back(sysInfoParams.set_in_prog);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700451 break;
452 case SYS_INFO_PARAM_SYSFW_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800453 {
Kevin Tunge4e18ca2025-06-05 10:21:23 +0800454 if ((platGetSysFWVer(respData, *hostId)) < 0)
Bonnie Loe9baaff2022-11-08 16:36:21 +0800455 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700456 break;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800457 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700458 case SYS_INFO_PARAM_SYS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800459 respData.insert(respData.end(), std::begin(sysInfoParams.sys_name),
460 std::end(sysInfoParams.sys_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700461 break;
462 case SYS_INFO_PARAM_PRI_OS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800463 respData.insert(respData.end(),
464 std::begin(sysInfoParams.pri_os_name),
465 std::end(sysInfoParams.pri_os_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700466 break;
467 case SYS_INFO_PARAM_PRESENT_OS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800468 respData.insert(respData.end(),
469 std::begin(sysInfoParams.present_os_name),
470 std::end(sysInfoParams.present_os_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700471 break;
472 case SYS_INFO_PARAM_PRESENT_OS_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800473 respData.insert(respData.end(),
474 std::begin(sysInfoParams.present_os_ver),
475 std::end(sysInfoParams.present_os_ver));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700476 break;
477 case SYS_INFO_PARAM_BMC_URL:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800478 respData.insert(respData.end(), std::begin(sysInfoParams.bmc_url),
479 std::end(sysInfoParams.bmc_url));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700480 break;
481 case SYS_INFO_PARAM_OS_HV_URL:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800482 respData.insert(respData.end(), std::begin(sysInfoParams.os_hv_url),
483 std::end(sysInfoParams.os_hv_url));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700484 break;
485 case SYS_INFO_PARAM_BIOS_CURRENT_BOOT_LIST:
486 len = appData[KEY_BIOS_BOOT_LEN].get<uint8_t>();
Patrick Williams010dee02024-08-16 15:19:44 -0400487 respData.insert(
488 respData.end(),
489 std::begin(sysInfoParams.bios_current_boot_list),
490 std::begin(sysInfoParams.bios_current_boot_list) + len);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700491 break;
492 case SYS_INFO_PARAM_BIOS_FIXED_BOOT_DEVICE:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800493 respData.insert(respData.end(),
494 std::begin(sysInfoParams.bios_fixed_boot_device),
495 std::end(sysInfoParams.bios_fixed_boot_device));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700496 break;
497 case SYS_INFO_PARAM_BIOS_RSTR_DFLT_SETTING:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800498 respData.insert(respData.end(),
499 std::begin(sysInfoParams.bios_rstr_dflt_setting),
500 std::end(sysInfoParams.bios_rstr_dflt_setting));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700501 break;
502 case SYS_INFO_PARAM_LAST_BOOT_TIME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800503 respData.insert(respData.end(),
504 std::begin(sysInfoParams.last_boot_time),
505 std::end(sysInfoParams.last_boot_time));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700506 break;
507 default:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800508 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700509 break;
510 }
Bonnie Loe9baaff2022-11-08 16:36:21 +0800511
512 return ipmi::responseSuccess(respData);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700513}
514
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700515void registerAPPFunctions()
516{
Vijay Khemka666a4d92019-04-03 11:27:24 -0700517 /* Get App data stored in json file */
Vijay Khemka802ccb12019-08-27 15:03:44 -0700518 std::ifstream file(JSON_APP_DATA_FILE);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700519 if (file)
Vijay Khemka802ccb12019-08-27 15:03:44 -0700520 {
Vijay Khemka666a4d92019-04-03 11:27:24 -0700521 file >> appData;
Vijay Khemka802ccb12019-08-27 15:03:44 -0700522 file.close();
523 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700524
George Liu0821a2e2025-04-03 10:12:10 +0800525 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_GET_SELFTEST_RESULTS, NULL,
Vijay Khemka666a4d92019-04-03 11:27:24 -0700526 ipmiAppGetSTResults,
527 PRIVILEGE_USER); // Get Self Test Results
George Liu0821a2e2025-04-03 10:12:10 +0800528 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_MFR_TEST_ON, NULL,
Vijay Khemka666a4d92019-04-03 11:27:24 -0700529 ipmiAppMfrTestOn,
530 PRIVILEGE_USER); // Manufacturing Test On
George Liu0821a2e2025-04-03 10:12:10 +0800531 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_SET_GLOBAL_ENABLES, NULL,
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700532 ipmiAppSetGlobalEnables,
Vijay Khemka666a4d92019-04-03 11:27:24 -0700533 PRIVILEGE_USER); // Set Global Enables
George Liu0821a2e2025-04-03 10:12:10 +0800534 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_GET_GLOBAL_ENABLES, NULL,
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700535 ipmiAppGetGlobalEnables,
536 PRIVILEGE_USER); // Get Global Enables
George Liu0821a2e2025-04-03 10:12:10 +0800537 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_CLEAR_MESSAGE_FLAGS, NULL,
Vijay Khemka666a4d92019-04-03 11:27:24 -0700538 ipmiAppClearMsgFlags,
539 PRIVILEGE_USER); // Clear Message flags
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530540#if BIC_ENABLED
541 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
542 ipmi::app::cmdGetSystemGuid, ipmi::Privilege::User,
543 ipmiAppGetSysGUID);
544#else
George Liu0821a2e2025-04-03 10:12:10 +0800545 ipmiPrintAndRegister(ipmi::netFnApp, CMD_APP_GET_SYS_GUID, NULL,
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700546 ipmiAppGetSysGUID,
547 PRIVILEGE_USER); // Get System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530548#endif
Bonnie Loe9baaff2022-11-08 16:36:21 +0800549 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
550 ipmi::app::cmdSetSystemInfoParameters,
551 ipmi::Privilege::User, ipmiAppSetSysInfoParams);
552
553 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
554 ipmi::app::cmdGetSystemInfoParameters,
555 ipmi::Privilege::User, ipmiAppGetSysInfoParams);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700556 return;
557}
558
559} // namespace ipmi