blob: e1e0529d9831b5ee2c7786c535e20c4d8a062e48 [file] [log] [blame]
Patrick Venturecf2d1b12018-12-11 18:22:36 -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 "ipmi_handler.hpp"
18
Patrick Venture2e12a432018-12-13 18:05:11 -080019#include <fcntl.h>
20
21#include <sstream>
22#include <string>
23#include <vector>
24
Patrick Venture9b534f02018-12-13 16:10:02 -080025namespace host_tool
26{
27
Patrick Venture2e12a432018-12-13 18:05:11 -080028bool IpmiHandler::open()
29{
30 const int device = 0;
31 const std::vector<std::string> formats = {"/dev/ipmi", "/dev/ipmi/",
32 "/dev/ipmidev/"};
33
34 for (const auto& format : formats)
35 {
36 std::ostringstream path;
37 path << format << device;
38
39 fd = sys->open(path.str().c_str(), O_RDWR);
40 if (fd < 0)
41 {
42 continue;
43 }
44 break;
45 }
46
47 /* Should we throw an exception here, since we exhausted these options?
48 * Maybe. :D
49 */
50 return !(fd < 0);
51}
52
Patrick Venture035bbbb2018-12-12 14:59:52 -080053std::vector<std::uint8_t>
54 IpmiHandler::sendPacket(const std::vector<std::uint8_t>& data)
Patrick Venturecf2d1b12018-12-11 18:22:36 -080055{
Patrick Venture035bbbb2018-12-12 14:59:52 -080056 return {};
Patrick Venturecf2d1b12018-12-11 18:22:36 -080057}
Patrick Venture9b534f02018-12-13 16:10:02 -080058
59} // namespace host_tool