blob: ed9e365475be6d2d5f0d67b9a86fa10217113e88 [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
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34#include <sstream>
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070035
36namespace ipmi
37{
38
39static void registerAPPFunctions() __attribute__((constructor));
40static constexpr size_t GUID_SIZE = 16;
41// TODO Make offset and location runtime configurable to ensure we
42// can make each define their own locations.
43static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
Vijay Khemka63c99be2020-05-27 19:14:35 -070044static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
Vijay Khemka666a4d92019-04-03 11:27:24 -070045
46// TODO: Need to store this info after identifying proper storage
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070047static uint8_t globEna = 0x09;
Vijay Khemka666a4d92019-04-03 11:27:24 -070048static SysInfoParam sysInfoParams;
Vijay Khemka802ccb12019-08-27 15:03:44 -070049nlohmann::json appData __attribute__((init_priority(101)));
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070050
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053051int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
52 std::vector<uint8_t>&);
53
Bonnie Loe9baaff2022-11-08 16:36:21 +080054static inline auto responseSystemInfoParamterNotSupportCommand()
55{
56 return response(IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED);
57}
58
Vijay Khemka63c99be2020-05-27 19:14:35 -070059void printGUID(uint8_t* guid, off_t offset)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070060{
61 std::cout << "Read GUID from offset : " << offset << " :\n";
Willy Tue39f9392022-06-15 13:24:20 -070062 for (size_t i = 0; i < GUID_SIZE; i++)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070063 {
64 int data = guid[i];
65 std::cout << std::hex << data << " ";
66 }
67 std::cout << std::endl;
68}
69
Vijay Khemka63c99be2020-05-27 19:14:35 -070070int getGUID(off_t offset, uint8_t* guid)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -070071{
72 int fd = -1;
73 ssize_t bytes_rd;
74 int ret = 0;
75
76 errno = 0;
77
78 // Check if file is present
79 if (access(FRU_EEPROM, F_OK) == -1)
80 {
81 std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
82 return errno;
83 }
84
85 // Open the file
86 fd = open(FRU_EEPROM, O_RDONLY);
87 if (fd == -1)
88 {
89 std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
90 return errno;
91 }
92
93 // seek to the offset
94 lseek(fd, offset, SEEK_SET);
95
96 // Read bytes from location
97 bytes_rd = read(fd, guid, GUID_SIZE);
98 if (bytes_rd != GUID_SIZE)
99 {
100 phosphor::logging::log<phosphor::logging::level::ERR>(
101 "GUID read data from EEPROM failed");
102 ret = errno;
103 }
104 else
105 {
106 printGUID(guid, offset);
107 }
108 close(fd);
109 return ret;
110}
111
Vijay Khemka63c99be2020-05-27 19:14:35 -0700112int getSystemGUID(uint8_t* guid)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700113{
114 return getGUID(OFFSET_SYS_GUID, guid);
115}
116
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700117//----------------------------------------------------------------------
Vijay Khemka666a4d92019-04-03 11:27:24 -0700118// Get Self Test Results (IPMI/Section 20.4) (CMD_APP_GET_SELFTEST_RESULTS)
119//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700120ipmi_ret_t ipmiAppGetSTResults(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
121 ipmi_response_t response,
122 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700123{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700124 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700125
126 // TODO: Following data needs to be updated based on self-test results
127 *res++ = 0x55; // Self-Test result
128 *res++ = 0x00; // Extra error info in case of failure
129
130 *data_len = 2;
131
132 return IPMI_CC_OK;
133}
134
135//----------------------------------------------------------------------
136// Manufacturing Test On (IPMI/Section 20.5) (CMD_APP_MFR_TEST_ON)
137//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700138ipmi_ret_t ipmiAppMfrTestOn(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
139 ipmi_response_t, ipmi_data_len_t data_len,
140 ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700141{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700142 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700143 std::string mfrTest = "sled-cycle";
Patrick Williams35208452022-06-24 06:12:15 -0500144 ipmi_ret_t rc = IPMI_CC_OK;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700145
146 if (!memcmp(req, mfrTest.data(), mfrTest.length()) &&
147 (*data_len == mfrTest.length()))
148 {
149 /* sled-cycle the BMC */
Patrick Williams35208452022-06-24 06:12:15 -0500150 auto ret = system("/usr/sbin/power-util sled-cycle");
151 if (ret)
152 {
153 rc = IPMI_CC_UNSPECIFIED_ERROR;
154 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700155 }
156 else
157 {
Patrick Williams35208452022-06-24 06:12:15 -0500158 rc = IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700159 }
160
161 *data_len = 0;
162
Patrick Williams35208452022-06-24 06:12:15 -0500163 return rc;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700164}
165
166//----------------------------------------------------------------------
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700167// Set Global Enables (CMD_APP_SET_GLOBAL_ENABLES)
168//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700169ipmi_ret_t ipmiAppSetGlobalEnables(ipmi_netfn_t, ipmi_cmd_t,
170 ipmi_request_t request, ipmi_response_t,
171 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700172{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700173 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700174
175 globEna = *req;
176 *data_len = 0;
177
178 return IPMI_CC_OK;
179}
180
181//----------------------------------------------------------------------
182// Get Global Enables (CMD_APP_GET_GLOBAL_ENABLES)
183//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700184ipmi_ret_t ipmiAppGetGlobalEnables(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700185 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700186 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700187{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700188 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700189
190 *data_len = 1;
191 *res++ = globEna;
192
193 return IPMI_CC_OK;
194}
195
196//----------------------------------------------------------------------
Vijay Khemka666a4d92019-04-03 11:27:24 -0700197// Clear Message flags (IPMI/Section 22.3) (CMD_APP_CLEAR_MESSAGE_FLAGS)
198//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700199ipmi_ret_t ipmiAppClearMsgFlags(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
200 ipmi_response_t, ipmi_data_len_t data_len,
201 ipmi_context_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700202{
203 // Do Nothing and just return success
204 *data_len = 0;
205
206 return IPMI_CC_OK;
207}
208
209//----------------------------------------------------------------------
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700210// Get System GUID (CMD_APP_GET_SYS_GUID)
211//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530212#if BIC_ENABLED
213ipmi::RspType<std::vector<uint8_t>>
214 ipmiAppGetSysGUID(ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
215
216{
217 std::vector<uint8_t> respData;
218
219 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
220
221 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
222 return ipmi::responseUnspecifiedError();
223
224 return ipmi::responseSuccess(respData);
225}
226
227#else
Willy Tue39f9392022-06-15 13:24:20 -0700228ipmi_ret_t ipmiAppGetSysGUID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
229 ipmi_response_t response, ipmi_data_len_t data_len,
230 ipmi_context_t)
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700231{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700232 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700233 if (getSystemGUID(res))
234 {
235 return IPMI_CC_UNSPECIFIED_ERROR;
236 }
237 *data_len = GUID_SIZE;
238 return IPMI_CC_OK;
239}
240
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530241#endif
242
Vijay Khemka666a4d92019-04-03 11:27:24 -0700243//----------------------------------------------------------------------
244// Platform specific functions for storing app data
245//----------------------------------------------------------------------
246
247void flush_app_data()
248{
Vijay Khemka802ccb12019-08-27 15:03:44 -0700249 std::ofstream file(JSON_APP_DATA_FILE);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700250 file << appData;
Vijay Khemka802ccb12019-08-27 15:03:44 -0700251 file.close();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700252 return;
253}
254
Bonnie Loe9baaff2022-11-08 16:36:21 +0800255static int platSetSysFWVer(uint8_t* ver, const std::string key)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700256{
257 std::stringstream ss;
258 int i;
259
260 /* TODO: implement byte 1: Set selector
261 * byte 2: encodeing, currently only supported
262 * ASCII which is value 0, UTF and unicode are
263 * not supported yet.
264 */
265 if (ver[1] & 0x0f)
266 return -1;
267
268 for (i = 3; i < 3 + ver[2]; i++)
269 {
270 ss << (char)ver[i];
271 }
272
Bonnie Loe9baaff2022-11-08 16:36:21 +0800273 appData[key] = ss.str();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700274 flush_app_data();
275
276 return 0;
277}
278
Bonnie Loe9baaff2022-11-08 16:36:21 +0800279static int platGetSysFWVer(std::vector<uint8_t>& respData,
280 const std::string key)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700281{
Bonnie Loe9baaff2022-11-08 16:36:21 +0800282 int len = -1;
Vijay Khemka666a4d92019-04-03 11:27:24 -0700283
Bonnie Loe9baaff2022-11-08 16:36:21 +0800284 if (!appData.contains(std::string(key)))
285 {
286 return -1;
287 }
288 std::string str = appData[key].get<std::string>();
289
290 respData.push_back(0); // byte 1: Set selector not supported
291 respData.push_back(0); // byte 2: Only ASCII supported
Vijay Khemka666a4d92019-04-03 11:27:24 -0700292
293 len = str.length();
Bonnie Loe9baaff2022-11-08 16:36:21 +0800294 respData.push_back(len); // byte 3: Size of version
295
296 for (auto c : str)
297 {
298 respData.push_back(c);
299 }
300
301 // Remaining byte fill to 0
302 for (int i = 0; i < SIZE_SYSFW_VER - (len + 3); i++)
303 {
304 respData.push_back(0);
305 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700306
307 return (len + 3);
308}
309
310//----------------------------------------------------------------------
311// Set Sys Info Params (IPMI/Sec 22.14a) (CMD_APP_SET_SYS_INFO_PARAMS)
312//----------------------------------------------------------------------
Bonnie Loe9baaff2022-11-08 16:36:21 +0800313ipmi::RspType<uint8_t> ipmiAppSetSysInfoParams(ipmi::Context::ptr ctx,
314 std::vector<uint8_t> req)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700315{
Vijay Khemka666a4d92019-04-03 11:27:24 -0700316 uint8_t param = req[0];
Bonnie Loe9baaff2022-11-08 16:36:21 +0800317 uint8_t req_len = req.size();
318 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700319
Bonnie Loe9baaff2022-11-08 16:36:21 +0800320 if (!hostId)
321 {
322 phosphor::logging::log<phosphor::logging::level::ERR>(
323 "Invalid Host Id received");
324 return ipmi::responseInvalidCommand();
325 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700326
327 switch (param)
328 {
329 case SYS_INFO_PARAM_SET_IN_PROG:
330 sysInfoParams.set_in_prog = req[1];
331 break;
332 case SYS_INFO_PARAM_SYSFW_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800333 {
Vijay Khemka666a4d92019-04-03 11:27:24 -0700334 memcpy(sysInfoParams.sysfw_ver, &req[1], SIZE_SYSFW_VER);
Bonnie Loe9baaff2022-11-08 16:36:21 +0800335 std::string version_key = KEY_SYSFW_VER + std::to_string(*hostId);
336 if (platSetSysFWVer(sysInfoParams.sysfw_ver, version_key))
337 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700338 break;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800339 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700340 case SYS_INFO_PARAM_SYS_NAME:
341 memcpy(sysInfoParams.sys_name, &req[1], SIZE_SYS_NAME);
342 break;
343 case SYS_INFO_PARAM_PRI_OS_NAME:
344 memcpy(sysInfoParams.pri_os_name, &req[1], SIZE_OS_NAME);
345 break;
346 case SYS_INFO_PARAM_PRESENT_OS_NAME:
347 memcpy(sysInfoParams.present_os_name, &req[1], SIZE_OS_NAME);
348 break;
349 case SYS_INFO_PARAM_PRESENT_OS_VER:
350 memcpy(sysInfoParams.present_os_ver, &req[1], SIZE_OS_VER);
351 break;
352 case SYS_INFO_PARAM_BMC_URL:
353 memcpy(sysInfoParams.bmc_url, &req[1], SIZE_BMC_URL);
354 break;
355 case SYS_INFO_PARAM_OS_HV_URL:
356 memcpy(sysInfoParams.os_hv_url, &req[1], SIZE_OS_HV_URL);
357 break;
358 case SYS_INFO_PARAM_BIOS_CURRENT_BOOT_LIST:
359 memcpy(sysInfoParams.bios_current_boot_list, &req[1], req_len);
360 appData[KEY_BIOS_BOOT_LEN] = req_len;
361 flush_app_data();
362 break;
363 case SYS_INFO_PARAM_BIOS_FIXED_BOOT_DEVICE:
364 if (SIZE_BIOS_FIXED_BOOT_DEVICE != req_len)
365 break;
366 memcpy(sysInfoParams.bios_fixed_boot_device, &req[1],
367 SIZE_BIOS_FIXED_BOOT_DEVICE);
368 break;
369 case SYS_INFO_PARAM_BIOS_RSTR_DFLT_SETTING:
370 if (SIZE_BIOS_RSTR_DFLT_SETTING != req_len)
371 break;
372 memcpy(sysInfoParams.bios_rstr_dflt_setting, &req[1],
373 SIZE_BIOS_RSTR_DFLT_SETTING);
374 break;
375 case SYS_INFO_PARAM_LAST_BOOT_TIME:
376 if (SIZE_LAST_BOOT_TIME != req_len)
377 break;
378 memcpy(sysInfoParams.last_boot_time, &req[1], SIZE_LAST_BOOT_TIME);
379 break;
380 default:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800381 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700382 break;
383 }
384
Bonnie Loe9baaff2022-11-08 16:36:21 +0800385 return ipmi::responseSuccess();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700386}
387
388//----------------------------------------------------------------------
389// Get Sys Info Params (IPMI/Sec 22.14b) (CMD_APP_GET_SYS_INFO_PARAMS)
390//----------------------------------------------------------------------
Bonnie Loe9baaff2022-11-08 16:36:21 +0800391ipmi::RspType<std::vector<uint8_t>>
392 ipmiAppGetSysInfoParams(ipmi::Context::ptr ctx, uint8_t, uint8_t param,
393 uint8_t, uint8_t)
Vijay Khemka666a4d92019-04-03 11:27:24 -0700394{
Willy Tue39f9392022-06-15 13:24:20 -0700395 int len;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800396 std::vector<uint8_t> respData;
397 respData.push_back(1); // Parameter revision
Vijay Khemka666a4d92019-04-03 11:27:24 -0700398
Bonnie Loe9baaff2022-11-08 16:36:21 +0800399 std::optional<size_t> hostId = findHost(ctx->hostIdx);
400
401 if (!hostId)
402 {
403 phosphor::logging::log<phosphor::logging::level::ERR>(
404 "Invalid Host Id received");
405 return ipmi::responseInvalidCommand();
406 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700407
408 switch (param)
409 {
410 case SYS_INFO_PARAM_SET_IN_PROG:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800411 respData.push_back(sysInfoParams.set_in_prog);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700412 break;
413 case SYS_INFO_PARAM_SYSFW_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800414 {
415 std::string version_key = KEY_SYSFW_VER + std::to_string(*hostId);
416 if ((platGetSysFWVer(respData, version_key)) < 0)
417 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700418 break;
Bonnie Loe9baaff2022-11-08 16:36:21 +0800419 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700420 case SYS_INFO_PARAM_SYS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800421 respData.insert(respData.end(), std::begin(sysInfoParams.sys_name),
422 std::end(sysInfoParams.sys_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700423 break;
424 case SYS_INFO_PARAM_PRI_OS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800425 respData.insert(respData.end(),
426 std::begin(sysInfoParams.pri_os_name),
427 std::end(sysInfoParams.pri_os_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700428 break;
429 case SYS_INFO_PARAM_PRESENT_OS_NAME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800430 respData.insert(respData.end(),
431 std::begin(sysInfoParams.present_os_name),
432 std::end(sysInfoParams.present_os_name));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700433 break;
434 case SYS_INFO_PARAM_PRESENT_OS_VER:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800435 respData.insert(respData.end(),
436 std::begin(sysInfoParams.present_os_ver),
437 std::end(sysInfoParams.present_os_ver));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700438 break;
439 case SYS_INFO_PARAM_BMC_URL:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800440 respData.insert(respData.end(), std::begin(sysInfoParams.bmc_url),
441 std::end(sysInfoParams.bmc_url));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700442 break;
443 case SYS_INFO_PARAM_OS_HV_URL:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800444 respData.insert(respData.end(), std::begin(sysInfoParams.os_hv_url),
445 std::end(sysInfoParams.os_hv_url));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700446 break;
447 case SYS_INFO_PARAM_BIOS_CURRENT_BOOT_LIST:
448 len = appData[KEY_BIOS_BOOT_LEN].get<uint8_t>();
Bonnie Loe9baaff2022-11-08 16:36:21 +0800449 respData.insert(respData.end(),
450 std::begin(sysInfoParams.bios_current_boot_list),
451 std::begin(sysInfoParams.bios_current_boot_list) +
452 len);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700453 break;
454 case SYS_INFO_PARAM_BIOS_FIXED_BOOT_DEVICE:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800455 respData.insert(respData.end(),
456 std::begin(sysInfoParams.bios_fixed_boot_device),
457 std::end(sysInfoParams.bios_fixed_boot_device));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700458 break;
459 case SYS_INFO_PARAM_BIOS_RSTR_DFLT_SETTING:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800460 respData.insert(respData.end(),
461 std::begin(sysInfoParams.bios_rstr_dflt_setting),
462 std::end(sysInfoParams.bios_rstr_dflt_setting));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700463 break;
464 case SYS_INFO_PARAM_LAST_BOOT_TIME:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800465 respData.insert(respData.end(),
466 std::begin(sysInfoParams.last_boot_time),
467 std::end(sysInfoParams.last_boot_time));
Vijay Khemka666a4d92019-04-03 11:27:24 -0700468 break;
469 default:
Bonnie Loe9baaff2022-11-08 16:36:21 +0800470 return ipmi::responseSystemInfoParamterNotSupportCommand();
Vijay Khemka666a4d92019-04-03 11:27:24 -0700471 break;
472 }
Bonnie Loe9baaff2022-11-08 16:36:21 +0800473
474 return ipmi::responseSuccess(respData);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700475}
476
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700477void registerAPPFunctions()
478{
Vijay Khemka666a4d92019-04-03 11:27:24 -0700479 /* Get App data stored in json file */
Vijay Khemka802ccb12019-08-27 15:03:44 -0700480 std::ifstream file(JSON_APP_DATA_FILE);
Vijay Khemka666a4d92019-04-03 11:27:24 -0700481 if (file)
Vijay Khemka802ccb12019-08-27 15:03:44 -0700482 {
Vijay Khemka666a4d92019-04-03 11:27:24 -0700483 file >> appData;
Vijay Khemka802ccb12019-08-27 15:03:44 -0700484 file.close();
485 }
Vijay Khemka666a4d92019-04-03 11:27:24 -0700486
487 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_GET_SELFTEST_RESULTS, NULL,
488 ipmiAppGetSTResults,
489 PRIVILEGE_USER); // Get Self Test Results
490 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_MFR_TEST_ON, NULL,
491 ipmiAppMfrTestOn,
492 PRIVILEGE_USER); // Manufacturing Test On
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700493 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_SET_GLOBAL_ENABLES, NULL,
494 ipmiAppSetGlobalEnables,
Vijay Khemka666a4d92019-04-03 11:27:24 -0700495 PRIVILEGE_USER); // Set Global Enables
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700496 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_GET_GLOBAL_ENABLES, NULL,
497 ipmiAppGetGlobalEnables,
498 PRIVILEGE_USER); // Get Global Enables
Vijay Khemka666a4d92019-04-03 11:27:24 -0700499 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_CLEAR_MESSAGE_FLAGS, NULL,
500 ipmiAppClearMsgFlags,
501 PRIVILEGE_USER); // Clear Message flags
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530502#if BIC_ENABLED
503 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
504 ipmi::app::cmdGetSystemGuid, ipmi::Privilege::User,
505 ipmiAppGetSysGUID);
506#else
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700507 ipmiPrintAndRegister(NETFUN_APP, CMD_APP_GET_SYS_GUID, NULL,
508 ipmiAppGetSysGUID,
509 PRIVILEGE_USER); // Get System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +0530510#endif
Bonnie Loe9baaff2022-11-08 16:36:21 +0800511 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
512 ipmi::app::cmdSetSystemInfoParameters,
513 ipmi::Privilege::User, ipmiAppSetSysInfoParams);
514
515 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
516 ipmi::app::cmdGetSystemInfoParameters,
517 ipmi::Privilege::User, ipmiAppGetSysInfoParams);
Vijay Khemkaa2d52f12019-03-27 14:54:00 -0700518 return;
519}
520
521} // namespace ipmi