Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 1 | // |
| 2 | // client.cpp |
| 3 | // ~~~~~~~~~~ |
| 4 | // |
| 5 | // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
| 6 | // |
| 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 9 | // |
| 10 | #include <array> |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 11 | #include <iostream> |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 12 | #include <boost/asio.hpp> |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 13 | |
| 14 | using boost::asio::ip::udp; |
| 15 | |
| 16 | int main(int argc, char* argv[]) { |
| 17 | try { |
| 18 | boost::asio::io_service io_service; |
| 19 | |
| 20 | udp::resolver resolver(io_service); |
| 21 | udp::resolver::query query(udp::v4(), "10.243.48.31", "623"); |
| 22 | udp::endpoint receiver_endpoint = *resolver.resolve(query); |
| 23 | |
| 24 | udp::socket socket(io_service); |
| 25 | socket.open(udp::v4()); |
| 26 | |
| 27 | std::string username = "root"; |
| 28 | std::string password = "two"; |
| 29 | uint8_t privilege_level = 4; |
| 30 | uint8_t seq_number = 1; |
| 31 | uint8_t command = 0x38; // AUTH_CAP_CMD |
| 32 | // std::array<uint8_t> ChannelAuthCap{0x80 | (0x0f & channel), |
| 33 | // privilege_level&0x0f}; |
| 34 | |
| 35 | uint8_t srcaddr = 0x81; // 0xC8? |
| 36 | uint8_t dstaddr = 0x20; |
| 37 | |
| 38 | uint8_t net_function = 0x06; |
| 39 | uint8_t lun = 0; |
| 40 | |
| 41 | uint8_t netfn_lun = static_cast<uint8_t>((net_function << 2) + lun); |
| 42 | uint8_t channel_number = |
| 43 | 0x0E + 0x80; // E is defined in spec as this channel |
| 44 | // 0x80 is requesting IPMI 2.0 |
| 45 | uint8_t byte1 = static_cast<uint8_t>(channel_number | 0x80); |
Ed Tanous | 9140a67 | 2017-04-24 17:01:32 -0700 | [diff] [blame^] | 46 | std::array<uint8_t, 2> payload{byte1, privilege_level}; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 47 | |
| 48 | int payload_sum = 0; |
| 49 | for (auto element : payload) { |
| 50 | payload_sum += element; |
| 51 | } |
| 52 | |
| 53 | uint8_t chk1 = (1 + ((~(dstaddr + netfn_lun)) & 0xff)) & 0xff; |
| 54 | uint8_t chk2 = srcaddr + (seq_number << 2) + command + payload_sum; |
| 55 | chk2 = (1 + ((~chk2) & 0xff)) & 0xff; |
| 56 | |
| 57 | uint8_t ptype = 0; |
| 58 | uint8_t session_id = 0; |
| 59 | |
| 60 | uint8_t seq_number2 = 0; |
Ed Tanous | b4a7bfa | 2017-04-04 17:23:00 -0700 | [diff] [blame] | 61 | uint8_t seq_number_lun = (seq_number << 2) + lun; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 62 | |
| 63 | uint8_t seq2 = 0xff; //???? |
| 64 | uint8_t rmcp_class = 0x07; |
| 65 | |
| 66 | std::vector<uint8_t> send_buf = { |
| 67 | 0x06, 0x00, seq2, |
| 68 | rmcp_class, 0x06, ptype, |
| 69 | session_id, seq_number2, 0x00, |
| 70 | 0x00, 0x00, 0x00, |
| 71 | 0x00, 0x00, 0x09, |
| 72 | 0x00, dstaddr, netfn_lun, |
| 73 | chk1, srcaddr, seq_number_lun, |
| 74 | command, channel_number, privilege_level, |
| 75 | chk2}; |
| 76 | |
| 77 | for (auto character : send_buf) { |
| 78 | std::cout << std::hex << static_cast<unsigned>(character) << " "; |
| 79 | } |
| 80 | std::cout << std::endl; |
| 81 | socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint); |
| 82 | |
| 83 | boost::array<unsigned char, 32> recv_buf; |
| 84 | udp::endpoint sender_endpoint; |
| 85 | size_t len = |
| 86 | socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint); |
Ed Tanous | 7d3dba4 | 2017-04-05 13:04:39 -0700 | [diff] [blame] | 87 | std::cout << len; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 88 | for (auto character : recv_buf) { |
| 89 | std::cout << std::hex << static_cast<unsigned>(character) << " "; |
| 90 | } |
| 91 | |
| 92 | std::cout << std::endl; |
| 93 | } catch (std::exception& e) { |
| 94 | std::cerr << e.what() << std::endl; |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |