appcommands.cpp (2515e0931ae981645cda726fd278e60b8f271f7c) | appcommands.cpp (63c99be4ac026a326d6953d608376edb0e60007a) |
---|---|
1/* 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 | 1/* 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 |
18#include <fcntl.h> |
|
18#include <ipmid/api.h> | 19#include <ipmid/api.h> |
19 | |
20#include <sys/stat.h> | 20#include <sys/stat.h> |
21#include <fcntl.h> | |
22#include <unistd.h> | 21#include <unistd.h> |
23#include <nlohmann/json.hpp> | 22 23#include <appcommands.hpp> |
24#include <commandutils.hpp> | 24#include <commandutils.hpp> |
25#include <iostream> 26#include <iomanip> 27#include <sstream> 28#include <fstream> | 25#include <nlohmann/json.hpp> |
29#include <phosphor-logging/log.hpp> 30#include <sdbusplus/message/types.hpp> | 26#include <phosphor-logging/log.hpp> 27#include <sdbusplus/message/types.hpp> |
31#include <appcommands.hpp> | |
32 | 28 |
29#include <fstream> 30#include <iomanip> 31#include <iostream> 32#include <sstream> 33 |
|
33namespace ipmi 34{ 35 36static void registerAPPFunctions() __attribute__((constructor)); 37static constexpr size_t GUID_SIZE = 16; 38// TODO Make offset and location runtime configurable to ensure we 39// can make each define their own locations. 40static constexpr off_t OFFSET_SYS_GUID = 0x17F0; | 34namespace ipmi 35{ 36 37static void registerAPPFunctions() __attribute__((constructor)); 38static constexpr size_t GUID_SIZE = 16; 39// TODO Make offset and location runtime configurable to ensure we 40// can make each define their own locations. 41static constexpr off_t OFFSET_SYS_GUID = 0x17F0; |
41static constexpr const char *FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom"; | 42static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom"; |
42 43// TODO: Need to store this info after identifying proper storage 44static uint8_t globEna = 0x09; 45static SysInfoParam sysInfoParams; 46nlohmann::json appData __attribute__((init_priority(101))); 47 | 43 44// TODO: Need to store this info after identifying proper storage 45static uint8_t globEna = 0x09; 46static SysInfoParam sysInfoParams; 47nlohmann::json appData __attribute__((init_priority(101))); 48 |
48void printGUID(uint8_t *guid, off_t offset) | 49void printGUID(uint8_t* guid, off_t offset) |
49{ 50 std::cout << "Read GUID from offset : " << offset << " :\n"; 51 for (int i = 0; i < GUID_SIZE; i++) 52 { 53 int data = guid[i]; 54 std::cout << std::hex << data << " "; 55 } 56 std::cout << std::endl; 57} 58 | 50{ 51 std::cout << "Read GUID from offset : " << offset << " :\n"; 52 for (int i = 0; i < GUID_SIZE; i++) 53 { 54 int data = guid[i]; 55 std::cout << std::hex << data << " "; 56 } 57 std::cout << std::endl; 58} 59 |
59int getGUID(off_t offset, uint8_t *guid) | 60int getGUID(off_t offset, uint8_t* guid) |
60{ 61 int fd = -1; 62 ssize_t bytes_rd; 63 int ret = 0; 64 65 errno = 0; 66 67 // Check if file is present --- 25 unchanged lines hidden (view full) --- 93 else 94 { 95 printGUID(guid, offset); 96 } 97 close(fd); 98 return ret; 99} 100 | 61{ 62 int fd = -1; 63 ssize_t bytes_rd; 64 int ret = 0; 65 66 errno = 0; 67 68 // Check if file is present --- 25 unchanged lines hidden (view full) --- 94 else 95 { 96 printGUID(guid, offset); 97 } 98 close(fd); 99 return ret; 100} 101 |
101int getSystemGUID(uint8_t *guid) | 102int getSystemGUID(uint8_t* guid) |
102{ 103 return getGUID(OFFSET_SYS_GUID, guid); 104} 105 106//---------------------------------------------------------------------- 107// Get Self Test Results (IPMI/Section 20.4) (CMD_APP_GET_SELFTEST_RESULTS) 108//---------------------------------------------------------------------- 109ipmi_ret_t ipmiAppGetSTResults(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 110 ipmi_request_t request, ipmi_response_t response, 111 ipmi_data_len_t data_len, ipmi_context_t context) 112{ | 103{ 104 return getGUID(OFFSET_SYS_GUID, guid); 105} 106 107//---------------------------------------------------------------------- 108// Get Self Test Results (IPMI/Section 20.4) (CMD_APP_GET_SELFTEST_RESULTS) 109//---------------------------------------------------------------------- 110ipmi_ret_t ipmiAppGetSTResults(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 111 ipmi_request_t request, ipmi_response_t response, 112 ipmi_data_len_t data_len, ipmi_context_t context) 113{ |
113 uint8_t *res = reinterpret_cast<uint8_t *>(response); | 114 uint8_t* res = reinterpret_cast<uint8_t*>(response); |
114 115 // TODO: Following data needs to be updated based on self-test results 116 *res++ = 0x55; // Self-Test result 117 *res++ = 0x00; // Extra error info in case of failure 118 119 *data_len = 2; 120 121 return IPMI_CC_OK; 122} 123 124//---------------------------------------------------------------------- 125// Manufacturing Test On (IPMI/Section 20.5) (CMD_APP_MFR_TEST_ON) 126//---------------------------------------------------------------------- 127ipmi_ret_t ipmiAppMfrTestOn(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 128 ipmi_request_t request, ipmi_response_t response, 129 ipmi_data_len_t data_len, ipmi_context_t context) 130{ | 115 116 // TODO: Following data needs to be updated based on self-test results 117 *res++ = 0x55; // Self-Test result 118 *res++ = 0x00; // Extra error info in case of failure 119 120 *data_len = 2; 121 122 return IPMI_CC_OK; 123} 124 125//---------------------------------------------------------------------- 126// Manufacturing Test On (IPMI/Section 20.5) (CMD_APP_MFR_TEST_ON) 127//---------------------------------------------------------------------- 128ipmi_ret_t ipmiAppMfrTestOn(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 129 ipmi_request_t request, ipmi_response_t response, 130 ipmi_data_len_t data_len, ipmi_context_t context) 131{ |
131 uint8_t *req = reinterpret_cast<uint8_t *>(request); | 132 uint8_t* req = reinterpret_cast<uint8_t*>(request); |
132 std::string mfrTest = "sled-cycle"; 133 134 if (!memcmp(req, mfrTest.data(), mfrTest.length()) && 135 (*data_len == mfrTest.length())) 136 { 137 /* sled-cycle the BMC */ 138 system("/usr/sbin/power-util sled-cycle"); 139 } --- 11 unchanged lines hidden (view full) --- 151// Set Global Enables (CMD_APP_SET_GLOBAL_ENABLES) 152//---------------------------------------------------------------------- 153ipmi_ret_t ipmiAppSetGlobalEnables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 154 ipmi_request_t request, 155 ipmi_response_t response, 156 ipmi_data_len_t data_len, 157 ipmi_context_t context) 158{ | 133 std::string mfrTest = "sled-cycle"; 134 135 if (!memcmp(req, mfrTest.data(), mfrTest.length()) && 136 (*data_len == mfrTest.length())) 137 { 138 /* sled-cycle the BMC */ 139 system("/usr/sbin/power-util sled-cycle"); 140 } --- 11 unchanged lines hidden (view full) --- 152// Set Global Enables (CMD_APP_SET_GLOBAL_ENABLES) 153//---------------------------------------------------------------------- 154ipmi_ret_t ipmiAppSetGlobalEnables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 155 ipmi_request_t request, 156 ipmi_response_t response, 157 ipmi_data_len_t data_len, 158 ipmi_context_t context) 159{ |
159 uint8_t *req = reinterpret_cast<uint8_t *>(request); | 160 uint8_t* req = reinterpret_cast<uint8_t*>(request); |
160 161 globEna = *req; 162 *data_len = 0; 163 164 return IPMI_CC_OK; 165} 166 167//---------------------------------------------------------------------- 168// Get Global Enables (CMD_APP_GET_GLOBAL_ENABLES) 169//---------------------------------------------------------------------- 170ipmi_ret_t ipmiAppGetGlobalEnables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 171 ipmi_request_t request, 172 ipmi_response_t response, 173 ipmi_data_len_t data_len, 174 ipmi_context_t context) 175{ | 161 162 globEna = *req; 163 *data_len = 0; 164 165 return IPMI_CC_OK; 166} 167 168//---------------------------------------------------------------------- 169// Get Global Enables (CMD_APP_GET_GLOBAL_ENABLES) 170//---------------------------------------------------------------------- 171ipmi_ret_t ipmiAppGetGlobalEnables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 172 ipmi_request_t request, 173 ipmi_response_t response, 174 ipmi_data_len_t data_len, 175 ipmi_context_t context) 176{ |
176 uint8_t *res = reinterpret_cast<uint8_t *>(response); | 177 uint8_t* res = reinterpret_cast<uint8_t*>(response); |
177 178 *data_len = 1; 179 *res++ = globEna; 180 181 return IPMI_CC_OK; 182} 183 184//---------------------------------------------------------------------- --- 13 unchanged lines hidden (view full) --- 198 199//---------------------------------------------------------------------- 200// Get System GUID (CMD_APP_GET_SYS_GUID) 201//---------------------------------------------------------------------- 202ipmi_ret_t ipmiAppGetSysGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 203 ipmi_request_t request, ipmi_response_t response, 204 ipmi_data_len_t data_len, ipmi_context_t context) 205{ | 178 179 *data_len = 1; 180 *res++ = globEna; 181 182 return IPMI_CC_OK; 183} 184 185//---------------------------------------------------------------------- --- 13 unchanged lines hidden (view full) --- 199 200//---------------------------------------------------------------------- 201// Get System GUID (CMD_APP_GET_SYS_GUID) 202//---------------------------------------------------------------------- 203ipmi_ret_t ipmiAppGetSysGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 204 ipmi_request_t request, ipmi_response_t response, 205 ipmi_data_len_t data_len, ipmi_context_t context) 206{ |
206 uint8_t *res = reinterpret_cast<uint8_t *>(response); | 207 uint8_t* res = reinterpret_cast<uint8_t*>(response); |
207 if (getSystemGUID(res)) 208 { 209 return IPMI_CC_UNSPECIFIED_ERROR; 210 } 211 *data_len = GUID_SIZE; 212 return IPMI_CC_OK; 213} 214 --- 4 unchanged lines hidden (view full) --- 219void flush_app_data() 220{ 221 std::ofstream file(JSON_APP_DATA_FILE); 222 file << appData; 223 file.close(); 224 return; 225} 226 | 208 if (getSystemGUID(res)) 209 { 210 return IPMI_CC_UNSPECIFIED_ERROR; 211 } 212 *data_len = GUID_SIZE; 213 return IPMI_CC_OK; 214} 215 --- 4 unchanged lines hidden (view full) --- 220void flush_app_data() 221{ 222 std::ofstream file(JSON_APP_DATA_FILE); 223 file << appData; 224 file.close(); 225 return; 226} 227 |
227static int platSetSysFWVer(uint8_t *ver) | 228static int platSetSysFWVer(uint8_t* ver) |
228{ 229 std::stringstream ss; 230 int i; 231 232 /* TODO: implement byte 1: Set selector 233 * byte 2: encodeing, currently only supported 234 * ASCII which is value 0, UTF and unicode are 235 * not supported yet. --- 7 unchanged lines hidden (view full) --- 243 } 244 245 appData[KEY_SYSFW_VER] = ss.str(); 246 flush_app_data(); 247 248 return 0; 249} 250 | 229{ 230 std::stringstream ss; 231 int i; 232 233 /* TODO: implement byte 1: Set selector 234 * byte 2: encodeing, currently only supported 235 * ASCII which is value 0, UTF and unicode are 236 * not supported yet. --- 7 unchanged lines hidden (view full) --- 244 } 245 246 appData[KEY_SYSFW_VER] = ss.str(); 247 flush_app_data(); 248 249 return 0; 250} 251 |
251static int platGetSysFWVer(uint8_t *ver) | 252static int platGetSysFWVer(uint8_t* ver) |
252{ 253 std::string str = appData[KEY_SYSFW_VER].get<std::string>(); 254 int len; 255 256 *ver++ = 0; // byte 1: Set selector not supported 257 *ver++ = 0; // byte 2: Only ASCII supported 258 259 len = str.length(); --- 7 unchanged lines hidden (view full) --- 267// Set Sys Info Params (IPMI/Sec 22.14a) (CMD_APP_SET_SYS_INFO_PARAMS) 268//---------------------------------------------------------------------- 269ipmi_ret_t ipmiAppSetSysInfoParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 270 ipmi_request_t request, 271 ipmi_response_t response, 272 ipmi_data_len_t data_len, 273 ipmi_context_t context) 274{ | 253{ 254 std::string str = appData[KEY_SYSFW_VER].get<std::string>(); 255 int len; 256 257 *ver++ = 0; // byte 1: Set selector not supported 258 *ver++ = 0; // byte 2: Only ASCII supported 259 260 len = str.length(); --- 7 unchanged lines hidden (view full) --- 268// Set Sys Info Params (IPMI/Sec 22.14a) (CMD_APP_SET_SYS_INFO_PARAMS) 269//---------------------------------------------------------------------- 270ipmi_ret_t ipmiAppSetSysInfoParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 271 ipmi_request_t request, 272 ipmi_response_t response, 273 ipmi_data_len_t data_len, 274 ipmi_context_t context) 275{ |
275 uint8_t *req = reinterpret_cast<uint8_t *>(request); | 276 uint8_t* req = reinterpret_cast<uint8_t*>(request); |
276 277 uint8_t param = req[0]; 278 uint8_t req_len = *data_len; 279 280 *data_len = 0; 281 282 switch (param) 283 { --- 57 unchanged lines hidden (view full) --- 341// Get Sys Info Params (IPMI/Sec 22.14b) (CMD_APP_GET_SYS_INFO_PARAMS) 342//---------------------------------------------------------------------- 343ipmi_ret_t ipmiAppGetSysInfoParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 344 ipmi_request_t request, 345 ipmi_response_t response, 346 ipmi_data_len_t data_len, 347 ipmi_context_t context) 348{ | 277 278 uint8_t param = req[0]; 279 uint8_t req_len = *data_len; 280 281 *data_len = 0; 282 283 switch (param) 284 { --- 57 unchanged lines hidden (view full) --- 342// Get Sys Info Params (IPMI/Sec 22.14b) (CMD_APP_GET_SYS_INFO_PARAMS) 343//---------------------------------------------------------------------- 344ipmi_ret_t ipmiAppGetSysInfoParams(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 345 ipmi_request_t request, 346 ipmi_response_t response, 347 ipmi_data_len_t data_len, 348 ipmi_context_t context) 349{ |
349 uint8_t *req = reinterpret_cast<uint8_t *>(request); 350 uint8_t *res = reinterpret_cast<uint8_t *>(response); | 350 uint8_t* req = reinterpret_cast<uint8_t*>(request); 351 uint8_t* res = reinterpret_cast<uint8_t*>(response); |
351 352 uint8_t param = req[1]; 353 uint8_t len; 354 355 *res++ = 1; // Parameter revision 356 *data_len = 1; 357 358 switch (param) --- 98 unchanged lines hidden --- | 352 353 uint8_t param = req[1]; 354 uint8_t len; 355 356 *res++ = 1; // Parameter revision 357 *data_len = 1; 358 359 switch (param) --- 98 unchanged lines hidden --- |