blob: cf9f3d142f39fda462357322c6545ea58c8a9886 [file] [log] [blame]
Ed Tanous1ccd57c2017-03-21 13:15:58 -07001//
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>
11#include <boost/array.hpp>
12#include <boost/asio.hpp>
13#include <iostream>
14
15using boost::asio::ip::udp;
16
17int main(int argc, char* argv[]) {
18 try {
19 boost::asio::io_service io_service;
20
21 udp::resolver resolver(io_service);
22 udp::resolver::query query(udp::v4(), "10.243.48.31", "623");
23 udp::endpoint receiver_endpoint = *resolver.resolve(query);
24
25 udp::socket socket(io_service);
26 socket.open(udp::v4());
27
28 std::string username = "root";
29 std::string password = "two";
30 uint8_t privilege_level = 4;
31 uint8_t seq_number = 1;
32 uint8_t command = 0x38; // AUTH_CAP_CMD
33 // std::array<uint8_t> ChannelAuthCap{0x80 | (0x0f & channel),
34 // privilege_level&0x0f};
35
36 uint8_t srcaddr = 0x81; // 0xC8?
37 uint8_t dstaddr = 0x20;
38
39 uint8_t net_function = 0x06;
40 uint8_t lun = 0;
41
42 uint8_t netfn_lun = static_cast<uint8_t>((net_function << 2) + lun);
43 uint8_t channel_number =
44 0x0E + 0x80; // E is defined in spec as this channel
45 // 0x80 is requesting IPMI 2.0
46 uint8_t byte1 = static_cast<uint8_t>(channel_number | 0x80);
47 boost::array<uint8_t, 2> payload{byte1, privilege_level};
48
49 int payload_sum = 0;
50 for (auto element : payload) {
51 payload_sum += element;
52 }
53
54 uint8_t chk1 = (1 + ((~(dstaddr + netfn_lun)) & 0xff)) & 0xff;
55 uint8_t chk2 = srcaddr + (seq_number << 2) + command + payload_sum;
56 chk2 = (1 + ((~chk2) & 0xff)) & 0xff;
57
58 uint8_t ptype = 0;
59 uint8_t session_id = 0;
60
61 uint8_t seq_number2 = 0;
Ed Tanousb4a7bfa2017-04-04 17:23:00 -070062 uint8_t seq_number_lun = (seq_number << 2) + lun;
Ed Tanous1ccd57c2017-03-21 13:15:58 -070063
64 uint8_t seq2 = 0xff; //????
65 uint8_t rmcp_class = 0x07;
66
67 std::vector<uint8_t> send_buf = {
68 0x06, 0x00, seq2,
69 rmcp_class, 0x06, ptype,
70 session_id, seq_number2, 0x00,
71 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x09,
73 0x00, dstaddr, netfn_lun,
74 chk1, srcaddr, seq_number_lun,
75 command, channel_number, privilege_level,
76 chk2};
77
78 for (auto character : send_buf) {
79 std::cout << std::hex << static_cast<unsigned>(character) << " ";
80 }
81 std::cout << std::endl;
82 socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint);
83
84 boost::array<unsigned char, 32> recv_buf;
85 udp::endpoint sender_endpoint;
86 size_t len =
87 socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint);
Ed Tanous7d3dba42017-04-05 13:04:39 -070088 std::cout << len;
Ed Tanous1ccd57c2017-03-21 13:15:58 -070089 for (auto character : recv_buf) {
90 std::cout << std::hex << static_cast<unsigned>(character) << " ";
91 }
92
93 std::cout << std::endl;
94 } catch (std::exception& e) {
95 std::cerr << e.what() << std::endl;
96 }
97
98 return 0;
99}