blob: 00668cd982c7ee96e6c5874da30dd73ad0d9ef48 [file] [log] [blame]
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -08001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "entity_name.hpp"
18
Patrick Venture0e9aae52020-08-13 13:07:09 -070019#include "commands.hpp"
Patrick Venture07f85152019-03-15 21:36:56 -070020#include "errors.hpp"
21#include "handler.hpp"
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080022
23#include <cstdint>
24#include <cstring>
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080025#include <string>
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080026#include <vector>
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080027
28namespace google
29{
30namespace ipmi
31{
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080032
33namespace
34{
35
36// TODO (jaghu) : Add a call to get getChannelMaxTransferSize.
37#ifndef MAX_IPMI_BUFFER
38#define MAX_IPMI_BUFFER 64
39#endif
40
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080041} // namespace
42
43struct GetEntityNameRequest
44{
45 uint8_t subcommand;
Patrick Venture45fad1b2019-03-18 16:52:14 -070046 uint8_t entityId;
47 uint8_t entityInstance;
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080048} __attribute__((packed));
49
50struct GetEntityNameReply
51{
52 uint8_t subcommand;
Patrick Venture45fad1b2019-03-18 16:52:14 -070053 uint8_t entityNameLength;
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080054} __attribute__((packed));
55
Patrick Venture45fad1b2019-03-18 16:52:14 -070056ipmi_ret_t getEntityName(const uint8_t* reqBuf, uint8_t* replyBuf,
Patrick Venture07f85152019-03-15 21:36:56 -070057 size_t* dataLen, HandlerInterface* handler)
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080058{
59 struct GetEntityNameRequest request;
60
61 if ((*dataLen) < sizeof(request))
62 {
63 std::fprintf(stderr, "Invalid command length: %u\n",
64 static_cast<uint32_t>(*dataLen));
65 return IPMI_CC_REQ_DATA_LEN_INVALID;
66 }
67
68 std::memcpy(&request, &reqBuf[0], sizeof(request));
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080069 std::string entityName;
70 try
71 {
Patrick Venture07f85152019-03-15 21:36:56 -070072 entityName =
Patrick Venture45fad1b2019-03-18 16:52:14 -070073 handler->getEntityName(request.entityId, request.entityInstance);
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080074 }
Patrick Venture07f85152019-03-15 21:36:56 -070075 catch (const IpmiException& e)
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080076 {
Patrick Venture07f85152019-03-15 21:36:56 -070077 return e.getIpmiError();
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080078 }
79
80 int length = sizeof(struct GetEntityNameReply) + entityName.length();
81
82 // TODO (jaghu) : Add a call to get getChannelMaxTransferSize.
83 if (length > MAX_IPMI_BUFFER)
84 {
85 std::fprintf(stderr, "Response would overflow response buffer\n");
86 return IPMI_CC_INVALID;
87 }
88
89 auto reply = reinterpret_cast<struct GetEntityNameReply*>(&replyBuf[0]);
90 reply->subcommand = SysEntityName;
Patrick Venture45fad1b2019-03-18 16:52:14 -070091 reply->entityNameLength = entityName.length();
William A. Kennington III5d789732021-06-24 03:39:31 -070092 std::memcpy(reply + 1, entityName.c_str(), entityName.length());
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080093
94 (*dataLen) = length;
95 return IPMI_CC_OK;
96}
97} // namespace ipmi
98} // namespace google