Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 1 | /* |
| 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 Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame^] | 19 | #include <fcntl.h> |
| 20 | |
| 21 | #include <sstream> |
| 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 25 | namespace host_tool |
| 26 | { |
| 27 | |
Patrick Venture | 2e12a43 | 2018-12-13 18:05:11 -0800 | [diff] [blame^] | 28 | bool 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 Venture | 035bbbb | 2018-12-12 14:59:52 -0800 | [diff] [blame] | 53 | std::vector<std::uint8_t> |
| 54 | IpmiHandler::sendPacket(const std::vector<std::uint8_t>& data) |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 55 | { |
Patrick Venture | 035bbbb | 2018-12-12 14:59:52 -0800 | [diff] [blame] | 56 | return {}; |
Patrick Venture | cf2d1b1 | 2018-12-11 18:22:36 -0800 | [diff] [blame] | 57 | } |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 58 | |
| 59 | } // namespace host_tool |