1a2056e9cSWilly Tu // Copyright 2021 Google LLC 2a2056e9cSWilly Tu // 3a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 4a2056e9cSWilly Tu // you may not use this file except in compliance with the License. 5a2056e9cSWilly Tu // You may obtain a copy of the License at 6a2056e9cSWilly Tu // 7a2056e9cSWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 8a2056e9cSWilly Tu // 9a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software 10a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 11a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a2056e9cSWilly Tu // See the License for the specific language governing permissions and 13a2056e9cSWilly Tu // limitations under the License. 14fd0f1cf9SJaghathiswari Rankappagounder Natarajan 15fd0f1cf9SJaghathiswari Rankappagounder Natarajan #include "entity_name.hpp" 16fd0f1cf9SJaghathiswari Rankappagounder Natarajan 170e9aae5dSPatrick Venture #include "commands.hpp" 1807f85150SPatrick Venture #include "errors.hpp" 1907f85150SPatrick Venture #include "handler.hpp" 20fd0f1cf9SJaghathiswari Rankappagounder Natarajan 21fd0f1cf9SJaghathiswari Rankappagounder Natarajan #include <cstdint> 22fd0f1cf9SJaghathiswari Rankappagounder Natarajan #include <cstring> 23*ff3cd8e9SWilly Tu #include <ipmid/api-types.hpp> 24fd0f1cf9SJaghathiswari Rankappagounder Natarajan #include <string> 25fd0f1cf9SJaghathiswari Rankappagounder Natarajan #include <vector> 26fd0f1cf9SJaghathiswari Rankappagounder Natarajan 27fd0f1cf9SJaghathiswari Rankappagounder Natarajan namespace google 28fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 29fd0f1cf9SJaghathiswari Rankappagounder Natarajan namespace ipmi 30fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 31fd0f1cf9SJaghathiswari Rankappagounder Natarajan 32fd0f1cf9SJaghathiswari Rankappagounder Natarajan namespace 33fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 34fd0f1cf9SJaghathiswari Rankappagounder Natarajan 35fd0f1cf9SJaghathiswari Rankappagounder Natarajan // TODO (jaghu) : Add a call to get getChannelMaxTransferSize. 36fd0f1cf9SJaghathiswari Rankappagounder Natarajan #ifndef MAX_IPMI_BUFFER 37fd0f1cf9SJaghathiswari Rankappagounder Natarajan #define MAX_IPMI_BUFFER 64 38fd0f1cf9SJaghathiswari Rankappagounder Natarajan #endif 39fd0f1cf9SJaghathiswari Rankappagounder Natarajan 40fd0f1cf9SJaghathiswari Rankappagounder Natarajan } // namespace 41fd0f1cf9SJaghathiswari Rankappagounder Natarajan 42fd0f1cf9SJaghathiswari Rankappagounder Natarajan struct GetEntityNameRequest 43fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 4445fad1bbSPatrick Venture uint8_t entityId; 4545fad1bbSPatrick Venture uint8_t entityInstance; 46fd0f1cf9SJaghathiswari Rankappagounder Natarajan } __attribute__((packed)); 47fd0f1cf9SJaghathiswari Rankappagounder Natarajan 48*ff3cd8e9SWilly Tu Resp getEntityName(const std::vector<std::uint8_t>& data, 49*ff3cd8e9SWilly Tu HandlerInterface* handler) 50fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 51fd0f1cf9SJaghathiswari Rankappagounder Natarajan struct GetEntityNameRequest request; 52fd0f1cf9SJaghathiswari Rankappagounder Natarajan 53*ff3cd8e9SWilly Tu if (data.size() < sizeof(request)) 54fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 55fd0f1cf9SJaghathiswari Rankappagounder Natarajan std::fprintf(stderr, "Invalid command length: %u\n", 56*ff3cd8e9SWilly Tu static_cast<uint32_t>(data.size())); 57*ff3cd8e9SWilly Tu return ::ipmi::responseReqDataLenInvalid(); 58fd0f1cf9SJaghathiswari Rankappagounder Natarajan } 59fd0f1cf9SJaghathiswari Rankappagounder Natarajan 60*ff3cd8e9SWilly Tu std::memcpy(&request, data.data(), sizeof(request)); 61fd0f1cf9SJaghathiswari Rankappagounder Natarajan std::string entityName; 62fd0f1cf9SJaghathiswari Rankappagounder Natarajan try 63fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 6407f85150SPatrick Venture entityName = 6545fad1bbSPatrick Venture handler->getEntityName(request.entityId, request.entityInstance); 66fd0f1cf9SJaghathiswari Rankappagounder Natarajan } 6707f85150SPatrick Venture catch (const IpmiException& e) 68fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 69*ff3cd8e9SWilly Tu return ::ipmi::response(e.getIpmiError()); 70fd0f1cf9SJaghathiswari Rankappagounder Natarajan } 71fd0f1cf9SJaghathiswari Rankappagounder Natarajan 72fd0f1cf9SJaghathiswari Rankappagounder Natarajan int length = sizeof(struct GetEntityNameReply) + entityName.length(); 73fd0f1cf9SJaghathiswari Rankappagounder Natarajan 74fd0f1cf9SJaghathiswari Rankappagounder Natarajan // TODO (jaghu) : Add a call to get getChannelMaxTransferSize. 75fd0f1cf9SJaghathiswari Rankappagounder Natarajan if (length > MAX_IPMI_BUFFER) 76fd0f1cf9SJaghathiswari Rankappagounder Natarajan { 77fd0f1cf9SJaghathiswari Rankappagounder Natarajan std::fprintf(stderr, "Response would overflow response buffer\n"); 78*ff3cd8e9SWilly Tu return ::ipmi::responseInvalidCommand(); 79fd0f1cf9SJaghathiswari Rankappagounder Natarajan } 80fd0f1cf9SJaghathiswari Rankappagounder Natarajan 81*ff3cd8e9SWilly Tu std::vector<std::uint8_t> reply; 82*ff3cd8e9SWilly Tu reply.reserve(entityName.length() + sizeof(struct GetEntityNameReply)); 83*ff3cd8e9SWilly Tu reply.emplace_back(entityName.length()); /* entityNameLength */ 84*ff3cd8e9SWilly Tu reply.insert(reply.end(), entityName.begin(), 85*ff3cd8e9SWilly Tu entityName.end()); /* entityName */ 86fd0f1cf9SJaghathiswari Rankappagounder Natarajan 87*ff3cd8e9SWilly Tu return ::ipmi::responseSuccess(SysOEMCommands::SysEntityName, reply); 88fd0f1cf9SJaghathiswari Rankappagounder Natarajan } 89fd0f1cf9SJaghathiswari Rankappagounder Natarajan } // namespace ipmi 90fd0f1cf9SJaghathiswari Rankappagounder Natarajan } // namespace google 91