blob: 9a62f811e56795afd7ebfd71171f8d90af31b6c0 [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 Venture07f85152019-03-15 21:36:56 -070019#include "errors.hpp"
20#include "handler.hpp"
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080021#include "main.hpp"
22
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;
54 uint8_t entityName[0];
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080055} __attribute__((packed));
56
Patrick Venture45fad1b2019-03-18 16:52:14 -070057ipmi_ret_t getEntityName(const uint8_t* reqBuf, uint8_t* replyBuf,
Patrick Venture07f85152019-03-15 21:36:56 -070058 size_t* dataLen, HandlerInterface* handler)
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080059{
60 struct GetEntityNameRequest request;
61
62 if ((*dataLen) < sizeof(request))
63 {
64 std::fprintf(stderr, "Invalid command length: %u\n",
65 static_cast<uint32_t>(*dataLen));
66 return IPMI_CC_REQ_DATA_LEN_INVALID;
67 }
68
69 std::memcpy(&request, &reqBuf[0], sizeof(request));
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080070 std::string entityName;
71 try
72 {
Patrick Venture07f85152019-03-15 21:36:56 -070073 entityName =
Patrick Venture45fad1b2019-03-18 16:52:14 -070074 handler->getEntityName(request.entityId, request.entityInstance);
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080075 }
Patrick Venture07f85152019-03-15 21:36:56 -070076 catch (const IpmiException& e)
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080077 {
Patrick Venture07f85152019-03-15 21:36:56 -070078 return e.getIpmiError();
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080079 }
80
81 int length = sizeof(struct GetEntityNameReply) + entityName.length();
82
83 // TODO (jaghu) : Add a call to get getChannelMaxTransferSize.
84 if (length > MAX_IPMI_BUFFER)
85 {
86 std::fprintf(stderr, "Response would overflow response buffer\n");
87 return IPMI_CC_INVALID;
88 }
89
90 auto reply = reinterpret_cast<struct GetEntityNameReply*>(&replyBuf[0]);
91 reply->subcommand = SysEntityName;
Patrick Venture45fad1b2019-03-18 16:52:14 -070092 reply->entityNameLength = entityName.length();
93 std::memcpy(reply->entityName, entityName.c_str(), entityName.length());
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080094
95 (*dataLen) = length;
96 return IPMI_CC_OK;
97}
98} // namespace ipmi
99} // namespace google